libclimate-ruby 0.17.0 → 0.17.0.2

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