rubycom 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +162 -146
- data/Rakefile +12 -12
- data/lib/rubycom.rb +156 -226
- data/lib/rubycom/arg_parse.rb +252 -0
- data/lib/rubycom/command_interface.rb +97 -0
- data/lib/rubycom/completions.rb +62 -0
- data/lib/rubycom/error_handler.rb +15 -0
- data/lib/rubycom/executor.rb +23 -0
- data/lib/rubycom/helpers.rb +98 -0
- data/lib/rubycom/output_handler.rb +15 -0
- data/lib/rubycom/parameter_extract.rb +262 -0
- data/lib/rubycom/singleton_commands.rb +78 -0
- data/lib/rubycom/sources.rb +99 -0
- data/lib/rubycom/version.rb +1 -1
- data/lib/rubycom/yard_doc.rb +146 -0
- data/rubycom.gemspec +14 -16
- data/test/rubycom/arg_parse_test.rb +247 -0
- data/test/rubycom/command_interface_test.rb +293 -0
- data/test/rubycom/completions_test.rb +94 -0
- data/test/rubycom/error_handler_test.rb +72 -0
- data/test/rubycom/executor_test.rb +64 -0
- data/test/rubycom/helpers_test.rb +467 -0
- data/test/rubycom/output_handler_test.rb +76 -0
- data/test/rubycom/parameter_extract_test.rb +141 -0
- data/test/rubycom/rubycom_test.rb +290 -548
- data/test/rubycom/singleton_commands_test.rb +122 -0
- data/test/rubycom/sources_test.rb +59 -0
- data/test/rubycom/util_test_bin.rb +8 -0
- data/test/rubycom/util_test_composite.rb +23 -20
- data/test/rubycom/util_test_module.rb +142 -112
- data/test/rubycom/util_test_no_singleton.rb +2 -2
- data/test/rubycom/util_test_sub_module.rb +13 -0
- data/test/rubycom/yard_doc_test.rb +165 -0
- metadata +61 -24
- data/lib/rubycom/arguments.rb +0 -133
- data/lib/rubycom/commands.rb +0 -63
- data/lib/rubycom/documentation.rb +0 -212
- data/test/rubycom/arguments_test.rb +0 -289
- data/test/rubycom/commands_test.rb +0 -51
- data/test/rubycom/documentation_test.rb +0 -186
- data/test/rubycom/util_test_job.yaml +0 -21
- data/test/rubycom/utility_tester.rb +0 -17
@@ -0,0 +1,76 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../../lib/rubycom/output_handler.rb"
|
2
|
+
|
3
|
+
require "#{File.dirname(__FILE__)}/util_test_module.rb"
|
4
|
+
require "#{File.dirname(__FILE__)}/util_test_composite.rb"
|
5
|
+
require "#{File.dirname(__FILE__)}/util_test_no_singleton.rb"
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class OutputHandlerTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def capture_out(&block)
|
12
|
+
original_stdout = $stdout
|
13
|
+
$stdout = fake = StringIO.new
|
14
|
+
begin
|
15
|
+
yield
|
16
|
+
ensure
|
17
|
+
$stdout = original_stdout
|
18
|
+
end
|
19
|
+
fake.string
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_process_output
|
23
|
+
test_result = 'test command output'
|
24
|
+
|
25
|
+
result = capture_out { Rubycom::OutputHandler.process_output(test_result) }
|
26
|
+
|
27
|
+
expected = "test command output\n"
|
28
|
+
assert_equal(expected, result)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_process_output_empty
|
32
|
+
test_result = ''
|
33
|
+
|
34
|
+
result = capture_out { Rubycom::OutputHandler.process_output(test_result) }
|
35
|
+
|
36
|
+
expected = "\n"
|
37
|
+
assert_equal(expected, result)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_process_output_nil
|
41
|
+
test_result = nil
|
42
|
+
|
43
|
+
result = capture_out { Rubycom::OutputHandler.process_output(test_result) }
|
44
|
+
|
45
|
+
expected = "\n"
|
46
|
+
assert_equal(expected, result)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_process_output_object
|
50
|
+
test_result = Object.new
|
51
|
+
|
52
|
+
result = capture_out { Rubycom::OutputHandler.process_output(test_result) }
|
53
|
+
|
54
|
+
expected = "--- !ruby/object {}\n"
|
55
|
+
assert_equal(expected, result)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_process_output_array
|
59
|
+
test_result = []
|
60
|
+
|
61
|
+
result = capture_out { Rubycom::OutputHandler.process_output(test_result) }
|
62
|
+
|
63
|
+
expected = "--- []\n"
|
64
|
+
assert_equal(expected, result)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_process_output_hash
|
68
|
+
test_result = {test: 'val'}
|
69
|
+
|
70
|
+
result = capture_out { Rubycom::OutputHandler.process_output(test_result) }
|
71
|
+
|
72
|
+
expected = "---\n:test: val\n"
|
73
|
+
assert_equal(expected, result)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../../lib/rubycom/parameter_extract.rb"
|
2
|
+
|
3
|
+
require "#{File.dirname(__FILE__)}/util_test_module.rb"
|
4
|
+
require "#{File.dirname(__FILE__)}/util_test_composite.rb"
|
5
|
+
require "#{File.dirname(__FILE__)}/util_test_no_singleton.rb"
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class ParameterExtractTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_extract_parameters
|
12
|
+
test_command = UtilTestModule.public_method(:test_command_with_return)
|
13
|
+
test_command_doc = {
|
14
|
+
:parameters => [
|
15
|
+
{:default => nil, :doc => "a test argument", :doc_type => "String", :param_name => "test_arg", :type => :req},
|
16
|
+
{:default => 1, :doc => "an optional test argument which happens to be an Integer", :doc_type => "Integer", :param_name => "test_option_int", :type => :opt}
|
17
|
+
]
|
18
|
+
}
|
19
|
+
test_command_line = {:args => ["UtilTestModule", "test_command_with_return", "testing_argument"], :opts => {"test_option_int" => 10}}
|
20
|
+
result = Rubycom::ParameterExtract.extract_parameters(test_command, test_command_line, test_command_doc)
|
21
|
+
test_command.parameters.each{|_, sym|
|
22
|
+
assert(result.has_key?(sym), 'extracted parameters should include values for each method parameter')
|
23
|
+
}
|
24
|
+
assert_equal('testing_argument', result[:test_arg])
|
25
|
+
assert_equal(10, result[:test_option_int])
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_extract_parameters_help_opt
|
29
|
+
test_command = UtilTestModule.public_method(:test_command_with_return)
|
30
|
+
test_command_doc = {
|
31
|
+
:parameters => [
|
32
|
+
{:default => nil, :doc => "a test argument", :doc_type => "String", :param_name => "test_arg", :type => :req},
|
33
|
+
{:default => 1, :doc => "an optional test argument which happens to be an Integer", :doc_type => "Integer", :param_name => "test_option_int", :type => :opt}
|
34
|
+
]
|
35
|
+
}
|
36
|
+
test_command_line = {:args => ["UtilTestModule", "test_command_with_return", "testing_argument"], :opts => {"test_option_int" => 10, "help" => true}}
|
37
|
+
result = nil
|
38
|
+
assert_raise(Rubycom::ParameterExtractError) { result = Rubycom::ParameterExtract.extract_parameters(test_command, test_command_line, test_command_doc) }
|
39
|
+
expected = nil
|
40
|
+
assert_equal(expected, result)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_extract_parameters_help_flag
|
44
|
+
test_command = UtilTestModule.public_method(:test_command_with_return)
|
45
|
+
test_command_doc = {
|
46
|
+
:parameters => [
|
47
|
+
{:default => nil, :doc => "a test argument", :doc_type => "String", :param_name => "test_arg", :type => :req},
|
48
|
+
{:default => 1, :doc => "an optional test argument which happens to be an Integer", :doc_type => "Integer", :param_name => "test_option_int", :type => :opt}
|
49
|
+
]
|
50
|
+
}
|
51
|
+
test_command_line = {:args => ["UtilTestModule", "test_command_with_return", "testing_argument"], :opts => {"test_option_int" => 10}, :flags => {"h" => true}}
|
52
|
+
result = nil
|
53
|
+
assert_raise(Rubycom::ParameterExtractError) { result = Rubycom::ParameterExtract.extract_parameters(test_command, test_command_line, test_command_doc) }
|
54
|
+
expected = nil
|
55
|
+
assert_equal(expected, result)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_extract_parameters_unknown_opts
|
59
|
+
test_command = UtilTestModule.public_method(:test_command_with_return)
|
60
|
+
test_command_doc = {
|
61
|
+
:parameters => [
|
62
|
+
{:default => nil, :doc => "a test argument", :doc_type => "String", :param_name => "test_arg", :type => :req},
|
63
|
+
{:default => 1, :doc => "an optional test argument which happens to be an Integer", :doc_type => "Integer", :param_name => "test_option_int", :type => :opt}
|
64
|
+
]
|
65
|
+
}
|
66
|
+
test_command_line = {:args => ["UtilTestModule", "test_command_with_return", "testing_argument"], :opts => {"test_option_int" => 10, "extraneous_opt" => true}}
|
67
|
+
result = Rubycom::ParameterExtract.extract_parameters(test_command, test_command_line, test_command_doc)
|
68
|
+
test_command.parameters.each{|_, sym|
|
69
|
+
assert(result.has_key?(sym), 'extracted parameters should include values for each method parameter')
|
70
|
+
}
|
71
|
+
assert_equal('testing_argument', result[:test_arg])
|
72
|
+
assert_equal(10, result[:test_option_int])
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_extract_parameters_unknown_flags
|
76
|
+
test_command = UtilTestModule.public_method(:test_command_with_return)
|
77
|
+
test_command_doc = {
|
78
|
+
:parameters => [
|
79
|
+
{:default => nil, :doc => "a test argument", :doc_type => "String", :param_name => "test_arg", :type => :req},
|
80
|
+
{:default => 1, :doc => "an optional test argument which happens to be an Integer", :doc_type => "Integer", :param_name => "test_option_int", :type => :opt}
|
81
|
+
]
|
82
|
+
}
|
83
|
+
test_command_line = {:args => ["UtilTestModule", "test_command_with_return", "testing_argument"], :opts => {"test_option_int" => 10}, :flags => {"z" => true}}
|
84
|
+
result = Rubycom::ParameterExtract.extract_parameters(test_command, test_command_line, test_command_doc)
|
85
|
+
test_command.parameters.each{|_, sym|
|
86
|
+
assert(result.has_key?(sym), 'extracted parameters should include values for each method parameter')
|
87
|
+
}
|
88
|
+
assert_equal('testing_argument', result[:test_arg])
|
89
|
+
assert_equal(10, result[:test_option_int])
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_extract_parameters_default
|
93
|
+
test_command = UtilTestModule.public_method(:test_command_with_return)
|
94
|
+
test_command_doc = {
|
95
|
+
:parameters => [
|
96
|
+
{:default => nil, :doc => "a test argument", :doc_type => "String", :param_name => "test_arg", :type => :req},
|
97
|
+
{:default => 1, :doc => "an optional test argument which happens to be an Integer", :doc_type => "Integer", :param_name => "test_option_int", :type => :opt}
|
98
|
+
]
|
99
|
+
}
|
100
|
+
test_command_line = {:args => ["UtilTestModule", "test_command_with_return", "testing_argument"]}
|
101
|
+
result = Rubycom::ParameterExtract.extract_parameters(test_command, test_command_line, test_command_doc)
|
102
|
+
test_command.parameters.each{|_, sym|
|
103
|
+
assert(result.has_key?(sym), 'extracted parameters should include values for each method parameter')
|
104
|
+
}
|
105
|
+
assert_equal('testing_argument', result[:test_arg])
|
106
|
+
assert_equal(1, result[:test_option_int])
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_extract_parameters_arr
|
110
|
+
test_command = UtilTestModule.public_method(:test_command_options_arr)
|
111
|
+
test_command_doc = {
|
112
|
+
:parameters => [
|
113
|
+
{:default => 'test_option_default', :doc => "an optional test argument", :doc_type => "String", :param_name => "test_option", :type => :opt},
|
114
|
+
{:default => nil, :doc => "an optional array of arguments", :doc_type => "Array", :param_name => "test_options", :type => :rest}
|
115
|
+
]
|
116
|
+
}
|
117
|
+
test_command_line = {:args => ["UtilTestModule", "test_command_options_arr", 'test_option1', 'test_option2', 1.0, false]}
|
118
|
+
result = Rubycom::ParameterExtract.extract_parameters(test_command, test_command_line, test_command_doc)
|
119
|
+
test_command.parameters.each{|_, sym|
|
120
|
+
assert(result.has_key?(sym), 'extracted parameters should include values for each method parameter')
|
121
|
+
}
|
122
|
+
assert_equal('test_option1', result[:test_option])
|
123
|
+
assert_equal(['test_option2', 1.0, false], result[:test_options])
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_extract_parameters_missing_required
|
127
|
+
test_command = UtilTestModule.public_method(:test_command_with_return)
|
128
|
+
test_command_doc = {
|
129
|
+
:parameters => [
|
130
|
+
{:default => nil, :doc => "a test argument", :doc_type => "String", :param_name => "test_arg", :type => :req},
|
131
|
+
{:default => 1, :doc => "an optional test argument which happens to be an Integer", :doc_type => "Integer", :param_name => "test_option_int", :type => :opt}
|
132
|
+
]
|
133
|
+
}
|
134
|
+
test_command_line = {:args => ["UtilTestModule", "test_command_with_return"], :opts => {"test_option_int" => 10}}
|
135
|
+
result = nil
|
136
|
+
assert_raise(Rubycom::ParameterExtractError) { result = Rubycom::ParameterExtract.extract_parameters(test_command, test_command_line, test_command_doc) }
|
137
|
+
expected = nil
|
138
|
+
assert_equal(expected, result)
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
@@ -1,548 +1,290 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}/../../lib/rubycom.rb"
|
2
|
-
|
3
|
-
require "#{File.dirname(__FILE__)}/util_test_module.rb"
|
4
|
-
require "#{File.dirname(__FILE__)}/util_test_composite.rb"
|
5
|
-
require "#{File.dirname(__FILE__)}/util_test_no_singleton.rb"
|
6
|
-
|
7
|
-
require 'test/unit'
|
8
|
-
require 'time'
|
9
|
-
|
10
|
-
class RubycomTest < Test::Unit::TestCase
|
11
|
-
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
expected_out = "
|
102
|
-
assert_equal(
|
103
|
-
assert_equal(expected_out
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
args =
|
122
|
-
result =
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
end
|
157
|
-
|
158
|
-
def
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
expected
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
expected
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
expected =
|
250
|
-
|
251
|
-
assert_equal(expected, result)
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
expected
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
def test_run_multi_args
|
293
|
-
mod = "util_test_composite.rb"
|
294
|
-
sub_mod = "UtilTestModule"
|
295
|
-
command = "test_command_with_args"
|
296
|
-
args = "a b"
|
297
|
-
expected = 'test_arg=a,another_test_arg=b'+"\n\n"
|
298
|
-
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{sub_mod} #{command} #{args})
|
299
|
-
assert_equal(expected, result)
|
300
|
-
end
|
301
|
-
|
302
|
-
def test_run_missing_required_arg
|
303
|
-
tst_out = ''
|
304
|
-
|
305
|
-
def tst_out.puts(data)
|
306
|
-
self << data.to_s << "\n"
|
307
|
-
nil
|
308
|
-
end
|
309
|
-
|
310
|
-
def tst_out.write(data)
|
311
|
-
self << data
|
312
|
-
end
|
313
|
-
|
314
|
-
o_stdout, $stdout = $stdout, tst_out
|
315
|
-
o_stderr, $stderr = $stderr, tst_out
|
316
|
-
|
317
|
-
base = UtilTestModule
|
318
|
-
args = ["test_command_with_return", "-test_option_int=2"]
|
319
|
-
result = Rubycom.run(base, args)
|
320
|
-
|
321
|
-
expected = nil
|
322
|
-
expected_out = "No argument available for test_arg\n"
|
323
|
-
|
324
|
-
assert_equal(expected, result)
|
325
|
-
assert_equal(expected_out, tst_out.lines.first)
|
326
|
-
Rubycom::Documentation.get_command_usage(base,args[0],args[1..-1]).each_line{|expected_line|
|
327
|
-
assert_equal(true, tst_out.lines.include?(expected_line))
|
328
|
-
}
|
329
|
-
ensure
|
330
|
-
$stdout = o_stdout
|
331
|
-
$stderr = o_stderr
|
332
|
-
end
|
333
|
-
|
334
|
-
def test_run_composite
|
335
|
-
tst_out = ''
|
336
|
-
|
337
|
-
def tst_out.write(data)
|
338
|
-
self << data
|
339
|
-
end
|
340
|
-
|
341
|
-
o_stdout, $stdout = $stdout, tst_out
|
342
|
-
o_stderr, $stderr = $stderr, tst_out
|
343
|
-
|
344
|
-
base = UtilTestComposite
|
345
|
-
args = ["test_composite_command", "Hello Composite"]
|
346
|
-
result = Rubycom.run(base, args)
|
347
|
-
|
348
|
-
expected = "Hello Composite"
|
349
|
-
expected_out = "Hello Composite"
|
350
|
-
assert_equal(expected, result)
|
351
|
-
assert_equal(expected_out, tst_out.split(/\n|\r|\r\n/).first)
|
352
|
-
ensure
|
353
|
-
$stdout = o_stdout
|
354
|
-
$stderr = o_stderr
|
355
|
-
end
|
356
|
-
|
357
|
-
def test_full_run_mixed_args
|
358
|
-
mod = "util_test_module.rb"
|
359
|
-
command = "test_command_mixed_options"
|
360
|
-
args = "testing_arg \"[test1, test2]\" -test_opt='testing_option' \"{a: 'test_hsh_arg'}\" -test_bool=true some other args"
|
361
|
-
expected = 'test_arg=testing_arg test_arr=["test1", "test2"] test_opt=testing_option test_hsh={"a"=>"test_hsh_arg"} test_bool=true test_rest=["some", "other", "args"]'+"\n"
|
362
|
-
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
363
|
-
assert_equal(expected, result)
|
364
|
-
end
|
365
|
-
|
366
|
-
def test_full_run_args_for_opts
|
367
|
-
mod = "util_test_module.rb"
|
368
|
-
command = "test_command_mixed_options"
|
369
|
-
args = "testing_arg test2 testing_option test_hsh_arg true some other args"
|
370
|
-
expected = "test_arg=testing_arg test_arr=test2 test_opt=testing_option test_hsh=test_hsh_arg test_bool=true test_rest=[\"some\", \"other\", \"args\"]"+"\n"
|
371
|
-
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
372
|
-
assert_equal(expected, result)
|
373
|
-
end
|
374
|
-
|
375
|
-
def test_full_run_mixed_args_solid_arr
|
376
|
-
mod = "util_test_module.rb"
|
377
|
-
command = "test_command_mixed_options"
|
378
|
-
args = "testing_arg [test1,test2] -test_opt='testing_option' \"{a: 'test_hsh_arg'}\" some other args"
|
379
|
-
expected = 'test_arg=testing_arg test_arr=["test1", "test2"] test_opt=testing_option test_hsh={"a"=>"test_hsh_arg"} test_bool=some test_rest=["other", "args"]'+"\n"
|
380
|
-
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
381
|
-
assert_equal(expected, result)
|
382
|
-
end
|
383
|
-
|
384
|
-
def test_full_run_mixed_args_quoted_solid_arr
|
385
|
-
mod = "util_test_module.rb"
|
386
|
-
command = "test_command_mixed_options"
|
387
|
-
args = 'testing_arg "[test1,test2]" -test_opt="testing_option" "{a: "test_hsh_arg"}" -test_bool=false some other args'
|
388
|
-
expected = 'test_arg=testing_arg test_arr=["test1", "test2"] test_opt=testing_option test_hsh={"a"=>"test_hsh_arg"} test_bool=false test_rest=["some", "other", "args"]'+"\n"
|
389
|
-
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
390
|
-
assert_equal(expected, result)
|
391
|
-
end
|
392
|
-
|
393
|
-
def test_full_run_mixed_args_odd_sp
|
394
|
-
mod = "util_test_module.rb"
|
395
|
-
command = "test_command_mixed_options"
|
396
|
-
args = 'testing_arg "[ test1 , test2 ]" -test_opt="testing_option" "{ a: "test_hsh_arg" }" -test_bool=false some other args'
|
397
|
-
expected = 'test_arg=testing_arg test_arr=["test1", "test2"] test_opt=testing_option test_hsh={"a"=>"test_hsh_arg"} test_bool=false test_rest=["some", "other", "args"]'+"\n"
|
398
|
-
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
399
|
-
assert_equal(expected, result)
|
400
|
-
end
|
401
|
-
|
402
|
-
def test_full_run_mixed_args_hash_rocket
|
403
|
-
mod = "util_test_module.rb"
|
404
|
-
command = "test_command_mixed_options"
|
405
|
-
args = 'testing_arg "[ test1 , test2 ]" -test_opt="testing_option" "{ :a => "test_hsh_arg" }" false some other args'
|
406
|
-
expected = 'test_arg=testing_arg test_arr=["test1", "test2"] test_opt=testing_option test_hsh={ :a => test_hsh_arg } test_bool=false test_rest=["some", "other", "args"]'+"\n"
|
407
|
-
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
408
|
-
assert_equal(expected, result)
|
409
|
-
end
|
410
|
-
|
411
|
-
def test_full_run_mixed_args_no_rest
|
412
|
-
mod = "util_test_module.rb"
|
413
|
-
command = "test_command_mixed_options"
|
414
|
-
args = "testing_arg \"[test1, test2]\" -test_opt='testing_option' \"{a: 'test_hsh_arg'}\""
|
415
|
-
expected = 'test_arg=testing_arg test_arr=["test1", "test2"] test_opt=testing_option test_hsh={"a"=>"test_hsh_arg"} test_bool=true test_rest=[]'+"\n"
|
416
|
-
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
417
|
-
assert_equal(expected, result)
|
418
|
-
end
|
419
|
-
|
420
|
-
def test_full_run_sharp_arg
|
421
|
-
mod = "util_test_module.rb"
|
422
|
-
command = "test_command_mixed_options"
|
423
|
-
args = '#' + " \"[test1, test2]\" -test_opt='testing_option' \"{a: 'test_hsh_arg'}\" -test_bool=true some other args"
|
424
|
-
expected = 'test_arg=# test_arr=["test1", "test2"] test_opt=testing_option test_hsh={"a"=>"test_hsh_arg"} test_bool=true test_rest=["some", "other", "args"]'+"\n"
|
425
|
-
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
426
|
-
assert_equal(expected, result)
|
427
|
-
end
|
428
|
-
|
429
|
-
def test_full_run_bang_arg
|
430
|
-
mod = "util_test_module.rb"
|
431
|
-
command = "test_command_mixed_options"
|
432
|
-
args = "! \"[test1, test2]\" -test_opt='testing_option' \"{a: 'test_hsh_arg'}\" -test_bool=true some other args"
|
433
|
-
expected = 'test_arg=! test_arr=["test1", "test2"] test_opt=testing_option test_hsh={"a"=>"test_hsh_arg"} test_bool=true test_rest=["some", "other", "args"]'+"\n"
|
434
|
-
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
435
|
-
assert_equal(expected, result)
|
436
|
-
end
|
437
|
-
|
438
|
-
def test_tab_complete_nil_arg
|
439
|
-
mod = UtilTestComposite
|
440
|
-
args = nil
|
441
|
-
expected = ["test_composite_command", "UtilTestNoSingleton", "UtilTestModule"]
|
442
|
-
result = Rubycom.tab_complete(mod, args)
|
443
|
-
assert_equal(expected, result)
|
444
|
-
end
|
445
|
-
|
446
|
-
def test_tab_complete_empty_arg
|
447
|
-
mod = UtilTestComposite
|
448
|
-
args = ['']
|
449
|
-
expected = ["test_composite_command", "UtilTestNoSingleton", "UtilTestModule"]
|
450
|
-
result = Rubycom.tab_complete(mod, args)
|
451
|
-
assert_equal(expected, result)
|
452
|
-
end
|
453
|
-
|
454
|
-
def test_tab_complete_partial_module
|
455
|
-
mod = UtilTestComposite
|
456
|
-
args = ['Util']
|
457
|
-
expected = ["UtilTestNoSingleton", "UtilTestModule"]
|
458
|
-
result = Rubycom.tab_complete(mod, args)
|
459
|
-
assert_equal(expected, result)
|
460
|
-
end
|
461
|
-
|
462
|
-
def test_tab_complete_partial_module_single_match
|
463
|
-
mod = UtilTestComposite
|
464
|
-
args = ['UtilTestM']
|
465
|
-
expected = ["UtilTestModule"]
|
466
|
-
result = Rubycom.tab_complete(mod, args)
|
467
|
-
assert_equal(expected, result)
|
468
|
-
end
|
469
|
-
|
470
|
-
def test_tab_complete_whole_module
|
471
|
-
mod = UtilTestComposite
|
472
|
-
args = ['UtilTestModule']
|
473
|
-
expected = ["test_command",
|
474
|
-
"test_command_no_docs",
|
475
|
-
"test_command_with_arg",
|
476
|
-
"test_command_arg_named_arg",
|
477
|
-
"test_command_with_args",
|
478
|
-
"test_command_with_options",
|
479
|
-
"test_command_all_options",
|
480
|
-
"test_command_options_arr",
|
481
|
-
"test_command_with_return",
|
482
|
-
"test_command_arg_timestamp",
|
483
|
-
"test_command_arg_false",
|
484
|
-
"test_command_arg_arr",
|
485
|
-
"test_command_arg_hash",
|
486
|
-
"test_command_mixed_options"]
|
487
|
-
result = Rubycom.tab_complete(mod, args)
|
488
|
-
assert_equal(expected, result)
|
489
|
-
end
|
490
|
-
|
491
|
-
def test_tab_complete_empty_sub_command
|
492
|
-
mod = UtilTestComposite
|
493
|
-
args = ['UtilTestModule', '']
|
494
|
-
expected = ["test_command",
|
495
|
-
"test_command_no_docs",
|
496
|
-
"test_command_with_arg",
|
497
|
-
"test_command_arg_named_arg",
|
498
|
-
"test_command_with_args",
|
499
|
-
"test_command_with_options",
|
500
|
-
"test_command_all_options",
|
501
|
-
"test_command_options_arr",
|
502
|
-
"test_command_with_return",
|
503
|
-
"test_command_arg_timestamp",
|
504
|
-
"test_command_arg_false",
|
505
|
-
"test_command_arg_arr",
|
506
|
-
"test_command_arg_hash",
|
507
|
-
"test_command_mixed_options"]
|
508
|
-
result = Rubycom.tab_complete(mod, args)
|
509
|
-
assert_equal(expected, result)
|
510
|
-
end
|
511
|
-
|
512
|
-
def test_tab_complete_partial_sub_command
|
513
|
-
mod = UtilTestComposite
|
514
|
-
args = ['UtilTestModule', 'test_command_ar']
|
515
|
-
expected = ["test_command_arg_named_arg",
|
516
|
-
"test_command_arg_timestamp",
|
517
|
-
"test_command_arg_false",
|
518
|
-
"test_command_arg_arr",
|
519
|
-
"test_command_arg_hash"]
|
520
|
-
result = Rubycom.tab_complete(mod, args)
|
521
|
-
assert_equal(expected, result)
|
522
|
-
end
|
523
|
-
|
524
|
-
def test_tab_complete_whole_sub_command_single_match
|
525
|
-
mod = UtilTestComposite
|
526
|
-
args = ['UtilTestModule', 'test_command_with_options']
|
527
|
-
expected = ['']
|
528
|
-
result = Rubycom.tab_complete(mod, args)
|
529
|
-
assert_equal(expected, result)
|
530
|
-
end
|
531
|
-
|
532
|
-
def test_tab_complete_whole_sub_command_multi_match
|
533
|
-
mod = UtilTestComposite
|
534
|
-
args = ['UtilTestModule', 'test_command_with_arg']
|
535
|
-
expected = ['']
|
536
|
-
result = Rubycom.tab_complete(mod, args)
|
537
|
-
assert_equal(expected, result)
|
538
|
-
end
|
539
|
-
|
540
|
-
def test_tab_complete_whole_sub_command_with_empty
|
541
|
-
mod = UtilTestComposite
|
542
|
-
args = ['UtilTestModule', 'test_command_with_args', '']
|
543
|
-
expected = ['']
|
544
|
-
result = Rubycom.tab_complete(mod, args)
|
545
|
-
assert_equal(expected, result)
|
546
|
-
end
|
547
|
-
|
548
|
-
end
|
1
|
+
require "#{File.dirname(__FILE__)}/../../lib/rubycom.rb"
|
2
|
+
|
3
|
+
require "#{File.dirname(__FILE__)}/util_test_module.rb"
|
4
|
+
require "#{File.dirname(__FILE__)}/util_test_composite.rb"
|
5
|
+
require "#{File.dirname(__FILE__)}/util_test_no_singleton.rb"
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'time'
|
9
|
+
|
10
|
+
class RubycomTest < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def capture_out(&block)
|
13
|
+
original_stdout = $stdout
|
14
|
+
$stdout = fake = StringIO.new
|
15
|
+
begin
|
16
|
+
yield
|
17
|
+
ensure
|
18
|
+
$stdout = original_stdout
|
19
|
+
end
|
20
|
+
fake.string
|
21
|
+
end
|
22
|
+
|
23
|
+
def capture_err(&block)
|
24
|
+
original_stderr = $stderr
|
25
|
+
$stderr = fake = StringIO.new
|
26
|
+
begin
|
27
|
+
yield
|
28
|
+
ensure
|
29
|
+
$stderr = original_stderr
|
30
|
+
end
|
31
|
+
fake.string
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_run
|
35
|
+
base = UtilTestModule
|
36
|
+
args = %w(test_command_with_arg HelloWorld)
|
37
|
+
result = nil
|
38
|
+
result_out = capture_out { result = Rubycom.run(base, args) }
|
39
|
+
|
40
|
+
expected = "test_arg=HelloWorld"
|
41
|
+
assert_equal(expected, result)
|
42
|
+
assert_equal(expected+"\n", result_out)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_run_help
|
46
|
+
base = UtilTestModule
|
47
|
+
args = %w(help)
|
48
|
+
result = nil
|
49
|
+
result_err = capture_err { result = Rubycom.run(base, args) }
|
50
|
+
|
51
|
+
assert_equal(nil, result)
|
52
|
+
assert(result_err.gsub(/\n|\r|\s/, '').size > 0, 'help output should not be empty')
|
53
|
+
assert(result_err.include?('Help Requested'), 'help output should state that help was requested')
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_run_nil_return
|
57
|
+
base = UtilTestModule
|
58
|
+
args = %w(test_command)
|
59
|
+
result = nil
|
60
|
+
result_out = capture_out { result = Rubycom.run(base, args) }
|
61
|
+
|
62
|
+
expected_out = "command test\n\n"
|
63
|
+
assert_equal(nil, result)
|
64
|
+
assert_equal(expected_out, result_out)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_run_hash_return
|
68
|
+
base = UtilTestModule
|
69
|
+
time = "#{Time.now.to_s}"
|
70
|
+
args = ['test_command_arg_timestamp', time]
|
71
|
+
result = nil
|
72
|
+
result_out = capture_out { result = Rubycom.run(base, args) }
|
73
|
+
|
74
|
+
expected = {test_time: Time.parse(time)}
|
75
|
+
expected_out = expected.to_yaml
|
76
|
+
assert_equal(expected, result)
|
77
|
+
assert_equal(expected_out, result_out)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_run_all_optional
|
81
|
+
base = UtilTestModule
|
82
|
+
args = %w(test_command_all_options)
|
83
|
+
result = nil
|
84
|
+
result_out = capture_out { result = Rubycom.run(base, args) }
|
85
|
+
|
86
|
+
e_test_arg = 'test_arg_default'
|
87
|
+
e_test_option = 'test_option_default'
|
88
|
+
expected_out = "Output is test_arg=#{e_test_arg},test_option=#{e_test_option}\n\n"
|
89
|
+
assert_equal(nil, result)
|
90
|
+
assert_equal(expected_out, result_out)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_run_all_opt_override_first
|
94
|
+
base = UtilTestModule
|
95
|
+
args = %w(test_command_all_options test_arg_modified)
|
96
|
+
result = nil
|
97
|
+
result_out = capture_out { result = Rubycom.run(base, args) }
|
98
|
+
|
99
|
+
e_test_arg = 'test_arg_modified'
|
100
|
+
e_test_option = 'test_option_default'
|
101
|
+
expected_out = "Output is test_arg=#{e_test_arg},test_option=#{e_test_option}\n\n"
|
102
|
+
assert_equal(nil, result)
|
103
|
+
assert_equal(expected_out, result_out)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_run_all_opt_override_first_alt
|
107
|
+
base = UtilTestModule
|
108
|
+
args = %w(test_command_all_options -test_arg=test_arg_modified)
|
109
|
+
result = nil
|
110
|
+
result_out = capture_out { result = Rubycom.run(base, args) }
|
111
|
+
|
112
|
+
e_test_arg = 'test_arg_modified'
|
113
|
+
e_test_option = 'test_option_default'
|
114
|
+
expected_out = "Output is test_arg=#{e_test_arg},test_option=#{e_test_option}\n\n"
|
115
|
+
assert_equal(nil, result)
|
116
|
+
assert_equal(expected_out, result_out)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_run_all_opt_override_second
|
120
|
+
base = UtilTestModule
|
121
|
+
args = %w(test_command_all_options -test_option=test_option_modified)
|
122
|
+
result = nil
|
123
|
+
result_out = capture_out { result = Rubycom.run(base, args) }
|
124
|
+
|
125
|
+
e_test_arg = 'test_arg_default'
|
126
|
+
e_test_option = 'test_option_modified'
|
127
|
+
expected_out = "Output is test_arg=#{e_test_arg},test_option=#{e_test_option}\n\n"
|
128
|
+
assert_equal(nil, result)
|
129
|
+
assert_equal(expected_out, result_out)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_run_all_opt_use_all_opt
|
133
|
+
base = UtilTestModule
|
134
|
+
args = %w(test_command_all_options -test_arg=test_arg_modified -test_option=test_option_modified)
|
135
|
+
result = nil
|
136
|
+
result_out = capture_out { result = Rubycom.run(base, args) }
|
137
|
+
|
138
|
+
e_test_arg = 'test_arg_modified'
|
139
|
+
e_test_option = 'test_option_modified'
|
140
|
+
expected_out = "Output is test_arg=#{e_test_arg},test_option=#{e_test_option}\n\n"
|
141
|
+
assert_equal(nil, result)
|
142
|
+
assert_equal(expected_out, result_out)
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_run_all_opt_reverse
|
146
|
+
base = UtilTestModule
|
147
|
+
args = %w(test_command_all_options -test_option=test_option_modified -test_arg=test_arg_modified)
|
148
|
+
result = nil
|
149
|
+
result_out = capture_out { result = Rubycom.run(base, args) }
|
150
|
+
|
151
|
+
e_test_arg = 'test_arg_modified'
|
152
|
+
e_test_option = 'test_option_modified'
|
153
|
+
expected_out = "Output is test_arg=#{e_test_arg},test_option=#{e_test_option}\n\n"
|
154
|
+
assert_equal(nil, result)
|
155
|
+
assert_equal(expected_out, result_out)
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_run_options_arr
|
159
|
+
mod = 'util_test_module.rb'
|
160
|
+
command = 'test_command_options_arr'
|
161
|
+
args = 'test_option1 test_option2 1.0 false'
|
162
|
+
expected = 'Output is test_option=test_option1,test_option_arr=["test_option2", 1.0, false]'+"\n\n"
|
163
|
+
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
164
|
+
assert_equal(expected, result)
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_run_multi_args
|
168
|
+
mod = 'util_test_bin.rb'
|
169
|
+
sub_mod = 'UtilTestModule'
|
170
|
+
command = 'test_command_with_args'
|
171
|
+
args = 'a b'
|
172
|
+
expected = 'test_arg=a,another_test_arg=b'+"\n\n"
|
173
|
+
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{sub_mod} #{command} #{args})
|
174
|
+
assert_equal(expected, result)
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_run_missing_required_arg
|
178
|
+
base = UtilTestModule
|
179
|
+
args = %w(test_command_with_return -test_option_int=2)
|
180
|
+
result = nil
|
181
|
+
result_err = capture_err { result = Rubycom.run(base, args) }
|
182
|
+
expected = 'Missing required argument: test_arg'
|
183
|
+
assert_equal(nil, result)
|
184
|
+
assert(result_err.gsub(/\n|\r|\s/, '').size > 0, 'error output should not be empty')
|
185
|
+
assert(result_err.include?(expected), "error output should include #{expected} but was #{result}")
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_run_composite
|
189
|
+
base = UtilTestComposite
|
190
|
+
args = ['test_composite_command', '\'Hello Composite\'']
|
191
|
+
result = nil
|
192
|
+
result_out = capture_out { result = Rubycom.run(base, args) }
|
193
|
+
|
194
|
+
expected = "Hello Composite"
|
195
|
+
expected_out = expected+"\n"
|
196
|
+
assert_equal(expected_out, result_out)
|
197
|
+
assert_equal(expected, result)
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_full_run_mixed_args
|
201
|
+
mod = 'util_test_module.rb'
|
202
|
+
command = 'test_command_mixed_options'
|
203
|
+
args = "testing_arg \"[test1, test2]\" -test_opt='testing_option' \"{a: 'test_hsh_arg'}\" -test_bool=true some other args"
|
204
|
+
expected = 'test_arg=testing_arg test_arr=["test1", "test2"] test_opt=testing_option test_hsh={"a"=>"test_hsh_arg"} test_bool=true test_rest=["some", "other", "args"]'+"\n"
|
205
|
+
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
206
|
+
assert_equal(expected, result)
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_full_run_mixed_names_with_shorts
|
210
|
+
mod = 'util_test_module.rb'
|
211
|
+
command = 'test_command_mixed_names'
|
212
|
+
args = "testing_arg \"[test1, test2]\" -opt='testing_option' -h =\"{a: 'test_hsh_arg'}\" --bool true some other args"
|
213
|
+
expected = 'arg_test=testing_arg arr=["test1", "test2"] opt=testing_option hsh={"a"=>"test_hsh_arg"} bool=true rest_test=["some", "other", "args"]'+"\n"
|
214
|
+
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
215
|
+
assert_equal(expected, result)
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_full_run_mixed_names_all_separators
|
219
|
+
mod = 'util_test_module.rb'
|
220
|
+
command = 'test_command_mixed_names'
|
221
|
+
args = "testing_arg --arr = \"[test1, test2]\" -opt= 'testing_option' -h =\"{a: 'test_hsh_arg'}\" --bool true some other args"
|
222
|
+
expected = 'arg_test=testing_arg arr=["test1", "test2"] opt=testing_option hsh={"a"=>"test_hsh_arg"} bool=true rest_test=["some", "other", "args"]'+"\n"
|
223
|
+
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
224
|
+
assert_equal(expected, result)
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_full_run_args_for_opts
|
228
|
+
mod = 'util_test_module.rb'
|
229
|
+
command = 'test_command_mixed_options'
|
230
|
+
args = 'testing_arg test2 testing_option test_hsh_arg true some other args'
|
231
|
+
expected = "test_arg=testing_arg test_arr=test2 test_opt=testing_option test_hsh=test_hsh_arg test_bool=true test_rest=[\"some\", \"other\", \"args\"]"+"\n"
|
232
|
+
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
233
|
+
assert_equal(expected, result)
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_full_run_mixed_args_solid_arr
|
237
|
+
mod = 'util_test_module.rb'
|
238
|
+
command = 'test_command_mixed_options'
|
239
|
+
args = "testing_arg [test1,test2] -test_opt='testing_option' \"{a: 'test_hsh_arg'}\" some other args"
|
240
|
+
expected = 'test_arg=testing_arg test_arr=["test1", "test2"] test_opt=testing_option test_hsh={"a"=>"test_hsh_arg"} test_bool=some test_rest=["other", "args"]'+"\n"
|
241
|
+
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
242
|
+
assert_equal(expected, result)
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_full_run_mixed_args_quoted_solid_arr
|
246
|
+
mod = 'util_test_module.rb'
|
247
|
+
command = 'test_command_mixed_options'
|
248
|
+
args = 'testing_arg "[test1,test2]" -test_opt="testing_option" "{a: "test_hsh_arg"}" -test_bool=false some other args'
|
249
|
+
expected = 'test_arg=testing_arg test_arr=["test1", "test2"] test_opt=testing_option test_hsh={"a"=>"test_hsh_arg"} test_bool=false test_rest=["some", "other", "args"]'+"\n"
|
250
|
+
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
251
|
+
assert_equal(expected, result)
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_full_run_mixed_args_odd_sp
|
255
|
+
mod = 'util_test_module.rb'
|
256
|
+
command = 'test_command_mixed_options'
|
257
|
+
args = 'testing_arg "[ test1 , test2 ]" -test_opt="testing_option" "{ a: "test_hsh_arg" }" -test_bool=false some other args'
|
258
|
+
expected = 'test_arg=testing_arg test_arr=["test1", "test2"] test_opt=testing_option test_hsh={"a"=>"test_hsh_arg"} test_bool=false test_rest=["some", "other", "args"]'+"\n"
|
259
|
+
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
260
|
+
assert_equal(expected, result)
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_full_run_mixed_args_hash_rocket
|
264
|
+
mod = 'util_test_module.rb'
|
265
|
+
command = 'test_command_mixed_options'
|
266
|
+
args = 'testing_arg "[ test1 , test2 ]" -test_opt="testing_option" "{ :a => "test_hsh_arg" }" false some other args'
|
267
|
+
expected = 'test_arg=testing_arg test_arr=["test1", "test2"] test_opt=testing_option test_hsh={ :a => test_hsh_arg } test_bool=false test_rest=["some", "other", "args"]'+"\n"
|
268
|
+
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
269
|
+
assert_equal(expected, result)
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_full_run_mixed_args_rest_no_extra
|
273
|
+
mod = 'util_test_module.rb'
|
274
|
+
command = 'test_command_mixed_options'
|
275
|
+
args = "testing_arg \"[test1, test2]\" -test_opt='testing_option' \"{a: 'test_hsh_arg'}\""
|
276
|
+
expected = 'test_arg=testing_arg test_arr=["test1", "test2"] test_opt=testing_option test_hsh={"a"=>"test_hsh_arg"} test_bool=true test_rest=[]'+"\n"
|
277
|
+
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
278
|
+
assert_equal(expected, result)
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_full_run_bang_arg
|
282
|
+
mod = 'util_test_module.rb'
|
283
|
+
command = 'test_command_mixed_options'
|
284
|
+
args = "! \"[test1, test2]\" -test_opt='testing_option' \"{a: 'test_hsh_arg'}\" -test_bool=true some other args"
|
285
|
+
expected = 'test_arg=! test_arr=["test1", "test2"] test_opt=testing_option test_hsh={"a"=>"test_hsh_arg"} test_bool=true test_rest=["some", "other", "args"]'+"\n"
|
286
|
+
result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
|
287
|
+
assert_equal(expected, result)
|
288
|
+
end
|
289
|
+
|
290
|
+
end
|