rubycom 0.3.2 → 0.4.0

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.
Files changed (43) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +162 -146
  3. data/Rakefile +12 -12
  4. data/lib/rubycom.rb +156 -226
  5. data/lib/rubycom/arg_parse.rb +252 -0
  6. data/lib/rubycom/command_interface.rb +97 -0
  7. data/lib/rubycom/completions.rb +62 -0
  8. data/lib/rubycom/error_handler.rb +15 -0
  9. data/lib/rubycom/executor.rb +23 -0
  10. data/lib/rubycom/helpers.rb +98 -0
  11. data/lib/rubycom/output_handler.rb +15 -0
  12. data/lib/rubycom/parameter_extract.rb +262 -0
  13. data/lib/rubycom/singleton_commands.rb +78 -0
  14. data/lib/rubycom/sources.rb +99 -0
  15. data/lib/rubycom/version.rb +1 -1
  16. data/lib/rubycom/yard_doc.rb +146 -0
  17. data/rubycom.gemspec +14 -16
  18. data/test/rubycom/arg_parse_test.rb +247 -0
  19. data/test/rubycom/command_interface_test.rb +293 -0
  20. data/test/rubycom/completions_test.rb +94 -0
  21. data/test/rubycom/error_handler_test.rb +72 -0
  22. data/test/rubycom/executor_test.rb +64 -0
  23. data/test/rubycom/helpers_test.rb +467 -0
  24. data/test/rubycom/output_handler_test.rb +76 -0
  25. data/test/rubycom/parameter_extract_test.rb +141 -0
  26. data/test/rubycom/rubycom_test.rb +290 -548
  27. data/test/rubycom/singleton_commands_test.rb +122 -0
  28. data/test/rubycom/sources_test.rb +59 -0
  29. data/test/rubycom/util_test_bin.rb +8 -0
  30. data/test/rubycom/util_test_composite.rb +23 -20
  31. data/test/rubycom/util_test_module.rb +142 -112
  32. data/test/rubycom/util_test_no_singleton.rb +2 -2
  33. data/test/rubycom/util_test_sub_module.rb +13 -0
  34. data/test/rubycom/yard_doc_test.rb +165 -0
  35. metadata +61 -24
  36. data/lib/rubycom/arguments.rb +0 -133
  37. data/lib/rubycom/commands.rb +0 -63
  38. data/lib/rubycom/documentation.rb +0 -212
  39. data/test/rubycom/arguments_test.rb +0 -289
  40. data/test/rubycom/commands_test.rb +0 -51
  41. data/test/rubycom/documentation_test.rb +0 -186
  42. data/test/rubycom/util_test_job.yaml +0 -21
  43. 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 test_run
13
- tst_out = ''
14
-
15
- def tst_out.write(data)
16
- self << data
17
- end
18
-
19
- o_stdout, $stdout = $stdout, tst_out
20
- o_stderr, $stderr = $stderr, tst_out
21
-
22
- base = UtilTestModule
23
- args = ["test_command_with_arg", "HelloWorld"]
24
- result = Rubycom.run(base, args)
25
-
26
- expected = "test_arg=HelloWorld"
27
- expected_out = expected
28
- assert_equal(expected, result)
29
- assert_equal(expected_out.gsub(/\n|\r|\s/, ''), tst_out.gsub(/\n|\r|\s/, ''))
30
- ensure
31
- $stdout = o_stdout
32
- $stderr = o_stderr
33
- end
34
-
35
- def test_run_help
36
- tst_out = ''
37
-
38
- def tst_out.write(data)
39
- self << data
40
- end
41
-
42
- o_stdout, $stdout = $stdout, tst_out
43
- o_stderr, $stderr = $stderr, tst_out
44
-
45
- base = UtilTestModule
46
- args = ["help"]
47
- result = Rubycom.run(base, args)
48
-
49
- expected = <<-END.gsub(/^ {4}/,'')
50
- Usage:
51
- UtilTestModule <command> [args]
52
-
53
- Commands:
54
- test_command - A basic test command
55
- test_command_no_docs
56
- test_command_with_arg - A test_command with one arg
57
- test_command_arg_named_arg - A test_command with an arg named arg
58
- test_command_with_args - A test_command with two args
59
- test_command_with_options - A test_command with an optional argument
60
- test_command_all_options - A test_command with all optional arguments
61
- test_command_options_arr - A test_command with an options array
62
- test_command_with_return - A test_command with a return argument
63
- test_command_arg_timestamp - A test_command with a Timestamp argument and an unnecessarily
64
- long description which should overflow when
65
- it tries to line up with other descriptions.
66
- test_command_arg_false - A test_command with a Boolean argument
67
- test_command_arg_arr - A test_command with an array argument
68
- test_command_arg_hash - A test_command with an Hash argument
69
- test_command_mixed_options - A test_command with several mixed options
70
-
71
- Default Commands:
72
- help - prints this help page
73
- job - run a job file
74
- register_completions - setup bash tab completion
75
- tab_complete - print a list of possible matches for a given word
76
-
77
- END
78
- expected_out = expected
79
- assert_equal(expected.gsub(/\n|\r|\s/, ''), result.gsub(/\n|\r|\s/, ''))
80
- assert_equal(expected_out.gsub(/\n|\r|\s/, ''), tst_out.gsub(/\n|\r|\s/, ''))
81
- ensure
82
- $stdout = o_stdout
83
- $stderr = o_stderr
84
- end
85
-
86
- def test_run_nil_return
87
- tst_out = ''
88
-
89
- def tst_out.write(data)
90
- self << data
91
- end
92
-
93
- o_stdout, $stdout = $stdout, tst_out
94
- o_stderr, $stderr = $stderr, tst_out
95
-
96
- base = UtilTestModule
97
- args = ["test_command"]
98
- result = Rubycom.run(base, args)
99
-
100
- expected = nil
101
- expected_out = "command test\n"
102
- assert_equal(expected, result)
103
- assert_equal(expected_out.gsub(/\n|\r|\s/, ''), tst_out.gsub(/\n|\r|\s/, ''))
104
- ensure
105
- $stdout = o_stdout
106
- $stderr = o_stderr
107
- end
108
-
109
- def test_run_hash_return
110
- tst_out = ''
111
-
112
- def tst_out.write(data)
113
- self << data
114
- end
115
-
116
- o_stdout, $stdout = $stdout, tst_out
117
- o_stderr, $stderr = $stderr, tst_out
118
-
119
- base = UtilTestModule
120
- time = Time.now.to_s
121
- args = ["test_command_arg_timestamp", time]
122
- result = Rubycom.run(base, args)
123
-
124
- expected = {:test_time => Time.parse(time)}
125
- expected_out = {test_time: Time.parse(time)}.to_yaml
126
- assert_equal(expected, result)
127
- assert_equal(expected_out.gsub(/\n|\r|\s/, ''), tst_out.gsub(/\n|\r|\s/, ''))
128
- ensure
129
- $stdout = o_stdout
130
- $stderr = o_stderr
131
- end
132
-
133
- def test_run_all_optional
134
- tst_out = ''
135
-
136
- def tst_out.write(data)
137
- self << data
138
- end
139
-
140
- o_stdout, $stdout = $stdout, tst_out
141
- o_stderr, $stderr = $stderr, tst_out
142
-
143
- base = UtilTestModule
144
- args = ["test_command_all_options"]
145
- result = Rubycom.run(base, args)
146
-
147
- e_test_arg = 'test_arg_default'
148
- e_test_option = 'test_option_default'
149
- expected = nil
150
- expected_out = "Output is test_arg=#{e_test_arg},test_option=#{e_test_option}\n"
151
- assert_equal(expected, result)
152
- assert_equal(expected_out.gsub(/\n|\r|\s/, ''), tst_out.gsub(/\n|\r|\s/, ''))
153
- ensure
154
- $stdout = o_stdout
155
- $stderr = o_stderr
156
- end
157
-
158
- def test_run_all_opt_override_first
159
- tst_out = ''
160
-
161
- def tst_out.write(data)
162
- self << data
163
- end
164
-
165
- o_stdout, $stdout = $stdout, tst_out
166
- o_stderr, $stderr = $stderr, tst_out
167
-
168
- base = UtilTestModule
169
- args = ["test_command_all_options", "test_arg_modified"]
170
- result = Rubycom.run(base, args)
171
-
172
- e_test_arg = 'test_arg_modified'
173
- e_test_option = 'test_option_default'
174
- expected = nil
175
- expected_out = "Output is test_arg=#{e_test_arg},test_option=#{e_test_option}\n"
176
- assert_equal(expected, result)
177
- assert_equal(expected_out.gsub(/\n|\r|\s/, ''), tst_out.gsub(/\n|\r|\s/, ''))
178
- ensure
179
- $stdout = o_stdout
180
- $stderr = o_stderr
181
- end
182
-
183
- def test_run_all_opt_override_first_alt
184
- tst_out = ''
185
-
186
- def tst_out.write(data)
187
- self << data
188
- end
189
-
190
- o_stdout, $stdout = $stdout, tst_out
191
- o_stderr, $stderr = $stderr, tst_out
192
-
193
- base = UtilTestModule
194
- args = ["test_command_all_options", "-test_arg=test_arg_modified"]
195
- result = Rubycom.run(base, args)
196
-
197
- e_test_arg = 'test_arg_modified'
198
- e_test_option = 'test_option_default'
199
- expected = nil
200
- expected_out = "Output is test_arg=#{e_test_arg},test_option=#{e_test_option}\n"
201
- assert_equal(expected, result)
202
- assert_equal(expected_out.gsub(/\n|\r|\s/, ''), tst_out.gsub(/\n|\r|\s/, ''))
203
- ensure
204
- $stdout = o_stdout
205
- $stderr = o_stderr
206
- end
207
-
208
- def test_run_all_opt_override_second
209
- tst_out = ''
210
-
211
- def tst_out.write(data)
212
- self << data
213
- end
214
-
215
- o_stdout, $stdout = $stdout, tst_out
216
- o_stderr, $stderr = $stderr, tst_out
217
-
218
- base = UtilTestModule
219
- args = ["test_command_all_options", "-test_option=test_option_modified"]
220
- result = Rubycom.run(base, args)
221
-
222
- e_test_arg = 'test_arg_default'
223
- e_test_option = 'test_option_modified'
224
- expected = nil
225
- expected_out = "Output is test_arg=#{e_test_arg},test_option=#{e_test_option}\n"
226
- assert_equal(expected, result)
227
- assert_equal(expected_out.gsub(/\n|\r|\s/, ''), tst_out.gsub(/\n|\r|\s/, ''))
228
- ensure
229
- $stdout = o_stdout
230
- $stderr = o_stderr
231
- end
232
-
233
- def test_run_all_opt_use_all_opt
234
- tst_out = ''
235
-
236
- def tst_out.write(data)
237
- self << data
238
- end
239
-
240
- o_stdout, $stdout = $stdout, tst_out
241
- o_stderr, $stderr = $stderr, tst_out
242
-
243
- base = UtilTestModule
244
- args = ["test_command_all_options", "-test_arg=test_arg_modified", "-test_option=test_option_modified"]
245
- result = Rubycom.run(base, args)
246
-
247
- e_test_arg = 'test_arg_modified'
248
- e_test_option = 'test_option_modified'
249
- expected = nil
250
- expected_out = "Output is test_arg=#{e_test_arg},test_option=#{e_test_option}\n"
251
- assert_equal(expected, result)
252
- assert_equal(expected_out.gsub(/\n|\r|\s/, ''), tst_out.gsub(/\n|\r|\s/, ''))
253
- ensure
254
- $stdout = o_stdout
255
- $stderr = o_stderr
256
- end
257
-
258
- def test_run_all_opt_reverse
259
- tst_out = ''
260
-
261
- def tst_out.write(data)
262
- self << data
263
- end
264
-
265
- o_stdout, $stdout = $stdout, tst_out
266
- o_stderr, $stderr = $stderr, tst_out
267
-
268
- base = UtilTestModule
269
- args = ["test_command_all_options", "-test_option=test_option_modified", "-test_arg=test_arg_modified"]
270
- result = Rubycom.run(base, args)
271
-
272
- e_test_arg = 'test_arg_modified'
273
- e_test_option = 'test_option_modified'
274
- expected = nil
275
- expected_out = "Output is test_arg=#{e_test_arg},test_option=#{e_test_option}\n"
276
- assert_equal(expected, result)
277
- assert_equal(expected_out.gsub(/\n|\r|\s/, ''), tst_out.gsub(/\n|\r|\s/, ''))
278
- ensure
279
- $stdout = o_stdout
280
- $stderr = o_stderr
281
- end
282
-
283
- def test_run_options_arr
284
- mod = "util_test_module.rb"
285
- command = "test_command_options_arr"
286
- args = "test_option1 test_option2 1.0 false"
287
- expected = 'Output is test_option=test_option1,test_option_arr=["test_option2", 1.0, false]'+"\n\n"
288
- result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
289
- assert_equal(expected, result)
290
- end
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