test-unit 2.5.1 → 2.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,8 +50,13 @@ h2. License
50
50
 
51
51
  This software is distributed under the same terms as ruby.
52
52
 
53
- Exception: lib/test/unit/diff.rb is a dual license of the
54
- Ruby license and PSF license.
53
+ Exception:
54
+
55
+ * lib/test/unit/diff.rb is a double license of the Ruby license and
56
+ PSF license.
57
+
58
+ * lib/test-unit.rb is a dual license of the Ruby license and LGPLv2.1
59
+ or later.
55
60
 
56
61
  h2. Authors
57
62
 
data/Rakefile CHANGED
@@ -248,7 +248,7 @@ task :publish => ["html:publish", "reference:publish"]
248
248
 
249
249
  desc "Tag the current revision."
250
250
  task :tag do
251
- sh("git tag -a #{version} -m 'release #{version}!!!'")
251
+ sh("git tag -a #{spec.version} -m 'release #{spec.version}!!!'")
252
252
  end
253
253
 
254
254
  namespace :release do
@@ -1,3 +1,22 @@
1
+ # Copyright (C) 2012 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
19
+
1
20
  module Test
2
21
  module Unit
3
22
  autoload :TestCase, "test/unit/testcase"
@@ -308,19 +308,190 @@ module Test # :nodoc:
308
308
  #
309
309
 
310
310
  module Unit
311
- # Set true when Test::Unit has run. If set to true Test::Unit
312
- # will not automatically run at exit.
313
- #
314
- # @deprecated Use Test::Unit::AutoRunner.need_auto_run= instead.
315
- def self.run=(have_run)
316
- AutoRunner.need_auto_run = (not have_run)
317
- end
311
+ class << self
312
+ # Set true when Test::Unit has run. If set to true Test::Unit
313
+ # will not automatically run at exit.
314
+ #
315
+ # @deprecated Use Test::Unit::AutoRunner.need_auto_run= instead.
316
+ def run=(have_run)
317
+ AutoRunner.need_auto_run = (not have_run)
318
+ end
319
+
320
+ # Already tests have run?
321
+ #
322
+ # @deprecated Use Test::Unit::AutoRunner.need_auto_run? instead.
323
+ def run?
324
+ not AutoRunner.need_auto_run?
325
+ end
326
+
327
+ # @api private
328
+ @@at_start_hooks = []
329
+
330
+ # Regsiter a hook that is run before running tests.
331
+ # To register multiple hooks, call this method multiple times.
332
+ #
333
+ # Here is an example test case:
334
+ # Test::Unit.at_start do
335
+ # # ...
336
+ # end
337
+ #
338
+ # class TestMyClass1 < Test::Unit::TestCase
339
+ # class << self
340
+ # def startup
341
+ # # ...
342
+ # end
343
+ # end
344
+ #
345
+ # def setup
346
+ # # ...
347
+ # end
348
+ #
349
+ # def test_my_class1
350
+ # # ...
351
+ # end
352
+ #
353
+ # def test_my_class2
354
+ # # ...
355
+ # end
356
+ # end
357
+ #
358
+ # class TestMyClass2 < Test::Unit::TestCase
359
+ # class << self
360
+ # def startup
361
+ # # ...
362
+ # end
363
+ # end
364
+ #
365
+ # def setup
366
+ # # ...
367
+ # end
368
+ #
369
+ # def test_my_class1
370
+ # # ...
371
+ # end
372
+ #
373
+ # def test_my_class2
374
+ # # ...
375
+ # end
376
+ # end
377
+ #
378
+ # Here is a call order:
379
+ # * at_start
380
+ # * TestMyClass1.startup
381
+ # * TestMyClass1#setup
382
+ # * TestMyClass1#test_my_class1
383
+ # * TestMyClass1#setup
384
+ # * TestMyClass1#test_my_class2
385
+ # * TestMyClass2#setup
386
+ # * TestMyClass2#test_my_class1
387
+ # * TestMyClass2#setup
388
+ # * TestMyClass2#test_my_class2
389
+ #
390
+ # @example
391
+ # Test::Unit.at_start do
392
+ # puts "Start!"
393
+ # end
394
+ #
395
+ # @yield A block that is run before running tests.
396
+ # @yieldreturn [void]
397
+ # @return [void]
398
+ #
399
+ # @since 2.5.2
400
+ def at_start(&hook)
401
+ @@at_start_hooks << hook
402
+ end
403
+
404
+ # @api private
405
+ def run_at_start_hooks
406
+ @@at_start_hooks.each do |hook|
407
+ hook.call
408
+ end
409
+ end
410
+
411
+ # @api private
412
+ @@at_exit_hooks = []
413
+
414
+ # Regsiter a hook that is run after running tests.
415
+ # To register multiple hooks, call this method multiple times.
416
+ #
417
+ # 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
+ #
429
+ # def teardown
430
+ # # ...
431
+ # end
432
+ #
433
+ # def test_my_class1
434
+ # # ...
435
+ # end
436
+ #
437
+ # def test_my_class2
438
+ # # ...
439
+ # end
440
+ # end
441
+ #
442
+ # class TestMyClass2 < Test::Unit::TestCase
443
+ # class << self
444
+ # def shutdown
445
+ # # ...
446
+ # end
447
+ # end
448
+ #
449
+ # def teardown
450
+ # # ...
451
+ # end
452
+ #
453
+ # def test_my_class1
454
+ # # ...
455
+ # end
456
+ #
457
+ # def test_my_class2
458
+ # # ...
459
+ # end
460
+ # end
461
+ #
462
+ # Here is a call order:
463
+ # * TestMyClass1#test_my_class1
464
+ # * TestMyClass1#teardown
465
+ # * TestMyClass1#test_my_class2
466
+ # * TestMyClass1#teardown
467
+ # * TestMyClass1.shutdown
468
+ # * TestMyClass2#test_my_class1
469
+ # * TestMyClass2#teardown
470
+ # * TestMyClass2#test_my_class2
471
+ # * TestMyClass2#teardown
472
+ # * TestMyClass2.shutdown
473
+ # * at_exit
474
+ #
475
+ # @example
476
+ # Test::Unit.at_exit do
477
+ # puts "Exit!"
478
+ # end
479
+ #
480
+ # @yield A block that is run after running tests.
481
+ # @yieldreturn [void]
482
+ # @return [void]
483
+ #
484
+ # @since 2.5.2
485
+ def at_exit(&hook)
486
+ @@at_exit_hooks << hook
487
+ end
318
488
 
319
- # Already tests have run?
320
- #
321
- # @deprecated Use Test::Unit::AutoRunner.need_auto_run? instead.
322
- def self.run?
323
- not AutoRunner.need_auto_run?
489
+ # @api private
490
+ def run_at_exit_hooks
491
+ @@at_exit_hooks.each do |hook|
492
+ hook.call
493
+ end
494
+ end
324
495
  end
325
496
  end
326
497
  end
@@ -1379,11 +1379,14 @@ EOT
1379
1379
  end
1380
1380
  end
1381
1381
 
1382
- ##
1383
- # Called whenever an assertion is made. Define this in classes that
1384
- # include Test::Unit::Assertions to record assertion counts.
1385
-
1386
- private
1382
+ public
1383
+ # Called whenever an assertion is made. Define this in classes
1384
+ # that include Test::Unit::Assertions to record assertion
1385
+ # counts.
1386
+ #
1387
+ # This is a public API for developers who extend test-unit.
1388
+ #
1389
+ # @return [void]
1387
1390
  def add_assertion
1388
1391
  end
1389
1392
 
@@ -1615,7 +1618,7 @@ EOT
1615
1618
 
1616
1619
  class << self
1617
1620
  def target?(object)
1618
- object.is_a?(Hash) or object == ENV
1621
+ object.is_a?(Hash) or ENV.equal?(object)
1619
1622
  end
1620
1623
  end
1621
1624
 
@@ -259,6 +259,23 @@ module Test
259
259
  end
260
260
  end
261
261
 
262
+ o.on('--location=LOCATION', String,
263
+ "Runs tests that defined in LOCATION.",
264
+ "LOCATION is one of PATH:LINE, PATH or LINE") do |location|
265
+ if /\A\d+\z/ =~ location
266
+ path = nil
267
+ line = location.to_i
268
+ else
269
+ path, line, = location.split(/:(\d+)/, 2)
270
+ line = line.to_i unless line.nil?
271
+ end
272
+ @filters << lambda do |test|
273
+ test.class.test_defined?(:path => path,
274
+ :line => line,
275
+ :method_name => test.method_name)
276
+ end
277
+ end
278
+
262
279
  priority_filter = Proc.new do |test|
263
280
  if @filters == [priority_filter]
264
281
  Priority::Checker.new(test).need_to_run?
@@ -15,11 +15,27 @@ module Test
15
15
  end
16
16
 
17
17
  def add_suite(destination, suite)
18
- to_delete = suite.tests.find_all {|t| !include?(t)}
18
+ to_delete = suite.tests.find_all do |test|
19
+ test.is_a?(TestCase) and !include?(test)
20
+ end
19
21
  to_delete.each {|t| suite.delete(t)}
20
22
  destination << suite unless suite.empty?
21
23
  end
22
24
 
25
+ def add_test_cases(suite, test_cases)
26
+ children_map = {}
27
+ test_cases.each do |descendant_test_case|
28
+ parent = descendant_test_case.ancestors[1]
29
+ children_map[parent] ||= []
30
+ children_map[parent] << descendant_test_case
31
+ end
32
+
33
+ root_test_cases = children_map.keys - test_cases
34
+ root_test_cases.each do |root_test_case|
35
+ add_test_case(suite, root_test_case, children_map)
36
+ end
37
+ end
38
+
23
39
  def include?(test)
24
40
  return true if(@filters.empty?)
25
41
  @filters.each do |filter|
@@ -33,6 +49,22 @@ module Test
33
49
  [suite.priority, suite.name || suite.to_s]
34
50
  end
35
51
  end
52
+
53
+ private
54
+ def add_test_case(suite, test_case, children_map)
55
+ children = children_map[test_case]
56
+ return if children.nil?
57
+
58
+ sub_suites = []
59
+ children.each do |child|
60
+ sub_suite = child.suite
61
+ add_test_case(sub_suite, child, children_map)
62
+ add_suite(sub_suites, sub_suite)
63
+ end
64
+ sort(sub_suites).each do |sub_suite|
65
+ suite << sub_suite
66
+ end
67
+ end
36
68
  end
37
69
  end
38
70
  end
@@ -10,11 +10,7 @@ module Test
10
10
 
11
11
  def collect(name=NAME)
12
12
  suite = TestSuite.new(name)
13
- sub_suites = []
14
- TestCase::DESCENDANTS.each do |descendant_test_case|
15
- add_suite(sub_suites, descendant_test_case.suite)
16
- end
17
- sort(sub_suites).each {|s| suite << s}
13
+ add_test_cases(suite, TestCase::DESCENDANTS)
18
14
  suite
19
15
  end
20
16
  end
@@ -106,9 +106,7 @@ module Test
106
106
  rescue LoadError
107
107
  @require_failed_infos << {:path => expanded_path, :exception => $!}
108
108
  end
109
- find_test_cases(already_gathered).each do |test_case|
110
- add_suite(test_suites, test_case.suite)
111
- end
109
+ add_test_cases(test_suites, find_test_cases(already_gathered))
112
110
  end
113
111
  end
114
112
 
@@ -17,56 +17,62 @@ module Test
17
17
  @@default_for_8_colors = nil
18
18
  def default_for_8_colors
19
19
  @@default_for_8_colors ||=
20
- new("pass" => Color.new("green", :foreground => false) +
20
+ new("pass" => Color.new("green", :background => true) +
21
21
  Color.new("white", :bold => true),
22
- "failure" => Color.new("red", :foreground => false) +
22
+ "failure" => Color.new("red", :background => true) +
23
23
  Color.new("white", :bold => true),
24
- "pending" => Color.new("magenta", :bold => true),
25
- "omission" => Color.new("blue", :bold => true),
26
- "notification" => Color.new("cyan", :bold => true),
27
- "error" => Color.new("yellow", :bold => true) +
28
- Color.new("black", :foreground => false),
29
- "case" => Color.new("white", :bold => true) +
30
- Color.new("blue", :foreground => false),
31
- "suite" => Color.new("white", :bold => true) +
32
- Color.new("green", :foreground => false),
33
- "diff-inserted-tag" => Color.new("red", :bold => true),
34
- "diff-deleted-tag" => Color.new("green", :bold => true),
35
- "diff-difference-tag" => Color.new("cyan", :bold => true),
36
- "diff-inserted" => Color.new("red", :foreground => false) +
24
+ "pending" => Color.new("magenta", :background => true) +
25
+ Color.new("white", :bold => true),
26
+ "omission" => Color.new("blue", :background => true) +
27
+ Color.new("white", :bold => true),
28
+ "notification" => Color.new("cyan", :background => true) +
29
+ Color.new("white", :bold => true),
30
+ "error" => Color.new("black", :background => true) +
31
+ Color.new("yellow", :bold => true),
32
+ "case" => Color.new("blue", :background => true) +
33
+ Color.new("white", :bold => true),
34
+ "suite" => Color.new("green", :background => true) +
35
+ Color.new("white", :bold => true),
36
+ "diff-inserted-tag" => Color.new("red", :background => true) +
37
+ Color.new("black", :bold => true),
38
+ "diff-deleted-tag" => Color.new("green", :background => true) +
39
+ Color.new("black", :bold => true),
40
+ "diff-difference-tag" => Color.new("cyan", :background => true) +
41
+ Color.new("white", :bold => true),
42
+ "diff-inserted" => Color.new("red", :background => true) +
37
43
  Color.new("white", :bold => true),
38
- "diff-deleted" => Color.new("green", :foreground => false) +
44
+ "diff-deleted" => Color.new("green", :background => true) +
39
45
  Color.new("white", :bold => true))
40
46
  end
41
47
 
42
48
  @@default_for_256_colors = nil
43
49
  def default_for_256_colors
44
50
  @@default_for_256_colors ||=
45
- new("pass" => Color.new("030", :foreground => false) +
51
+ new("pass" => Color.new("030", :background => true) +
46
52
  Color.new("555", :bold => true),
47
- "failure" => Color.new("300", :foreground => false) +
53
+ "failure" => Color.new("300", :background => true) +
48
54
  Color.new("555", :bold => true),
49
- "pending" => Color.new("303", :foreground => false) +
55
+ "pending" => Color.new("303", :background => true) +
50
56
  Color.new("555", :bold => true),
51
- "omission" => Color.new("001", :foreground => false) +
57
+ "omission" => Color.new("001", :background => true) +
52
58
  Color.new("555", :bold => true),
53
- "notification" => Color.new("011", :foreground => false) +
59
+ "notification" => Color.new("011", :background => true) +
54
60
  Color.new("555", :bold => true),
55
- "error" => Color.new("550", :bold => true) +
56
- Color.new("000", :foreground => false),
57
- "case" => Color.new("220", :foreground => false) +
61
+ "error" => Color.new("000", :background => true) +
62
+ Color.new("550", :bold => true),
63
+ "case" => Color.new("220", :background => true) +
58
64
  Color.new("555", :bold => true),
59
- "suite" => Color.new("110", :foreground => false) +
65
+ "suite" => Color.new("110", :background => true) +
60
66
  Color.new("555", :bold => true),
61
- "diff-inserted-tag" => Color.new("500", :foreground => false) +
67
+ "diff-inserted-tag" => Color.new("500", :background => true) +
62
68
  Color.new("000", :bold => true),
63
- "diff-deleted-tag" => Color.new("050", :foreground => false) +
69
+ "diff-deleted-tag" => Color.new("050", :background => true) +
64
70
  Color.new("000", :bold => true),
65
- "diff-difference-tag" => Color.new("005", :foreground => false) +
71
+ "diff-difference-tag" => Color.new("005", :background => true) +
66
72
  Color.new("555", :bold => true),
67
- "diff-inserted" => Color.new("300", :foreground => false) +
73
+ "diff-inserted" => Color.new("300", :background => true) +
68
74
  Color.new("555", :bold => true),
69
- "diff-deleted" => Color.new("030", :foreground => false) +
75
+ "diff-deleted" => Color.new("030", :background => true) +
70
76
  Color.new("555", :bold => true))
71
77
  end
72
78