test-unit 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +19 -0
- data/Manifest.txt +2 -0
- data/README.txt +3 -1
- data/TODO +1 -0
- data/lib/test/unit/assertions.rb +26 -12
- data/lib/test/unit/autorunner.rb +2 -0
- data/lib/test/unit/collector.rb +1 -1
- data/lib/test/unit/fixture.rb +5 -14
- data/lib/test/unit/priority.rb +17 -2
- data/lib/test/unit/testcase.rb +4 -5
- data/lib/test/unit/util/method-owner-finder.rb +28 -0
- data/lib/test/unit/version.rb +1 -1
- data/test/test-priority.rb +30 -0
- data/test/util/test-method-owner-finder.rb +38 -0
- metadata +5 -3
data/History.txt
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
=== 2.0.2 / 2008-12-21
|
2
|
+
|
3
|
+
* 2 major enhancements
|
4
|
+
|
5
|
+
* re-support ruby 1.8.5.
|
6
|
+
* improve exception object comparison.
|
7
|
+
|
8
|
+
* 3 bug fixes
|
9
|
+
|
10
|
+
* [#22723]: collector fails on anonymous classes
|
11
|
+
* [#22986]: Test names with '?' blow up on Windows
|
12
|
+
* [#22988]: don't create .test-result on non-priority mode.
|
13
|
+
|
14
|
+
* Thanks
|
15
|
+
|
16
|
+
* Erik Hollensbe
|
17
|
+
* Daniel Berger
|
18
|
+
* Bill Lear
|
19
|
+
|
1
20
|
=== 2.0.1 / 2008-11-09
|
2
21
|
|
3
22
|
* 19 major enhancements
|
data/Manifest.txt
CHANGED
@@ -41,6 +41,7 @@ lib/test/unit/ui/testrunner.rb
|
|
41
41
|
lib/test/unit/ui/testrunnermediator.rb
|
42
42
|
lib/test/unit/ui/testrunnerutilities.rb
|
43
43
|
lib/test/unit/util/backtracefilter.rb
|
44
|
+
lib/test/unit/util/method-owner-finder.rb
|
44
45
|
lib/test/unit/util/observable.rb
|
45
46
|
lib/test/unit/util/procwrapper.rb
|
46
47
|
lib/test/unit/version.rb
|
@@ -73,6 +74,7 @@ test/test_testresult.rb
|
|
73
74
|
test/test_testsuite.rb
|
74
75
|
test/testunit-test-util.rb
|
75
76
|
test/ui/test_testrunmediator.rb
|
77
|
+
test/util/test-method-owner-finder.rb
|
76
78
|
test/util/test_backtracefilter.rb
|
77
79
|
test/util/test_observable.rb
|
78
80
|
test/util/test_procwrapper.rb
|
data/README.txt
CHANGED
data/lib/test/unit/assertions.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
require 'test/unit/assertionfailederror'
|
6
6
|
require 'test/unit/util/backtracefilter'
|
7
|
+
require 'test/unit/util/method-owner-finder'
|
7
8
|
require 'test/unit/diff'
|
8
9
|
|
9
10
|
module Test
|
@@ -909,9 +910,7 @@ EOM
|
|
909
910
|
end
|
910
911
|
|
911
912
|
def inspect
|
912
|
-
|
913
|
-
if inspect_method.respond_to?(:owner) and
|
914
|
-
inspect_method.owner == Exception
|
913
|
+
if default_inspect?
|
915
914
|
"#{@exception.class.inspect}(#{@exception.message.inspect})"
|
916
915
|
else
|
917
916
|
@exception.inspect
|
@@ -921,6 +920,18 @@ EOM
|
|
921
920
|
def method_missing(name, *args, &block)
|
922
921
|
@exception.send(name, *args, &block)
|
923
922
|
end
|
923
|
+
|
924
|
+
private
|
925
|
+
def default_inspect?
|
926
|
+
inspect_method = @exception.method(:inspect)
|
927
|
+
if inspect_method.respond_to?(:owner) and
|
928
|
+
inspect_method.owner == Exception
|
929
|
+
true
|
930
|
+
else
|
931
|
+
default_inspect_method = Exception.instance_method(:inspect)
|
932
|
+
default_inspect_method.bind(@exception).call == @exception.inspect
|
933
|
+
end
|
934
|
+
end
|
924
935
|
end
|
925
936
|
|
926
937
|
def initialize(test_case, expected_exceptions)
|
@@ -987,15 +998,18 @@ EOM
|
|
987
998
|
|
988
999
|
def expected_object?(actual_exception)
|
989
1000
|
@expected_objects.any? do |expected_object|
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
1001
|
+
expected_object == actual_exception or
|
1002
|
+
fallback_exception_object_equal(expected_object, actual_exception)
|
1003
|
+
end
|
1004
|
+
end
|
1005
|
+
|
1006
|
+
def fallback_exception_object_equal(expected_object, actual_exception)
|
1007
|
+
owner = Util::MethodOwnerFinder.find(expected_object, :==)
|
1008
|
+
if owner == Kernel or owner == Exception
|
1009
|
+
expected_object.class == actual_exception.class and
|
1010
|
+
expected_object.message == actual_exception.message
|
1011
|
+
else
|
1012
|
+
false
|
999
1013
|
end
|
1000
1014
|
end
|
1001
1015
|
end
|
data/lib/test/unit/autorunner.rb
CHANGED
@@ -196,8 +196,10 @@ module Test
|
|
196
196
|
o.on("--[no-]priority-mode",
|
197
197
|
"Runs some tests based on their priority.") do |priority_mode|
|
198
198
|
if priority_mode
|
199
|
+
Priority.enable
|
199
200
|
@filters |= [priority_filter]
|
200
201
|
else
|
202
|
+
Priority.disable
|
201
203
|
@filters -= [priority_filter]
|
202
204
|
end
|
203
205
|
end
|
data/lib/test/unit/collector.rb
CHANGED
data/lib/test/unit/fixture.rb
CHANGED
@@ -90,17 +90,14 @@ module Test
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def add_fixture_method_name(how, variable_name, method_name)
|
93
|
-
|
94
|
-
self.instance_variable_set(variable_name, [])
|
95
|
-
end
|
96
|
-
methods = self.instance_variable_get(variable_name)
|
93
|
+
methods = instance_eval("#{variable_name} ||= []")
|
97
94
|
|
98
95
|
if how == :prepend
|
99
96
|
methods = [method_name] | methods
|
100
97
|
else
|
101
98
|
methods = methods | [method_name]
|
102
99
|
end
|
103
|
-
|
100
|
+
instance_variable_set(variable_name, methods)
|
104
101
|
end
|
105
102
|
|
106
103
|
def registered_methods_variable_name(fixture, order)
|
@@ -144,15 +141,9 @@ module Test
|
|
144
141
|
interested_ancestors.inject([]) do |result, ancestor|
|
145
142
|
if ancestor.is_a?(Class)
|
146
143
|
ancestor.class_eval do
|
147
|
-
methods = []
|
148
|
-
unregistered_methods =
|
149
|
-
|
150
|
-
methods = instance_variable_get(methods_variable)
|
151
|
-
end
|
152
|
-
if instance_variable_defined?(unregistered_methods_variable)
|
153
|
-
unregistered_methods =
|
154
|
-
instance_variable_get(unregistered_methods_variable)
|
155
|
-
end
|
144
|
+
methods = instance_eval("#{methods_variable} ||= []")
|
145
|
+
unregistered_methods =
|
146
|
+
instance_eval("#{unregistered_methods_variable} ||= []")
|
156
147
|
(result | methods) - unregistered_methods
|
157
148
|
end
|
158
149
|
else
|
data/lib/test/unit/priority.rb
CHANGED
@@ -13,6 +13,19 @@ module Test
|
|
13
13
|
teardown :priority_teardown, :after => :append
|
14
14
|
end
|
15
15
|
end
|
16
|
+
|
17
|
+
@@enabled = false
|
18
|
+
def enabled?
|
19
|
+
@@enabled
|
20
|
+
end
|
21
|
+
|
22
|
+
def enable
|
23
|
+
@@enabled = true
|
24
|
+
end
|
25
|
+
|
26
|
+
def disable
|
27
|
+
@@enabled = false
|
28
|
+
end
|
16
29
|
end
|
17
30
|
|
18
31
|
class Checker
|
@@ -90,7 +103,7 @@ module Test
|
|
90
103
|
def result_dir
|
91
104
|
components = [".test-result",
|
92
105
|
@test.class.name || "AnonymousTestCase",
|
93
|
-
|
106
|
+
escaped_method_name]
|
94
107
|
parent_directories = [File.dirname($0), Dir.pwd]
|
95
108
|
if Process.respond_to?(:uid)
|
96
109
|
parent_directories << File.join(Dir.tmpdir, Process.uid.to_s)
|
@@ -112,7 +125,7 @@ module Test
|
|
112
125
|
end
|
113
126
|
|
114
127
|
def escaped_method_name
|
115
|
-
@method_name.to_s.gsub(/[!?=]$/) do |matched|
|
128
|
+
@test.method_name.to_s.gsub(/[!?=]$/) do |matched|
|
116
129
|
case matched
|
117
130
|
when "!"
|
118
131
|
".destructive"
|
@@ -135,10 +148,12 @@ module Test
|
|
135
148
|
end
|
136
149
|
|
137
150
|
def priority_setup
|
151
|
+
return unless Priority.enabled?
|
138
152
|
Checker.new(self).setup
|
139
153
|
end
|
140
154
|
|
141
155
|
def priority_teardown
|
156
|
+
return unless Priority.enabled?
|
142
157
|
Checker.new(self).teardown
|
143
158
|
end
|
144
159
|
end
|
data/lib/test/unit/testcase.rb
CHANGED
@@ -17,6 +17,7 @@ require 'test/unit/priority'
|
|
17
17
|
require 'test/unit/testsuite'
|
18
18
|
require 'test/unit/assertionfailederror'
|
19
19
|
require 'test/unit/util/backtracefilter'
|
20
|
+
require 'test/unit/util/method-owner-finder'
|
20
21
|
|
21
22
|
module Test
|
22
23
|
module Unit
|
@@ -192,11 +193,9 @@ module Test
|
|
192
193
|
throw :invalid_test unless respond_to?(test_method_name)
|
193
194
|
test_method = method(test_method_name)
|
194
195
|
throw :invalid_test if test_method.arity > 0
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
throw :invalid_test
|
199
|
-
end
|
196
|
+
owner = Util::MethodOwnerFinder.find(self, test_method_name)
|
197
|
+
if owner.class != Module and self.class != owner
|
198
|
+
throw :invalid_test
|
200
199
|
end
|
201
200
|
@method_name = test_method_name
|
202
201
|
@test_passed = true
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Test
|
2
|
+
module Unit
|
3
|
+
module Util
|
4
|
+
module MethodOwnerFinder
|
5
|
+
module_function
|
6
|
+
def find(object, method_name)
|
7
|
+
method = object.method(method_name)
|
8
|
+
return method.owner if method.respond_to?(:owner)
|
9
|
+
|
10
|
+
if /\((.+?)\)\#/ =~ method.to_s
|
11
|
+
owner_name = $1
|
12
|
+
if /\A#</ =~ owner_name
|
13
|
+
ObjectSpace.each_object(Module) do |mod|
|
14
|
+
return mod if mod.to_s == owner_name
|
15
|
+
end
|
16
|
+
else
|
17
|
+
owner_name.split(/::/).inject(Object) do |parent, name|
|
18
|
+
parent.const_get(name)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
else
|
22
|
+
object.class
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/test/unit/version.rb
CHANGED
data/test/test-priority.rb
CHANGED
@@ -86,4 +86,34 @@ class TestUnitPriority < Test::Unit::TestCase
|
|
86
86
|
end
|
87
87
|
assert_in_delta(expected, n_need_to_run.to_f / n, delta)
|
88
88
|
end
|
89
|
+
|
90
|
+
class SpecialNameTestCase < Test::Unit::TestCase
|
91
|
+
class << self
|
92
|
+
def suite
|
93
|
+
Test::Unit::TestSuite.new(name)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_question?
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_exclamation!
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_equal=
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_escaped?
|
108
|
+
assert_escaped_name("test_question.predicate", "test_question?")
|
109
|
+
assert_escaped_name("test_exclamation.destructive", "test_exclamation!")
|
110
|
+
assert_escaped_name("test_equal.equal", "test_equal=")
|
111
|
+
end
|
112
|
+
|
113
|
+
def assert_escaped_name(expected, test_method_name)
|
114
|
+
checker = Checker.new(SpecialNameTestCase.new(test_method_name))
|
115
|
+
passed_file = checker.send(:passed_file)
|
116
|
+
method_name_component = File.basename(File.dirname(passed_file))
|
117
|
+
assert_equal(expected, method_name_component)
|
118
|
+
end
|
89
119
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require 'test/unit/util/method-owner-finder'
|
4
|
+
|
5
|
+
class TestUnitMethodOwnerFinder < Test::Unit::TestCase
|
6
|
+
def test_find
|
7
|
+
assert_equal(Exception, find(RuntimeError.new, :inspect))
|
8
|
+
assert_equal(Exception, find(Exception.new, :inspect))
|
9
|
+
|
10
|
+
anonymous_class = Class.new do
|
11
|
+
end
|
12
|
+
assert_equal(Kernel, find(anonymous_class.new, :inspect))
|
13
|
+
|
14
|
+
anonymous_parent_class = Class.new do
|
15
|
+
def inspect
|
16
|
+
super + " by anonymous parent class"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
anonymous_sub_class = Class.new(anonymous_parent_class) do
|
20
|
+
end
|
21
|
+
assert_equal(anonymous_parent_class, find(anonymous_sub_class.new, :inspect))
|
22
|
+
|
23
|
+
anonymous_module = Module.new do
|
24
|
+
def inspect
|
25
|
+
super + " by anonymous module"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
anonymous_include_class = Class.new do
|
29
|
+
include anonymous_module
|
30
|
+
end
|
31
|
+
assert_equal(anonymous_module, find(anonymous_include_class.new, :inspect))
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def find(object, method_name)
|
36
|
+
Test::Unit::Util::MethodOwnerFinder.find(object, method_name)
|
37
|
+
end
|
38
|
+
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.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2008-
|
13
|
+
date: 2008-12-21 00:00:00 +09:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/test/unit/ui/testrunnermediator.rb
|
80
80
|
- lib/test/unit/ui/testrunnerutilities.rb
|
81
81
|
- lib/test/unit/util/backtracefilter.rb
|
82
|
+
- lib/test/unit/util/method-owner-finder.rb
|
82
83
|
- lib/test/unit/util/observable.rb
|
83
84
|
- lib/test/unit/util/procwrapper.rb
|
84
85
|
- lib/test/unit/version.rb
|
@@ -111,6 +112,7 @@ files:
|
|
111
112
|
- test/test_testsuite.rb
|
112
113
|
- test/testunit-test-util.rb
|
113
114
|
- test/ui/test_testrunmediator.rb
|
115
|
+
- test/util/test-method-owner-finder.rb
|
114
116
|
- test/util/test_backtracefilter.rb
|
115
117
|
- test/util/test_observable.rb
|
116
118
|
- test/util/test_procwrapper.rb
|
@@ -137,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
139
|
requirements: []
|
138
140
|
|
139
141
|
rubyforge_project: test-unit
|
140
|
-
rubygems_version: 1.
|
142
|
+
rubygems_version: 1.3.1
|
141
143
|
signing_key:
|
142
144
|
specification_version: 2
|
143
145
|
summary: Test::Unit 2.x - Improved version of Test::Unit bundled in Ruby 1.8.x
|