libclimate-ruby 0.17.0 → 0.17.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,299 +12,299 @@ require 'stringio'
12
12
 
13
13
  class Test_Climate_values_constraints < Test::Unit::TestCase
14
14
 
15
- def test_constrain_with_no_constraint
16
-
17
- stdout = StringIO.new
18
- stderr = StringIO.new
19
-
20
- climate = LibCLImate::Climate.new do |cl|
21
-
22
- cl.exit_on_missing = false
23
-
24
- cl.stdout = stdout
25
- cl.stderr = stderr
26
- end
27
-
28
- stdout.string = ''
29
- stderr.string = ''
30
- r = climate.run [ ]
31
- assert_equal 0, r.values.size
32
- assert_empty stdout.string
33
- assert_empty stderr.string
34
-
35
- stdout.string = ''
36
- stderr.string = ''
37
- r = climate.run [ 'value-1' ]
38
- assert_equal 1, r.values.size
39
- assert_empty stdout.string
40
- assert_empty stderr.string
41
- end
42
-
43
- def test_constrain_with_integer
44
-
45
- stdout = StringIO.new
46
- stderr = StringIO.new
47
-
48
- climate = LibCLImate::Climate.new do |cl|
49
-
50
- cl.exit_on_missing = false
51
-
52
- cl.stdout = stdout
53
- cl.stderr = stderr
54
-
55
- cl.constrain_values = 2
56
- end
57
-
58
- stdout.string = ''
59
- stderr.string = ''
60
- r = climate.run [ ]
61
- assert_equal 0, r.values.size
62
- assert_empty stdout.string
63
- assert_not_empty stderr.string
64
- assert_match /wrong number of values.*0 given.*2 required.*/, stderr.string
65
-
66
- stdout.string = ''
67
- stderr.string = ''
68
- r = climate.run [ 'value-1' ]
69
- assert_equal 1, r.values.size
70
- assert_empty stdout.string
71
- assert_not_empty stderr.string
72
- assert_match /wrong number of values.*1 given.*2 required.*/, stderr.string
73
-
74
- stdout.string = ''
75
- stderr.string = ''
76
- r = climate.run [ 'value-1', 'value-2' ]
77
- assert_equal 2, r.values.size
78
- assert_empty stdout.string
79
- assert_empty stderr.string
80
-
81
- stdout.string = ''
82
- stderr.string = ''
83
- r = climate.run [ 'value-1', 'value-2', 'value-3' ]
84
- assert_equal 3, r.values.size
85
- assert_empty stdout.string
86
- assert_not_empty stderr.string
87
- assert_match /wrong number of values.*3 given.*2 required.*/, stderr.string
88
- end
89
-
90
- def test_constrain_with_integer_and_names
91
-
92
- stdout = StringIO.new
93
- stderr = StringIO.new
94
-
95
- climate = LibCLImate::Climate.new(value_attributes: true) do |cl|
96
-
97
- cl.exit_on_missing = false
98
-
99
- cl.stdout = stdout
100
- cl.stderr = stderr
101
-
102
- cl.constrain_values = 2
103
- cl.value_names = [
104
-
105
- 'input-path',
106
- 'output-path',
107
- ]
108
- end
109
-
110
- stdout.string = ''
111
- stderr.string = ''
112
- r = climate.run [ ]
113
- assert_equal 0, r.values.size
114
- assert_empty stdout.string
115
- assert_not_empty stderr.string
116
- assert_match /input-path not specified.*#{climate.usage_help_suffix}/, stderr.string
117
-
118
- stdout.string = ''
119
- stderr.string = ''
120
- r = climate.run [ 'value-1' ]
121
- assert_equal 1, r.values.size
122
- assert_empty stdout.string
123
- assert_not_empty stderr.string
124
- assert_match /output-path not specified.*#{climate.usage_help_suffix}/, stderr.string
125
-
126
- stdout.string = ''
127
- stderr.string = ''
128
- r = climate.run [ 'value-1', 'value-2' ]
129
- assert_equal 2, r.values.size
130
- assert_empty stdout.string
131
- assert_empty stderr.string
132
- assert r.respond_to? :input_path
133
- assert r.respond_to? :output_path
134
-
135
- stdout.string = ''
136
- stderr.string = ''
137
- r = climate.run [ 'value-1', 'value-2', 'value-3' ]
138
- assert_equal 3, r.values.size
139
- assert_empty stdout.string
140
- assert_not_empty stderr.string
141
- assert_match /wrong number of values.*3 given.*2 required.*/, stderr.string
142
- end
143
-
144
- def test_constrain_with_integer_and_names_2
145
-
146
- stdout = StringIO.new
147
- stderr = StringIO.new
148
-
149
- climate = LibCLImate::Climate.new(value_attributes: true) do |cl|
150
-
151
- cl.exit_on_missing = false
152
-
153
- cl.stdout = stdout
154
- cl.stderr = stderr
155
-
156
- cl.constrain_values = 1..2
157
- cl.value_names = [
158
-
159
- 'input-path',
160
- 'output-path',
161
- ]
162
- end
163
-
164
- stdout.string = ''
165
- stderr.string = ''
166
- r = climate.run [ ]
167
- assert_equal 0, r.values.size
168
- assert_empty stdout.string
169
- assert_not_empty stderr.string
170
- assert_match /input-path not specified.*#{climate.usage_help_suffix}/, stderr.string
171
-
172
- stdout.string = ''
173
- stderr.string = ''
174
- r = climate.run [ 'value-1' ]
175
- assert_equal 1, r.values.size
176
- assert_empty stdout.string
177
- assert_empty stderr.string
178
- assert r.respond_to? :input_path
179
- assert r.respond_to? :output_path
180
- assert_equal 'value-1', r.input_path
181
- assert_nil r.output_path
182
-
183
- stdout.string = ''
184
- stderr.string = ''
185
- r = climate.run [ 'value-1', 'value-2' ]
186
- assert_equal 2, r.values.size
187
- assert_empty stdout.string
188
- assert_empty stderr.string
189
- assert r.respond_to? :input_path
190
- assert r.respond_to? :output_path
191
- assert_equal 'value-1', r.input_path
192
- assert_equal 'value-2', r.output_path
193
-
194
- stdout.string = ''
195
- stderr.string = ''
196
- r = climate.run [ 'value-1', 'value-2', 'value-3' ]
197
- assert_equal 3, r.values.size
198
- assert_empty stdout.string
199
- assert_not_empty stderr.string
200
- assert_match /wrong number of values.*3 given.*2 required.*/, stderr.string
201
- end
202
-
203
- def test_constrain_with_simple_range
204
-
205
- stdout = StringIO.new
206
- stderr = StringIO.new
207
-
208
- climate = LibCLImate::Climate.new do |cl|
209
-
210
- cl.exit_on_missing = false
211
-
212
- cl.stdout = stdout
213
- cl.stderr = stderr
214
-
215
- cl.constrain_values = 0..2
216
- end
217
-
218
- stdout.string = ''
219
- stderr.string = ''
220
- r = climate.run [ ]
221
- assert_equal 0, r.values.size
222
- assert_empty stdout.string
223
- assert_empty stderr.string
224
-
225
- stdout.string = ''
226
- stderr.string = ''
227
- r = climate.run [ 'value-1' ]
228
- assert_equal 1, r.values.size
229
- assert_empty stdout.string
230
- assert_empty stderr.string
231
-
232
- stdout.string = ''
233
- stderr.string = ''
234
- r = climate.run [ 'value-1', 'value-2' ]
235
- assert_equal 2, r.values.size
236
- assert_empty stdout.string
237
- assert_empty stderr.string
238
-
239
- stdout.string = ''
240
- stderr.string = ''
241
- r = climate.run [ 'value-1', 'value-2', 'value-3' ]
242
- assert_equal 3, r.values.size
243
- assert_empty stdout.string
244
- assert_not_empty stderr.string
245
-
246
- stdout.string = ''
247
- stderr.string = ''
248
- r = climate.run [ 'value-1', 'value-2', 'value-3', 'value-4' ]
249
- assert_equal 4, r.values.size
250
- assert_empty stdout.string
251
- assert_not_empty stderr.string
252
- end
253
-
254
- def test_constrain_with_simple_array
255
-
256
- stdout = StringIO.new
257
- stderr = StringIO.new
258
-
259
- climate = LibCLImate::Climate.new do |cl|
260
-
261
- cl.exit_on_missing = false
262
-
263
- cl.stdout = stdout
264
- cl.stderr = stderr
265
-
266
- cl.constrain_values = [ 1, 3 ]
267
-
268
- cl.program_name = "myprog"
269
- cl.usage_help_suffix = ''
270
- end
271
-
272
- stdout.string = ''
273
- stderr.string = ''
274
- r = climate.run [ ]
275
- assert_equal 0, r.values.size
276
- assert_empty stdout.string
277
- assert_not_empty stderr.string
278
-
279
- stdout.string = ''
280
- stderr.string = ''
281
- r = climate.run [ 'value-1' ]
282
- assert_equal 1, r.values.size
283
- assert_empty stdout.string
284
- assert_empty stderr.string
285
-
286
- stdout.string = ''
287
- stderr.string = ''
288
- r = climate.run [ 'value-1', 'value-2' ]
289
- assert_equal 2, r.values.size
290
- assert_empty stdout.string
291
- assert_not_empty stderr.string
292
-
293
- stdout.string = ''
294
- stderr.string = ''
295
- r = climate.run [ 'value-1', 'value-2', 'value-3' ]
296
- assert_equal 3, r.values.size
297
- assert_empty stdout.string
298
- assert_empty stderr.string
299
-
300
- stdout.string = ''
301
- stderr.string = ''
302
- assert_equal '', stderr.string
303
- r = climate.run [ 'value-1', 'value-2', 'value-3', 'value-4' ]
304
- assert_equal 4, r.values.size
305
- assert_empty stdout.string
306
- assert_not_empty stderr.string
307
- assert_equal "myprog: wrong number of values: 4 given, [1, 3] required\n", stderr.string
308
- end
15
+ def test_constrain_with_no_constraint
16
+
17
+ stdout = StringIO.new
18
+ stderr = StringIO.new
19
+
20
+ climate = LibCLImate::Climate.new do |cl|
21
+
22
+ cl.exit_on_missing = false
23
+
24
+ cl.stdout = stdout
25
+ cl.stderr = stderr
26
+ end
27
+
28
+ stdout.string = ''
29
+ stderr.string = ''
30
+ r = climate.run [ ]
31
+ assert_equal 0, r.values.size
32
+ assert_empty stdout.string
33
+ assert_empty stderr.string
34
+
35
+ stdout.string = ''
36
+ stderr.string = ''
37
+ r = climate.run [ 'value-1' ]
38
+ assert_equal 1, r.values.size
39
+ assert_empty stdout.string
40
+ assert_empty stderr.string
41
+ end
42
+
43
+ def test_constrain_with_integer
44
+
45
+ stdout = StringIO.new
46
+ stderr = StringIO.new
47
+
48
+ climate = LibCLImate::Climate.new do |cl|
49
+
50
+ cl.exit_on_missing = false
51
+
52
+ cl.stdout = stdout
53
+ cl.stderr = stderr
54
+
55
+ cl.constrain_values = 2
56
+ end
57
+
58
+ stdout.string = ''
59
+ stderr.string = ''
60
+ r = climate.run [ ]
61
+ assert_equal 0, r.values.size
62
+ assert_empty stdout.string
63
+ assert_not_empty stderr.string
64
+ assert_match /wrong number of values.*0 given.*2 required.*/, stderr.string
65
+
66
+ stdout.string = ''
67
+ stderr.string = ''
68
+ r = climate.run [ 'value-1' ]
69
+ assert_equal 1, r.values.size
70
+ assert_empty stdout.string
71
+ assert_not_empty stderr.string
72
+ assert_match /wrong number of values.*1 given.*2 required.*/, stderr.string
73
+
74
+ stdout.string = ''
75
+ stderr.string = ''
76
+ r = climate.run [ 'value-1', 'value-2' ]
77
+ assert_equal 2, r.values.size
78
+ assert_empty stdout.string
79
+ assert_empty stderr.string
80
+
81
+ stdout.string = ''
82
+ stderr.string = ''
83
+ r = climate.run [ 'value-1', 'value-2', 'value-3' ]
84
+ assert_equal 3, r.values.size
85
+ assert_empty stdout.string
86
+ assert_not_empty stderr.string
87
+ assert_match /wrong number of values.*3 given.*2 required.*/, stderr.string
88
+ end
89
+
90
+ def test_constrain_with_integer_and_names
91
+
92
+ stdout = StringIO.new
93
+ stderr = StringIO.new
94
+
95
+ climate = LibCLImate::Climate.new(value_attributes: true) do |cl|
96
+
97
+ cl.exit_on_missing = false
98
+
99
+ cl.stdout = stdout
100
+ cl.stderr = stderr
101
+
102
+ cl.constrain_values = 2
103
+ cl.value_names = [
104
+
105
+ 'input-path',
106
+ 'output-path',
107
+ ]
108
+ end
109
+
110
+ stdout.string = ''
111
+ stderr.string = ''
112
+ r = climate.run [ ]
113
+ assert_equal 0, r.values.size
114
+ assert_empty stdout.string
115
+ assert_not_empty stderr.string
116
+ assert_match /input-path not specified.*#{climate.usage_help_suffix}/, stderr.string
117
+
118
+ stdout.string = ''
119
+ stderr.string = ''
120
+ r = climate.run [ 'value-1' ]
121
+ assert_equal 1, r.values.size
122
+ assert_empty stdout.string
123
+ assert_not_empty stderr.string
124
+ assert_match /output-path not specified.*#{climate.usage_help_suffix}/, stderr.string
125
+
126
+ stdout.string = ''
127
+ stderr.string = ''
128
+ r = climate.run [ 'value-1', 'value-2' ]
129
+ assert_equal 2, r.values.size
130
+ assert_empty stdout.string
131
+ assert_empty stderr.string
132
+ assert r.respond_to? :input_path
133
+ assert r.respond_to? :output_path
134
+
135
+ stdout.string = ''
136
+ stderr.string = ''
137
+ r = climate.run [ 'value-1', 'value-2', 'value-3' ]
138
+ assert_equal 3, r.values.size
139
+ assert_empty stdout.string
140
+ assert_not_empty stderr.string
141
+ assert_match /wrong number of values.*3 given.*2 required.*/, stderr.string
142
+ end
143
+
144
+ def test_constrain_with_integer_and_names_2
145
+
146
+ stdout = StringIO.new
147
+ stderr = StringIO.new
148
+
149
+ climate = LibCLImate::Climate.new(value_attributes: true) do |cl|
150
+
151
+ cl.exit_on_missing = false
152
+
153
+ cl.stdout = stdout
154
+ cl.stderr = stderr
155
+
156
+ cl.constrain_values = 1..2
157
+ cl.value_names = [
158
+
159
+ 'input-path',
160
+ 'output-path',
161
+ ]
162
+ end
163
+
164
+ stdout.string = ''
165
+ stderr.string = ''
166
+ r = climate.run [ ]
167
+ assert_equal 0, r.values.size
168
+ assert_empty stdout.string
169
+ assert_not_empty stderr.string
170
+ assert_match /input-path not specified.*#{climate.usage_help_suffix}/, stderr.string
171
+
172
+ stdout.string = ''
173
+ stderr.string = ''
174
+ r = climate.run [ 'value-1' ]
175
+ assert_equal 1, r.values.size
176
+ assert_empty stdout.string
177
+ assert_empty stderr.string
178
+ assert r.respond_to? :input_path
179
+ assert r.respond_to? :output_path
180
+ assert_equal 'value-1', r.input_path
181
+ assert_nil r.output_path
182
+
183
+ stdout.string = ''
184
+ stderr.string = ''
185
+ r = climate.run [ 'value-1', 'value-2' ]
186
+ assert_equal 2, r.values.size
187
+ assert_empty stdout.string
188
+ assert_empty stderr.string
189
+ assert r.respond_to? :input_path
190
+ assert r.respond_to? :output_path
191
+ assert_equal 'value-1', r.input_path
192
+ assert_equal 'value-2', r.output_path
193
+
194
+ stdout.string = ''
195
+ stderr.string = ''
196
+ r = climate.run [ 'value-1', 'value-2', 'value-3' ]
197
+ assert_equal 3, r.values.size
198
+ assert_empty stdout.string
199
+ assert_not_empty stderr.string
200
+ assert_match /wrong number of values.*3 given.*2 required.*/, stderr.string
201
+ end
202
+
203
+ def test_constrain_with_simple_range
204
+
205
+ stdout = StringIO.new
206
+ stderr = StringIO.new
207
+
208
+ climate = LibCLImate::Climate.new do |cl|
209
+
210
+ cl.exit_on_missing = false
211
+
212
+ cl.stdout = stdout
213
+ cl.stderr = stderr
214
+
215
+ cl.constrain_values = 0..2
216
+ end
217
+
218
+ stdout.string = ''
219
+ stderr.string = ''
220
+ r = climate.run [ ]
221
+ assert_equal 0, r.values.size
222
+ assert_empty stdout.string
223
+ assert_empty stderr.string
224
+
225
+ stdout.string = ''
226
+ stderr.string = ''
227
+ r = climate.run [ 'value-1' ]
228
+ assert_equal 1, r.values.size
229
+ assert_empty stdout.string
230
+ assert_empty stderr.string
231
+
232
+ stdout.string = ''
233
+ stderr.string = ''
234
+ r = climate.run [ 'value-1', 'value-2' ]
235
+ assert_equal 2, r.values.size
236
+ assert_empty stdout.string
237
+ assert_empty stderr.string
238
+
239
+ stdout.string = ''
240
+ stderr.string = ''
241
+ r = climate.run [ 'value-1', 'value-2', 'value-3' ]
242
+ assert_equal 3, r.values.size
243
+ assert_empty stdout.string
244
+ assert_not_empty stderr.string
245
+
246
+ stdout.string = ''
247
+ stderr.string = ''
248
+ r = climate.run [ 'value-1', 'value-2', 'value-3', 'value-4' ]
249
+ assert_equal 4, r.values.size
250
+ assert_empty stdout.string
251
+ assert_not_empty stderr.string
252
+ end
253
+
254
+ def test_constrain_with_simple_array
255
+
256
+ stdout = StringIO.new
257
+ stderr = StringIO.new
258
+
259
+ climate = LibCLImate::Climate.new do |cl|
260
+
261
+ cl.exit_on_missing = false
262
+
263
+ cl.stdout = stdout
264
+ cl.stderr = stderr
265
+
266
+ cl.constrain_values = [ 1, 3 ]
267
+
268
+ cl.program_name = "myprog"
269
+ cl.usage_help_suffix = ''
270
+ end
271
+
272
+ stdout.string = ''
273
+ stderr.string = ''
274
+ r = climate.run [ ]
275
+ assert_equal 0, r.values.size
276
+ assert_empty stdout.string
277
+ assert_not_empty stderr.string
278
+
279
+ stdout.string = ''
280
+ stderr.string = ''
281
+ r = climate.run [ 'value-1' ]
282
+ assert_equal 1, r.values.size
283
+ assert_empty stdout.string
284
+ assert_empty stderr.string
285
+
286
+ stdout.string = ''
287
+ stderr.string = ''
288
+ r = climate.run [ 'value-1', 'value-2' ]
289
+ assert_equal 2, r.values.size
290
+ assert_empty stdout.string
291
+ assert_not_empty stderr.string
292
+
293
+ stdout.string = ''
294
+ stderr.string = ''
295
+ r = climate.run [ 'value-1', 'value-2', 'value-3' ]
296
+ assert_equal 3, r.values.size
297
+ assert_empty stdout.string
298
+ assert_empty stderr.string
299
+
300
+ stdout.string = ''
301
+ stderr.string = ''
302
+ assert_equal '', stderr.string
303
+ r = climate.run [ 'value-1', 'value-2', 'value-3', 'value-4' ]
304
+ assert_equal 4, r.values.size
305
+ assert_empty stdout.string
306
+ assert_not_empty stderr.string
307
+ assert_equal "myprog: wrong number of values: 4 given, [1, 3] required\n", stderr.string
308
+ end
309
309
  end
310
310
 
@@ -15,37 +15,37 @@ require 'stringio'
15
15
 
16
16
  class Test_Climate_with_blocks < Test::Unit::TestCase
17
17
 
18
- def test_flag_with_block
18
+ def test_flag_with_block
19
19
 
20
- is_verbose = false
20
+ is_verbose = false
21
21
 
22
- climate = LibCLImate::Climate.new do |cl|
22
+ climate = LibCLImate::Climate.new do |cl|
23
23
 
24
- cl.add_flag('--verbose') { is_verbose = true }
25
- end
24
+ cl.add_flag('--verbose') { is_verbose = true }
25
+ end
26
26
 
27
- argv = %w{ --verbose }
27
+ argv = %w{ --verbose }
28
28
 
29
- climate.run argv
29
+ climate.run argv
30
30
 
31
- assert is_verbose, "block associated with flag '--verbose' was not executed"
32
- end
31
+ assert is_verbose, "block associated with flag '--verbose' was not executed"
32
+ end
33
33
 
34
- def test_option_with_block
34
+ def test_option_with_block
35
35
 
36
- flavour = nil
36
+ flavour = nil
37
37
 
38
- climate = LibCLImate::Climate.new do |cl|
38
+ climate = LibCLImate::Climate.new do |cl|
39
39
 
40
- cl.add_option('--flavour') { |o| flavour = o.value }
41
- end
40
+ cl.add_option('--flavour') { |o| flavour = o.value }
41
+ end
42
42
 
43
- argv = %w{ --flavour=blueberry }
43
+ argv = %w{ --flavour=blueberry }
44
44
 
45
- climate.run argv
45
+ climate.run argv
46
46
 
47
- assert_equal 'blueberry', flavour
48
- end
47
+ assert_equal 'blueberry', flavour
48
+ end
49
49
  end
50
50
 
51
51
  # ############################## end of file ############################# #