test-unit 2.0.9 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/COPYING +56 -0
  2. data/GPL +340 -0
  3. data/History.txt +7 -3
  4. data/Manifest.txt +27 -2
  5. data/PSFL +271 -0
  6. data/README.txt +18 -0
  7. data/Rakefile +18 -5
  8. data/html/bar.png +0 -0
  9. data/html/bar.svg +153 -0
  10. data/html/developer.png +0 -0
  11. data/html/developer.svg +469 -0
  12. data/html/famfamfam-logo.png +0 -0
  13. data/html/favicon.ico +0 -0
  14. data/html/favicon.png +0 -0
  15. data/html/favicon.svg +82 -0
  16. data/html/heading-mark.png +0 -0
  17. data/html/heading-mark.svg +393 -0
  18. data/html/index.html +235 -13
  19. data/html/index.html.ja +258 -15
  20. data/html/install.png +0 -0
  21. data/html/install.svg +636 -0
  22. data/html/jp.png +0 -0
  23. data/html/kinotan-failure.png +0 -0
  24. data/html/kinotan-pass.png +0 -0
  25. data/html/logo.png +0 -0
  26. data/html/logo.svg +483 -0
  27. data/html/reference.png +0 -0
  28. data/html/rubyforge.png +0 -0
  29. data/html/tango-logo.png +0 -0
  30. data/html/test-unit.css +339 -0
  31. data/html/tutorial.png +0 -0
  32. data/html/tutorial.svg +559 -0
  33. data/html/us.png +0 -0
  34. data/lib/test/unit.rb +6 -1
  35. data/lib/test/unit/assertions.rb +36 -0
  36. data/lib/test/unit/autorunner.rb +5 -2
  37. data/lib/test/unit/collector/load.rb +1 -1
  38. data/lib/test/unit/color-scheme.rb +1 -1
  39. data/lib/test/unit/diff.rb +7 -0
  40. data/lib/test/unit/testcase.rb +5 -0
  41. data/lib/test/unit/testresult.rb +34 -2
  42. data/lib/test/unit/ui/console/testrunner.rb +9 -45
  43. data/lib/test/unit/ui/tap/testrunner.rb +0 -9
  44. data/lib/test/unit/ui/testrunner.rb +25 -0
  45. data/lib/test/unit/version.rb +1 -1
  46. data/test/test-color-scheme.rb +1 -1
  47. data/test/test_assertions.rb +27 -3
  48. metadata +53 -14
  49. data/html/classic.html +0 -15
  50. data/html/test-unit-classic.png +0 -0
Binary file
@@ -90,8 +90,13 @@ module Test # :nodoc:
90
90
  #
91
91
  # Test::Unit is copyright (c) 2000-2003 Nathaniel Talbott. It is free
92
92
  # software, and is distributed under the Ruby license. See the COPYING
93
- # file in the standard Ruby distribution for details.
93
+ # file.
94
94
  #
95
+ # Exception: lib/test/unit/diff.rb is copyright (c)
96
+ # 2008-2010 Kouhei Sutou and 2001-2008 Python Software
97
+ # Foundation. It is free software, and is distributed
98
+ # under the Ruby license and/or the PSF license. See the
99
+ # COPYING file and PSFL file.
95
100
  #
96
101
  # == Warranty
97
102
  #
@@ -914,6 +914,42 @@ EOT
914
914
  end
915
915
  end
916
916
 
917
+ ##
918
+ # Passes if +path+ exists.
919
+ #
920
+ # Example:
921
+ # assert_path_exist("/tmp") # -> pass
922
+ # assert_path_exist("/bin/sh") # -> pass
923
+ # assert_path_exist("/nonexistent") # -> fail
924
+ def assert_path_exist(path, message=nil)
925
+ _wrap_assertion do
926
+ failure_message = build_message(message,
927
+ "<?> expected to exist",
928
+ path)
929
+ assert_block(failure_message) do
930
+ File.exist?(path)
931
+ end
932
+ end
933
+ end
934
+
935
+ ##
936
+ # Passes if +path+ doesn't exist.
937
+ #
938
+ # Example:
939
+ # assert_path_not_exist("/nonexistent") # -> pass
940
+ # assert_path_not_exist("/tmp") # -> fail
941
+ # assert_path_not_exist("/bin/sh") # -> fail
942
+ def assert_path_not_exist(path, message=nil)
943
+ _wrap_assertion do
944
+ failure_message = build_message(message,
945
+ "<?> expected to not exist",
946
+ path)
947
+ assert_block(failure_message) do
948
+ not File.exist?(path)
949
+ end
950
+ end
951
+ end
952
+
917
953
  ##
918
954
  # Builds a failure message. +head+ is added before the +template+ and
919
955
  # +arguments+ replaces the '?'s positionally in the template.
@@ -99,7 +99,7 @@ module Test
99
99
 
100
100
  attr_reader :suite, :runner_options
101
101
  attr_accessor :filters, :to_run, :pattern, :exclude, :base, :workdir
102
- attr_accessor :color_scheme
102
+ attr_accessor :color_scheme, :listeners
103
103
  attr_writer :runner, :collector
104
104
 
105
105
  def initialize(standalone)
@@ -113,6 +113,7 @@ module Test
113
113
  @runner_options = {}
114
114
  @default_arguments = []
115
115
  @workdir = nil
116
+ @listeners = []
116
117
  config_file = "test-unit.yml"
117
118
  if File.exist?(config_file)
118
119
  load_config(config_file)
@@ -300,6 +301,8 @@ module Test
300
301
  runner = @runner[self]
301
302
  return false if runner.nil?
302
303
  @runner_options[:color_scheme] ||= @color_scheme
304
+ @runner_options[:listeners] ||= []
305
+ @runner_options[:listeners].concat(@listeners)
303
306
  Dir.chdir(@workdir) if @workdir
304
307
  runner.run(suite, @runner_options).passed?
305
308
  end
@@ -342,7 +345,7 @@ module Test
342
345
  end
343
346
 
344
347
  def global_config_file
345
- File.expand_path("~/.test-unit.xml")
348
+ File.expand_path("~/.test-unit.yml")
346
349
  rescue ArgumentError
347
350
  nil
348
351
  end
@@ -95,7 +95,7 @@ module Test
95
95
 
96
96
  def collect_file(path, test_suites, already_gathered)
97
97
  @program_file ||= File.expand_path($0)
98
- return if @program_file == path.to_s
98
+ return if @program_file == path.expand_path.to_s
99
99
  add_load_path(path.expand_path.dirname) do
100
100
  require(path.to_s)
101
101
  find_test_cases(already_gathered).each do |test_case|
@@ -8,7 +8,7 @@ module Test
8
8
  class << self
9
9
  @@default = nil
10
10
  def default
11
- @@default ||= new("success" =>
11
+ @@default ||= new("pass" =>
12
12
  Color.new("green", :foreground => false) +
13
13
  Color.new("white", :bold => true),
14
14
  "failure" =>
@@ -1,4 +1,11 @@
1
1
  # port of Python's difflib.
2
+ #
3
+ # Copyright (c) 2001-2008 Python Software Foundation; All Rights Reserved
4
+ # Copyright (c) 2008-2010 Kouhei Sutou; All Rights Reserved
5
+ #
6
+ # It is free software, and is distributed under the Ruby
7
+ # license and/or the PSF license. See the COPYING file and
8
+ # PSFL file.
2
9
 
3
10
  module Test
4
11
  module Unit
@@ -450,6 +450,7 @@ module Test
450
450
  notify("#{self.class}\##{@method_name} was redefined")
451
451
  end
452
452
  __send__(@method_name)
453
+ add_pass
453
454
  end
454
455
 
455
456
  def handle_exception(exception)
@@ -473,6 +474,10 @@ module Test
473
474
  def add_assertion
474
475
  current_result.add_assertion
475
476
  end
477
+
478
+ def add_pass
479
+ current_result.add_pass
480
+ end
476
481
  end
477
482
  end
478
483
  end
@@ -34,11 +34,11 @@ module Test
34
34
  CHANGED = "CHANGED"
35
35
  FAULT = "FAULT"
36
36
 
37
- attr_reader :run_count, :assertion_count, :faults
37
+ attr_reader :run_count, :pass_count, :assertion_count, :faults
38
38
 
39
39
  # Constructs a new, empty TestResult.
40
40
  def initialize
41
- @run_count, @assertion_count = 0, 0
41
+ @run_count, @pass_count, @assertion_count = 0, 0, 0
42
42
  @summary_generators = []
43
43
  @problem_checkers = []
44
44
  @faults = []
@@ -51,6 +51,10 @@ module Test
51
51
  notify_changed
52
52
  end
53
53
 
54
+ def add_pass
55
+ @pass_count += 1
56
+ end
57
+
54
58
  # Records an individual assertion.
55
59
  def add_assertion
56
60
  @assertion_count += 1
@@ -65,6 +69,25 @@ module Test
65
69
  *@summary_generators.collect {|generator| send(generator)}].join(", ")
66
70
  end
67
71
 
72
+ # Returnes a string that shows result status.
73
+ def status
74
+ if passed?
75
+ if pending_count > 0
76
+ "pending"
77
+ elsif omission_count > 0
78
+ "omission"
79
+ elsif notification_count > 0
80
+ "notification"
81
+ else
82
+ "pass"
83
+ end
84
+ elsif error_count > 0
85
+ "error"
86
+ elsif failure_count > 0
87
+ "failure"
88
+ end
89
+ end
90
+
68
91
  def to_s
69
92
  summary
70
93
  end
@@ -75,6 +98,15 @@ module Test
75
98
  @problem_checkers.all? {|checker| not send(checker)}
76
99
  end
77
100
 
101
+ def pass_percentage
102
+ n_tests = @run_count - omission_count
103
+ if n_tests.zero?
104
+ 0
105
+ else
106
+ 100.0 * (@pass_count / n_tests.to_f)
107
+ end
108
+ end
109
+
78
110
  private
79
111
  def notify_changed
80
112
  notify_listeners(CHANGED, self)
@@ -38,23 +38,14 @@ module Test
38
38
  @progress_row_max = @options[:progress_row_max]
39
39
  @progress_row_max ||= guess_progress_row_max
40
40
  @already_outputted = false
41
- @n_successes = 0
42
- @n_omissions = 0
43
41
  @indent = 0
44
42
  @top_level = true
45
43
  @faults = []
46
44
  end
47
45
 
48
- # Begins the test run.
49
- def start
50
- setup_mediator
51
- attach_to_mediator
52
- return start_mediator
53
- end
54
-
55
46
  private
56
47
  def setup_mediator
57
- @mediator = create_mediator(@suite)
48
+ super
58
49
  output_setup_end
59
50
  end
60
51
 
@@ -64,10 +55,6 @@ module Test
64
55
  output("Loaded suite #{suite_name}")
65
56
  end
66
57
 
67
- def create_mediator(suite)
68
- return TestRunnerMediator.new(suite)
69
- end
70
-
71
58
  def attach_to_mediator
72
59
  @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
73
60
  @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
@@ -78,14 +65,9 @@ module Test
78
65
  @mediator.add_listener(TestSuite::FINISHED, &method(:test_suite_finished))
79
66
  end
80
67
 
81
- def start_mediator
82
- return @mediator.run_suite
83
- end
84
-
85
68
  def add_fault(fault)
86
69
  @faults << fault
87
70
  output_progress(fault.single_character_display, fault_color(fault))
88
- @n_omissions += 1 if fault.is_a?(Omission)
89
71
  @already_outputted = true if fault.critical?
90
72
  end
91
73
 
@@ -109,13 +91,7 @@ module Test
109
91
  output("Finished in #{elapsed_time} seconds.")
110
92
  nl
111
93
  output(@result, result_color)
112
- n_tests = @result.run_count - @n_omissions
113
- if n_tests.zero?
114
- pass_percentage = 0
115
- else
116
- pass_percentage = 100.0 * (@n_successes / n_tests.to_f)
117
- end
118
- output("%g%% passed" % pass_percentage, result_color)
94
+ output("%g%% passed" % @result.pass_percentage, result_color)
119
95
  end
120
96
 
121
97
  def output_fault(fault)
@@ -159,7 +135,7 @@ module Test
159
135
  def output_fault_message(fault)
160
136
  output(fault.user_message) if fault.user_message
161
137
  output_single("<")
162
- output_single(fault.inspected_expected, color("success"))
138
+ output_single(fault.inspected_expected, color("pass"))
163
139
  output("> expected but was")
164
140
  output_single("<")
165
141
  output_single(fault.inspected_actual, color("failure"))
@@ -195,8 +171,7 @@ module Test
195
171
 
196
172
  def test_finished(name)
197
173
  unless @already_outputted
198
- @n_successes += 1
199
- output_progress(".", color("success"))
174
+ output_progress(".", color("pass"))
200
175
  end
201
176
  @already_outputted = false
202
177
 
@@ -272,7 +247,10 @@ module Test
272
247
  end
273
248
 
274
249
  def color(name)
275
- @color_scheme[name] || ColorScheme.default[name]
250
+ _color = @color_scheme[name]
251
+ _color ||= @color_scheme["success"] if name == "pass"
252
+ _color ||= ColorScheme.default[name]
253
+ _color
276
254
  end
277
255
 
278
256
  def fault_color(fault)
@@ -280,21 +258,7 @@ module Test
280
258
  end
281
259
 
282
260
  def result_color
283
- if @result.passed?
284
- if @result.pending_count > 0
285
- color("pending")
286
- elsif @result.omission_count > 0
287
- color("omission")
288
- elsif @result.notification_count > 0
289
- color("notification")
290
- else
291
- color("success")
292
- end
293
- elsif @result.error_count > 0
294
- color("error")
295
- elsif @result.failure_count > 0
296
- color("failure")
297
- end
261
+ color(@result.status)
298
262
  end
299
263
 
300
264
  def guess_color_availability
@@ -33,11 +33,6 @@ module Test
33
33
  end
34
34
 
35
35
  private
36
- def setup_mediator
37
- @mediator = TestRunnerMediator.new(@suite)
38
- attach_to_mediator
39
- end
40
-
41
36
  def attach_to_mediator
42
37
  @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
43
38
  @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
@@ -46,10 +41,6 @@ module Test
46
41
  @mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
47
42
  end
48
43
 
49
- def start_mediator
50
- @mediator.run_suite
51
- end
52
-
53
44
  def add_fault(fault)
54
45
  puts("not ok #{@n_tests} - #{fault.short_display}")
55
46
  fault.long_display.each_line do |line|
@@ -6,6 +6,7 @@ module Test
6
6
  class TestRunner
7
7
  extend TestRunnerUtilities
8
8
 
9
+ attr_reader :listeners
9
10
  def initialize(suite, options={})
10
11
  if suite.respond_to?(:suite)
11
12
  @suite = suite.suite
@@ -13,6 +14,30 @@ module Test
13
14
  @suite = suite
14
15
  end
15
16
  @options = options
17
+ @listeners = @options[:listeners] || []
18
+ end
19
+
20
+ # Begins the test run.
21
+ def start
22
+ setup_mediator
23
+ attach_to_mediator
24
+ attach_listeners
25
+ start_mediator
26
+ end
27
+
28
+ private
29
+ def setup_mediator
30
+ @mediator = TestRunnerMediator.new(@suite)
31
+ end
32
+
33
+ def attach_listeners
34
+ @listeners.each do |listener|
35
+ listener.attach_to_mediator(@mediator)
36
+ end
37
+ end
38
+
39
+ def start_mediator
40
+ @mediator.run_suite
16
41
  end
17
42
 
18
43
  def diff_target_string?(string)
@@ -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.9'
5
+ VERSION = '2.1.0'
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  class TestUnitColorScheme < Test::Unit::TestCase
2
2
  def test_default
3
3
  assert_equal({
4
- "success" => color("green", :foreground => false) +
4
+ "pass" => color("green", :foreground => false) +
5
5
  color("white", :bold => true),
6
6
  "failure" => color("red", :foreground => false) +
7
7
  color("white", :bold => true),
@@ -837,9 +837,10 @@ EOM
837
837
  assert_in_delta(0.5, 0.4, 0.05, "message")
838
838
  }
839
839
  object = Object.new
840
+ inspected_object = AssertionMessage.convert(object)
840
841
  check_fails("The arguments must respond to to_f; " +
841
842
  "the first float did not.\n" +
842
- "<#{object.inspect}>.respond_to?(:to_f) expected\n" +
843
+ "<#{inspected_object}>.respond_to?(:to_f) expected\n" +
843
844
  "(Class: <Object>)") {
844
845
  assert_in_delta(object, 0.4, 0.1)
845
846
  }
@@ -1143,17 +1144,40 @@ EOM
1143
1144
  assert_alias_method(object, :other, :original_method)
1144
1145
  end
1145
1146
 
1146
- check_fails("<#{object.inspect}>.nonexistent doesn't exist\n" +
1147
+ inspected_object = AssertionMessage.convert(object)
1148
+ check_fails("<#{inspected_object}>.nonexistent doesn't exist\n" +
1147
1149
  "(Class: <Object>)") do
1148
1150
  assert_alias_method(object, :nonexistent, :original_method)
1149
1151
  end
1150
1152
 
1151
- check_fails("<#{object.inspect}>.nonexistent doesn't exist\n" +
1153
+ check_fails("<#{inspected_object}>.nonexistent doesn't exist\n" +
1152
1154
  "(Class: <Object>)") do
1153
1155
  assert_alias_method(object, :alias_method, :nonexistent)
1154
1156
  end
1155
1157
  end
1156
1158
 
1159
+ def test_assert_path_exist
1160
+ check_nothing_fails do
1161
+ assert_path_exist(__FILE__)
1162
+ end
1163
+
1164
+ nonexistent_file = __FILE__ + ".nonexistent"
1165
+ check_fails("<#{nonexistent_file.inspect}> expected to exist") do
1166
+ assert_path_exist(nonexistent_file)
1167
+ end
1168
+ end
1169
+
1170
+ def test_assert_path_not_exist
1171
+ nonexistent_file = __FILE__ + ".nonexistent"
1172
+ check_nothing_fails do
1173
+ assert_path_not_exist(nonexistent_file)
1174
+ end
1175
+
1176
+ check_fails("<#{__FILE__.inspect}> expected to not exist") do
1177
+ assert_path_not_exist(__FILE__)
1178
+ end
1179
+ end
1180
+
1157
1181
  private
1158
1182
  def add_failure(message, location=caller, options=nil)
1159
1183
  unless @catch_assertions