zentest-without-autotest 4.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +21 -0
- data/.gitignore +1 -0
- data/History.txt +631 -0
- data/README.markdown +96 -0
- data/Rakefile +70 -0
- data/VERSION +1 -0
- data/bin/multigem +4 -0
- data/bin/multiruby +50 -0
- data/bin/multiruby_setup +73 -0
- data/bin/zentest +28 -0
- data/example_dot_autotest.rb +12 -0
- data/lib/focus.rb +21 -0
- data/lib/functional_test_matrix.rb +92 -0
- data/lib/multiruby.rb +426 -0
- data/lib/zentest.rb +576 -0
- data/lib/zentest_mapping.rb +117 -0
- data/test/helper.rb +6 -0
- data/test/test_focus.rb +34 -0
- data/test/test_zentest.rb +560 -0
- data/test/test_zentest_mapping.rb +238 -0
- data/zentest-without-autotest.gemspec +62 -0
- metadata +81 -0
@@ -0,0 +1,117 @@
|
|
1
|
+
##
|
2
|
+
# ZenTestMapping - mapping method names from impl to test.
|
3
|
+
#
|
4
|
+
# Method names are mapped bidirectionally in the following way:
|
5
|
+
#
|
6
|
+
# method test_method
|
7
|
+
# method? test_method_eh (too much exposure to Canadians :)
|
8
|
+
# method! test_method_bang
|
9
|
+
# method= test_method_equals
|
10
|
+
# [] test_index
|
11
|
+
# * test_times
|
12
|
+
# == test_equals2
|
13
|
+
# === test_equals3
|
14
|
+
#
|
15
|
+
# Further, any of the test methods should be able to have arbitrary
|
16
|
+
# extensions put on the name to distinguish edge cases:
|
17
|
+
#
|
18
|
+
# method test_method
|
19
|
+
# method test_method_simple
|
20
|
+
# method test_method_no_network
|
21
|
+
#
|
22
|
+
# To allow for unmapped test methods (ie, non-unit tests), name them:
|
23
|
+
#
|
24
|
+
# test_integration_.*
|
25
|
+
|
26
|
+
module ZenTestMapping
|
27
|
+
|
28
|
+
@@orig_method_map = {
|
29
|
+
'!' => 'bang',
|
30
|
+
'%' => 'percent',
|
31
|
+
'&' => 'and',
|
32
|
+
'*' => 'times',
|
33
|
+
'**' => 'times2',
|
34
|
+
'+' => 'plus',
|
35
|
+
'-' => 'minus',
|
36
|
+
'/' => 'div',
|
37
|
+
'<' => 'lt',
|
38
|
+
'<=' => 'lte',
|
39
|
+
'<=>' => 'spaceship',
|
40
|
+
"<\<" => 'lt2',
|
41
|
+
'==' => 'equals2',
|
42
|
+
'===' => 'equals3',
|
43
|
+
'=~' => 'equalstilde',
|
44
|
+
'>' => 'gt',
|
45
|
+
'>=' => 'ge',
|
46
|
+
'>>' => 'gt2',
|
47
|
+
'+@' => 'unary_plus',
|
48
|
+
'-@' => 'unary_minus',
|
49
|
+
'[]' => 'index',
|
50
|
+
'[]=' => 'index_equals',
|
51
|
+
'^' => 'carat',
|
52
|
+
'|' => 'or',
|
53
|
+
'~' => 'tilde',
|
54
|
+
}
|
55
|
+
|
56
|
+
@@method_map = @@orig_method_map.merge(@@orig_method_map.invert)
|
57
|
+
|
58
|
+
@@mapped_re = @@orig_method_map.values.sort_by { |k| k.length }.map {|s|
|
59
|
+
Regexp.escape(s)
|
60
|
+
}.reverse.join("|")
|
61
|
+
|
62
|
+
def munge name
|
63
|
+
name = name.to_s.dup
|
64
|
+
|
65
|
+
is_cls_method = name.sub!(/^self\./, '')
|
66
|
+
|
67
|
+
name = @@method_map[name] if @@method_map.has_key? name
|
68
|
+
name = name.sub(/=$/, '_equals')
|
69
|
+
name = name.sub(/\?$/, '_eh')
|
70
|
+
name = name.sub(/\!$/, '_bang')
|
71
|
+
|
72
|
+
name = yield name if block_given?
|
73
|
+
|
74
|
+
name = "class_" + name if is_cls_method
|
75
|
+
|
76
|
+
name
|
77
|
+
end
|
78
|
+
|
79
|
+
# Generates a test method name from a normal method,
|
80
|
+
# taking into account names composed of metacharacters
|
81
|
+
# (used for arithmetic, etc
|
82
|
+
def normal_to_test name
|
83
|
+
"test_#{munge name}"
|
84
|
+
end
|
85
|
+
|
86
|
+
def unmunge name
|
87
|
+
name = name.to_s.dup
|
88
|
+
|
89
|
+
is_cls_method = name.sub!(/^class_/, '')
|
90
|
+
|
91
|
+
name = name.sub(/_equals(_.*)?$/, '=') unless name =~ /index/
|
92
|
+
name = name.sub(/_bang(_.*)?$/, '!')
|
93
|
+
name = name.sub(/_eh(_.*)?$/, '?')
|
94
|
+
name = name.sub(/^(#{@@mapped_re})(_.*)?$/) {$1}
|
95
|
+
name = yield name if block_given?
|
96
|
+
name = @@method_map[name] if @@method_map.has_key? name
|
97
|
+
name = 'self.' + name if is_cls_method
|
98
|
+
|
99
|
+
name
|
100
|
+
end
|
101
|
+
|
102
|
+
# Converts a method name beginning with test to its
|
103
|
+
# corresponding normal method name, taking into account
|
104
|
+
# symbolic names which may have been anglicised by
|
105
|
+
# #normal_to_test().
|
106
|
+
def test_to_normal(name, klassname=nil)
|
107
|
+
unmunge(name.to_s.sub(/^test_/, '')) do |n|
|
108
|
+
if defined? @inherited_methods then
|
109
|
+
known_methods = (@inherited_methods[klassname] || {}).keys.sort.reverse
|
110
|
+
known_methods_re = known_methods.map {|s| Regexp.escape(s) }.join("|")
|
111
|
+
n = n.sub(/^(#{known_methods_re})(_.*)?$/) { $1 } unless
|
112
|
+
known_methods_re.empty?
|
113
|
+
n
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/test/helper.rb
ADDED
data/test/test_focus.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test/helper'
|
2
|
+
require 'focus'
|
3
|
+
|
4
|
+
class TestFocus < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@x = 1
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
assert_equal 2, @x
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_focus
|
14
|
+
@x += 1
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_ignore1
|
18
|
+
flunk "ignore me!"
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_ignore2
|
22
|
+
flunk "ignore me!"
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_ignore3
|
26
|
+
flunk "ignore me!"
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_focus2
|
30
|
+
@x += 1
|
31
|
+
end
|
32
|
+
|
33
|
+
focus :test_focus, :test_focus2
|
34
|
+
end
|
@@ -0,0 +1,560 @@
|
|
1
|
+
abort "rubinius does not support features required by zentest" if
|
2
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
|
3
|
+
|
4
|
+
require 'test/helper'
|
5
|
+
# I do this so I can still run ZenTest against the tests and itself...
|
6
|
+
require 'zentest' unless defined? $ZENTEST
|
7
|
+
|
8
|
+
# These are just classes set up for quick testing.
|
9
|
+
# TODO: need to test a compound class name Mod::Cls
|
10
|
+
|
11
|
+
class Cls1 # ZenTest SKIP
|
12
|
+
def meth1; end
|
13
|
+
def self.meth2; end
|
14
|
+
end
|
15
|
+
|
16
|
+
class TestCls1 # ZenTest SKIP
|
17
|
+
def setup; end
|
18
|
+
def teardown; end
|
19
|
+
def test_meth1; end
|
20
|
+
def test_meth2; assert(true, "something"); end
|
21
|
+
end
|
22
|
+
|
23
|
+
class SuperDuper # ZenTest SKIP
|
24
|
+
def self.cls_inherited; end
|
25
|
+
def inherited; end
|
26
|
+
def overridden; end
|
27
|
+
end
|
28
|
+
|
29
|
+
class LowlyOne < SuperDuper # ZenTest SKIP
|
30
|
+
def self.cls_extended; end
|
31
|
+
def overridden; end
|
32
|
+
def extended; end
|
33
|
+
def pretty_print; end
|
34
|
+
def pretty_print_cycle; end
|
35
|
+
end
|
36
|
+
|
37
|
+
# This is the good case where there are no missing methods on either side.
|
38
|
+
|
39
|
+
class Blah0
|
40
|
+
def missingtest; end
|
41
|
+
def notmissing1; end
|
42
|
+
def notmissing2; end
|
43
|
+
|
44
|
+
# found by zentest on testcase1.rb
|
45
|
+
def missingimpl; end
|
46
|
+
end
|
47
|
+
|
48
|
+
class TestBlah0
|
49
|
+
def setup; end
|
50
|
+
def teardown; end
|
51
|
+
|
52
|
+
def test_notmissing1
|
53
|
+
assert(true, "a test")
|
54
|
+
end
|
55
|
+
def test_notmissing2_ext1
|
56
|
+
assert(true, "a test")
|
57
|
+
end
|
58
|
+
def test_notmissing2_ext2
|
59
|
+
flunk("a failed test")
|
60
|
+
end
|
61
|
+
def test_missingimpl; end
|
62
|
+
def test_missingtest; end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Blah1
|
66
|
+
def missingtest; end
|
67
|
+
def notmissing1; end
|
68
|
+
def notmissing2; end
|
69
|
+
end
|
70
|
+
|
71
|
+
class TestBlah1
|
72
|
+
def test_notmissing1; end
|
73
|
+
def test_notmissing2_ext1; end
|
74
|
+
def test_notmissing2_ext2; end
|
75
|
+
def test_missingimpl; Blah1.new.missingimpl; end
|
76
|
+
def test_integration_blah1; end
|
77
|
+
def test_integration_blah2; end
|
78
|
+
def test_integration_blah3; end
|
79
|
+
end
|
80
|
+
|
81
|
+
module Something2
|
82
|
+
class Blah2
|
83
|
+
def missingtest; end
|
84
|
+
def notmissing1; end
|
85
|
+
def notmissing2; end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
module TestSomething2
|
90
|
+
class TestBlah2
|
91
|
+
def test_notmissing1; end
|
92
|
+
def test_notmissing2_ext1; end
|
93
|
+
def test_notmissing2_ext2; end
|
94
|
+
def test_missingimpl; end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# only test classes
|
99
|
+
class TestBlah3
|
100
|
+
def test_missingimpl; end
|
101
|
+
end
|
102
|
+
# only regular classes
|
103
|
+
class Blah4
|
104
|
+
def missingtest1; end
|
105
|
+
def missingtest2; end
|
106
|
+
end
|
107
|
+
|
108
|
+
# subclassing a builtin class
|
109
|
+
class MyHash5 < Hash
|
110
|
+
def []; end
|
111
|
+
def missingtest1; end
|
112
|
+
end
|
113
|
+
|
114
|
+
# nested class
|
115
|
+
module MyModule6
|
116
|
+
class MyClass6
|
117
|
+
def []; end
|
118
|
+
def missingtest1; end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# nested class
|
123
|
+
module MyModule7; end # in 1.9+ you'll not need this
|
124
|
+
class MyModule7::MyClass7
|
125
|
+
def []; end
|
126
|
+
def missingtest1; end
|
127
|
+
end
|
128
|
+
|
129
|
+
class MyClass8
|
130
|
+
def self.foobar; end
|
131
|
+
def MyClass8.foobaz; end
|
132
|
+
end
|
133
|
+
|
134
|
+
class TestTrueClass; end
|
135
|
+
|
136
|
+
class TestZenTest < Test::Unit::TestCase
|
137
|
+
def setup
|
138
|
+
@tester = ZenTest.new()
|
139
|
+
end
|
140
|
+
|
141
|
+
############################################################
|
142
|
+
# Utility Methods
|
143
|
+
|
144
|
+
def util_simple_setup
|
145
|
+
@tester.klasses = {
|
146
|
+
"Something" =>
|
147
|
+
{
|
148
|
+
"method1" => true,
|
149
|
+
"method1!" => true,
|
150
|
+
"method1=" => true,
|
151
|
+
"method1?" => true,
|
152
|
+
"attrib" => true,
|
153
|
+
"attrib=" => true,
|
154
|
+
"equal?" => true,
|
155
|
+
"self.method3" => true,
|
156
|
+
"self.[]" => true,
|
157
|
+
},
|
158
|
+
}
|
159
|
+
@tester.test_klasses = {
|
160
|
+
"TestSomething" =>
|
161
|
+
{
|
162
|
+
"test_class_method4" => true,
|
163
|
+
"test_method2" => true,
|
164
|
+
"setup" => true,
|
165
|
+
"teardown" => true,
|
166
|
+
"test_class_index" => true,
|
167
|
+
},
|
168
|
+
}
|
169
|
+
@tester.inherited_methods = @tester.test_klasses.merge(@tester.klasses)
|
170
|
+
@generated_code = "
|
171
|
+
require 'test/unit/testcase'
|
172
|
+
require 'test/unit' if $0 == __FILE__
|
173
|
+
|
174
|
+
class Something
|
175
|
+
def self.method4(*args)
|
176
|
+
raise NotImplementedError, 'Need to write self.method4'
|
177
|
+
end
|
178
|
+
|
179
|
+
def method2(*args)
|
180
|
+
raise NotImplementedError, 'Need to write method2'
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
class TestSomething < Test::Unit::TestCase
|
185
|
+
def test_class_method3
|
186
|
+
raise NotImplementedError, 'Need to write test_class_method3'
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_attrib
|
190
|
+
raise NotImplementedError, 'Need to write test_attrib'
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_attrib_equals
|
194
|
+
raise NotImplementedError, 'Need to write test_attrib_equals'
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_equal_eh
|
198
|
+
raise NotImplementedError, 'Need to write test_equal_eh'
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_method1
|
202
|
+
raise NotImplementedError, 'Need to write test_method1'
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_method1_bang
|
206
|
+
raise NotImplementedError, 'Need to write test_method1_bang'
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_method1_eh
|
210
|
+
raise NotImplementedError, 'Need to write test_method1_eh'
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_method1_equals
|
214
|
+
raise NotImplementedError, 'Need to write test_method1_equals'
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# Number of errors detected: 10
|
219
|
+
"
|
220
|
+
end
|
221
|
+
|
222
|
+
############################################################
|
223
|
+
# Accessors & Adders:
|
224
|
+
|
225
|
+
def test_initialize
|
226
|
+
assert(@tester,"Tester must be initialized")
|
227
|
+
# TODO: should do more at this stage
|
228
|
+
end
|
229
|
+
|
230
|
+
############################################################
|
231
|
+
# Converters and Testers:
|
232
|
+
|
233
|
+
def test_is_test_class
|
234
|
+
# classes
|
235
|
+
assert(@tester.is_test_class(TestCls1),
|
236
|
+
"All test classes must start with Test")
|
237
|
+
assert(!@tester.is_test_class(Cls1),
|
238
|
+
"Classes not starting with Test must not be test classes")
|
239
|
+
# strings
|
240
|
+
assert(@tester.is_test_class("TestCls1"),
|
241
|
+
"All test classes must start with Test")
|
242
|
+
assert(@tester.is_test_class("TestMod::TestCls1"),
|
243
|
+
"All test modules must start with test as well")
|
244
|
+
assert(!@tester.is_test_class("Cls1"),
|
245
|
+
"Classes not starting with Test must not be test classes")
|
246
|
+
assert(!@tester.is_test_class("NotTestMod::TestCls1"),
|
247
|
+
"Modules not starting with Test must not be test classes")
|
248
|
+
assert(!@tester.is_test_class("NotTestMod::NotTestCls1"),
|
249
|
+
"All names must start with Test to be test classes")
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_is_test_class_reversed
|
253
|
+
old = $r
|
254
|
+
$r = true
|
255
|
+
assert(@tester.is_test_class("Cls1Test"),
|
256
|
+
"Reversed: All test classes must end with Test")
|
257
|
+
assert(@tester.is_test_class("ModTest::Cls1Test"),
|
258
|
+
"Reversed: All test classes must end with Test")
|
259
|
+
assert(!@tester.is_test_class("TestMod::TestCls1"),
|
260
|
+
"Reversed: All test classes must end with Test")
|
261
|
+
$r = old
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_convert_class_name
|
265
|
+
|
266
|
+
assert_equal('Cls1', @tester.convert_class_name(TestCls1))
|
267
|
+
assert_equal('TestCls1', @tester.convert_class_name(Cls1))
|
268
|
+
|
269
|
+
assert_equal('Cls1', @tester.convert_class_name('TestCls1'))
|
270
|
+
assert_equal('TestCls1', @tester.convert_class_name('Cls1'))
|
271
|
+
|
272
|
+
assert_equal('TestModule::TestCls1',
|
273
|
+
@tester.convert_class_name('Module::Cls1'))
|
274
|
+
assert_equal('Module::Cls1',
|
275
|
+
@tester.convert_class_name('TestModule::TestCls1'))
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_convert_class_name_reversed
|
279
|
+
old = $r
|
280
|
+
$r = true
|
281
|
+
|
282
|
+
assert_equal('Cls1', @tester.convert_class_name("Cls1Test"))
|
283
|
+
assert_equal('Cls1Test', @tester.convert_class_name(Cls1))
|
284
|
+
|
285
|
+
assert_equal('Cls1', @tester.convert_class_name('Cls1Test'))
|
286
|
+
assert_equal('Cls1Test', @tester.convert_class_name('Cls1'))
|
287
|
+
|
288
|
+
assert_equal('ModuleTest::Cls1Test',
|
289
|
+
@tester.convert_class_name('Module::Cls1'))
|
290
|
+
assert_equal('Module::Cls1',
|
291
|
+
@tester.convert_class_name('ModuleTest::Cls1Test'))
|
292
|
+
$r = old
|
293
|
+
end
|
294
|
+
|
295
|
+
############################################################
|
296
|
+
# Missing Classes and Methods:
|
297
|
+
|
298
|
+
def test_missing_methods_empty
|
299
|
+
missing = @tester.missing_methods
|
300
|
+
assert_equal({}, missing)
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_add_missing_method_normal
|
304
|
+
@tester.add_missing_method("SomeClass", "some_method")
|
305
|
+
missing = @tester.missing_methods
|
306
|
+
assert_equal({"SomeClass" => { "some_method" => true } }, missing)
|
307
|
+
end
|
308
|
+
|
309
|
+
def test_add_missing_method_duplicates
|
310
|
+
@tester.add_missing_method("SomeClass", "some_method")
|
311
|
+
@tester.add_missing_method("SomeClass", "some_method")
|
312
|
+
@tester.add_missing_method("SomeClass", "some_method")
|
313
|
+
missing = @tester.missing_methods
|
314
|
+
assert_equal({"SomeClass" => { "some_method" => true } }, missing)
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_analyze_simple
|
318
|
+
self.util_simple_setup
|
319
|
+
|
320
|
+
@tester.analyze
|
321
|
+
missing = @tester.missing_methods
|
322
|
+
expected = {
|
323
|
+
"Something" => {
|
324
|
+
"method2" => true,
|
325
|
+
"self.method4" => true,
|
326
|
+
},
|
327
|
+
"TestSomething" => {
|
328
|
+
"test_class_method3" => true,
|
329
|
+
"test_attrib" => true,
|
330
|
+
"test_attrib_equals" => true,
|
331
|
+
"test_equal_eh" => true,
|
332
|
+
"test_method1" => true,
|
333
|
+
"test_method1_eh"=>true,
|
334
|
+
"test_method1_bang"=>true,
|
335
|
+
"test_method1_equals"=>true,
|
336
|
+
}
|
337
|
+
}
|
338
|
+
assert_equal(expected, missing)
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_create_method
|
342
|
+
list = @tester.create_method(" ", 1, "wobble")
|
343
|
+
assert_equal([" def wobble(*args)",
|
344
|
+
" raise NotImplementedError, 'Need to write wobble'",
|
345
|
+
" end"],list)
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_methods_and_tests
|
349
|
+
@tester.process_class("ZenTest")
|
350
|
+
@tester.process_class("TestZenTest")
|
351
|
+
m,t = @tester.methods_and_tests("ZenTest", "TestZenTest")
|
352
|
+
assert(m.include?("methods_and_tests"))
|
353
|
+
assert(t.include?("test_methods_and_tests"))
|
354
|
+
end
|
355
|
+
|
356
|
+
def test_generate_code_simple
|
357
|
+
self.util_simple_setup
|
358
|
+
|
359
|
+
@tester.analyze
|
360
|
+
str = @tester.generate_code[1..-1].join("\n")
|
361
|
+
exp = @generated_code
|
362
|
+
|
363
|
+
assert_equal(exp, str)
|
364
|
+
end
|
365
|
+
|
366
|
+
def test_get_class_good
|
367
|
+
assert_equal(Object, @tester.get_class("Object"))
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_get_class_bad
|
371
|
+
assert_nil(@tester.get_class("ZZZObject"))
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_get_inherited_methods_for_subclass
|
375
|
+
expect = { "inherited" => true, "overridden" => true }
|
376
|
+
result = @tester.get_inherited_methods_for("LowlyOne", false)
|
377
|
+
|
378
|
+
assert_equal(expect, result)
|
379
|
+
end
|
380
|
+
|
381
|
+
def test_get_inherited_methods_for_subclass_full
|
382
|
+
expect = Object.instance_methods + %w( inherited overridden )
|
383
|
+
expect.map! { |m| m.to_s }
|
384
|
+
result = @tester.get_inherited_methods_for("LowlyOne", true)
|
385
|
+
|
386
|
+
assert_equal(expect.sort, result.keys.sort)
|
387
|
+
end
|
388
|
+
|
389
|
+
def test_get_inherited_methods_for_superclass
|
390
|
+
expect = { }
|
391
|
+
result = @tester.get_inherited_methods_for("SuperDuper", false)
|
392
|
+
|
393
|
+
assert_equal(expect.keys.sort, result.keys.sort)
|
394
|
+
end
|
395
|
+
|
396
|
+
def test_get_inherited_methods_for_superclass_full
|
397
|
+
expect = Object.instance_methods.map { |m| m.to_s }
|
398
|
+
result = @tester.get_inherited_methods_for("SuperDuper", true)
|
399
|
+
|
400
|
+
assert_equal(expect.sort, result.keys.sort)
|
401
|
+
end
|
402
|
+
|
403
|
+
def test_get_methods_for_subclass
|
404
|
+
expect = {
|
405
|
+
"self.cls_extended" => true,
|
406
|
+
"overridden" => true,
|
407
|
+
"extended" => true
|
408
|
+
}
|
409
|
+
result = @tester.get_methods_for("LowlyOne")
|
410
|
+
|
411
|
+
assert_equal(expect, result)
|
412
|
+
end
|
413
|
+
|
414
|
+
def test_get_methods_for_subclass_full
|
415
|
+
expect = {
|
416
|
+
"self.cls_inherited" => true,
|
417
|
+
"self.cls_extended" => true,
|
418
|
+
"overridden" => true,
|
419
|
+
"extended" => true
|
420
|
+
}
|
421
|
+
result = @tester.get_methods_for("LowlyOne", true)
|
422
|
+
|
423
|
+
assert_equal(expect, result)
|
424
|
+
end
|
425
|
+
|
426
|
+
def test_get_methods_for_superclass
|
427
|
+
expect = {
|
428
|
+
"self.cls_inherited" => true,
|
429
|
+
"overridden" => true,
|
430
|
+
"inherited" => true }
|
431
|
+
result = @tester.get_methods_for("SuperDuper")
|
432
|
+
|
433
|
+
assert_equal(expect, result)
|
434
|
+
end
|
435
|
+
|
436
|
+
def test_result
|
437
|
+
self.util_simple_setup
|
438
|
+
|
439
|
+
@tester.analyze
|
440
|
+
@tester.generate_code
|
441
|
+
str = @tester.result.split($/, 2).last
|
442
|
+
exp = @generated_code
|
443
|
+
|
444
|
+
assert_equal(exp, str)
|
445
|
+
end
|
446
|
+
|
447
|
+
def test_load_file
|
448
|
+
# HACK raise NotImplementedError, 'Need to write test_load_file'
|
449
|
+
end
|
450
|
+
|
451
|
+
def test_scan_files
|
452
|
+
# HACK raise NotImplementedError, 'Need to write test_scan_files'
|
453
|
+
end
|
454
|
+
|
455
|
+
def test_process_class
|
456
|
+
assert_equal({}, @tester.klasses)
|
457
|
+
assert_equal({}, @tester.test_klasses)
|
458
|
+
assert_equal({}, @tester.inherited_methods["SuperDuper"])
|
459
|
+
@tester.process_class("SuperDuper")
|
460
|
+
assert_equal({"SuperDuper"=> {
|
461
|
+
"self.cls_inherited"=>true,
|
462
|
+
"inherited"=>true,
|
463
|
+
"overridden"=>true}},
|
464
|
+
@tester.klasses)
|
465
|
+
assert_equal({}, @tester.test_klasses)
|
466
|
+
assert_equal({}, @tester.inherited_methods["SuperDuper"])
|
467
|
+
end
|
468
|
+
|
469
|
+
def test_klasses_equals
|
470
|
+
self.util_simple_setup
|
471
|
+
assert_equal({"Something"=> {
|
472
|
+
"self.method3"=>true,
|
473
|
+
"equal?"=>true,
|
474
|
+
"attrib="=>true,
|
475
|
+
"self.[]"=>true,
|
476
|
+
"method1"=>true,
|
477
|
+
"method1="=>true,
|
478
|
+
"method1?"=>true,
|
479
|
+
"method1!"=>true,
|
480
|
+
"method1"=>true,
|
481
|
+
"attrib"=>true}}, @tester.klasses)
|
482
|
+
@tester.klasses= {"whoopie" => {}}
|
483
|
+
assert_equal({"whoopie"=> {}}, @tester.klasses)
|
484
|
+
end
|
485
|
+
|
486
|
+
# REFACTOR: this should probably be cleaned up and on ZenTest side
|
487
|
+
def util_testcase(*klasses)
|
488
|
+
zentest = ZenTest.new
|
489
|
+
klasses.each do |klass|
|
490
|
+
zentest.process_class(klass)
|
491
|
+
end
|
492
|
+
zentest.analyze
|
493
|
+
zentest.generate_code
|
494
|
+
return zentest.result.split("\n")[1..-1].join("\n")
|
495
|
+
end
|
496
|
+
|
497
|
+
def test_testcase0
|
498
|
+
expected = '# Number of errors detected: 0'
|
499
|
+
assert_equal expected, util_testcase("Blah0", "TestBlah0")
|
500
|
+
end
|
501
|
+
|
502
|
+
HEADER = "\nrequire 'test/unit/testcase'\nrequire 'test/unit' if $0 == __FILE__\n\n"
|
503
|
+
|
504
|
+
def test_testcase1
|
505
|
+
expected = "#{HEADER}class Blah1\n def missingimpl(*args)\n raise NotImplementedError, 'Need to write missingimpl'\n end\nend\n\nclass TestBlah1 < Test::Unit::TestCase\n def test_missingtest\n raise NotImplementedError, 'Need to write test_missingtest'\n end\nend\n\n# Number of errors detected: 2"
|
506
|
+
|
507
|
+
assert_equal expected, util_testcase("Blah1", "TestBlah1")
|
508
|
+
end
|
509
|
+
|
510
|
+
def test_testcase2
|
511
|
+
expected = "#{HEADER}module Something2\n class Blah2\n def missingimpl(*args)\n raise NotImplementedError, 'Need to write missingimpl'\n end\n end\nend\n\nmodule TestSomething2\n class TestBlah2 < Test::Unit::TestCase\n def test_missingtest\n raise NotImplementedError, 'Need to write test_missingtest'\n end\n end\nend\n\n# Number of errors detected: 2"
|
512
|
+
|
513
|
+
assert_equal expected, util_testcase("Something2::Blah2", "TestSomething2::TestBlah2")
|
514
|
+
end
|
515
|
+
|
516
|
+
def test_testcase3
|
517
|
+
expected = "#{HEADER}class Blah3\n def missingimpl(*args)\n raise NotImplementedError, 'Need to write missingimpl'\n end\nend\n\n# Number of errors detected: 1"
|
518
|
+
|
519
|
+
assert_equal expected, util_testcase("TestBlah3")
|
520
|
+
end
|
521
|
+
|
522
|
+
def test_testcase4
|
523
|
+
expected = "#{HEADER}class TestBlah4 < Test::Unit::TestCase\n def test_missingtest1\n raise NotImplementedError, 'Need to write test_missingtest1'\n end\n\n def test_missingtest2\n raise NotImplementedError, 'Need to write test_missingtest2'\n end\nend\n\n# Number of errors detected: 3"
|
524
|
+
|
525
|
+
assert_equal expected, util_testcase("Blah4")
|
526
|
+
end
|
527
|
+
|
528
|
+
def test_testcase5
|
529
|
+
expected = "#{HEADER}class TestMyHash5 < Test::Unit::TestCase\n def test_index\n raise NotImplementedError, 'Need to write test_index'\n end\n\n def test_missingtest1\n raise NotImplementedError, 'Need to write test_missingtest1'\n end\nend\n\n# Number of errors detected: 3"
|
530
|
+
|
531
|
+
assert_equal expected, util_testcase("MyHash5")
|
532
|
+
end
|
533
|
+
|
534
|
+
def test_testcase6
|
535
|
+
expected = "#{HEADER}module TestMyModule6\n class TestMyClass6 < Test::Unit::TestCase\n def test_index\n raise NotImplementedError, 'Need to write test_index'\n end\n\n def test_missingtest1\n raise NotImplementedError, 'Need to write test_missingtest1'\n end\n end\nend\n\n# Number of errors detected: 3"
|
536
|
+
|
537
|
+
assert_equal expected, util_testcase("MyModule6::MyClass6")
|
538
|
+
end
|
539
|
+
|
540
|
+
def test_testcase7
|
541
|
+
expected = "#{HEADER}module TestMyModule7\n class TestMyClass7 < Test::Unit::TestCase\n def test_index\n raise NotImplementedError, 'Need to write test_index'\n end\n\n def test_missingtest1\n raise NotImplementedError, 'Need to write test_missingtest1'\n end\n end\nend\n\n# Number of errors detected: 3"
|
542
|
+
|
543
|
+
assert_equal expected, util_testcase("MyModule7::MyClass7")
|
544
|
+
end
|
545
|
+
|
546
|
+
def test_testcase8
|
547
|
+
expected = "#{HEADER}class TestMyClass8 < Test::Unit::TestCase\n def test_class_foobar\n raise NotImplementedError, 'Need to write test_class_foobar'\n end\n\n def test_class_foobaz\n raise NotImplementedError, 'Need to write test_class_foobaz'\n end\nend\n\n# Number of errors detected: 3"
|
548
|
+
|
549
|
+
assert_equal expected, util_testcase("MyClass8")
|
550
|
+
end
|
551
|
+
|
552
|
+
def test_testcase9
|
553
|
+
# stupid YAML is breaking my tests. Enters via Test::Rails. order dependent.
|
554
|
+
TrueClass.send :remove_method, :taguri, :taguri=, :to_yaml if defined? YAML
|
555
|
+
|
556
|
+
expected = "#{HEADER}class TestTrueClass < Test::Unit::TestCase\n def test_and\n raise NotImplementedError, 'Need to write test_and'\n end\n\n def test_carat\n raise NotImplementedError, 'Need to write test_carat'\n end\n\n def test_or\n raise NotImplementedError, 'Need to write test_or'\n end\n\n def test_to_s\n raise NotImplementedError, 'Need to write test_to_s'\n end\nend\n\n# Number of errors detected: 4"
|
557
|
+
|
558
|
+
assert_equal expected, util_testcase("TestTrueClass")
|
559
|
+
end
|
560
|
+
end
|