test-unit 2.0.7 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,26 @@
1
+ === 2.0.8 / 2010-06-02
2
+
3
+ * 5 major enchancements
4
+ * collect *_test.rb and *-test.rb files as test files.
5
+ * [#28181] improve assert_in_delta message.
6
+ [Suggested by David MARCHALAND]
7
+ * show string encoding in assert_equal failure message if
8
+ they are different.
9
+ * change default color scheme:
10
+ * success: green back + white
11
+ * failure: red back + white
12
+ * add capture_output.
13
+
14
+ * 2 bug fixes
15
+ * fix a bug that console runner on verbose mode causes an
16
+ error for long test name (>= 61).
17
+ * [#28093] Autorunner ignores all files in a directory named test by default
18
+ [Reported by Florian Frank]
19
+
20
+ * Thanks
21
+ * Florian Frank
22
+ * David MARCHALAND
23
+
1
24
  === 2.0.7 / 2010-03-09
2
25
 
3
26
  * 4 major enhancements
@@ -14,7 +37,7 @@
14
37
  * [#27792] require 'fileutils' and 'tmpdir' lazily for non-priority
15
38
  mode users. [Suggested by David MARCHALAND]
16
39
 
17
- * 2n bug fixes
40
+ * 2 bug fixes
18
41
  * [#27892] modify processed arguments array destructively.
19
42
  [Reported by Bob Saveland]
20
43
  * work without HOME environment variable.
data/README.txt CHANGED
@@ -54,3 +54,4 @@ This software is distributed under the same terms as ruby.
54
54
  * David MARCHALAND: Suggestions and bug reports.
55
55
  * Andrew Grimm: A bug report.
56
56
  * Champak Ch: A bug report.
57
+ * Florian Frank: A bug report.
@@ -1,6 +1,6 @@
1
1
  # Author:: Nathaniel Talbott.
2
2
  # Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
3
- # Copyright (c) 2009 Kouhei Sutou.
3
+ # Copyright (c) 2009-2010 Kouhei Sutou. All rights reserved.
4
4
  # License:: Ruby license.
5
5
 
6
6
  require 'test/unit/assertionfailederror'
@@ -80,10 +80,23 @@ module Test
80
80
  public
81
81
  def assert_equal(expected, actual, message=nil)
82
82
  diff = AssertionMessage.delayed_diff(expected, actual)
83
- full_message = build_message(message, <<EOT, expected, actual, diff)
83
+ if expected.respond_to?(:encoding) and
84
+ actual.respond_to?(:encoding) and
85
+ expected.encoding != actual.encoding
86
+ format = <<EOT
87
+ <?>(?) expected but was
88
+ <?>(?).?
89
+ EOT
90
+ full_message = build_message(message, format,
91
+ expected, expected.encoding.name,
92
+ actual, actual.encoding.name,
93
+ diff)
94
+ else
95
+ full_message = build_message(message, <<EOT, expected, actual, diff)
84
96
  <?> expected but was
85
97
  <?>.?
86
98
  EOT
99
+ end
87
100
  begin
88
101
  assert_block(full_message) { expected == actual }
89
102
  rescue AssertionFailedError => failure
@@ -539,18 +552,73 @@ EOT
539
552
  public
540
553
  def assert_in_delta(expected_float, actual_float, delta, message="")
541
554
  _wrap_assertion do
542
- {expected_float => "first float", actual_float => "second float", delta => "delta"}.each do |float, name|
543
- assert_respond_to(float, :to_f, "The arguments must respond to to_f; the #{name} did not")
544
- end
545
- assert_operator(delta, :>=, 0.0, "The delta should not be negative")
546
- full_message = build_message(message, <<EOT, expected_float, actual_float, delta)
547
- <?> and
548
- <?> expected to be within
549
- <?> of each other.
555
+ _assert_in_delta_validate_arguments(expected_float,
556
+ actual_float,
557
+ delta)
558
+ full_message = _assert_in_delta_message(expected_float,
559
+ actual_float,
560
+ delta,
561
+ message)
562
+ assert_block(full_message) do
563
+ (expected_float.to_f - actual_float.to_f).abs <= delta.to_f
564
+ end
565
+ end
566
+ end
567
+
568
+ # :stopdoc:
569
+ private
570
+ def _assert_in_delta_validate_arguments(expected_float,
571
+ actual_float,
572
+ delta)
573
+ {
574
+ expected_float => "first float",
575
+ actual_float => "second float",
576
+ delta => "delta"
577
+ }.each do |float, name|
578
+ assert_respond_to(float, :to_f,
579
+ "The arguments must respond to to_f; " +
580
+ "the #{name} did not")
581
+ end
582
+ assert_operator(delta, :>=, 0.0, "The delta should not be negative")
583
+ end
584
+
585
+ def _assert_in_delta_message(expected_float, actual_float, delta,
586
+ message)
587
+ format = <<-EOT
588
+ <?> expected but was
589
+ <?> (tolerance <?>).
590
+ EOT
591
+ arguments = [expected_float, actual_float, delta]
592
+ normalized_expected = expected_float.to_f
593
+ normalized_actual = actual_float.to_f
594
+ normalized_delta = delta.to_f
595
+ relation_format = nil
596
+ relation_arguments = nil
597
+ if normalized_actual < normalized_expected - normalized_delta
598
+ relation_format = "<<?> < <?>-<?>(?) <= <?>+<?>(?)>"
599
+ relation_arguments = [actual_float,
600
+ expected_float, delta, expected_float - delta,
601
+ expected_float, delta, expected_float + delta]
602
+ elsif normalized_expected - normalized_delta < normalized_actual
603
+ relation_format = "<<?>-<?>(?) <= <?>+<?>(?) < <?>>"
604
+ relation_arguments = [expected_float, delta, expected_float - delta,
605
+ expected_float, delta, expected_float + delta,
606
+ actual_float]
607
+ end
608
+
609
+ if relation_format
610
+ format << <<-EOT
611
+
612
+ Relation:
613
+ #{relation_format}
550
614
  EOT
551
- assert_block(full_message) { (expected_float.to_f - actual_float.to_f).abs <= delta.to_f }
615
+ arguments.concat(relation_arguments)
552
616
  end
617
+
618
+ build_message(message, format, *arguments)
553
619
  end
620
+ public
621
+ # :startdoc:
554
622
 
555
623
  ##
556
624
  # Passes if the method send returns a true value.
@@ -15,7 +15,7 @@ module Test
15
15
  super
16
16
  @system_excludes = [/~\z/, /\A\.\#/]
17
17
  @system_directory_excludes = [/\A(?:CVS|\.svn|\.git)\z/]
18
- @patterns = [/\Atest[_\-].+\.rb\z/m]
18
+ @patterns = [/\Atest[_\-].+\.rb\z/m, /[_\-]test\.rb\z/]
19
19
  @excludes = []
20
20
  @base = nil
21
21
  end
@@ -28,11 +28,17 @@ module Test
28
28
  def collect(*froms)
29
29
  add_load_path(@base) do
30
30
  froms = ["."] if froms.empty?
31
- test_suites = froms.collect do |from|
32
- test_suite = collect_recursive(resolve_path(from), find_test_cases)
33
- test_suite = nil if test_suite.tests.empty?
34
- test_suite
35
- end.compact
31
+ test_suites = []
32
+ already_gathered = find_test_cases
33
+ froms.each do |from|
34
+ from = resolve_path(from)
35
+ if from.directory?
36
+ test_suite = collect_recursive(from, already_gathered)
37
+ test_suites << test_suite unless test_suite.tests.empty?
38
+ else
39
+ collect_file(from, test_suites, already_gathered)
40
+ end
41
+ end
36
42
 
37
43
  if test_suites.size > 1
38
44
  test_suite = TestSuite.new("[#{froms.join(', ')}]")
@@ -88,6 +94,8 @@ module Test
88
94
  end
89
95
 
90
96
  def collect_file(path, test_suites, already_gathered)
97
+ @program_file ||= File.expand_path($0)
98
+ return if @program_file == path.to_s
91
99
  add_load_path(path.expand_path.dirname) do
92
100
  require(path.to_s)
93
101
  find_test_cases(already_gathered).each do |test_case|
@@ -8,8 +8,12 @@ module Test
8
8
  class << self
9
9
  @@default = nil
10
10
  def default
11
- @@default ||= new("success" => Color.new("green", :bold => true),
12
- "failure" => Color.new("red", :bold => true),
11
+ @@default ||= new("success" =>
12
+ Color.new("green", :foreground => false) +
13
+ Color.new("white", :bold => true),
14
+ "failure" =>
15
+ Color.new("red", :foreground => false) +
16
+ Color.new("white", :bold => true),
13
17
  "pending" => Color.new("magenta", :bold => true),
14
18
  "omission" => Color.new("blue", :bold => true),
15
19
  "notification" => Color.new("cyan", :bold => true),
@@ -717,7 +717,16 @@ module Test
717
717
 
718
718
  def diff(differ_class, from, to, options={})
719
719
  differ = differ_class.new(from.split(/\r?\n/), to.split(/\r?\n/))
720
- differ.diff(options).join("\n")
720
+ lines = differ.diff(options)
721
+ if Object.const_defined?(:EncodingError)
722
+ begin
723
+ lines.join("\n")
724
+ rescue EncodingError
725
+ lines.collect {|line| line.force_encoding("ASCII-8BIT")}.join("\n")
726
+ end
727
+ else
728
+ lines.join("\n")
729
+ end
721
730
  end
722
731
  end
723
732
  end
@@ -19,6 +19,7 @@ require 'test/unit/priority'
19
19
  require 'test/unit/testsuite'
20
20
  require 'test/unit/assertionfailederror'
21
21
  require 'test/unit/util/backtracefilter'
22
+ require 'test/unit/util/output'
22
23
  require 'test/unit/util/method-owner-finder'
23
24
 
24
25
  module Test
@@ -82,6 +83,7 @@ module Test
82
83
  include Priority
83
84
  include Assertions
84
85
  include Util::BacktraceFilter
86
+ include Util::Output
85
87
 
86
88
  STARTED = name + "::STARTED" # :nodoc:
87
89
  FINISHED = name + "::FINISHED" # :nodoc:
@@ -188,7 +188,7 @@ module Test
188
188
  right_space = 8 * 2
189
189
  left_space = @progress_row_max - right_space
190
190
  left_space = left_space - indent.size - name.size
191
- tab_stop = "\t" * ((left_space - 1) / 8)
191
+ tab_stop = "\t" * ([left_space - 1, 0].max / 8)
192
192
  output_single("#{indent}#{name}:#{tab_stop}", nil, VERBOSE)
193
193
  @test_start = Time.now
194
194
  end
@@ -9,6 +9,7 @@ module Test
9
9
  module_function
10
10
  def filter_backtrace(backtrace, prefix=nil)
11
11
  return ["No backtrace"] unless(backtrace)
12
+ return backtrace if ENV["TEST_UNIT_ALL_BACKTRACE"]
12
13
  split_p = if(prefix)
13
14
  prefix.split(TESTUNIT_FILE_SEPARATORS)
14
15
  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.7'
5
+ VERSION = '2.0.8'
6
6
  end
7
7
  end
@@ -13,8 +13,9 @@ class TestUnitCollectorLoad < Test::Unit::TestCase
13
13
  ::Object.const_set(@temporary_test_cases_module_name, Module.new)
14
14
 
15
15
  @test_dir = Pathname(Dir.tmpdir) + "test-unit"
16
- @test_dir.rmtree if @test_dir.exist?
17
- @test_dir.mkpath
16
+ @extra_test_dir = Pathname(Dir.tmpdir) + "test-unit-extra"
17
+ ensure_clean_directory(@test_dir)
18
+ ensure_clean_directory(@extra_test_dir)
18
19
  end
19
20
 
20
21
  setup
@@ -215,6 +216,53 @@ EOT
215
216
  end
216
217
  end
217
218
 
219
+ setup
220
+ def setup_extra_top_level_test_cases
221
+ @test_cases12 = @extra_test_dir + "test_cases12.rb"
222
+ @test_cases12.open("w") do |test_case|
223
+ test_case.puts(<<-EOT)
224
+ module #{@temporary_test_cases_module_name}
225
+ class TestCase121 < Test::Unit::TestCase
226
+ def test121_1
227
+ end
228
+
229
+ def test121_2
230
+ end
231
+ end
232
+
233
+ class TestCase122 < Test::Unit::TestCase
234
+ def test122_1
235
+ end
236
+
237
+ def test122_2
238
+ end
239
+ end
240
+ end
241
+ EOT
242
+ end
243
+ end
244
+
245
+ setup
246
+ def setup_sub_level_extra_test_cases
247
+ @sub_extra_test_dir = @extra_test_dir + "sub"
248
+ @sub_extra_test_dir.mkpath
249
+
250
+ @cases13_test = @sub_extra_test_dir + "13cases_test.rb"
251
+ @cases13_test.open("w") do |test_case|
252
+ test_case.puts(<<-EOT)
253
+ module #{@temporary_test_cases_module_name}
254
+ class SubTestCase13 < Test::Unit::TestCase
255
+ def test13_1
256
+ end
257
+
258
+ def test13_2
259
+ end
260
+ end
261
+ end
262
+ EOT
263
+ end
264
+ end
265
+
218
266
  def teardown
219
267
  @test_dir.rmtree if @test_dir.exist?
220
268
  ::Object.send(:remove_const, @temporary_test_cases_module_name)
@@ -231,6 +279,21 @@ EOT
231
279
  @sub_test_dir.to_s)
232
280
  end
233
281
 
282
+ def test_simple_collect_test_suffix
283
+ assert_collect([:suite, {:name => @extra_test_dir.basename.to_s},
284
+ [:suite, {:name => _test_case_name("TestCase121")},
285
+ [:test, {:name => "test121_1"}],
286
+ [:test, {:name => "test121_2"}]],
287
+ [:suite, {:name => _test_case_name("TestCase122")},
288
+ [:test, {:name => "test122_1"}],
289
+ [:test, {:name => "test122_2"}]],
290
+ [:suite, {:name => @sub_extra_test_dir.basename.to_s},
291
+ [:suite, {:name => _test_case_name("SubTestCase13")},
292
+ [:test, {:name => "test13_1"}],
293
+ [:test, {:name => "test13_2"}]]]],
294
+ @extra_test_dir.to_s)
295
+ end
296
+
234
297
  def test_multilevel_collect
235
298
  assert_collect([:suite, {:name => "."},
236
299
  [:suite, {:name => _test_case_name("TestCase1")},
@@ -253,13 +316,39 @@ EOT
253
316
  end
254
317
 
255
318
  def test_collect_file
256
- assert_collect([:suite, {:name => @test_case1.basename.to_s},
257
- [:suite, {:name => _test_case_name("TestCase1")},
258
- [:test, {:name => "test1_1"}],
259
- [:test, {:name => "test1_2"}]]],
319
+ assert_collect([:suite, {:name => _test_case_name("TestCase1")},
320
+ [:test, {:name => "test1_1"}],
321
+ [:test, {:name => "test1_2"}]],
260
322
  @test_case1.to_s)
323
+ end
261
324
 
262
- assert_collect(nil, @no_load_sub_test_case5.to_s)
325
+ def test_collect_file_no_pattern_match_file_name
326
+ assert_collect([:suite, {:name => _test_case_name("NoLoadSubTestCase5")},
327
+ [:test, {:name => "test5_1"}],
328
+ [:test, {:name => "test5_2"}]],
329
+ @no_load_sub_test_case5.to_s)
330
+ end
331
+
332
+ def test_collect_file_test_cases
333
+ assert_collect([:suite, {:name => "[#{@test_cases12}]"},
334
+ [:suite, {:name => _test_case_name("TestCase121")},
335
+ [:test, {:name => "test121_1"}],
336
+ [:test, {:name => "test121_2"}]],
337
+ [:suite, {:name => _test_case_name("TestCase122")},
338
+ [:test, {:name => "test122_1"}],
339
+ [:test, {:name => "test122_2"}]]],
340
+ @test_cases12.to_s)
341
+ end
342
+
343
+ def test_collect_files
344
+ assert_collect([:suite,
345
+ {:name => "[#{@test_case1}, #{@test_case2}]"},
346
+ [:suite, {:name => _test_case_name("TestCase1")},
347
+ [:test, {:name => "test1_1"}],
348
+ [:test, {:name => "test1_2"}]],
349
+ [:suite, {:name => _test_case_name("TestCase2")},
350
+ [:test, {:name => "test2"}]]],
351
+ @test_case1.to_s, @test_case2.to_s)
263
352
  end
264
353
 
265
354
  def test_nil_pattern
@@ -297,7 +386,7 @@ EOT
297
386
  [:test, {:name => "test4_2"}]],
298
387
  [:suite, {:name => _test_case_name("SubTestCase6")},
299
388
  [:test, {:name => "test6"}]]],
300
- [:suite, {:name => @sub2_test_dir.basename.to_s},
389
+ [:suite, {:name => @sub2_test_dir.basename.to_s},
301
390
  [:suite, {:name => _test_case_name("Sub2TestCase8")},
302
391
  [:test, {:name => "test8_1"}],
303
392
  [:test, {:name => "test8_2"}]],
@@ -318,6 +407,11 @@ EOT
318
407
  end
319
408
  end
320
409
 
410
+ def ensure_clean_directory(directory)
411
+ directory.rmtree if directory.exist?
412
+ directory.mkpath
413
+ end
414
+
321
415
  def keep_required_files
322
416
  required_files = $".dup
323
417
  yield
@@ -1,8 +1,10 @@
1
1
  class TestUnitColorScheme < Test::Unit::TestCase
2
2
  def test_default
3
3
  assert_equal({
4
- "success" => color("green", :bold => true),
5
- "failure" => color("red", :bold => true),
4
+ "success" => color("green", :foreground => false) +
5
+ color("white", :bold => true),
6
+ "failure" => color("red", :foreground => false) +
7
+ color("white", :bold => true),
6
8
  "pending" => color("magenta", :bold => true),
7
9
  "omission" => color("blue", :bold => true),
8
10
  "notification" => color("cyan", :bold => true),
@@ -1,6 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
1
3
  # Author:: Nathaniel Talbott.
2
4
  # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
3
- # Copyright (c) 2009 Kouhei Sutou.
5
+ # Copyright (c) 2009-2010 Kouhei Sutou. All rights reserved.
4
6
  # License:: Ruby license.
5
7
 
6
8
  require 'test/unit'
@@ -311,6 +313,21 @@ EOM
311
313
  end
312
314
  end
313
315
 
316
+ def test_assert_equal_with_different_encoding
317
+ utf8_string = "こんにちは"
318
+ unless utf8_string.respond_to?(:force_encoding)
319
+ omit("encoding test is for Ruby >= 1.9")
320
+ end
321
+ ascii_8bit_string = utf8_string.dup.force_encoding("ascii-8bit")
322
+ message = <<-EOM.chomp
323
+ <"こんにちは">("UTF-8") expected but was
324
+ <#{ascii_8bit_string.inspect}>("ASCII-8BIT").
325
+ EOM
326
+ check_fails(message) do
327
+ assert_equal(utf8_string, ascii_8bit_string)
328
+ end
329
+ end
330
+
314
331
  def test_assert_raise_success
315
332
  return_value = nil
316
333
  check_nothing_fails(true) do
@@ -811,7 +828,12 @@ EOM
811
828
  end
812
829
  assert_in_delta(0.1, float_thing, 0.1)
813
830
  }
814
- check_fails("message.\n<0.5> and\n<0.4> expected to be within\n<0.05> of each other.") {
831
+ check_fails("message.\n" +
832
+ "<0.5> expected but was\n" +
833
+ "<0.4> (tolerance <0.05>).\n" +
834
+ "\n" +
835
+ "Relation:\n" +
836
+ "<<0.4> < <0.5>-<0.05>(0.45) <= <0.5>+<0.05>(0.55)>") {
815
837
  assert_in_delta(0.5, 0.4, 0.05, "message")
816
838
  }
817
839
  object = Object.new
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-unit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
4
+ prerelease: false
5
+ segments:
6
+ - 2
7
+ - 0
8
+ - 8
9
+ version: 2.0.8
5
10
  platform: ruby
6
11
  authors:
7
12
  - Kouhei Sutou
@@ -10,39 +15,23 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-03-09 00:00:00 +09:00
18
+ date: 2010-06-02 00:00:00 +09:00
14
19
  default_executable:
15
20
  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:
36
21
  - !ruby/object:Gem::Dependency
37
22
  name: hoe
38
- type: :development
39
- version_requirement:
40
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
41
25
  requirements:
42
26
  - - ">="
43
27
  - !ruby/object:Gem::Version
44
- version: 2.5.0
45
- version:
28
+ segments:
29
+ - 2
30
+ - 4
31
+ - 0
32
+ version: 2.4.0
33
+ type: :development
34
+ version_requirements: *id001
46
35
  description: |-
47
36
  Test::Unit 2.x - Improved version of Test::Unit bundled in
48
37
  Ruby 1.8.x.
@@ -158,30 +147,32 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
147
  requirements:
159
148
  - - ">="
160
149
  - !ruby/object:Gem::Version
150
+ segments:
151
+ - 0
161
152
  version: "0"
162
- version:
163
153
  required_rubygems_version: !ruby/object:Gem::Requirement
164
154
  requirements:
165
155
  - - ">="
166
156
  - !ruby/object:Gem::Version
157
+ segments:
158
+ - 0
167
159
  version: "0"
168
- version:
169
160
  requirements: []
170
161
 
171
162
  rubyforge_project: test-unit
172
- rubygems_version: 1.3.5
163
+ rubygems_version: 1.3.6
173
164
  signing_key:
174
165
  specification_version: 3
175
166
  summary: Test::Unit 2.x - Improved version of Test::Unit bundled in Ruby 1.8.x
176
167
  test_files:
177
168
  - test/test_failure.rb
178
- - test/collector/test_objectspace.rb
179
- - test/collector/test_dir.rb
180
- - test/test_testsuite.rb
181
- - test/test_assertions.rb
182
- - test/util/test_observable.rb
183
169
  - test/util/test_procwrapper.rb
184
170
  - test/util/test_backtracefilter.rb
171
+ - test/util/test_observable.rb
172
+ - test/test_testsuite.rb
173
+ - test/test_error.rb
185
174
  - test/ui/test_testrunmediator.rb
175
+ - test/collector/test_dir.rb
176
+ - test/collector/test_objectspace.rb
186
177
  - test/test_testresult.rb
187
- - test/test_error.rb
178
+ - test/test_assertions.rb