rubycom 0.2.5 → 0.3.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.
@@ -0,0 +1,51 @@
1
+ require "#{File.dirname(__FILE__)}/../../lib/rubycom/commands.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 CommandsTest < Test::Unit::TestCase
10
+
11
+ def test_get_top_level_commands
12
+ test_command_list = [:test_command, :test_command_no_docs, :test_command_with_arg, :test_command_arg_named_arg,
13
+ :test_command_with_args, :test_command_with_options, :test_command_all_options,
14
+ :test_command_options_arr, :test_command_with_return, :test_command_arg_timestamp,
15
+ :test_command_arg_false, :test_command_arg_arr, :test_command_arg_hash,
16
+ :test_command_mixed_options]
17
+ result_command_list = Rubycom::Commands.get_top_level_commands(UtilTestModule)
18
+ assert_equal(test_command_list.length, result_command_list.length)
19
+ test_command_list.each { |sym|
20
+ assert_includes(result_command_list, sym)
21
+ }
22
+ end
23
+
24
+ def test_get_top_level_commands_nil_base
25
+ test_command_list = []
26
+ result_command_list = Rubycom::Commands.get_top_level_commands(nil)
27
+ assert_equal(test_command_list.length, result_command_list.length)
28
+ test_command_list.each { |sym|
29
+ assert_includes(result_command_list, sym)
30
+ }
31
+ end
32
+
33
+ def test_get_commands_nil_base
34
+ test_command_list = []
35
+ result_command_list = Rubycom::Commands.get_commands(nil)
36
+ assert_equal(test_command_list.length, result_command_list.length)
37
+ test_command_list.each { |sym|
38
+ assert_includes(result_command_list, sym)
39
+ }
40
+ end
41
+
42
+ def test_get_top_level_commands_singleton_base
43
+ test_command_list = []
44
+ result_command_list = Rubycom::Commands.get_top_level_commands(UtilTestNoSingleton)
45
+ assert_equal(test_command_list.length, result_command_list.length)
46
+ test_command_list.each { |sym|
47
+ assert_includes(result_command_list, sym)
48
+ }
49
+ end
50
+
51
+ end
@@ -0,0 +1,186 @@
1
+ require "#{File.dirname(__FILE__)}/../../lib/rubycom/documentation.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 DocumentationTest < Test::Unit::TestCase
10
+
11
+ def test_get_doc
12
+ method = UtilTestModule.public_method(:test_command_with_return)
13
+ result_hash = Rubycom::Documentation.get_doc(method)
14
+ assert_equal('A test_command with a return argument'.gsub(/\n|\r|\s/, ''), result_hash[:desc].join("\n").gsub(/\n|\r|\s/, ''))
15
+ assert_equal(2, result_hash[:param].size)
16
+ assert_equal('[String] test_arg a test argument'.gsub(/\n|\r|\s/, ''), result_hash[:param][0].gsub(/\n|\r|\s/, ''))
17
+ assert_equal('[Integer] test_option_int an optional test argument which happens to be an Integer'.gsub(/\n|\r|\s/, ''), result_hash[:param][1].gsub(/\n|\r|\s/, ''))
18
+ assert_equal(2, result_hash[:return].size)
19
+ assert_equal('[Array] an array including both params if test_option_int != 1'.gsub(/\n|\r|\s/, ''), result_hash[:return][0].gsub(/\n|\r|\s/, ''))
20
+ assert_equal('[String] a the first param if test_option_int == 1'.gsub(/\n|\r|\s/, ''), result_hash[:return][1].gsub(/\n|\r|\s/, ''))
21
+ end
22
+
23
+ def test_get_command_usage
24
+ base = UtilTestModule
25
+ command_name = 'test_command_arg_false'
26
+ result = Rubycom::Documentation.get_command_usage(base, command_name)
27
+ expected = <<-END.gsub(/^ {4}/, '')
28
+ Usage: test_command_arg_false [-test_flag=false]
29
+ Parameters:
30
+ [Boolean] test_flag a test Boolean argument
31
+ Returns:
32
+ [Boolean] the flag passed in
33
+ END
34
+ assert_equal(expected.gsub(/\n|\r|\s/, ''), result.gsub(/\n|\r|\s/, ''))
35
+ end
36
+
37
+ def test_get_command_usage_nil_base
38
+ base = nil
39
+ command_name = 'test_command'
40
+ assert_raise(Rubycom::CLIError) { Rubycom::Documentation.get_command_usage(base, command_name) }
41
+ end
42
+
43
+ def test_get_command_usage_nil_command
44
+ base = UtilTestModule
45
+ command_name = nil
46
+ result = Rubycom::Documentation.get_command_usage(base, command_name)
47
+ assert_equal('No command specified.', result)
48
+ end
49
+
50
+ def test_get_command_usage_no_command
51
+ base = UtilTestModule
52
+ command_name = ''
53
+ result = Rubycom::Documentation.get_command_usage(base, command_name)
54
+ assert_equal('No command specified.', result)
55
+ end
56
+
57
+ def test_get_command_usage_bad_base
58
+ base = ":asd"
59
+ command_name = 'test_command_with_options'
60
+ assert_raise(Rubycom::CLIError) { Rubycom::Documentation.get_command_usage(base, command_name) }
61
+ end
62
+
63
+ def test_get_command_usage_invalid_command
64
+ base = UtilTestModule
65
+ command_name = '123asd!@#'
66
+ assert_raise(Rubycom::CLIError) { Rubycom::Documentation.get_command_usage(base, command_name) }
67
+ end
68
+
69
+ def test_get_command_summary
70
+ base = UtilTestModule
71
+ command_name = 'test_command_with_options'
72
+ expected = "test_command_with_options - A test_command with an optional argument\n"
73
+ result = Rubycom::Documentation.get_command_summary(base, command_name)
74
+ assert_equal(expected.gsub(/\n|\r|\s/, ''), result.gsub(/\n|\r|\s/, ''))
75
+ end
76
+
77
+ def test_get_command_summary_no_command
78
+ base = UtilTestModule
79
+ command_name = ''
80
+ result = Rubycom::Documentation.get_command_summary(base, command_name)
81
+ assert_equal('No command specified.', result)
82
+ end
83
+
84
+ def test_get_command_summary_nil_base
85
+ base = nil
86
+ command_name = 'test_command_with_options'
87
+ assert_raise(Rubycom::CLIError) { Rubycom::Documentation.get_command_summary(base, command_name) }
88
+ end
89
+
90
+ def test_get_command_summary_nil_command
91
+ base = UtilTestModule
92
+ command_name = nil
93
+ result = Rubycom::Documentation.get_command_summary(base, command_name)
94
+ assert_equal('No command specified.', result)
95
+ end
96
+
97
+ def test_get_command_summary_wrong_base
98
+ base = UtilTestNoSingleton
99
+ command_name = 'test_command_with_options'
100
+ assert_raise(Rubycom::CLIError) { Rubycom::Documentation.get_command_summary(base, command_name) }
101
+ end
102
+
103
+ def test_get_command_summary_bad_command
104
+ base = UtilTestModule
105
+ command_name = '!_fail_command_'
106
+ assert_raise(Rubycom::CLIError) { Rubycom::Documentation.get_command_summary(base, command_name) }
107
+ end
108
+
109
+ def test_get_usage
110
+ base = UtilTestModule
111
+ result = Rubycom::Documentation.get_usage(base)
112
+ expected = <<-END.gsub(/^ {4}/, '')
113
+ Usage:
114
+ UtilTestModule <command> [args]
115
+
116
+ Commands:
117
+ test_command - A basic test command
118
+ test_command_no_docs
119
+ test_command_with_arg - A test_command with one arg
120
+ test_command_arg_named_arg - A test_command with an arg named arg
121
+ test_command_with_args - A test_command with two args
122
+ test_command_with_options - A test_command with an optional argument
123
+ test_command_all_options - A test_command with all optional arguments
124
+ test_command_options_arr - A test_command with an options array
125
+ test_command_with_return - A test_command with a return argument
126
+ test_command_arg_timestamp - A test_command with a Timestamp argument and an unnecessarily
127
+ long description which should overflow when
128
+ it tries to line up with other descriptions.
129
+ test_command_arg_false - A test_command with a Boolean argument
130
+ test_command_arg_arr - A test_command with an array argument
131
+ test_command_arg_hash - A test_command with an Hash argument
132
+ test_command_mixed_options - A test_command with several mixed options
133
+
134
+ END
135
+ assert_equal(expected.gsub(/\n|\r|\s/, ''), result.gsub(/\n|\r|\s/, ''))
136
+ end
137
+
138
+ def test_get_usage_nil_base
139
+ base = nil
140
+ result = Rubycom::Documentation.get_usage(base)
141
+ assert_equal('', result)
142
+ end
143
+
144
+ def test_get_usage_no_singleton_base
145
+ base = UtilTestNoSingleton
146
+ result = Rubycom::Documentation.get_usage(base)
147
+ assert_equal('', result)
148
+ end
149
+
150
+ def test_get_summary
151
+ base = UtilTestModule
152
+ result = Rubycom::Documentation.get_summary(base)
153
+ expected = <<-END.gsub(/^ {4}/, '')
154
+ Commands:
155
+ test_command - A basic test command
156
+ test_command_no_docs
157
+ test_command_with_arg - A test_command with one arg
158
+ test_command_arg_named_arg - A test_command with an arg named arg
159
+ test_command_with_args - A test_command with two args
160
+ test_command_with_options - A test_command with an optional argument
161
+ test_command_all_options - A test_command with all optional arguments
162
+ test_command_options_arr - A test_command with an options array
163
+ test_command_with_return - A test_command with a return argument
164
+ test_command_arg_timestamp - A test_command with a Timestamp argument and an unnecessarily
165
+ long description which should overflow when
166
+ it tries to line up with other descriptions.
167
+ test_command_arg_false - A test_command with a Boolean argument
168
+ test_command_arg_arr - A test_command with an array argument
169
+ test_command_arg_hash - A test_command with an Hash argument
170
+ test_command_mixed_options - A test_command with several mixed options
171
+ END
172
+ assert_equal(expected.gsub(/\n|\r|\s/, ''), result.gsub(/\n|\r|\s/, ''))
173
+ end
174
+
175
+ def test_get_summary_nil_base
176
+ base = nil
177
+ result = Rubycom::Documentation.get_summary(base)
178
+ assert_equal('No Commands found for .', result)
179
+ end
180
+
181
+ def test_get_summary_no_singleton_base
182
+ base = UtilTestNoSingleton
183
+ result = Rubycom::Documentation.get_summary(base)
184
+ assert_equal('No Commands found for UtilTestNoSingleton.', result)
185
+ end
186
+ end
@@ -0,0 +1,527 @@
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
+ tst_out = ''
285
+
286
+ def tst_out.write(data)
287
+ self << data
288
+ end
289
+
290
+ o_stdout, $stdout = $stdout, tst_out
291
+ o_stderr, $stderr = $stderr, tst_out
292
+
293
+ base = UtilTestModule
294
+ args = ["test_command_options_arr", "test_option1", "test_option2", 1.0, false]
295
+ result = Rubycom.run(base, args)
296
+
297
+ e_test_arg = 'test_option1'
298
+ e_test_options = ["test_option2", 1.0, false]
299
+ expected = nil
300
+ expected_out = "Output is test_option=#{e_test_arg},test_option_arr=#{e_test_options}\n"
301
+ assert_equal(expected, result)
302
+ assert_equal(expected_out.gsub(/\n|\r|\s/, ''), tst_out.gsub(/\n|\r|\s/, ''))
303
+ ensure
304
+ $stdout = o_stdout
305
+ $stderr = o_stderr
306
+ end
307
+
308
+ def test_run_missing_required_arg
309
+ tst_out = ''
310
+
311
+ def tst_out.puts(data)
312
+ self << data.to_s << "\n"
313
+ nil
314
+ end
315
+
316
+ def tst_out.write(data)
317
+ self << data
318
+ end
319
+
320
+ o_stdout, $stdout = $stdout, tst_out
321
+ o_stderr, $stderr = $stderr, tst_out
322
+
323
+ base = UtilTestModule
324
+ args = ["test_command_with_return", "-test_option_int=2"]
325
+ result = Rubycom.run(base, args)
326
+
327
+ expected = nil
328
+ expected_out = "No argument available for test_arg\n"
329
+
330
+ assert_equal(expected, result)
331
+ assert_equal(expected_out, tst_out.lines.first)
332
+ Rubycom::Documentation.get_command_usage(base,args[0],args[1..-1]).each_line{|expected_line|
333
+ assert_equal(true, tst_out.lines.include?(expected_line))
334
+ }
335
+ ensure
336
+ $stdout = o_stdout
337
+ $stderr = o_stderr
338
+ end
339
+
340
+ def test_run_composite
341
+ tst_out = ''
342
+
343
+ def tst_out.write(data)
344
+ self << data
345
+ end
346
+
347
+ o_stdout, $stdout = $stdout, tst_out
348
+ o_stderr, $stderr = $stderr, tst_out
349
+
350
+ base = UtilTestComposite
351
+ args = ["test_composite_command", "Hello Composite"]
352
+ result = Rubycom.run(base, args)
353
+
354
+ expected = "Hello Composite"
355
+ expected_out = "Hello Composite"
356
+ assert_equal(expected, result)
357
+ assert_equal(expected_out, tst_out.split(/\n|\r|\r\n/).first)
358
+ ensure
359
+ $stdout = o_stdout
360
+ $stderr = o_stderr
361
+ end
362
+
363
+ def test_full_run_mixed_args
364
+ mod = "util_test_module.rb"
365
+ command = "test_command_mixed_options"
366
+ args = "testing_arg \"[test1, test2]\" -test_opt='testing_option' \"{a: 'test_hsh_arg'}\" -test_bool=true some other args"
367
+ 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"
368
+ result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
369
+ assert_equal(expected, result)
370
+ end
371
+
372
+ def test_full_run_mixed_args_solid_arr
373
+ mod = "util_test_module.rb"
374
+ command = "test_command_mixed_options"
375
+ args = "testing_arg [test1,test2] -test_opt='testing_option' \"{a: 'test_hsh_arg'}\" some other args"
376
+ 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"
377
+ result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
378
+ assert_equal(expected, result)
379
+ end
380
+
381
+ def test_full_run_mixed_args_quoted_solid_arr
382
+ mod = "util_test_module.rb"
383
+ command = "test_command_mixed_options"
384
+ args = 'testing_arg "[test1,test2]" -test_opt="testing_option" "{a: "test_hsh_arg"}" -test_bool=false some other args'
385
+ 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"
386
+ result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
387
+ assert_equal(expected, result)
388
+ end
389
+
390
+ def test_full_run_mixed_args_odd_sp
391
+ mod = "util_test_module.rb"
392
+ command = "test_command_mixed_options"
393
+ args = 'testing_arg "[ test1 , test2 ]" -test_opt="testing_option" "{ a: "test_hsh_arg" }" -test_bool=false some other args'
394
+ 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"
395
+ result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
396
+ assert_equal(expected, result)
397
+ end
398
+
399
+ def test_full_run_mixed_args_hash_rocket
400
+ mod = "util_test_module.rb"
401
+ command = "test_command_mixed_options"
402
+ args = 'testing_arg "[ test1 , test2 ]" -test_opt="testing_option" "{ :a => "test_hsh_arg" }" false some other args'
403
+ 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"
404
+ result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
405
+ assert_equal(expected, result)
406
+ end
407
+
408
+ def test_full_run_mixed_args_no_rest
409
+ mod = "util_test_module.rb"
410
+ command = "test_command_mixed_options"
411
+ args = "testing_arg \"[test1, test2]\" -test_opt='testing_option' \"{a: 'test_hsh_arg'}\""
412
+ 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"
413
+ result = %x(ruby #{File.expand_path(File.dirname(__FILE__))}/#{mod} #{command} #{args})
414
+ assert_equal(expected, result)
415
+ end
416
+
417
+ def test_tab_complete_nil_arg
418
+ mod = UtilTestComposite
419
+ args = nil
420
+ expected = ["test_composite_command", "UtilTestNoSingleton", "UtilTestModule"]
421
+ result = Rubycom.tab_complete(mod, args)
422
+ assert_equal(expected, result)
423
+ end
424
+
425
+ def test_tab_complete_empty_arg
426
+ mod = UtilTestComposite
427
+ args = ['']
428
+ expected = ["test_composite_command", "UtilTestNoSingleton", "UtilTestModule"]
429
+ result = Rubycom.tab_complete(mod, args)
430
+ assert_equal(expected, result)
431
+ end
432
+
433
+ def test_tab_complete_partial_module
434
+ mod = UtilTestComposite
435
+ args = ['Util']
436
+ expected = ["UtilTestNoSingleton", "UtilTestModule"]
437
+ result = Rubycom.tab_complete(mod, args)
438
+ assert_equal(expected, result)
439
+ end
440
+
441
+ def test_tab_complete_partial_module_single_match
442
+ mod = UtilTestComposite
443
+ args = ['UtilTestM']
444
+ expected = ["UtilTestModule"]
445
+ result = Rubycom.tab_complete(mod, args)
446
+ assert_equal(expected, result)
447
+ end
448
+
449
+ def test_tab_complete_whole_module
450
+ mod = UtilTestComposite
451
+ args = ['UtilTestModule']
452
+ expected = ["test_command",
453
+ "test_command_no_docs",
454
+ "test_command_with_arg",
455
+ "test_command_arg_named_arg",
456
+ "test_command_with_args",
457
+ "test_command_with_options",
458
+ "test_command_all_options",
459
+ "test_command_options_arr",
460
+ "test_command_with_return",
461
+ "test_command_arg_timestamp",
462
+ "test_command_arg_false",
463
+ "test_command_arg_arr",
464
+ "test_command_arg_hash",
465
+ "test_command_mixed_options"]
466
+ result = Rubycom.tab_complete(mod, args)
467
+ assert_equal(expected, result)
468
+ end
469
+
470
+ def test_tab_complete_empty_sub_command
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_partial_sub_command
492
+ mod = UtilTestComposite
493
+ args = ['UtilTestModule', 'test_command_ar']
494
+ expected = ["test_command_arg_named_arg",
495
+ "test_command_arg_timestamp",
496
+ "test_command_arg_false",
497
+ "test_command_arg_arr",
498
+ "test_command_arg_hash"]
499
+ result = Rubycom.tab_complete(mod, args)
500
+ assert_equal(expected, result)
501
+ end
502
+
503
+ def test_tab_complete_whole_sub_command_single_match
504
+ mod = UtilTestComposite
505
+ args = ['UtilTestModule', 'test_command_with_options']
506
+ expected = ['']
507
+ result = Rubycom.tab_complete(mod, args)
508
+ assert_equal(expected, result)
509
+ end
510
+
511
+ def test_tab_complete_whole_sub_command_multi_match
512
+ mod = UtilTestComposite
513
+ args = ['UtilTestModule', 'test_command_with_arg']
514
+ expected = ['']
515
+ result = Rubycom.tab_complete(mod, args)
516
+ assert_equal(expected, result)
517
+ end
518
+
519
+ def test_tab_complete_whole_sub_command_with_empty
520
+ mod = UtilTestComposite
521
+ args = ['UtilTestModule', 'test_command_with_args', '']
522
+ expected = ['']
523
+ result = Rubycom.tab_complete(mod, args)
524
+ assert_equal(expected, result)
525
+ end
526
+
527
+ end