test-unit 2.0.6 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,31 @@
1
+ === 2.0.7 / 2010-03-09
2
+
3
+ * 4 major enhancements
4
+ * detect redefined test methods.
5
+ * [INTERFACE IMCOMPATIBLE] multiple --name and --testcase
6
+ options narrow down targets instead of adding targets.
7
+ * [#27764] accept custom test_order for each test case.
8
+ [Suggested by David MARCHALAND]
9
+ * [#27790] ignore omitted tests from 'n% passed' report.
10
+ [Suggested by Daniel Berger]
11
+
12
+ * 2 minor enchancements
13
+ * [#27832] ignore .git directory. [Suggested by Daniel Berger]
14
+ * [#27792] require 'fileutils' and 'tmpdir' lazily for non-priority
15
+ mode users. [Suggested by David MARCHALAND]
16
+
17
+ * 2n bug fixes
18
+ * [#27892] modify processed arguments array destructively.
19
+ [Reported by Bob Saveland]
20
+ * work without HOME environment variable.
21
+ [Reported by Champak Ch]
22
+
23
+ * Thanks
24
+ * David MARCHALAND
25
+ * Daniel Berger
26
+ * Bob Saveland
27
+ * Champak Ch
28
+
1
29
  === 2.0.6 / 2010-01-09
2
30
 
3
31
  * 3 major enhancements
data/README.txt CHANGED
@@ -51,5 +51,6 @@ This software is distributed under the same terms as ruby.
51
51
  * Diego Pettenò: A bug report.
52
52
  * Angelo Lakra: A bug report.
53
53
  * Mike Pomraning: A bug report.
54
- * David MARCHALAND: A bug report.
54
+ * David MARCHALAND: Suggestions and bug reports.
55
55
  * Andrew Grimm: A bug report.
56
+ * Champak Ch: A bug report.
@@ -117,27 +117,21 @@ module Test
117
117
  if File.exist?(config_file)
118
118
  load_config(config_file)
119
119
  else
120
- global_config_file = File.expand_path("~/.test-unit.xml")
121
- load_config(global_config_file) if File.exist?(global_config_file)
120
+ load_global_config
122
121
  end
123
122
  yield(self) if block_given?
124
123
  end
125
124
 
126
125
  def process_args(args = ARGV)
127
- default_arguments = @default_arguments.dup
128
126
  begin
129
- @default_arguments.concat(args)
130
- options.order!(@default_arguments) {|arg| @to_run << arg}
127
+ args.unshift(*@default_arguments)
128
+ options.order!(args) {|arg| @to_run << arg}
131
129
  rescue OptionParser::ParseError => e
132
130
  puts e
133
131
  puts options
134
132
  exit(false)
135
- else
136
- @filters << proc{false} unless(@filters.empty?)
137
133
  end
138
134
  not @to_run.empty?
139
- ensure
140
- @default_arguments = default_arguments
141
135
  end
142
136
 
143
137
  def options
@@ -186,9 +180,9 @@ module Test
186
180
  n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n)
187
181
  case n
188
182
  when Regexp
189
- @filters << proc{|t| n =~ t.method_name ? true : nil}
183
+ @filters << proc{|t| n =~ t.method_name ? true : false}
190
184
  else
191
- @filters << proc{|t| n == t.method_name ? true : nil}
185
+ @filters << proc{|t| n == t.method_name}
192
186
  end
193
187
  end
194
188
 
@@ -198,17 +192,17 @@ module Test
198
192
  n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n)
199
193
  case n
200
194
  when Regexp
201
- @filters << proc{|t| n =~ t.class.name ? true : nil}
195
+ @filters << proc{|t| n =~ t.class.name ? true : false}
202
196
  else
203
- @filters << proc{|t| n == t.class.name ? true : nil}
197
+ @filters << proc{|t| n == t.class.name}
204
198
  end
205
199
  end
206
200
 
207
201
  priority_filter = Proc.new do |test|
208
- if @filters.size > 2
209
- nil
202
+ if @filters == [priority_filter]
203
+ Priority::Checker.new(test).need_to_run?
210
204
  else
211
- Priority::Checker.new(test).need_to_run? or nil
205
+ nil
212
206
  end
213
207
  end
214
208
  o.on("--[no-]priority-mode",
@@ -346,6 +340,17 @@ module Test
346
340
  def default_collector
347
341
  self.class.collector(@standalone ? :load : :descendant)
348
342
  end
343
+
344
+ def global_config_file
345
+ File.expand_path("~/.test-unit.xml")
346
+ rescue ArgumentError
347
+ nil
348
+ end
349
+
350
+ def load_global_config
351
+ file = global_config_file
352
+ load_config(file) if file and File.exist?(file)
353
+ end
349
354
  end
350
355
  end
351
356
  end
@@ -23,14 +23,7 @@ module Test
23
23
  def include?(test)
24
24
  return true if(@filters.empty?)
25
25
  @filters.each do |filter|
26
- result = filter[test]
27
- if(result.nil?)
28
- next
29
- elsif(!result)
30
- return false
31
- else
32
- return true
33
- end
26
+ return false if filter[test] == false
34
27
  end
35
28
  true
36
29
  end
@@ -60,7 +60,7 @@ module Test
60
60
  next if(e == '.' || e == '..')
61
61
  e_name = dir_name ? @file.join(dir_name, e) : e
62
62
  if @file.directory?(realdir(e_name))
63
- next if /\A(?:CVS|\.svn)\z/ =~ e
63
+ next if /\A(?:CVS|\.svn|\.git)\z/ =~ e
64
64
  sub_suite = recursive_collect(e_name, already_gathered)
65
65
  sub_suites << sub_suite unless(sub_suite.empty?)
66
66
  else
@@ -14,7 +14,7 @@ module Test
14
14
  def initialize
15
15
  super
16
16
  @system_excludes = [/~\z/, /\A\.\#/]
17
- @system_directory_excludes = [/\A(?:CVS|\.svn)\z/]
17
+ @system_directory_excludes = [/\A(?:CVS|\.svn|\.git)\z/]
18
18
  @patterns = [/\Atest[_\-].+\.rb\z/m]
19
19
  @excludes = []
20
20
  @base = nil
@@ -60,6 +60,10 @@ module Test
60
60
  def to_s
61
61
  long_display
62
62
  end
63
+
64
+ def critical?
65
+ true
66
+ end
63
67
  end
64
68
 
65
69
  module ErrorHandler
@@ -59,6 +59,10 @@ module Test
59
59
  long_display
60
60
  end
61
61
 
62
+ def critical?
63
+ true
64
+ end
65
+
62
66
  def diff
63
67
  @diff ||= compute_diff
64
68
  end
@@ -41,6 +41,10 @@ module Test
41
41
  def to_s
42
42
  long_display
43
43
  end
44
+
45
+ def critical?
46
+ false
47
+ end
44
48
  end
45
49
 
46
50
  class NotifiedError < StandardError
@@ -79,16 +83,16 @@ module Test
79
83
  module NotificationHandler
80
84
  class << self
81
85
  def included(base)
82
- base.exception_handler(:handle_Notified_error)
86
+ base.exception_handler(:handle_notified_error)
83
87
  end
84
88
  end
85
89
 
86
90
  private
87
- def handle_Notified_error(exception)
91
+ def handle_notified_error(exception)
88
92
  return false unless exception.is_a?(NotifiedError)
89
93
  notification = Notification.new(name,
90
- filter_backtrace(exception.backtrace),
91
- exception.message)
94
+ filter_backtrace(exception.backtrace),
95
+ exception.message)
92
96
  add_notification(notification)
93
97
  true
94
98
  end
@@ -41,6 +41,10 @@ module Test
41
41
  def to_s
42
42
  long_display
43
43
  end
44
+
45
+ def critical?
46
+ true
47
+ end
44
48
  end
45
49
 
46
50
  class OmittedError < StandardError
@@ -41,6 +41,10 @@ module Test
41
41
  def to_s
42
42
  long_display
43
43
  end
44
+
45
+ def critical?
46
+ true
47
+ end
44
48
  end
45
49
 
46
50
  class PendedError < StandardError
@@ -1,6 +1,3 @@
1
- require "fileutils"
2
- require "tmpdir"
3
-
4
1
  module Test
5
2
  module Unit
6
3
  module Priority
@@ -20,6 +17,8 @@ module Test
20
17
  end
21
18
 
22
19
  def enable
20
+ require "fileutils"
21
+ require "tmpdir"
23
22
  @@enabled = true
24
23
  end
25
24
 
@@ -94,10 +94,15 @@ module Test
94
94
  DESCENDANTS << sub_class
95
95
  end
96
96
 
97
- @@added_methods = []
97
+ @@added_methods = {}
98
98
  def method_added(name) # :nodoc:
99
99
  super
100
- @@added_methods << name.to_s
100
+ added_methods = (@@added_methods[self] ||= [])
101
+ stringified_name = name.to_s
102
+ if added_methods.include?(stringified_name)
103
+ attribute(:redefined, true, {}, stringified_name)
104
+ end
105
+ added_methods << stringified_name
101
106
  end
102
107
 
103
108
  # Rolls up all of the test* methods in the fixture into
@@ -191,12 +196,12 @@ module Test
191
196
  def shutdown
192
197
  end
193
198
 
194
- @@test_order = AVAILABLE_ORDERS.first
199
+ @@test_orders = {}
195
200
 
196
201
  # Returns the current test order. This returns
197
202
  # +:alphabetic+ by default.
198
203
  def test_order
199
- @@test_order
204
+ @@test_orders[self] || AVAILABLE_ORDERS.first
200
205
  end
201
206
 
202
207
  # Sets the current test order.
@@ -209,7 +214,7 @@ module Test
209
214
  # [:defined]
210
215
  # Tests are sorted in defined order.
211
216
  def test_order=(order)
212
- @@test_order = order
217
+ @@test_orders[self] = order
213
218
  end
214
219
 
215
220
  # Defines a test in declarative syntax.
@@ -266,9 +271,10 @@ module Test
266
271
  end
267
272
 
268
273
  def sort_test_names_in_defined_order(test_names)
274
+ added_methods = @@added_methods[self]
269
275
  test_names.sort do |test1, test2|
270
- test1_defined_order = @@added_methods.index(test1)
271
- test2_defined_order = @@added_methods.index(test2)
276
+ test1_defined_order = added_methods.index(test1)
277
+ test2_defined_order = added_methods.index(test2)
272
278
  if test1_defined_order and test2_defined_order
273
279
  test1_defined_order <=> test2_defined_order
274
280
  elsif test1_defined_order
@@ -438,6 +444,9 @@ module Test
438
444
  end
439
445
 
440
446
  def run_test
447
+ if self.class.get_attribute(@method_name, :redefined)
448
+ notify("#{self.class}\##{@method_name} was redefined")
449
+ end
441
450
  __send__(@method_name)
442
451
  end
443
452
 
@@ -39,6 +39,7 @@ module Test
39
39
  @progress_row_max ||= guess_progress_row_max
40
40
  @already_outputted = false
41
41
  @n_successes = 0
42
+ @n_omissions = 0
42
43
  @indent = 0
43
44
  @top_level = true
44
45
  @faults = []
@@ -84,7 +85,8 @@ module Test
84
85
  def add_fault(fault)
85
86
  @faults << fault
86
87
  output_progress(fault.single_character_display, fault_color(fault))
87
- @already_outputted = true
88
+ @n_omissions += 1 if fault.is_a?(Omission)
89
+ @already_outputted = true if fault.critical?
88
90
  end
89
91
 
90
92
  def started(result)
@@ -107,7 +109,7 @@ module Test
107
109
  output("Finished in #{elapsed_time} seconds.")
108
110
  nl
109
111
  output(@result, result_color)
110
- n_tests = @result.run_count
112
+ n_tests = @result.run_count - @n_omissions
111
113
  if n_tests.zero?
112
114
  pass_percentage = 0
113
115
  else
@@ -2,6 +2,6 @@
2
2
  # HACK: quick and dirty to get integrated into the new project - ryan
3
3
  module Test
4
4
  module Unit
5
- VERSION = '2.0.6'
5
+ VERSION = '2.0.7'
6
6
  end
7
7
  end
@@ -66,7 +66,7 @@ class TestUnitCollectorDescendant < Test::Unit::TestCase
66
66
  collector.filter = [Proc.new {false}, Proc.new {true}]
67
67
  end
68
68
 
69
- assert_collect(full_suite) do |collector|
69
+ assert_collect(empty_suite) do |collector|
70
70
  collector.filter = [Proc.new {true}, Proc.new {false}]
71
71
  end
72
72
 
@@ -90,13 +90,11 @@ class TestUnitCollectorDescendant < Test::Unit::TestCase
90
90
  end
91
91
  end
92
92
 
93
- expected = empty_suite
94
93
  suite1 = Test::Unit::TestSuite.new(@test_case1.name)
95
94
  suite1 << @test_case1.new("test_1")
96
95
  suite2 = Test::Unit::TestSuite.new(@test_case2.name)
97
96
  suite2 << @test_case2.new("test_0")
98
- expected << suite1 << suite2
99
- assert_collect(expected) do |collector|
97
+ assert_collect(empty_suite) do |collector|
100
98
  filters = [Proc.new {|test| test.method_name == 'test_1' ? true : nil},
101
99
  Proc.new {|test| test.method_name == 'test_0' ? true : nil},
102
100
  Proc.new {false}]
@@ -196,6 +196,25 @@ EOT
196
196
  end
197
197
  end
198
198
 
199
+ setup
200
+ def setup_sub_git_test_cases
201
+ @sub_git_test_dir = @sub_test_dir + ".git"
202
+ @sub_git_test_dir.mkpath
203
+
204
+ @sub_git_test_case11 = @sub_git_test_dir + "test_case11.rb"
205
+
206
+ @sub_git_test_case11.open("w") do |test_case|
207
+ test_case.puts(<<-EOT)
208
+ module #{@temporary_test_cases_module_name}
209
+ class SubGitTestCase11 < Test::Unit::TestCase
210
+ def test11
211
+ end
212
+ end
213
+ end
214
+ EOT
215
+ end
216
+ end
217
+
199
218
  def teardown
200
219
  @test_dir.rmtree if @test_dir.exist?
201
220
  ::Object.send(:remove_const, @temporary_test_cases_module_name)
@@ -72,7 +72,7 @@ module Test
72
72
  assert_equal(empty_suite, @c.collect)
73
73
 
74
74
  @c.filter = [proc{true}, proc{false}]
75
- assert_equal(full_suite, @c.collect)
75
+ assert_equal(empty_suite, @c.collect)
76
76
 
77
77
  @c.filter = [proc{nil}, proc{false}]
78
78
  assert_equal(empty_suite, @c.collect)
@@ -87,10 +87,12 @@ module Test
87
87
  assert_equal(expected, @c.collect)
88
88
 
89
89
  expected = TestSuite.new(ObjectSpace::NAME)
90
- expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1'))
91
- expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
92
- @c.filter = [proc{|t| t.method_name == 'test_1' ? true : nil}, proc{|t| t.method_name == 'test_0' ? true : nil}, proc{false}]
93
- assert_equal(expected, @c.collect)
90
+ TestSuite.new(@tc1.name) << @tc1.new('test_1')
91
+ TestSuite.new(@tc2.name) << @tc2.new('test_0')
92
+ @c.filter = [proc{|t| t.method_name == 'test_1' ? true : nil},
93
+ proc{|t| t.method_name == 'test_0' ? true : nil},
94
+ proc{false}]
95
+ assert_equal(empty_suite, @c.collect)
94
96
  end
95
97
  end
96
98
  end
@@ -7,6 +7,7 @@ require 'test/unit'
7
7
  module Test
8
8
  module Unit
9
9
  class TestTestCase < TestCase
10
+ self.test_order = :random
10
11
  def test_creation
11
12
  tc = Class.new(TestCase) do
12
13
  def test_with_arguments(arg1, arg2)
@@ -469,52 +470,68 @@ module Test
469
470
  end
470
471
 
471
472
  def test_defined_order
472
- keep_test_order do
473
- test_case = Class.new(Test::Unit::TestCase) do
474
- def test_z
475
- end
473
+ test_case = Class.new(Test::Unit::TestCase) do
474
+ def test_z
475
+ end
476
476
 
477
- def test_1
478
- end
477
+ def test_1
478
+ end
479
479
 
480
- def test_a
481
- end
480
+ def test_a
482
481
  end
482
+ end
483
483
 
484
- assert_equal(["test_1", "test_a", "test_z"],
485
- test_case.suite.tests.collect {|test| test.method_name})
484
+ assert_equal(["test_1", "test_a", "test_z"],
485
+ test_case.suite.tests.collect {|test| test.method_name})
486
486
 
487
- test_case.test_order = :defined
488
- assert_equal(["test_z", "test_1", "test_a"],
489
- test_case.suite.tests.collect {|test| test.method_name})
490
- end
487
+ test_case.test_order = :defined
488
+ assert_equal(["test_z", "test_1", "test_a"],
489
+ test_case.suite.tests.collect {|test| test.method_name})
491
490
  end
492
491
 
493
492
  def test_declarative_style
494
- keep_test_order do
495
- test_case = Class.new(Test::Unit::TestCase) do
496
- test "declarative style test definition" do
497
- end
493
+ test_case = Class.new(Test::Unit::TestCase) do
494
+ test "declarative style test definition" do
495
+ end
498
496
 
499
- test "include parenthesis" do
500
- end
497
+ test "include parenthesis" do
498
+ end
501
499
 
502
- test "1 + 2 = 3" do
503
- end
500
+ test "1 + 2 = 3" do
504
501
  end
502
+ end
505
503
 
506
- test_case.test_order = :defined
504
+ test_case.test_order = :defined
507
505
 
508
- assert_equal(["test_declarative_style_test_definition",
509
- "test_include_parenthesis",
510
- "test_1_2_3"],
511
- test_case.suite.tests.collect {|test| test.method_name})
506
+ assert_equal(["test_declarative_style_test_definition",
507
+ "test_include_parenthesis",
508
+ "test_1_2_3"],
509
+ test_case.suite.tests.collect {|test| test.method_name})
510
+
511
+ assert_equal(["declarative style test definition",
512
+ "include parenthesis",
513
+ "1 + 2 = 3"],
514
+ test_case.suite.tests.collect {|test| test.description})
515
+ end
516
+
517
+ def test_redefine_method
518
+ test_case = Class.new(Test::Unit::TestCase) do
519
+ def test_name
520
+ end
521
+ alias_method :test_name2, :test_name
512
522
 
513
- assert_equal(["declarative style test definition",
514
- "include parenthesis",
515
- "1 + 2 = 3"],
516
- test_case.suite.tests.collect {|test| test.description})
523
+ def test_name
524
+ end
517
525
  end
526
+
527
+ suite = test_case.suite
528
+ assert_equal(["test_name", "test_name2"],
529
+ suite.tests.collect {|test| test.method_name})
530
+ result = TestResult.new
531
+ suite.run(result) {}
532
+ assert_equal("2 tests, 0 assertions, 0 failures, " +
533
+ "0 errors, 0 pendings, 0 omissions, 1 notifications",
534
+ result.summary)
518
535
  end
519
536
 
520
537
  private
@@ -522,13 +539,6 @@ module Test
522
539
  add_assertion
523
540
  raise AssertionFailedError.new(message) unless passed
524
541
  end
525
-
526
- def keep_test_order
527
- order = TestCase.test_order
528
- yield
529
- ensure
530
- TestCase.test_order = order
531
- end
532
542
  end
533
543
  end
534
544
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-unit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
@@ -10,9 +10,29 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-09 00:00:00 +09:00
13
+ date: 2010-03-09 00:00:00 +09:00
14
14
  default_executable:
15
15
  dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rubyforge
18
+ type: :development
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 2.0.4
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: gemcutter
28
+ type: :development
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.5.0
35
+ version:
16
36
  - !ruby/object:Gem::Dependency
17
37
  name: hoe
18
38
  type: :development
@@ -21,7 +41,7 @@ dependencies:
21
41
  requirements:
22
42
  - - ">="
23
43
  - !ruby/object:Gem::Version
24
- version: 2.4.0
44
+ version: 2.5.0
25
45
  version:
26
46
  description: |-
27
47
  Test::Unit 2.x - Improved version of Test::Unit bundled in