test-unit 3.1.5 → 3.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/BSDL +24 -0
  3. data/COPYING +41 -41
  4. data/README.md +24 -17
  5. data/Rakefile +21 -24
  6. data/doc/text/getting-started.md +246 -0
  7. data/doc/text/news.md +797 -56
  8. data/lib/test/unit/assertion-failed-error.rb +35 -0
  9. data/lib/test/unit/assertions.rb +542 -220
  10. data/lib/test/unit/attribute.rb +78 -4
  11. data/lib/test/unit/auto-runner-loader.rb +17 -0
  12. data/lib/test/unit/autorunner.rb +175 -78
  13. data/lib/test/unit/code-snippet-fetcher.rb +7 -7
  14. data/lib/test/unit/collector/descendant.rb +1 -0
  15. data/lib/test/unit/collector/dir.rb +4 -2
  16. data/lib/test/unit/collector/load.rb +25 -15
  17. data/lib/test/unit/collector/objectspace.rb +1 -0
  18. data/lib/test/unit/collector.rb +31 -0
  19. data/lib/test/unit/color-scheme.rb +29 -2
  20. data/lib/test/unit/data-sets.rb +127 -0
  21. data/lib/test/unit/data.rb +121 -12
  22. data/lib/test/unit/diff.rb +10 -11
  23. data/lib/test/unit/fixture.rb +77 -27
  24. data/lib/test/unit/notification.rb +9 -7
  25. data/lib/test/unit/omission.rb +34 -31
  26. data/lib/test/unit/pending.rb +12 -11
  27. data/lib/test/unit/priority.rb +7 -5
  28. data/lib/test/unit/runner/console.rb +20 -1
  29. data/lib/test/unit/test-suite-creator.rb +30 -9
  30. data/lib/test/unit/testcase.rb +349 -196
  31. data/lib/test/unit/testresult.rb +7 -0
  32. data/lib/test/unit/testsuite.rb +1 -1
  33. data/lib/test/unit/ui/console/testrunner.rb +171 -60
  34. data/lib/test/unit/ui/emacs/testrunner.rb +5 -5
  35. data/lib/test/unit/ui/testrunnermediator.rb +9 -7
  36. data/lib/test/unit/util/backtracefilter.rb +17 -5
  37. data/lib/test/unit/util/memory-usage.rb +47 -0
  38. data/lib/test/unit/util/observable.rb +2 -2
  39. data/lib/test/unit/util/output.rb +5 -4
  40. data/lib/test/unit/util/procwrapper.rb +4 -4
  41. data/lib/test/unit/version.rb +1 -1
  42. data/lib/test/unit/warning.rb +3 -0
  43. data/lib/test/unit.rb +177 -161
  44. data/lib/test-unit.rb +2 -17
  45. metadata +20 -94
  46. data/GPL +0 -339
  47. data/LGPL +0 -502
  48. data/test/collector/test-descendant.rb +0 -178
  49. data/test/collector/test-load.rb +0 -442
  50. data/test/collector/test_dir.rb +0 -406
  51. data/test/collector/test_objectspace.rb +0 -100
  52. data/test/fixtures/header-label.csv +0 -3
  53. data/test/fixtures/header-label.tsv +0 -3
  54. data/test/fixtures/header.csv +0 -3
  55. data/test/fixtures/header.tsv +0 -3
  56. data/test/fixtures/no-header.csv +0 -2
  57. data/test/fixtures/no-header.tsv +0 -2
  58. data/test/fixtures/plus.csv +0 -3
  59. data/test/run-test.rb +0 -22
  60. data/test/test-assertions.rb +0 -2157
  61. data/test/test-attribute-matcher.rb +0 -38
  62. data/test/test-attribute.rb +0 -123
  63. data/test/test-code-snippet.rb +0 -37
  64. data/test/test-color-scheme.rb +0 -82
  65. data/test/test-color.rb +0 -47
  66. data/test/test-data.rb +0 -281
  67. data/test/test-diff.rb +0 -518
  68. data/test/test-emacs-runner.rb +0 -60
  69. data/test/test-error.rb +0 -26
  70. data/test/test-failure.rb +0 -33
  71. data/test/test-fault-location-detector.rb +0 -163
  72. data/test/test-fixture.rb +0 -659
  73. data/test/test-notification.rb +0 -33
  74. data/test/test-omission.rb +0 -81
  75. data/test/test-pending.rb +0 -70
  76. data/test/test-priority.rb +0 -173
  77. data/test/test-test-case.rb +0 -1171
  78. data/test/test-test-result.rb +0 -113
  79. data/test/test-test-suite-creator.rb +0 -97
  80. data/test/test-test-suite.rb +0 -150
  81. data/test/testunit-test-util.rb +0 -31
  82. data/test/ui/test_testrunmediator.rb +0 -20
  83. data/test/util/test-method-owner-finder.rb +0 -38
  84. data/test/util/test-output.rb +0 -11
  85. data/test/util/test_backtracefilter.rb +0 -41
  86. data/test/util/test_observable.rb +0 -102
  87. data/test/util/test_procwrapper.rb +0 -36
data/lib/test/unit.rb CHANGED
@@ -1,12 +1,14 @@
1
+ require "test/unit/warning"
2
+
1
3
  require 'test/unit/testcase'
2
4
  require 'test/unit/autorunner'
3
5
 
4
6
  module Test # :nodoc:
5
7
  #
6
- # = Test::Unit - Ruby Unit Testing Framework
7
- #
8
- # == Introduction
9
- #
8
+ # # Test::Unit - Ruby Unit Testing Framework
9
+ #
10
+ # ## Introduction
11
+ #
10
12
  # Unit testing is making waves all over the place, largely due to the
11
13
  # fact that it is a core practice of XP. While XP is great, unit testing
12
14
  # has been around for a long time and has always been a good idea. One
@@ -18,19 +20,19 @@ module Test # :nodoc:
18
20
  # as possible, you slowly build up a wall of things that cannot break
19
21
  # without you immediately knowing about it. This is when unit testing
20
22
  # hits its peak usefulness.
21
- #
23
+ #
22
24
  # Enter Test::Unit, a framework for unit testing in Ruby, helping you to
23
25
  # design, debug and evaluate your code by making it easy to write and
24
26
  # have tests for it.
25
- #
26
- #
27
- # == Notes
28
- #
27
+ #
28
+ #
29
+ # ## Notes
30
+ #
29
31
  # Test::Unit has grown out of and superceded Lapidary.
30
- #
31
- #
32
- # == Feedback
33
- #
32
+ #
33
+ #
34
+ # ## Feedback
35
+ #
34
36
  # I like (and do my best to practice) XP, so I value early releases,
35
37
  # user feedback, and clean, simple, expressive code. There is always
36
38
  # room for improvement in everything I do, and Test::Unit is no
@@ -41,79 +43,84 @@ module Test # :nodoc:
41
43
  # hear about any successes you have with Test::Unit, and any
42
44
  # documentation you might add will be greatly appreciated. My contact
43
45
  # info is below.
44
- #
45
- #
46
- # == Contact Information
47
- #
48
- # A lot of discussion happens about Ruby in general on the ruby-talk
49
- # mailing list (http://www.ruby-lang.org/en/ml.html), and you can ask
50
- # any questions you might have there. I monitor the list, as do many
51
- # other helpful Rubyists, and you're sure to get a quick answer. Of
52
- # course, you're also welcome to email me (Nathaniel Talbott) directly
53
- # at mailto:testunit@talbott.ws, and I'll do my best to help you out.
54
- #
55
- #
56
- # == Credits
57
- #
46
+ #
47
+ #
48
+ # ## Contact Information
49
+ #
50
+ # * [GitHub issues on
51
+ # test-unit/test-unit](https://github.com/test-unit/test-unit/issues):
52
+ # If you have any issues, please report them to here.
53
+ #
54
+ # * [GitHub pull requests on
55
+ # test-unit/test-unit](https://github.com/test-unit/test-unit/pulls):
56
+ # If you have any patches, please report them to here.
57
+ #
58
+ # * [ruby-talk mailing
59
+ # list](https://www.ruby-lang.org/en/community/mailing-lists/):
60
+ # If you have any questions, you can ask them here.
61
+ #
62
+ #
63
+ # ## Credits
64
+ #
58
65
  # I'd like to thank...
59
- #
66
+ #
60
67
  # Matz, for a great language!
61
- #
68
+ #
62
69
  # Masaki Suketa, for his work on RubyUnit, which filled a vital need in
63
70
  # the Ruby world for a very long time. I'm also grateful for his help in
64
71
  # polishing Test::Unit and getting the RubyUnit compatibility layer
65
72
  # right. His graciousness in allowing Test::Unit to supercede RubyUnit
66
73
  # continues to be a challenge to me to be more willing to defer my own
67
74
  # rights.
68
- #
75
+ #
69
76
  # Ken McKinlay, for his interest and work on unit testing, and for his
70
77
  # willingness to dialog about it. He was also a great help in pointing
71
78
  # out some of the holes in the RubyUnit compatibility layer.
72
- #
79
+ #
73
80
  # Dave Thomas, for the original idea that led to the extremely simple
74
81
  # "require 'test/unit'", plus his code to improve it even more by
75
82
  # allowing the selection of tests from the command-line. Also, without
76
83
  # RDoc, the documentation for Test::Unit would stink a lot more than it
77
84
  # does now.
78
- #
85
+ #
79
86
  # Everyone who's helped out with bug reports, feature ideas,
80
87
  # encouragement to continue, etc. It's a real privilege to be a part of
81
88
  # the Ruby community.
82
- #
89
+ #
83
90
  # The guys at RoleModel Software, for putting up with me repeating, "But
84
91
  # this would be so much easier in Ruby!" whenever we're coding in Java.
85
- #
92
+ #
86
93
  # My Creator, for giving me life, and giving it more abundantly.
87
- #
88
- #
89
- # == License
90
- #
94
+ #
95
+ #
96
+ # ## License
97
+ #
91
98
  # Test::Unit is copyright (c) 2000-2003 Nathaniel Talbott. It is free
92
99
  # software, and is distributed under the Ruby license. See the COPYING
93
100
  # file.
94
- #
101
+ #
95
102
  # Exception: lib/test/unit/diff.rb is copyright (c)
96
103
  # 2008-2010 Kouhei Sutou and 2001-2008 Python Software
97
104
  # Foundation. It is free software, and is distributed
98
105
  # under the Ruby license and/or the PSF license. See the
99
106
  # COPYING file and PSFL file.
100
- #
101
- # == Warranty
102
- #
107
+ #
108
+ # ## Warranty
109
+ #
103
110
  # This software is provided "as is" and without any express or
104
111
  # implied warranties, including, without limitation, the implied
105
112
  # warranties of merchantibility and fitness for a particular
106
113
  # purpose.
107
- #
108
- #
109
- # == Author
110
- #
114
+ #
115
+ #
116
+ # ## Author
117
+ #
111
118
  # Nathaniel Talbott.
112
119
  # Copyright (c) 2000-2003, Nathaniel Talbott
113
120
  #
114
121
  # ----
115
122
  #
116
- # = Usage
123
+ # # Usage
117
124
  #
118
125
  # The general idea behind unit testing is that you write a _test_
119
126
  # _method_ that makes certain _assertions_ about your code, working
@@ -125,7 +132,7 @@ module Test # :nodoc:
125
132
  # pieces.
126
133
  #
127
134
  #
128
- # == Assertions
135
+ # ## Assertions
129
136
  #
130
137
  # These are the heart of the framework. Think of an assertion as a
131
138
  # statement of expected outcome, i.e. "I assert that x should be equal
@@ -137,7 +144,7 @@ module Test # :nodoc:
137
144
  # of the current assertions, see Test::Unit::Assertions.
138
145
  #
139
146
  #
140
- # == Test Method & Test Fixture
147
+ # ## Test Method & Test Fixture
141
148
  #
142
149
  # Obviously, these assertions have to be called within a context that
143
150
  # knows about them and can do something meaningful with their
@@ -197,7 +204,7 @@ module Test # :nodoc:
197
204
  # end
198
205
  #
199
206
  #
200
- # == Test Runners
207
+ # ## Test Runners
201
208
  #
202
209
  # So, now you have this great test class, but you still
203
210
  # need a way to run it and view any failures that occur
@@ -208,10 +215,10 @@ module Test # :nodoc:
208
215
  # runner simply set default test runner ID to
209
216
  # Test::Unit::AutoRunner:
210
217
  #
211
- # require 'test/unit'
212
- # Test::Unit::AutoRunner.default_runner = "gtk2"
218
+ # require 'test/unit'
219
+ # Test::Unit::AutoRunner.default_runner = "gtk2"
213
220
  #
214
- # == Test Suite
221
+ # ## Test Suite
215
222
  #
216
223
  # As more and more unit tests accumulate for a given project, it
217
224
  # becomes a real drag running them one at a time, and it also
@@ -228,17 +235,17 @@ module Test # :nodoc:
228
235
  # 'test/unit'. What does this mean? It means you could
229
236
  # write the above test case like this instead:
230
237
  #
231
- # require 'test/unit'
232
- # require 'test_myfirsttests'
233
- # require 'test_moretestsbyme'
234
- # require 'test_anothersetoftests'
238
+ # require 'test/unit'
239
+ # require 'test_myfirsttests'
240
+ # require 'test_moretestsbyme'
241
+ # require 'test_anothersetoftests'
235
242
  #
236
243
  # Test::Unit is smart enough to find all the test cases existing in
237
244
  # the ObjectSpace and wrap them up into a suite for you. It then runs
238
245
  # the dynamic suite using the console TestRunner.
239
246
  #
240
247
  #
241
- # == Configuration file
248
+ # ## Configuration file
242
249
  #
243
250
  # Test::Unit reads 'test-unit.yml' in the current working
244
251
  # directory as Test::Unit's configuration file. It can
@@ -254,53 +261,58 @@ module Test # :nodoc:
254
261
  #
255
262
  # Here are sample color scheme definitions:
256
263
  #
257
- # color_schemes:
258
- # inverted:
259
- # success:
260
- # name: red
261
- # bold: true
262
- # failure:
263
- # name: green
264
- # bold: true
265
- # other_scheme:
266
- # ...
264
+ # color_schemes:
265
+ # inverted:
266
+ # success:
267
+ # name: red
268
+ # bold: true
269
+ # failure:
270
+ # name: green
271
+ # bold: true
272
+ # other_scheme:
273
+ # ...
267
274
  #
268
275
  # Here are the syntax of color scheme definitions:
269
276
  #
270
- # color_schemes:
271
- # SCHEME_NAME:
272
- # EVENT_NAME:
273
- # name: COLOR_NAME
274
- # intensity: BOOLEAN
275
- # bold: BOOLEAN
276
- # italic: BOOLEAN
277
- # underline: BOOLEAN
278
- # ...
279
- # ...
280
- #
281
- # SCHEME_NAME:: the name of the color scheme
282
- # EVENT_NAME:: one of [success, failure, pending,
283
- # omission, notification, error]
284
- # COLOR_NAME:: one of [black, red, green, yellow, blue,
285
- # magenta, cyan, white]
286
- # BOOLEAN:: true or false
277
+ # color_schemes:
278
+ # SCHEME_NAME:
279
+ # EVENT_NAME:
280
+ # name: COLOR_NAME
281
+ # intensity: BOOLEAN
282
+ # bold: BOOLEAN
283
+ # italic: BOOLEAN
284
+ # underline: BOOLEAN
285
+ # ...
286
+ # ...
287
+ #
288
+ # SCHEME_NAME
289
+ # : the name of the color scheme
290
+ #
291
+ # EVENT_NAME
292
+ # : one of [success, failure, pending, omission, notification, error]
293
+ #
294
+ # COLOR_NAME
295
+ # : one of [black, red, green, yellow, blue, magenta, cyan, white]
296
+ #
297
+ # BOOLEAN
298
+ # : true or false
287
299
  #
288
300
  # You can use the above 'inverted' color scheme with the
289
301
  # following configuration:
290
302
  #
291
- # runner: console
292
- # console_options:
293
- # color_scheme: inverted
294
- # color_schemes:
295
- # inverted:
296
- # success:
297
- # name: red
298
- # bold: true
299
- # failure:
300
- # name: green
301
- # bold: true
303
+ # runner: console
304
+ # console_options:
305
+ # color_scheme: inverted
306
+ # color_schemes:
307
+ # inverted:
308
+ # success:
309
+ # name: red
310
+ # bold: true
311
+ # failure:
312
+ # name: green
313
+ # bold: true
302
314
  #
303
- # == Questions?
315
+ # ## Questions?
304
316
  #
305
317
  # I'd really like to get feedback from all levels of Ruby
306
318
  # practitioners about typos, grammatical errors, unclear statements,
@@ -312,14 +324,14 @@ module Test # :nodoc:
312
324
  # Set true when Test::Unit has run. If set to true Test::Unit
313
325
  # will not automatically run at exit.
314
326
  #
315
- # @deprecated Use Test::Unit::AutoRunner.need_auto_run= instead.
327
+ # @deprecated Use {Test::Unit::AutoRunner.need_auto_run=} instead.
316
328
  def run=(have_run)
317
329
  AutoRunner.need_auto_run = (not have_run)
318
330
  end
319
331
 
320
332
  # Already tests have run?
321
333
  #
322
- # @deprecated Use Test::Unit::AutoRunner.need_auto_run? instead.
334
+ # @deprecated Use {Test::Unit::AutoRunner.need_auto_run?} instead.
323
335
  def run?
324
336
  not AutoRunner.need_auto_run?
325
337
  end
@@ -327,55 +339,57 @@ module Test # :nodoc:
327
339
  # @api private
328
340
  @@at_start_hooks = []
329
341
 
330
- # Regsiter a hook that is run before running tests.
342
+ # Register a hook that is run before running tests.
331
343
  # To register multiple hooks, call this method multiple times.
332
344
  #
333
345
  # Here is an example test case:
334
- # Test::Unit.at_start do
335
- # # ...
336
- # end
337
346
  #
338
- # class TestMyClass1 < Test::Unit::TestCase
339
- # class << self
340
- # def startup
341
- # # ...
342
- # end
343
- # end
344
- #
345
- # def setup
347
+ # Test::Unit.at_start do
346
348
  # # ...
347
349
  # end
348
350
  #
349
- # def test_my_class1
350
- # # ...
351
- # end
351
+ # class TestMyClass1 < Test::Unit::TestCase
352
+ # class << self
353
+ # def startup
354
+ # # ...
355
+ # end
356
+ # end
352
357
  #
353
- # def test_my_class2
354
- # # ...
355
- # end
356
- # end
358
+ # def setup
359
+ # # ...
360
+ # end
357
361
  #
358
- # class TestMyClass2 < Test::Unit::TestCase
359
- # class << self
360
- # def startup
362
+ # def test_my_class1
361
363
  # # ...
362
364
  # end
363
- # end
364
365
  #
365
- # def setup
366
- # # ...
366
+ # def test_my_class2
367
+ # # ...
368
+ # end
367
369
  # end
368
370
  #
369
- # def test_my_class1
370
- # # ...
371
- # end
371
+ # class TestMyClass2 < Test::Unit::TestCase
372
+ # class << self
373
+ # def startup
374
+ # # ...
375
+ # end
376
+ # end
372
377
  #
373
- # def test_my_class2
374
- # # ...
378
+ # def setup
379
+ # # ...
380
+ # end
381
+ #
382
+ # def test_my_class1
383
+ # # ...
384
+ # end
385
+ #
386
+ # def test_my_class2
387
+ # # ...
388
+ # end
375
389
  # end
376
- # end
377
390
  #
378
391
  # Here is a call order:
392
+ #
379
393
  # * at_start
380
394
  # * TestMyClass1.startup
381
395
  # * TestMyClass1#setup
@@ -411,55 +425,57 @@ module Test # :nodoc:
411
425
  # @api private
412
426
  @@at_exit_hooks = []
413
427
 
414
- # Regsiter a hook that is run after running tests.
428
+ # Register a hook that is run after running tests.
415
429
  # To register multiple hooks, call this method multiple times.
416
430
  #
417
431
  # Here is an example test case:
418
- # Test::Unit.at_exit do
419
- # # ...
420
- # end
421
- #
422
- # class TestMyClass1 < Test::Unit::TestCase
423
- # class << self
424
- # def shutdown
425
- # # ...
426
- # end
427
- # end
428
432
  #
429
- # def teardown
433
+ # Test::Unit.at_exit do
430
434
  # # ...
431
435
  # end
432
436
  #
433
- # def test_my_class1
434
- # # ...
435
- # end
437
+ # class TestMyClass1 < Test::Unit::TestCase
438
+ # class << self
439
+ # def shutdown
440
+ # # ...
441
+ # end
442
+ # end
436
443
  #
437
- # def test_my_class2
438
- # # ...
439
- # end
440
- # end
444
+ # def teardown
445
+ # # ...
446
+ # end
441
447
  #
442
- # class TestMyClass2 < Test::Unit::TestCase
443
- # class << self
444
- # def shutdown
448
+ # def test_my_class1
445
449
  # # ...
446
450
  # end
447
- # end
448
451
  #
449
- # def teardown
450
- # # ...
452
+ # def test_my_class2
453
+ # # ...
454
+ # end
451
455
  # end
452
456
  #
453
- # def test_my_class1
454
- # # ...
455
- # end
457
+ # class TestMyClass2 < Test::Unit::TestCase
458
+ # class << self
459
+ # def shutdown
460
+ # # ...
461
+ # end
462
+ # end
456
463
  #
457
- # def test_my_class2
458
- # # ...
464
+ # def teardown
465
+ # # ...
466
+ # end
467
+ #
468
+ # def test_my_class1
469
+ # # ...
470
+ # end
471
+ #
472
+ # def test_my_class2
473
+ # # ...
474
+ # end
459
475
  # end
460
- # end
461
476
  #
462
477
  # Here is a call order:
478
+ #
463
479
  # * TestMyClass1#test_my_class1
464
480
  # * TestMyClass1#teardown
465
481
  # * TestMyClass1#test_my_class2
data/lib/test-unit.rb CHANGED
@@ -1,21 +1,6 @@
1
1
  # Copyright (C) 2012-2015 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # License: Ruby's or LGPLv2.1 or later
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License as published by the Free Software Foundation; either
8
- # version 2.1 of the License, or (at your option) any later version.
9
- #
10
- # This library is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # Lesser General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Lesser General Public
16
- # License along with this library; if not, write to the Free Software
17
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
- # 02110-1301 USA
2
+
3
+ require "test/unit/warning"
19
4
 
20
5
  module Test
21
6
  module Unit