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.
- 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,293 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../../lib/rubycom/command_interface.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 CommandInterfaceTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_build_interface_nil_command
|
12
|
+
test_command = nil
|
13
|
+
test_doc = {
|
14
|
+
:short_doc => "A command module used for testing.",
|
15
|
+
:full_doc => "A command module used for testing\n\nThis module contains most of the test case input methods.",
|
16
|
+
:sub_command_docs => {
|
17
|
+
:non_command => "A test non-command method.",
|
18
|
+
:test_command => "A basic test command.",
|
19
|
+
:test_command_no_docs => "",
|
20
|
+
:test_command_with_arg => "A test_command with one arg.",
|
21
|
+
:test_command_arg_named_arg => "A test_command with an arg named arg.",
|
22
|
+
:test_command_with_args => "A test_command with two args.",
|
23
|
+
:test_command_with_options => "A test_command with an optional argument.",
|
24
|
+
:test_command_all_options => "A test_command with all optional arguments.",
|
25
|
+
:test_command_options_arr => "A test_command with an options array.",
|
26
|
+
:test_command_with_return => "A test_command with a return argument.",
|
27
|
+
:test_command_arg_timestamp => "A test_command with a Timestamp argument and an unnecessarily long description which should overflow when it tries to line up with other descriptions.",
|
28
|
+
:test_command_arg_false => "A test_command with a Boolean argument.",
|
29
|
+
:test_command_arg_arr => "A test_command with an array argument.",
|
30
|
+
:test_command_arg_hash => "A test_command with an Hash argument.",
|
31
|
+
:test_command_mixed_options => "A test_command with several mixed options."
|
32
|
+
}
|
33
|
+
}
|
34
|
+
result = nil
|
35
|
+
assert_raise(ArgumentError) { result = Rubycom::CommandInterface.build_interface(test_command, test_doc) }
|
36
|
+
|
37
|
+
assert_equal(nil, result, "#{result} should be nil")
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_build_interface_nil_doc
|
41
|
+
test_command = UtilTestModule
|
42
|
+
test_doc = nil
|
43
|
+
result = nil
|
44
|
+
assert_raise(ArgumentError) { result = Rubycom::CommandInterface.build_interface(test_command, test_doc) }
|
45
|
+
|
46
|
+
assert_equal(nil, result, "#{result} should be nil")
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_build_interface_empty_doc
|
50
|
+
test_command = UtilTestModule
|
51
|
+
test_doc = {}
|
52
|
+
result = Rubycom::CommandInterface.build_interface(test_command, test_doc)
|
53
|
+
|
54
|
+
assert_equal(result.gsub(/\s|\n|\r\n/,''), "Usage:UtilTestModule<command>[args]Description:","#{result} should be empty")
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_build_interface_module
|
58
|
+
test_command = UtilTestModule
|
59
|
+
test_doc = {
|
60
|
+
:short_doc => "A command module used for testing.",
|
61
|
+
:full_doc => "A command module used for testing\n\nThis module contains most of the test case input methods.",
|
62
|
+
:sub_command_docs => {
|
63
|
+
:non_command => "A test non-command method.",
|
64
|
+
:test_command => "A basic test command.",
|
65
|
+
:test_command_no_docs => "",
|
66
|
+
:test_command_with_arg => "A test_command with one arg.",
|
67
|
+
:test_command_arg_named_arg => "A test_command with an arg named arg.",
|
68
|
+
:test_command_with_args => "A test_command with two args.",
|
69
|
+
:test_command_with_options => "A test_command with an optional argument.",
|
70
|
+
:test_command_all_options => "A test_command with all optional arguments.",
|
71
|
+
:test_command_options_arr => "A test_command with an options array.",
|
72
|
+
:test_command_with_return => "A test_command with a return argument.",
|
73
|
+
:test_command_arg_timestamp => "A test_command with a Timestamp argument and an unnecessarily long description which should overflow when it tries to line up with other descriptions.",
|
74
|
+
:test_command_arg_false => "A test_command with a Boolean argument.",
|
75
|
+
:test_command_arg_arr => "A test_command with an array argument.",
|
76
|
+
:test_command_arg_hash => "A test_command with an Hash argument.",
|
77
|
+
:test_command_mixed_options => "A test_command with several mixed options."
|
78
|
+
}
|
79
|
+
}
|
80
|
+
result = Rubycom::CommandInterface.build_interface(test_command, test_doc)
|
81
|
+
|
82
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(test_doc[:full_doc].gsub(/\s|\n|\r\n/,'')),"#{result} should include #{test_doc[:full_doc]}")
|
83
|
+
test_doc[:sub_command_docs].each{|cmd,doc|
|
84
|
+
assert(result.include?(cmd.to_s),"#{result} should include #{cmd.to_s}")
|
85
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(doc.gsub(/\s|\n|\r\n/,'')),"#{result} should include #{doc}")
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_build_interface_method
|
90
|
+
test_command = UtilTestModule.public_method(:test_command_with_return)
|
91
|
+
test_doc = {
|
92
|
+
:full_doc => "A test_command with a return argument",
|
93
|
+
:short_doc => "A test_command with a return argument.",
|
94
|
+
:parameters => [
|
95
|
+
{:default => nil, :doc => "a test argument", :doc_type => "String", :param_name => "test_arg", :type => :req},
|
96
|
+
{:default => 1, :doc => "an optional test argument which happens to be an Integer", :doc_type => "Integer", :param_name => "test_option_int", :type => :opt }
|
97
|
+
],
|
98
|
+
:tags => [
|
99
|
+
{:name => "test_arg", :tag_name => "param", :text => "a test argument", :types => ["String"]},
|
100
|
+
{:name => "test_option_int", :tag_name => "param", :text => "an optional test argument which happens to be an Integer", :types => ["Integer"]},
|
101
|
+
{:name => nil, :tag_name => "return", :text => "an array including both params if test_option_int != 1", :types => ["Array"]},
|
102
|
+
{:name => nil, :tag_name => "return", :text => "a the first param if test_option_int == 1", :types => ["String"]}
|
103
|
+
]
|
104
|
+
}
|
105
|
+
result = Rubycom::CommandInterface.build_interface(test_command, test_doc)
|
106
|
+
|
107
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(test_doc[:full_doc].gsub(/\s|\n|\r\n/,'')),"#{result} should include #{test_doc[:full_doc]}")
|
108
|
+
test_doc[:tags].each{|tag|
|
109
|
+
if tag[:name].nil?
|
110
|
+
assert(result.include?(tag[:tag_name].to_s),"#{result} should include #{tag[:tag_name].to_s}")
|
111
|
+
else
|
112
|
+
assert(result.include?(tag[:name].to_s),"#{result} should include #{tag[:name].to_s}")
|
113
|
+
end
|
114
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?("#{tag[:types]}"),"#{result} should include #{tag[:types]}")
|
115
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(tag[:text].gsub(/\s|\n|\r\n/,'')),"#{result} should include #{tag[:text]}")
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_build_usage_module
|
120
|
+
test_command = UtilTestModule
|
121
|
+
test_doc = {
|
122
|
+
:short_doc => "A command module used for testing.",
|
123
|
+
:full_doc => "A command module used for testing\n\nThis module contains most of the test case input methods.",
|
124
|
+
:sub_command_docs => {
|
125
|
+
:non_command => "A test non-command method.",
|
126
|
+
:test_command => "A basic test command.",
|
127
|
+
:test_command_no_docs => "",
|
128
|
+
:test_command_with_arg => "A test_command with one arg.",
|
129
|
+
:test_command_arg_named_arg => "A test_command with an arg named arg.",
|
130
|
+
:test_command_with_args => "A test_command with two args.",
|
131
|
+
:test_command_with_options => "A test_command with an optional argument.",
|
132
|
+
:test_command_all_options => "A test_command with all optional arguments.",
|
133
|
+
:test_command_options_arr => "A test_command with an options array.",
|
134
|
+
:test_command_with_return => "A test_command with a return argument.",
|
135
|
+
:test_command_arg_timestamp => "A test_command with a Timestamp argument and an unnecessarily long description which should overflow when it tries to line up with other descriptions.",
|
136
|
+
:test_command_arg_false => "A test_command with a Boolean argument.",
|
137
|
+
:test_command_arg_arr => "A test_command with an array argument.",
|
138
|
+
:test_command_arg_hash => "A test_command with an Hash argument.",
|
139
|
+
:test_command_mixed_options => "A test_command with several mixed options."
|
140
|
+
}
|
141
|
+
}
|
142
|
+
result = Rubycom::CommandInterface.build_usage(test_command, test_doc)
|
143
|
+
|
144
|
+
assert(result.include?(test_command.to_s),"#{result} should include #{test_command.to_s}")
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_build_usage_method
|
148
|
+
test_command = UtilTestModule.public_method(:test_command_with_return)
|
149
|
+
test_doc = {
|
150
|
+
:full_doc => "A test_command with a return argument",
|
151
|
+
:short_doc => "A test_command with a return argument.",
|
152
|
+
:parameters => [
|
153
|
+
{:default => nil, :doc => "a test argument", :doc_type => "String", :param_name => "test_arg", :type => :req},
|
154
|
+
{:default => 1, :doc => "an optional test argument which happens to be an Integer", :doc_type => "Integer", :param_name => "test_option_int", :type => :opt}
|
155
|
+
],
|
156
|
+
:tags => [
|
157
|
+
{:name => "test_arg", :tag_name => "param", :text => "a test argument", :types => ["String"]},
|
158
|
+
{:name => "test_option_int", :tag_name => "param", :text => "an optional test argument which happens to be an Integer", :types => ["Integer"]},
|
159
|
+
{:name => nil, :tag_name => "return", :text => "an array including both params if test_option_int != 1", :types => ["Array"]},
|
160
|
+
{:name => nil, :tag_name => "return", :text => "the first param if test_option_int == 1", :types => ["String"]}
|
161
|
+
]
|
162
|
+
}
|
163
|
+
result = Rubycom::CommandInterface.build_usage(test_command, test_doc)
|
164
|
+
|
165
|
+
assert(result.include?(test_command.name.to_s),"#{result} should include #{test_command.name.to_s}")
|
166
|
+
test_doc[:parameters].each{|param|
|
167
|
+
if param[:type] == :req
|
168
|
+
assert(result.include?("<#{param[:param_name]}>"),"#{result} should include <#{param[:param_name]}>")
|
169
|
+
else
|
170
|
+
assert(result.include?(param[:param_name]),"#{result} should include #{param[:param_name]}")
|
171
|
+
end
|
172
|
+
}
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_build_options_module
|
176
|
+
test_command = UtilTestModule
|
177
|
+
test_doc = {
|
178
|
+
:short_doc => "A command module used for testing.",
|
179
|
+
:full_doc => "A command module used for testing\n\nThis module contains most of the test case input methods.",
|
180
|
+
:sub_command_docs => {
|
181
|
+
:non_command => "A test non-command method.",
|
182
|
+
:test_command => "A basic test command.",
|
183
|
+
:test_command_no_docs => "",
|
184
|
+
:test_command_with_arg => "A test_command with one arg.",
|
185
|
+
:test_command_arg_named_arg => "A test_command with an arg named arg.",
|
186
|
+
:test_command_with_args => "A test_command with two args.",
|
187
|
+
:test_command_with_options => "A test_command with an optional argument.",
|
188
|
+
:test_command_all_options => "A test_command with all optional arguments.",
|
189
|
+
:test_command_options_arr => "A test_command with an options array.",
|
190
|
+
:test_command_with_return => "A test_command with a return argument.",
|
191
|
+
:test_command_arg_timestamp => "A test_command with a Timestamp argument and an unnecessarily long description which should overflow when it tries to line up with other descriptions.",
|
192
|
+
:test_command_arg_false => "A test_command with a Boolean argument.",
|
193
|
+
:test_command_arg_arr => "A test_command with an array argument.",
|
194
|
+
:test_command_arg_hash => "A test_command with an Hash argument.",
|
195
|
+
:test_command_mixed_options => "A test_command with several mixed options."
|
196
|
+
}
|
197
|
+
}
|
198
|
+
result = Rubycom::CommandInterface.build_options(test_command, test_doc)
|
199
|
+
|
200
|
+
assert(result.include?("<command>"),"#{result} should include <command>")
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_build_options_method
|
204
|
+
test_command = UtilTestModule.public_method(:test_command_with_return)
|
205
|
+
test_doc = {
|
206
|
+
:full_doc => "A test_command with a return argument",
|
207
|
+
:short_doc => "A test_command with a return argument.",
|
208
|
+
:parameters => [
|
209
|
+
{:default => nil, :doc => "a test argument", :doc_type => "String", :param_name => "test_arg", :type => :req},
|
210
|
+
{:default => 1, :doc => "an optional test argument which happens to be an Integer", :doc_type => "Integer", :param_name => "test_option_int", :type => :opt}
|
211
|
+
],
|
212
|
+
:tags => [
|
213
|
+
{:name => "test_arg", :tag_name => "param", :text => "a test argument", :types => ["String"]},
|
214
|
+
{:name => "test_option_int", :tag_name => "param", :text => "an optional test argument which happens to be an Integer", :types => ["Integer"]},
|
215
|
+
{:name => nil, :tag_name => "return", :text => "an array including both params if test_option_int != 1", :types => ["Array"]},
|
216
|
+
{:name => nil, :tag_name => "return", :text => "the first param if test_option_int == 1", :types => ["String"]}
|
217
|
+
]
|
218
|
+
}
|
219
|
+
result = Rubycom::CommandInterface.build_options(test_command, test_doc)
|
220
|
+
|
221
|
+
test_doc[:parameters].each{|param|
|
222
|
+
if param[:type] == :req
|
223
|
+
assert(result.include?("<#{param[:param_name]}>"),"#{result} should include <#{param[:param_name]}>")
|
224
|
+
else
|
225
|
+
assert(result.include?(param[:param_name]),"#{result} should include #{param[:param_name]}")
|
226
|
+
end
|
227
|
+
}
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_build_details_module
|
231
|
+
test_command = UtilTestModule
|
232
|
+
test_doc = {
|
233
|
+
:short_doc => "A command module used for testing.",
|
234
|
+
:full_doc => "A command module used for testing\n\nThis module contains most of the test case input methods.",
|
235
|
+
:sub_command_docs => {
|
236
|
+
:non_command => "A test non-command method.",
|
237
|
+
:test_command => "A basic test command.",
|
238
|
+
:test_command_no_docs => "",
|
239
|
+
:test_command_with_arg => "A test_command with one arg.",
|
240
|
+
:test_command_arg_named_arg => "A test_command with an arg named arg.",
|
241
|
+
:test_command_with_args => "A test_command with two args.",
|
242
|
+
:test_command_with_options => "A test_command with an optional argument.",
|
243
|
+
:test_command_all_options => "A test_command with all optional arguments.",
|
244
|
+
:test_command_options_arr => "A test_command with an options array.",
|
245
|
+
:test_command_with_return => "A test_command with a return argument.",
|
246
|
+
:test_command_arg_timestamp => "A test_command with a Timestamp argument and an unnecessarily long description which should overflow when it tries to line up with other descriptions.",
|
247
|
+
:test_command_arg_false => "A test_command with a Boolean argument.",
|
248
|
+
:test_command_arg_arr => "A test_command with an array argument.",
|
249
|
+
:test_command_arg_hash => "A test_command with an Hash argument.",
|
250
|
+
:test_command_mixed_options => "A test_command with several mixed options."
|
251
|
+
}
|
252
|
+
}
|
253
|
+
result = Rubycom::CommandInterface.build_details(test_command, test_doc)
|
254
|
+
|
255
|
+
assert(result.include?("Sub Commands:"),"#{result} should include Sub Commands:")
|
256
|
+
test_doc[:sub_command_docs].each{|cmd,doc|
|
257
|
+
assert(result.include?(cmd.to_s),"#{result} should include #{cmd.to_s}")
|
258
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(doc.gsub(/\s|\n|\r\n/,'')),"#{result} should include #{doc}")
|
259
|
+
}
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_build_details_method
|
263
|
+
test_command = UtilTestModule.public_method(:test_command_with_return)
|
264
|
+
test_doc = {
|
265
|
+
:full_doc => "A test_command with a return argument",
|
266
|
+
:short_doc => "A test_command with a return argument.",
|
267
|
+
:parameters => [
|
268
|
+
{:default => nil, :doc => "a test argument", :doc_type => "String", :param_name => "test_arg", :required => true},
|
269
|
+
{:default => 1, :doc => "an optional test argument which happens to be an Integer", :doc_type => "Integer", :param_name => "test_option_int", :required => false}
|
270
|
+
],
|
271
|
+
:tags => [
|
272
|
+
{:name => "test_arg", :tag_name => "param", :text => "a test argument", :types => ["String"]},
|
273
|
+
{:name => "test_option_int", :tag_name => "param", :text => "an optional test argument which happens to be an Integer", :types => ["Integer"]},
|
274
|
+
{:name => nil, :tag_name => "return", :text => "an array including both params if test_option_int != 1", :types => ["Array"]},
|
275
|
+
{:name => nil, :tag_name => "return", :text => "the first param if test_option_int == 1", :types => ["String"]}
|
276
|
+
]
|
277
|
+
}
|
278
|
+
result = Rubycom::CommandInterface.build_details(test_command, test_doc)
|
279
|
+
|
280
|
+
assert(result.include?("Parameters:"),"#{result} should include Parameters:")
|
281
|
+
assert(result.include?("Returns:"),"#{result} should include Returns:")
|
282
|
+
test_doc[:tags].each{|tag|
|
283
|
+
if tag[:name].nil?
|
284
|
+
assert(result.include?(tag[:tag_name].to_s),"#{result} should include #{tag[:tag_name].to_s}")
|
285
|
+
else
|
286
|
+
assert(result.include?(tag[:name].to_s),"#{result} should include #{tag[:name].to_s}")
|
287
|
+
end
|
288
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?("#{tag[:types]}"),"#{result} should include #{tag[:types]}")
|
289
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(tag[:text].gsub(/\s|\n|\r\n/,'')),"#{result} should include #{tag[:text]}")
|
290
|
+
}
|
291
|
+
end
|
292
|
+
|
293
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../../lib/rubycom/completions.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 CompletionsTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_tab_complete_nil
|
12
|
+
base = nil
|
13
|
+
arguments = nil
|
14
|
+
command_plugin = nil
|
15
|
+
result = Rubycom::Completions.tab_complete(base, arguments, command_plugin)
|
16
|
+
expected = []
|
17
|
+
assert_equal(expected, result)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_tab_complete_empty
|
21
|
+
base = ''
|
22
|
+
arguments = []
|
23
|
+
command_plugin = Rubycom::SingletonCommands
|
24
|
+
result = Rubycom::Completions.tab_complete(base, arguments, command_plugin)
|
25
|
+
expected = []
|
26
|
+
assert_equal(expected, result)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_tab_complete_command_empty
|
30
|
+
base = UtilTestModule
|
31
|
+
arguments = []
|
32
|
+
command_plugin = Rubycom::SingletonCommands
|
33
|
+
result = Rubycom::Completions.tab_complete(base, arguments, command_plugin)
|
34
|
+
expected = UtilTestModule.singleton_methods(false).map{|n|n.to_s}
|
35
|
+
assert_equal(expected, result)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_tab_complete_command_single_match
|
39
|
+
base = UtilTestModule
|
40
|
+
arguments = ['test_command']
|
41
|
+
command_plugin = Rubycom::SingletonCommands
|
42
|
+
result = Rubycom::Completions.tab_complete(base, arguments, command_plugin)
|
43
|
+
expected = []
|
44
|
+
assert_equal(expected, result)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_tab_complete_command_all_match
|
48
|
+
base = UtilTestModule
|
49
|
+
arguments = ['test_']
|
50
|
+
command_plugin = Rubycom::SingletonCommands
|
51
|
+
result = Rubycom::Completions.tab_complete(base, arguments, command_plugin)
|
52
|
+
expected = UtilTestModule.singleton_methods(false).map{|n|n.to_s}
|
53
|
+
assert_equal(expected, result)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_tab_complete_command_partial_match
|
57
|
+
base = UtilTestModule
|
58
|
+
arguments = ['test_command_with']
|
59
|
+
command_plugin = Rubycom::SingletonCommands
|
60
|
+
result = Rubycom::Completions.tab_complete(base, arguments, command_plugin)
|
61
|
+
expected = UtilTestModule.singleton_methods(false).map{|n|n.to_s}.select{|n|n.start_with?(arguments[0])}
|
62
|
+
assert_equal(expected, result)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_tab_complete_module_empty
|
66
|
+
base = UtilTestComposite
|
67
|
+
arguments = []
|
68
|
+
command_plugin = Rubycom::SingletonCommands
|
69
|
+
result = Rubycom::Completions.tab_complete(base, arguments, command_plugin)
|
70
|
+
expected = UtilTestComposite.singleton_methods(false).map{|n|n.to_s}+
|
71
|
+
UtilTestComposite.included_modules.reject{|n|n == Rubycom}.map{|n|n.to_s}
|
72
|
+
assert_equal(expected, result)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_tab_complete_module_partial_match
|
76
|
+
base = UtilTestComposite
|
77
|
+
arguments = ['Util']
|
78
|
+
command_plugin = Rubycom::SingletonCommands
|
79
|
+
result = Rubycom::Completions.tab_complete(base, arguments, command_plugin)
|
80
|
+
expected = UtilTestComposite.included_modules.reject{|n|n == Rubycom}.map{|n|n.to_s}
|
81
|
+
assert_equal(expected, result)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_tab_complete_module_single_match
|
85
|
+
base = UtilTestComposite
|
86
|
+
arguments = ['UtilTestModule']
|
87
|
+
command_plugin = Rubycom::SingletonCommands
|
88
|
+
result = Rubycom::Completions.tab_complete(base, arguments, command_plugin)
|
89
|
+
expected = UtilTestModule.singleton_methods(false).map{|n|n.to_s}
|
90
|
+
assert_equal(expected, result)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../../lib/rubycom/error_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 ErrorHandlerTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def capture_err(&block)
|
12
|
+
original_stderr = $stderr
|
13
|
+
$stderr = fake = StringIO.new
|
14
|
+
begin
|
15
|
+
yield
|
16
|
+
ensure
|
17
|
+
$stderr = original_stderr
|
18
|
+
end
|
19
|
+
fake.string
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_handle_error
|
23
|
+
test_error = StandardError.new("test error")
|
24
|
+
test_cli_output = 'some test output'
|
25
|
+
|
26
|
+
result = capture_err { Rubycom::ErrorHandler.handle_error(test_error, test_cli_output) }
|
27
|
+
|
28
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(test_error.to_s.gsub(/\s|\n|\r\n/,'')),"#{result} should include #{test_error.to_s}")
|
29
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(test_cli_output.gsub(/\s|\n|\r\n/,'')),"#{result} should include #{test_cli_output}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_handle_error_string
|
33
|
+
test_error = 'test error string'
|
34
|
+
test_cli_output = 'some test output'
|
35
|
+
|
36
|
+
result = capture_err { Rubycom::ErrorHandler.handle_error(test_error, test_cli_output) }
|
37
|
+
|
38
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(test_error.to_s.gsub(/\s|\n|\r\n/,'')),"#{result} should include #{test_error.to_s}")
|
39
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(test_cli_output.gsub(/\s|\n|\r\n/,'')),"#{result} should include #{test_cli_output}")
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_handle_error_nil
|
43
|
+
test_error = nil
|
44
|
+
test_cli_output = nil
|
45
|
+
|
46
|
+
result = capture_err { Rubycom::ErrorHandler.handle_error(test_error, test_cli_output) }
|
47
|
+
|
48
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(test_error.to_s.gsub(/\s|\n|\r\n/,'')),"#{result} should include #{test_error.to_s}")
|
49
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(test_cli_output.to_s.gsub(/\s|\n|\r\n/,'')),"#{result} should include #{test_cli_output}")
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_handle_error_empty
|
53
|
+
test_error = ''
|
54
|
+
test_cli_output = ''
|
55
|
+
|
56
|
+
result = capture_err { Rubycom::ErrorHandler.handle_error(test_error, test_cli_output) }
|
57
|
+
|
58
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(test_error.to_s.gsub(/\s|\n|\r\n/,'')),"#{result} should include #{test_error.to_s}")
|
59
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(test_cli_output.gsub(/\s|\n|\r\n/,'')),"#{result} should include #{test_cli_output}")
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_handle_error_object
|
63
|
+
test_error = Object.new
|
64
|
+
test_cli_output = Object.new
|
65
|
+
|
66
|
+
result = capture_err { Rubycom::ErrorHandler.handle_error(test_error, test_cli_output) }
|
67
|
+
|
68
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(test_error.to_s.gsub(/\s|\n|\r\n/,'')),"#{result} should include #{test_error.to_s}")
|
69
|
+
assert(result.gsub(/\s|\n|\r\n/,'').include?(test_cli_output.to_s.gsub(/\s|\n|\r\n/,'')),"#{result} should include #{test_cli_output}")
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|