test-unit 1.2.3 → 2.0.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 (60) hide show
  1. data/History.txt +27 -0
  2. data/Manifest.txt +30 -8
  3. data/README.txt +9 -4
  4. data/Rakefile +16 -1
  5. data/bin/testrb +0 -0
  6. data/lib/test/unit/assertions.rb +148 -48
  7. data/lib/test/unit/attribute.rb +125 -0
  8. data/lib/test/unit/autorunner.rb +101 -71
  9. data/lib/test/unit/collector/descendant.rb +23 -0
  10. data/lib/test/unit/collector/dir.rb +1 -1
  11. data/lib/test/unit/collector/load.rb +135 -0
  12. data/lib/test/unit/color.rb +61 -0
  13. data/lib/test/unit/diff.rb +524 -0
  14. data/lib/test/unit/error.rb +70 -2
  15. data/lib/test/unit/exceptionhandler.rb +39 -0
  16. data/lib/test/unit/failure.rb +63 -4
  17. data/lib/test/unit/fixture.rb +185 -0
  18. data/lib/test/unit/notification.rb +125 -0
  19. data/lib/test/unit/omission.rb +143 -0
  20. data/lib/test/unit/pending.rb +146 -0
  21. data/lib/test/unit/priority.rb +146 -0
  22. data/lib/test/unit/runner/console.rb +46 -0
  23. data/lib/test/unit/runner/emacs.rb +8 -0
  24. data/lib/test/unit/testcase.rb +193 -76
  25. data/lib/test/unit/testresult.rb +37 -28
  26. data/lib/test/unit/testsuite.rb +35 -1
  27. data/lib/test/unit/ui/console/outputlevel.rb +14 -0
  28. data/lib/test/unit/ui/console/testrunner.rb +96 -28
  29. data/lib/test/unit/ui/emacs/testrunner.rb +49 -0
  30. data/lib/test/unit/ui/testrunner.rb +20 -0
  31. data/lib/test/unit/ui/testrunnermediator.rb +28 -19
  32. data/lib/test/unit/ui/testrunnerutilities.rb +2 -7
  33. data/lib/test/unit/util/backtracefilter.rb +2 -1
  34. data/lib/test/unit/version.rb +1 -1
  35. data/test/collector/test_descendant.rb +135 -0
  36. data/test/collector/test_load.rb +333 -0
  37. data/test/run-test.rb +13 -0
  38. data/test/test_assertions.rb +221 -56
  39. data/test/test_attribute.rb +86 -0
  40. data/test/test_color.rb +37 -0
  41. data/test/test_diff.rb +477 -0
  42. data/test/test_emacs_runner.rb +60 -0
  43. data/test/test_fixture.rb +275 -0
  44. data/test/test_notification.rb +33 -0
  45. data/test/test_omission.rb +81 -0
  46. data/test/test_pending.rb +70 -0
  47. data/test/test_priority.rb +89 -0
  48. data/test/test_testcase.rb +160 -5
  49. data/test/test_testresult.rb +61 -52
  50. data/test/testunit_test_util.rb +14 -0
  51. data/test/ui/test_testrunmediator.rb +20 -0
  52. metadata +53 -23
  53. data/lib/test/unit/ui/fox/testrunner.rb +0 -268
  54. data/lib/test/unit/ui/gtk/testrunner.rb +0 -416
  55. data/lib/test/unit/ui/gtk2/testrunner.rb +0 -465
  56. data/lib/test/unit/ui/tk/testrunner.rb +0 -260
  57. data/test/runit/test_assert.rb +0 -402
  58. data/test/runit/test_testcase.rb +0 -91
  59. data/test/runit/test_testresult.rb +0 -144
  60. data/test/runit/test_testsuite.rb +0 -49
@@ -0,0 +1,60 @@
1
+ require 'test/unit'
2
+ require 'test/unit/ui/emacs/testrunner'
3
+
4
+ class TestUnitEmacsRunner < Test::Unit::TestCase
5
+ def test_format_failure_with_a_location
6
+ runner = create_runner
7
+ test_name = "test_failure"
8
+ file = "/home/user/test_xxx.rb"
9
+ line = "3"
10
+ info = "in `xxx'"
11
+ location = "#{file}:#{line}: #{info}"
12
+ message = "FAIL!!!"
13
+ failure = Test::Unit::Failure.new(test_name, [location], message)
14
+ assert_equal(<<-EOM.chomp, runner.send(:format_fault, failure))
15
+ Failure:
16
+ #{test_name} [#{file}:#{line}]:
17
+ #{message}
18
+ EOM
19
+ end
20
+
21
+ def test_format_failure_with_locations
22
+ runner = create_runner
23
+ test_name = "test_failure"
24
+ locations = ["/home/user/test_xxx.rb:3: in `xxx'",
25
+ "/home/user/yyy/test_yyy.rb:999: in `yyy'",
26
+ "/home/user/xyz/zzz.rb:29: in `zzz'"]
27
+ message = "Many backtrace!!!"
28
+ failure = Test::Unit::Failure.new(test_name, locations, message)
29
+ assert_equal(<<-EOM.chomp, runner.send(:format_fault, failure))
30
+ Failure:
31
+ #{test_name}
32
+ #{locations.join("\n")}:
33
+ #{message}
34
+ EOM
35
+ end
36
+
37
+ def test_format_error
38
+ runner = create_runner
39
+ test_name = "test_error"
40
+ message = "Error Message!!!"
41
+ backtrace = ["/home/user/test_xxx.rb:3: in `xxx'",
42
+ "/home/user/yyy/test_yyy.rb:999: in `yyy'",
43
+ "/home/user/xyz/zzz.rb:29: in `zzz'"]
44
+ exception = RuntimeError.new(message)
45
+ exception.set_backtrace(backtrace)
46
+ error = Test::Unit::Error.new(test_name, exception)
47
+ assert_equal(<<-EOM.chomp, runner.send(:format_fault, error))
48
+ Error:
49
+ #{test_name}:
50
+ #{exception.class.name}: #{message}
51
+ #{backtrace.join("\n")}
52
+ EOM
53
+ end
54
+
55
+ private
56
+ def create_runner(suite=nil)
57
+ suite ||= Test::Unit::TestSuite.new
58
+ Test::Unit::UI::Emacs::TestRunner.new(suite)
59
+ end
60
+ end
@@ -0,0 +1,275 @@
1
+ class TestUnitFixture < Test::Unit::TestCase
2
+ def test_setup_without_option
3
+ test_case = assert_setup([:setup,
4
+ :custom_setup_method0,
5
+ :custom_setup_method1,
6
+ :custom_setup_method3],
7
+ [])
8
+ assert_inherited_setup([:setup,
9
+ :custom_setup_method0,
10
+ :custom_setup_method1,
11
+ :custom_setup_method3],
12
+ test_case)
13
+ assert_inherited_setup([:setup], nil)
14
+ end
15
+
16
+ def test_setup_with_before_option
17
+ test_case = assert_setup([:custom_setup_method3,
18
+ :custom_setup_method0,
19
+ :custom_setup_method1,
20
+ :setup],
21
+ [[{:before => :append}],
22
+ [{:before => :append}],
23
+ [{:before => :prepend}],
24
+ [{:before => :prepend}]])
25
+ assert_inherited_setup([:custom_setup_method3,
26
+ :custom_setup_method0,
27
+ :custom_setup_method1,
28
+ :setup],
29
+ test_case)
30
+ assert_inherited_setup([:setup], nil)
31
+ end
32
+
33
+ def test_setup_with_after_option
34
+ test_case = assert_setup([:setup,
35
+ :custom_setup_method3,
36
+ :custom_setup_method0,
37
+ :custom_setup_method1],
38
+ [[{:after => :append}],
39
+ [{:after => :append}],
40
+ [{:after => :prepend}],
41
+ [{:after => :prepend}]])
42
+ assert_inherited_setup([:setup,
43
+ :custom_setup_method3,
44
+ :custom_setup_method0,
45
+ :custom_setup_method1],
46
+ test_case)
47
+ assert_inherited_setup([:setup], nil)
48
+ end
49
+
50
+ def test_setup_with_invalid_option
51
+ assert_invalid_setup_option(:unknown => true)
52
+ assert_invalid_setup_option(:before => :unknown)
53
+ assert_invalid_setup_option(:after => :unknown)
54
+ end
55
+
56
+ def test_teardown_without_option
57
+ test_case = assert_teardown([:custom_teardown_method3,
58
+ :custom_teardown_method1,
59
+ :custom_teardown_method0,
60
+ :teardown],
61
+ [])
62
+ assert_inherited_teardown([:custom_teardown_method3,
63
+ :custom_teardown_method1,
64
+ :custom_teardown_method0,
65
+ :teardown],
66
+ test_case)
67
+ assert_inherited_teardown([:teardown], nil)
68
+ end
69
+
70
+ def test_teardown_with_before_option
71
+ test_case = assert_teardown([:custom_teardown_method3,
72
+ :custom_teardown_method0,
73
+ :custom_teardown_method1,
74
+ :teardown],
75
+ [[{:before => :append}],
76
+ [{:before => :append}],
77
+ [{:before => :prepend}],
78
+ [{:before => :prepend}]])
79
+ assert_inherited_teardown([:custom_teardown_method3,
80
+ :custom_teardown_method0,
81
+ :custom_teardown_method1,
82
+ :teardown],
83
+ test_case)
84
+ assert_inherited_teardown([:teardown], nil)
85
+ end
86
+
87
+ def test_teardown_with_after_option
88
+ test_case = assert_teardown([:teardown,
89
+ :custom_teardown_method3,
90
+ :custom_teardown_method0,
91
+ :custom_teardown_method1],
92
+ [[{:after => :append}],
93
+ [{:after => :append}],
94
+ [{:after => :prepend}],
95
+ [{:after => :prepend}]])
96
+ assert_inherited_teardown([:teardown,
97
+ :custom_teardown_method3,
98
+ :custom_teardown_method0,
99
+ :custom_teardown_method1],
100
+ test_case)
101
+ assert_inherited_teardown([:teardown], nil)
102
+ end
103
+
104
+ def test_teardown_with_invalid_option
105
+ assert_invalid_teardown_option(:unknown => true)
106
+ assert_invalid_teardown_option(:before => :unknown)
107
+ assert_invalid_teardown_option(:after => :unknown)
108
+ end
109
+
110
+ private
111
+ def assert_setup(expected, setup_options)
112
+ called = []
113
+ test_case = Class.new(Test::Unit::TestCase) do
114
+ @@called = called
115
+ def setup
116
+ @@called << :setup
117
+ end
118
+
119
+ setup(*(setup_options[0] || []))
120
+ def custom_setup_method0
121
+ @@called << :custom_setup_method0
122
+ end
123
+
124
+ def custom_setup_method1
125
+ @@called << :custom_setup_method1
126
+ end
127
+ setup(*[:custom_setup_method1, *(setup_options[1] || [])])
128
+
129
+ setup(*(setup_options[2] || []))
130
+ def custom_setup_method2
131
+ @@called << :custom_setup_method2
132
+ end
133
+ unregister_setup(:custom_setup_method2)
134
+
135
+ setup(*(setup_options[3] || []))
136
+ def custom_setup_method3
137
+ @@called << :custom_setup_method3
138
+ end
139
+
140
+ def test_nothing
141
+ end
142
+ end
143
+
144
+ test_case.new("test_nothing").run(Test::Unit::TestResult.new) {}
145
+ assert_equal(expected, called)
146
+ test_case
147
+ end
148
+
149
+ def assert_inherited_setup(expected, parent)
150
+ called = []
151
+ inherited_test_case = Class.new(parent || Test::Unit::TestCase) do
152
+ @@called = called
153
+ def setup
154
+ @@called << :setup
155
+ end
156
+
157
+ def custom_setup_method0
158
+ @@called << :custom_setup_method0
159
+ end
160
+
161
+ def custom_setup_method1
162
+ @@called << :custom_setup_method1
163
+ end
164
+
165
+ def custom_setup_method2
166
+ @@called << :custom_setup_method2
167
+ end
168
+
169
+ def custom_setup_method3
170
+ @@called << :custom_setup_method3
171
+ end
172
+
173
+ def test_nothing
174
+ end
175
+ end
176
+
177
+ inherited_test_case.new("test_nothing").run(Test::Unit::TestResult.new) {}
178
+ assert_equal(expected, called)
179
+ end
180
+
181
+ def assert_teardown(expected, teardown_options)
182
+ called = []
183
+ test_case = Class.new(Test::Unit::TestCase) do
184
+ @@called = called
185
+ def teardown
186
+ @@called << :teardown
187
+ end
188
+
189
+ teardown(*(teardown_options[0] || []))
190
+ def custom_teardown_method0
191
+ @@called << :custom_teardown_method0
192
+ end
193
+
194
+ def custom_teardown_method1
195
+ @@called << :custom_teardown_method1
196
+ end
197
+ teardown(*[:custom_teardown_method1, *(teardown_options[1] || [])])
198
+
199
+ teardown(*(teardown_options[2] || []))
200
+ def custom_teardown_method2
201
+ @@called << :custom_teardown_method2
202
+ end
203
+ unregister_teardown(:custom_teardown_method2)
204
+
205
+ teardown(*(teardown_options[3] || []))
206
+ def custom_teardown_method3
207
+ @@called << :custom_teardown_method3
208
+ end
209
+
210
+ def test_nothing
211
+ end
212
+ end
213
+
214
+ test_case.new("test_nothing").run(Test::Unit::TestResult.new) {}
215
+ assert_equal(expected, called)
216
+ test_case
217
+ end
218
+
219
+ def assert_inherited_teardown(expected, parent)
220
+ called = []
221
+ inherited_test_case = Class.new(parent || Test::Unit::TestCase) do
222
+ @@called = called
223
+ def teardown
224
+ @@called << :teardown
225
+ end
226
+
227
+ def custom_teardown_method0
228
+ @@called << :custom_teardown_method0
229
+ end
230
+
231
+ def custom_teardown_method1
232
+ @@called << :custom_teardown_method1
233
+ end
234
+
235
+ def custom_teardown_method2
236
+ @@called << :custom_teardown_method2
237
+ end
238
+
239
+ def custom_teardown_method3
240
+ @@called << :custom_teardown_method3
241
+ end
242
+
243
+ def test_nothing
244
+ end
245
+ end
246
+
247
+ inherited_test_case.new("test_nothing").run(Test::Unit::TestResult.new) {}
248
+ assert_equal(expected, called)
249
+ end
250
+
251
+ def assert_invalid_option(fixture_type, option)
252
+ exception = assert_raise(ArgumentError) do
253
+ Class.new(Test::Unit::TestCase) do
254
+ def test_nothing
255
+ end
256
+
257
+ send(fixture_type, option)
258
+ def fixture
259
+ end
260
+ end
261
+ end
262
+ assert_equal("must be {:before => :prepend}, {:before => :append}, " +
263
+ "{:after => :prepend} or {:after => :append}" +
264
+ ": #{option.inspect}",
265
+ exception.message)
266
+ end
267
+
268
+ def assert_invalid_setup_option(option)
269
+ assert_invalid_option(:setup, option)
270
+ end
271
+
272
+ def assert_invalid_teardown_option(option)
273
+ assert_invalid_option(:teardown, option)
274
+ end
275
+ end
@@ -0,0 +1,33 @@
1
+ require 'test/unit'
2
+ require 'testunit_test_util'
3
+
4
+ class TestNotification < Test::Unit::TestCase
5
+ include TestUnitTestUtil
6
+
7
+ class TestCase < Test::Unit::TestCase
8
+ class << self
9
+ def suite
10
+ Test::Unit::TestSuite.new(name)
11
+ end
12
+ end
13
+
14
+ def test_notify
15
+ notify("1st notify")
16
+ notify("2nd notify. Reach here.")
17
+ end
18
+ end
19
+
20
+ def test_notify
21
+ result = run_test("test_notify")
22
+ assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \
23
+ "0 omissions, 2 notifications",
24
+ result.to_s)
25
+ assert_fault_messages(["1st notify", "2nd notify. Reach here."],
26
+ result.notifications)
27
+ end
28
+
29
+ private
30
+ def run_test(name)
31
+ super(TestCase, name)
32
+ end
33
+ end
@@ -0,0 +1,81 @@
1
+ require 'test/unit'
2
+ require 'testunit_test_util'
3
+
4
+ class TestUnitOmission < Test::Unit::TestCase
5
+ include TestUnitTestUtil
6
+
7
+ class TestCase < Test::Unit::TestCase
8
+ class << self
9
+ def suite
10
+ Test::Unit::TestSuite.new(name)
11
+ end
12
+ end
13
+
14
+ def test_omit
15
+ omit("1st omit")
16
+ omit("2nd omit. Should not be reached here.")
17
+ assert(true, "Should not be reached here too.")
18
+ end
19
+
20
+ def test_omit_with_condition
21
+ omit_if(false, "Never omit.")
22
+ omit_unless(true, "Never omit too.")
23
+ omit_if(true, "Should omit.")
24
+ omit("The last omit. Should not be reached here.")
25
+ end
26
+
27
+ def test_omit_with_block
28
+ omit("Omit block") do
29
+ flunk("Should not be reached here.")
30
+ end
31
+ assert(true, "Should be reached here.")
32
+ end
33
+
34
+ def test_omit_with_block_and_condition
35
+ omit_if(false, "Never omit.") do
36
+ assert(true, "Should be reached here.")
37
+ end
38
+ omit_if(true, "Should omit.") do
39
+ flunk("Never reached here.")
40
+ end
41
+ assert(true, "Should be reached here too.")
42
+ end
43
+ end
44
+
45
+ def test_omit
46
+ result = run_test("test_omit")
47
+ assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \
48
+ "1 omissions, 0 notifications",
49
+ result.to_s)
50
+ assert_fault_messages(["1st omit"], result.omissions)
51
+ end
52
+
53
+ def test_omit_with_condition
54
+ result = run_test("test_omit_with_condition")
55
+ assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \
56
+ "1 omissions, 0 notifications",
57
+ result.to_s)
58
+ assert_fault_messages(["Should omit."], result.omissions)
59
+ end
60
+
61
+ def test_omit_with_block
62
+ result = run_test("test_omit_with_block")
63
+ assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, " \
64
+ "1 omissions, 0 notifications",
65
+ result.to_s)
66
+ assert_fault_messages(["Omit block"], result.omissions)
67
+ end
68
+
69
+ def test_omit_with_condition_and_block
70
+ result = run_test("test_omit_with_block_and_condition")
71
+ assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, " \
72
+ "1 omissions, 0 notifications",
73
+ result.to_s)
74
+ assert_fault_messages(["Should omit."], result.omissions)
75
+ end
76
+
77
+ private
78
+ def run_test(name)
79
+ super(TestCase, name)
80
+ end
81
+ end