test-unit 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +26 -0
- data/Manifest.txt +1 -1
- data/README.txt +2 -0
- data/Rakefile +6 -1
- data/TODO +3 -0
- data/lib/test/unit/assertions.rb +152 -23
- data/lib/test/unit/autorunner.rb +26 -4
- data/lib/test/unit/color-scheme.rb +3 -2
- data/lib/test/unit/priority.rb +21 -1
- data/lib/test/unit/testcase.rb +101 -36
- data/lib/test/unit/ui/console/testrunner.rb +7 -4
- data/lib/test/unit/version.rb +1 -1
- data/test/test-color-scheme.rb +2 -1
- data/test/test-pending.rb +1 -1
- data/test/{test_testcase.rb → test-testcase.rb} +33 -4
- data/test/test_assertions.rb +98 -12
- data/test/ui/test_testrunmediator.rb +1 -1
- metadata +20 -13
data/History.txt
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
=== 2.0.3 / 2009-07-19
|
2
|
+
|
3
|
+
* 6 major enhancements
|
4
|
+
* add assert_predicate.
|
5
|
+
* add assert_not_predicate.
|
6
|
+
* [#24210] assert_kind_of supports an array of classes or modules.
|
7
|
+
[Daniel Berger]
|
8
|
+
* assert_instance_of supports an array of classes or modules.
|
9
|
+
* add --default-priority option.
|
10
|
+
* [#26627] add --order option. [Daniel Berger]
|
11
|
+
|
12
|
+
* 4 minor enhancements
|
13
|
+
* use yellow foreground + black background for error.
|
14
|
+
* don't show diff for long string.
|
15
|
+
* accept "*term-color" TERM environment as colorizable terminal.
|
16
|
+
(e.g. Apple's Terminal)
|
17
|
+
* [#26268] add a workaround for test-spec's after_all. [Angelo Lakra]
|
18
|
+
|
19
|
+
* 1 bug fix
|
20
|
+
* [#23586] re-support ruby 1.9.1. [Diego Pettenò]
|
21
|
+
|
22
|
+
* Thanks
|
23
|
+
* Diego Pettenò
|
24
|
+
* Daniel Berger
|
25
|
+
* Angelo Lakra
|
26
|
+
|
1
27
|
=== 2.0.2 / 2008-12-21
|
2
28
|
|
3
29
|
* 2 major enhancements
|
data/Manifest.txt
CHANGED
@@ -66,10 +66,10 @@ test/test-notification.rb
|
|
66
66
|
test/test-omission.rb
|
67
67
|
test/test-pending.rb
|
68
68
|
test/test-priority.rb
|
69
|
+
test/test-testcase.rb
|
69
70
|
test/test_assertions.rb
|
70
71
|
test/test_error.rb
|
71
72
|
test/test_failure.rb
|
72
|
-
test/test_testcase.rb
|
73
73
|
test/test_testresult.rb
|
74
74
|
test/test_testsuite.rb
|
75
75
|
test/testunit-test-util.rb
|
data/README.txt
CHANGED
data/Rakefile
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
+
gem 'rdoc'
|
4
5
|
require 'hoe'
|
5
6
|
require './lib/test/unit/version.rb'
|
6
7
|
|
8
|
+
ENV["NODOT"] = "yes"
|
9
|
+
|
7
10
|
version = Test::Unit::VERSION
|
8
11
|
ENV["VERSION"] = version
|
9
|
-
Hoe.
|
12
|
+
Hoe.spec('test-unit') do |p|
|
13
|
+
Hoe::Test::SUPPORTED_TEST_FRAMEWORKS[:testunit2] = "test/run-test.rb"
|
14
|
+
p.version = version
|
10
15
|
p.developer('Kouhei Sutou', 'kou@cozmixng.org')
|
11
16
|
p.developer('Ryan Davis', 'ryand-ruby@zenspider.com')
|
12
17
|
|
data/TODO
CHANGED
data/lib/test/unit/assertions.rb
CHANGED
@@ -1,5 +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
4
|
# License:: Ruby license.
|
4
5
|
|
5
6
|
require 'test/unit/assertionfailederror'
|
@@ -153,21 +154,43 @@ EOT
|
|
153
154
|
|
154
155
|
|
155
156
|
##
|
156
|
-
# Passes if +object+
|
157
|
+
# Passes if +object+.instance_of?(+klass+). When +klass+ is
|
158
|
+
# an array of classes, it passes if any class
|
159
|
+
# satisfies +object.instance_of?(class).
|
157
160
|
#
|
158
161
|
# Example:
|
159
|
-
# assert_instance_of
|
162
|
+
# assert_instance_of(String, 'foo') # -> pass
|
163
|
+
# assert_instance_of([Fixnum, NilClass], 100) # -> pass
|
164
|
+
# assert_instance_of([Numeric, NilClass], 100) # -> fail
|
160
165
|
|
161
166
|
public
|
162
167
|
def assert_instance_of(klass, object, message="")
|
163
168
|
_wrap_assertion do
|
164
|
-
|
165
|
-
|
169
|
+
klasses = nil
|
170
|
+
klasses = klass if klass.is_a?(Array)
|
171
|
+
assert_block("The first parameter to assert_instance_of should be " +
|
172
|
+
"a Class or an Array of Class.") do
|
173
|
+
if klasses
|
174
|
+
klasses.all? {|k| k.is_a?(Class)}
|
175
|
+
else
|
176
|
+
klass.is_a?(Class)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
klass_message = AssertionMessage.maybe_container(klass) do |value|
|
180
|
+
"<#{value}>"
|
181
|
+
end
|
182
|
+
full_message = build_message(message, <<EOT, object, klass_message, object.class)
|
166
183
|
<?> expected to be an instance of
|
167
|
-
|
184
|
+
? but was
|
168
185
|
<?>.
|
169
186
|
EOT
|
170
|
-
assert_block(full_message)
|
187
|
+
assert_block(full_message) do
|
188
|
+
if klasses
|
189
|
+
klasses.any? {|k| object.instance_of?(k)}
|
190
|
+
else
|
191
|
+
object.instance_of?(klass)
|
192
|
+
end
|
193
|
+
end
|
171
194
|
end
|
172
195
|
end
|
173
196
|
|
@@ -186,17 +209,45 @@ EOT
|
|
186
209
|
end
|
187
210
|
|
188
211
|
##
|
189
|
-
# Passes if +object+
|
212
|
+
# Passes if +object+.kind_of?(+klass+). When +klass+ is
|
213
|
+
# an array of classes or modules, it passes if any
|
214
|
+
# class or module satisfies +object.kind_of?(class_or_module).
|
190
215
|
#
|
191
216
|
# Example:
|
192
|
-
# assert_kind_of
|
217
|
+
# assert_kind_of(Object, 'foo') # -> pass
|
218
|
+
# assert_kind_of([Fixnum, NilClass], 100) # -> pass
|
219
|
+
# assert_kind_of([Fixnum, NilClass], "string") # -> fail
|
193
220
|
|
194
221
|
public
|
195
222
|
def assert_kind_of(klass, object, message="")
|
196
223
|
_wrap_assertion do
|
197
|
-
|
198
|
-
|
199
|
-
assert_block(
|
224
|
+
klasses = nil
|
225
|
+
klasses = klass if klass.is_a?(Array)
|
226
|
+
assert_block("The first parameter to assert_kind_of should be " +
|
227
|
+
"a kind_of Module or an Array of a kind_of Module.") do
|
228
|
+
if klasses
|
229
|
+
klasses.all? {|k| k.kind_of?(Module)}
|
230
|
+
else
|
231
|
+
klass.kind_of?(Module)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
klass_message = AssertionMessage.maybe_container(klass) do |value|
|
235
|
+
"<#{value}>"
|
236
|
+
end
|
237
|
+
full_message = build_message(message,
|
238
|
+
"<?> expected to be kind_of\\?\n" +
|
239
|
+
"? but was\n" +
|
240
|
+
"<?>.",
|
241
|
+
object,
|
242
|
+
klass_message,
|
243
|
+
object.class)
|
244
|
+
assert_block(full_message) do
|
245
|
+
if klasses
|
246
|
+
klasses.any? {|k| object.kind_of?(k)}
|
247
|
+
else
|
248
|
+
object.kind_of?(klass)
|
249
|
+
end
|
250
|
+
end
|
200
251
|
end
|
201
252
|
end
|
202
253
|
|
@@ -209,17 +260,18 @@ EOT
|
|
209
260
|
public
|
210
261
|
def assert_respond_to(object, method, message="")
|
211
262
|
_wrap_assertion do
|
212
|
-
full_message = build_message(
|
213
|
-
|
263
|
+
full_message = build_message(message,
|
264
|
+
"<?>.kind_of\\?(Symbol) or\n" +
|
265
|
+
"<?>.respond_to\\?(:to_str) expected",
|
266
|
+
method, method)
|
214
267
|
assert_block(full_message) do
|
215
|
-
method.kind_of?(Symbol)
|
268
|
+
method.kind_of?(Symbol) or method.respond_to?(:to_str)
|
216
269
|
end
|
217
|
-
full_message = build_message(message,
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
assert_block(full_message) { object.respond_to?(method) }
|
270
|
+
full_message = build_message(message,
|
271
|
+
"<?>.respond_to\\?(?) expected\n" +
|
272
|
+
"(Class: <?>)",
|
273
|
+
object, method, object.class)
|
274
|
+
assert_block(full_message) {object.respond_to?(method)}
|
223
275
|
end
|
224
276
|
end
|
225
277
|
|
@@ -693,6 +745,50 @@ EOT
|
|
693
745
|
end
|
694
746
|
end
|
695
747
|
|
748
|
+
##
|
749
|
+
# Passes if +object+.+predicate+
|
750
|
+
#
|
751
|
+
# Example:
|
752
|
+
# assert_predicate([], :empty?) # -> pass
|
753
|
+
# assert_predicate([1], :empty?) # -> fail
|
754
|
+
def assert_predicate(object, predicate, message=nil)
|
755
|
+
_wrap_assertion do
|
756
|
+
assert_respond_to(object, predicate, message)
|
757
|
+
actual = object.send(predicate)
|
758
|
+
full_message = build_message(message,
|
759
|
+
"<?>.? is true value expected but was\n" +
|
760
|
+
"<?>",
|
761
|
+
object,
|
762
|
+
AssertionMessage.literal(predicate),
|
763
|
+
actual)
|
764
|
+
assert_block(full_message) do
|
765
|
+
actual
|
766
|
+
end
|
767
|
+
end
|
768
|
+
end
|
769
|
+
|
770
|
+
##
|
771
|
+
# Passes if +object+.+predicate+
|
772
|
+
#
|
773
|
+
# Example:
|
774
|
+
# assert_not_predicate([1], :empty?) # -> pass
|
775
|
+
# assert_not_predicate([], :empty?) # -> fail
|
776
|
+
def assert_not_predicate(object, predicate, message=nil)
|
777
|
+
_wrap_assertion do
|
778
|
+
assert_respond_to(object, predicate, message)
|
779
|
+
actual = object.send(predicate)
|
780
|
+
full_message = build_message(message,
|
781
|
+
"<?>.? is false value expected but was\n" +
|
782
|
+
"<?>",
|
783
|
+
object,
|
784
|
+
AssertionMessage.literal(predicate),
|
785
|
+
actual)
|
786
|
+
assert_block(full_message) do
|
787
|
+
not actual
|
788
|
+
end
|
789
|
+
end
|
790
|
+
end
|
791
|
+
|
696
792
|
##
|
697
793
|
# Builds a failure message. +head+ is added before the +template+ and
|
698
794
|
# +arguments+ replaces the '?'s positionally in the template.
|
@@ -780,6 +876,19 @@ EOT
|
|
780
876
|
DelayedLiteral.new(block)
|
781
877
|
end
|
782
878
|
|
879
|
+
def maybe_container(value, &formatter)
|
880
|
+
MaybeContainer.new(value, &formatter)
|
881
|
+
end
|
882
|
+
|
883
|
+
MAX_DIFF_TARGET_STRING_SIZE = 300
|
884
|
+
def diff_target_string?(string)
|
885
|
+
if string.respond_to?(:bytesize)
|
886
|
+
string.bytesize < MAX_DIFF_TARGET_STRING_SIZE
|
887
|
+
else
|
888
|
+
string.size < MAX_DIFF_TARGET_STRING_SIZE
|
889
|
+
end
|
890
|
+
end
|
891
|
+
|
783
892
|
def delayed_diff(from, to)
|
784
893
|
delayed_literal do
|
785
894
|
if !from.is_a?(String) or !to.is_a?(String)
|
@@ -787,7 +896,9 @@ EOT
|
|
787
896
|
to = convert(to)
|
788
897
|
end
|
789
898
|
|
790
|
-
diff =
|
899
|
+
diff = nil
|
900
|
+
diff = "" if !diff_target_string?(from) or !diff_target_string?(to)
|
901
|
+
diff ||= Diff.readable(from, to)
|
791
902
|
if /^[-+]/ !~ diff
|
792
903
|
diff = ""
|
793
904
|
elsif /^[ ?]/ =~ diff or /(?:.*\n){2,}/ =~ diff
|
@@ -833,7 +944,7 @@ EOM
|
|
833
944
|
def initialize(value)
|
834
945
|
@value = value
|
835
946
|
end
|
836
|
-
|
947
|
+
|
837
948
|
def inspect
|
838
949
|
@value.to_s
|
839
950
|
end
|
@@ -843,12 +954,30 @@ EOM
|
|
843
954
|
def initialize(value)
|
844
955
|
@value = value
|
845
956
|
end
|
846
|
-
|
957
|
+
|
847
958
|
def inspect
|
848
959
|
@value.call.to_s
|
849
960
|
end
|
850
961
|
end
|
851
962
|
|
963
|
+
class MaybeContainer
|
964
|
+
def initialize(value, &formatter)
|
965
|
+
@value = value
|
966
|
+
@formatter = formatter
|
967
|
+
end
|
968
|
+
|
969
|
+
def inspect
|
970
|
+
if @value.is_a?(Array)
|
971
|
+
values = @value.collect do |value|
|
972
|
+
@formatter.call(AssertionMessage.convert(value))
|
973
|
+
end
|
974
|
+
"[#{values.join(', ')}]"
|
975
|
+
else
|
976
|
+
@formatter.call(AssertionMessage.convert(@value))
|
977
|
+
end
|
978
|
+
end
|
979
|
+
end
|
980
|
+
|
852
981
|
class Template
|
853
982
|
def self.create(string)
|
854
983
|
parts = (string ? string.scan(/(?=[^\\])\?|(?:\\\?|[^\?])+/m) : [])
|
data/lib/test/unit/autorunner.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'test/unit'
|
2
1
|
require 'test/unit/color-scheme'
|
3
2
|
require 'optparse'
|
4
3
|
|
@@ -204,6 +203,13 @@ module Test
|
|
204
203
|
end
|
205
204
|
end
|
206
205
|
|
206
|
+
o.on("--default-priority=PRIORITY",
|
207
|
+
Priority.available_values,
|
208
|
+
"Uses PRIORITY as default priority",
|
209
|
+
"(#{keyword_display(Priority.available_values)})") do |priority|
|
210
|
+
Priority.default = priority
|
211
|
+
end
|
212
|
+
|
207
213
|
o.on('-I', "--load-path=DIR[#{File::PATH_SEPARATOR}DIR...]",
|
208
214
|
"Appends directory list to $LOAD_PATH.") do |dirs|
|
209
215
|
$LOAD_PATH.concat(dirs.split(File::PATH_SEPARATOR))
|
@@ -221,6 +227,12 @@ module Test
|
|
221
227
|
load_config(file)
|
222
228
|
end
|
223
229
|
|
230
|
+
o.on("--order=ORDER", TestCase::AVAILABLE_ORDERS,
|
231
|
+
"Run tests in a test case in ORDER order.",
|
232
|
+
"(#{keyword_display(TestCase::AVAILABLE_ORDERS)})") do |order|
|
233
|
+
TestCase.test_order = order
|
234
|
+
end
|
235
|
+
|
224
236
|
ADDITIONAL_OPTIONS.each do |option_builder|
|
225
237
|
option_builder.call(self, o)
|
226
238
|
end
|
@@ -252,10 +264,20 @@ module Test
|
|
252
264
|
end
|
253
265
|
|
254
266
|
def keyword_display(keywords)
|
255
|
-
keywords.collect do |keyword, _|
|
267
|
+
keywords = keywords.collect do |keyword, _|
|
256
268
|
keyword.to_s
|
257
|
-
end.uniq.sort
|
258
|
-
|
269
|
+
end.uniq.sort
|
270
|
+
|
271
|
+
i = 0
|
272
|
+
keywords.collect do |keyword|
|
273
|
+
if (i > 0 and keyword[0] == keywords[i - 1][0]) or
|
274
|
+
((i < keywords.size - 1) and (keyword[0] == keywords[i + 1][0]))
|
275
|
+
n = 2
|
276
|
+
else
|
277
|
+
n = 1
|
278
|
+
end
|
279
|
+
i += 1
|
280
|
+
keyword.sub(/^(.{#{n}})([A-Za-z]+)(?=\w*$)/, '\\1[\\2]')
|
259
281
|
end.join(", ")
|
260
282
|
end
|
261
283
|
|
@@ -13,7 +13,8 @@ module Test
|
|
13
13
|
"pending" => Color.new("magenta", :bold => true),
|
14
14
|
"omission" => Color.new("blue", :bold => true),
|
15
15
|
"notification" => Color.new("cyan", :bold => true),
|
16
|
-
"error" => Color.new("yellow", :bold => true)
|
16
|
+
"error" => Color.new("yellow", :bold => true) +
|
17
|
+
Color.new("black", :foreground => false))
|
17
18
|
end
|
18
19
|
|
19
20
|
@@schemes = {}
|
@@ -64,7 +65,7 @@ module Test
|
|
64
65
|
|
65
66
|
private
|
66
67
|
def make_color(color_spec)
|
67
|
-
if color_spec.is_a?(Color)
|
68
|
+
if color_spec.is_a?(Color) or color_spec.is_a?(MixColor)
|
68
69
|
color_spec
|
69
70
|
else
|
70
71
|
color_name = nil
|
data/lib/test/unit/priority.rb
CHANGED
@@ -26,6 +26,19 @@ module Test
|
|
26
26
|
def disable
|
27
27
|
@@enabled = false
|
28
28
|
end
|
29
|
+
|
30
|
+
@@default = :normal
|
31
|
+
def default
|
32
|
+
@@default || :normal
|
33
|
+
end
|
34
|
+
|
35
|
+
def default=(default)
|
36
|
+
@@default = default
|
37
|
+
end
|
38
|
+
|
39
|
+
def available_values
|
40
|
+
Checker.available_priorities
|
41
|
+
end
|
29
42
|
end
|
30
43
|
|
31
44
|
class Checker
|
@@ -36,7 +49,7 @@ module Test
|
|
36
49
|
end
|
37
50
|
|
38
51
|
def need_to_run?(test)
|
39
|
-
priority = test[:priority] ||
|
52
|
+
priority = test[:priority] || Priority.default
|
40
53
|
if have_priority?(priority)
|
41
54
|
send(priority_check_method_name(priority), test)
|
42
55
|
else
|
@@ -44,6 +57,13 @@ module Test
|
|
44
57
|
end
|
45
58
|
end
|
46
59
|
|
60
|
+
def available_priorities
|
61
|
+
methods(false).collect do |name|
|
62
|
+
/\Arun_priority_(.+)\?\z/ =~ name.to_s
|
63
|
+
$1
|
64
|
+
end.compact
|
65
|
+
end
|
66
|
+
|
47
67
|
def run_priority_must?(test)
|
48
68
|
true
|
49
69
|
end
|
data/lib/test/unit/testcase.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
#--
|
2
2
|
#
|
3
3
|
# Author:: Nathaniel Talbott.
|
4
|
-
# Copyright::
|
4
|
+
# Copyright::
|
5
|
+
# * Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
|
6
|
+
# * Copyright (c) 2008-2009 Kouhei Sutou <tt><kou@clear-code.com></tt>
|
5
7
|
# License:: Ruby license.
|
6
8
|
|
7
9
|
require 'test/unit/attribute'
|
@@ -60,14 +62,14 @@ module Test
|
|
60
62
|
# end
|
61
63
|
#
|
62
64
|
# Here is a call order:
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
65
|
+
# * startup
|
66
|
+
# * setup
|
67
|
+
# * test_my_method1
|
68
|
+
# * teardown
|
69
|
+
# * setup
|
70
|
+
# * test_my_method2
|
71
|
+
# * teardown
|
72
|
+
# * shutdown
|
71
73
|
class TestCase
|
72
74
|
include Attribute
|
73
75
|
include Fixture
|
@@ -81,24 +83,29 @@ module Test
|
|
81
83
|
include Assertions
|
82
84
|
include Util::BacktraceFilter
|
83
85
|
|
84
|
-
STARTED = name + "::STARTED"
|
85
|
-
FINISHED = name + "::FINISHED"
|
86
|
+
STARTED = name + "::STARTED" # :nodoc:
|
87
|
+
FINISHED = name + "::FINISHED" # :nodoc:
|
86
88
|
|
87
|
-
DESCENDANTS = []
|
89
|
+
DESCENDANTS = [] # :nodoc:
|
90
|
+
AVAILABLE_ORDERS = [:alphabetic, :random, :defined] # :nodoc:
|
88
91
|
|
89
92
|
class << self
|
90
|
-
def inherited(sub_class)
|
93
|
+
def inherited(sub_class) # :nodoc:
|
91
94
|
DESCENDANTS << sub_class
|
92
95
|
end
|
93
96
|
|
97
|
+
@@added_methods = []
|
98
|
+
def method_added(name) # :nodoc:
|
99
|
+
super
|
100
|
+
@@added_methods << name.to_s
|
101
|
+
end
|
102
|
+
|
94
103
|
# Rolls up all of the test* methods in the fixture into
|
95
104
|
# one suite, creating a new instance of the fixture for
|
96
105
|
# each method.
|
97
106
|
def suite
|
98
|
-
method_names = public_instance_methods(true).collect {|name| name.to_s}
|
99
|
-
tests = method_names.delete_if {|method_name| method_name !~ /^test./}
|
100
107
|
suite = TestSuite.new(name, self)
|
101
|
-
|
108
|
+
collect_test_names.each do |test|
|
102
109
|
catch(:invalid_test) do
|
103
110
|
suite << new(test)
|
104
111
|
end
|
@@ -137,11 +144,11 @@ module Test
|
|
137
144
|
# end
|
138
145
|
#
|
139
146
|
# Here is a call order:
|
140
|
-
#
|
141
|
-
#
|
142
|
-
#
|
143
|
-
#
|
144
|
-
#
|
147
|
+
# * startup
|
148
|
+
# * setup
|
149
|
+
# * test_my_class1 (or test_my_class2)
|
150
|
+
# * setup
|
151
|
+
# * test_my_class2 (or test_my_class1)
|
145
152
|
#
|
146
153
|
# Note that you should not assume test order. Tests
|
147
154
|
# should be worked in any order.
|
@@ -173,16 +180,74 @@ module Test
|
|
173
180
|
# end
|
174
181
|
#
|
175
182
|
# Here is a call order:
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
183
|
+
# * test_my_class1 (or test_my_class2)
|
184
|
+
# * teardown
|
185
|
+
# * test_my_class2 (or test_my_class1)
|
186
|
+
# * teardown
|
187
|
+
# * shutdown
|
181
188
|
#
|
182
189
|
# Note that you should not assume test order. Tests
|
183
190
|
# should be worked in any order.
|
184
191
|
def shutdown
|
185
192
|
end
|
193
|
+
|
194
|
+
@@test_order = AVAILABLE_ORDERS.first
|
195
|
+
|
196
|
+
# Returns the current test order. This returns
|
197
|
+
# +:alphabetic+ by default.
|
198
|
+
def test_order
|
199
|
+
@@test_order
|
200
|
+
end
|
201
|
+
|
202
|
+
# Sets the current test order.
|
203
|
+
#
|
204
|
+
# Here are the available _order_:
|
205
|
+
# [:alphabetic]
|
206
|
+
# Default. Tests are sorted in alphabetic order.
|
207
|
+
# [:random]
|
208
|
+
# Tests are sorted in random order.
|
209
|
+
# [:defined]
|
210
|
+
# Tests are sorted in defined order.
|
211
|
+
def test_order=(order)
|
212
|
+
@@test_order = order
|
213
|
+
end
|
214
|
+
|
215
|
+
# :stopdoc:
|
216
|
+
private
|
217
|
+
def collect_test_names
|
218
|
+
method_names = public_instance_methods(true).collect do |name|
|
219
|
+
name.to_s
|
220
|
+
end
|
221
|
+
test_names = method_names.find_all do |method_name|
|
222
|
+
method_name =~ /^test./
|
223
|
+
end
|
224
|
+
send("sort_test_names_in_#{test_order}_order", test_names)
|
225
|
+
end
|
226
|
+
|
227
|
+
def sort_test_names_in_alphabetic_order(test_names)
|
228
|
+
test_names.sort
|
229
|
+
end
|
230
|
+
|
231
|
+
def sort_test_names_in_random_order(test_names)
|
232
|
+
test_names.sort_by {rand(test_names.size)}
|
233
|
+
end
|
234
|
+
|
235
|
+
def sort_test_names_in_defined_order(test_names)
|
236
|
+
test_names.sort do |test1, test2|
|
237
|
+
test1_defined_order = @@added_methods.index(test1)
|
238
|
+
test2_defined_order = @@added_methods.index(test2)
|
239
|
+
if test1_defined_order and test2_defined_order
|
240
|
+
test1_defined_order <=> test2_defined_order
|
241
|
+
elsif test1_defined_order
|
242
|
+
1
|
243
|
+
elsif test2_defined_order
|
244
|
+
-1
|
245
|
+
else
|
246
|
+
test1 <=> test2
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
# :startdoc:
|
186
251
|
end
|
187
252
|
|
188
253
|
attr_reader :method_name
|
@@ -225,7 +290,7 @@ module Test
|
|
225
290
|
result.add_run
|
226
291
|
yield(FINISHED, name)
|
227
292
|
ensure
|
228
|
-
@_result = nil
|
293
|
+
# @_result = nil # For test-spec's after_all :<
|
229
294
|
end
|
230
295
|
end
|
231
296
|
|
@@ -255,10 +320,10 @@ module Test
|
|
255
320
|
# end
|
256
321
|
#
|
257
322
|
# Here is a call order:
|
258
|
-
#
|
259
|
-
#
|
260
|
-
#
|
261
|
-
#
|
323
|
+
# * setup
|
324
|
+
# * my_setup1
|
325
|
+
# * my_setup2
|
326
|
+
# * test_my_class
|
262
327
|
def setup
|
263
328
|
end
|
264
329
|
|
@@ -288,13 +353,13 @@ module Test
|
|
288
353
|
# end
|
289
354
|
#
|
290
355
|
# Here is a call order:
|
291
|
-
#
|
292
|
-
#
|
293
|
-
#
|
294
|
-
#
|
356
|
+
# * test_my_class
|
357
|
+
# * my_teardown2
|
358
|
+
# * my_teardown1
|
359
|
+
# * teardown
|
295
360
|
def teardown
|
296
361
|
end
|
297
|
-
|
362
|
+
|
298
363
|
def default_test
|
299
364
|
flunk("No tests were specified")
|
300
365
|
end
|
@@ -185,10 +185,13 @@ module Test
|
|
185
185
|
|
186
186
|
def guess_color_availability
|
187
187
|
return false unless @output.tty?
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
188
|
+
case ENV["TERM"]
|
189
|
+
when /term(?:-color)?\z/, "screen"
|
190
|
+
true
|
191
|
+
else
|
192
|
+
return true if ENV["EMACS"] == "t"
|
193
|
+
false
|
194
|
+
end
|
192
195
|
end
|
193
196
|
|
194
197
|
def guess_progress_row_max
|
data/lib/test/unit/version.rb
CHANGED
data/test/test-color-scheme.rb
CHANGED
@@ -6,7 +6,8 @@ class TestUnitColorScheme < Test::Unit::TestCase
|
|
6
6
|
"pending" => color("magenta", :bold => true),
|
7
7
|
"omission" => color("blue", :bold => true),
|
8
8
|
"notification" => color("cyan", :bold => true),
|
9
|
-
"error" => color("yellow", :bold => true)
|
9
|
+
"error" => color("yellow", :bold => true) +
|
10
|
+
color("black", :foreground => false),
|
10
11
|
},
|
11
12
|
Test::Unit::ColorScheme.default.to_hash)
|
12
13
|
end
|
data/test/test-pending.rb
CHANGED
@@ -6,7 +6,7 @@ require 'test/unit'
|
|
6
6
|
|
7
7
|
module Test
|
8
8
|
module Unit
|
9
|
-
class
|
9
|
+
class TestTestCase < TestCase
|
10
10
|
def test_creation
|
11
11
|
tc = Class.new(TestCase) do
|
12
12
|
def test_with_arguments(arg1, arg2)
|
@@ -267,7 +267,7 @@ module Test
|
|
267
267
|
def test_re_raise_exception
|
268
268
|
test_case = Class.new(TestCase) do
|
269
269
|
def test_raise_interrupt
|
270
|
-
raise Interrupt
|
270
|
+
raise Interrupt, "from test"
|
271
271
|
end
|
272
272
|
end
|
273
273
|
|
@@ -342,7 +342,7 @@ module Test
|
|
342
342
|
test_case = Class.new(TestCase) do
|
343
343
|
class << self
|
344
344
|
def startup
|
345
|
-
raise Interrupt
|
345
|
+
raise Interrupt, "from startup"
|
346
346
|
end
|
347
347
|
end
|
348
348
|
|
@@ -383,7 +383,7 @@ module Test
|
|
383
383
|
test_case = Class.new(TestCase) do
|
384
384
|
class << self
|
385
385
|
def shutdown
|
386
|
-
raise Interrupt
|
386
|
+
raise Interrupt, "from shutdown"
|
387
387
|
end
|
388
388
|
end
|
389
389
|
|
@@ -468,11 +468,40 @@ module Test
|
|
468
468
|
end
|
469
469
|
end
|
470
470
|
|
471
|
+
def test_defined_order
|
472
|
+
keep_test_order do
|
473
|
+
test_case = Class.new(Test::Unit::TestCase) do
|
474
|
+
def test_z
|
475
|
+
end
|
476
|
+
|
477
|
+
def test_1
|
478
|
+
end
|
479
|
+
|
480
|
+
def test_a
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
assert_equal(["test_1", "test_a", "test_z"],
|
485
|
+
test_case.suite.tests.collect {|test| test.method_name})
|
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
|
491
|
+
end
|
492
|
+
|
471
493
|
private
|
472
494
|
def check(message, passed)
|
473
495
|
add_assertion
|
474
496
|
raise AssertionFailedError.new(message) unless passed
|
475
497
|
end
|
498
|
+
|
499
|
+
def keep_test_order
|
500
|
+
order = TestCase.test_order
|
501
|
+
yield
|
502
|
+
ensure
|
503
|
+
TestCase.test_order = order
|
504
|
+
end
|
476
505
|
end
|
477
506
|
end
|
478
507
|
end
|
data/test/test_assertions.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Author:: Nathaniel Talbott.
|
2
2
|
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
3
|
+
# Copyright (c) 2009 Kouhei Sutou.
|
3
4
|
# License:: Ruby license.
|
4
5
|
|
5
6
|
require 'test/unit'
|
@@ -245,6 +246,37 @@ EOM
|
|
245
246
|
end
|
246
247
|
end
|
247
248
|
|
249
|
+
def test_assert_equal_with_large_string
|
250
|
+
message = <<-EOM.chomp
|
251
|
+
<#{("a\n" + "x" * 297).inspect}> expected but was
|
252
|
+
<#{"x".inspect}>.
|
253
|
+
|
254
|
+
diff:
|
255
|
+
+ x
|
256
|
+
- a
|
257
|
+
- #{"x" * 297}
|
258
|
+
|
259
|
+
folded diff:
|
260
|
+
+ x
|
261
|
+
- a
|
262
|
+
- #{"x" * 78}
|
263
|
+
- #{"x" * 78}
|
264
|
+
- #{"x" * 78}
|
265
|
+
- #{"x" * 63}
|
266
|
+
EOM
|
267
|
+
check_fails(message) do
|
268
|
+
assert_equal("a\n" + "x" * 297, "x")
|
269
|
+
end
|
270
|
+
|
271
|
+
message = <<-EOM.chomp
|
272
|
+
<#{("a\n" + "x" * 298).inspect}> expected but was
|
273
|
+
<#{"x".inspect}>.
|
274
|
+
EOM
|
275
|
+
check_fails(message) do
|
276
|
+
assert_equal("a\n" + "x" * 298, "x")
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
248
280
|
def test_assert_raise_success
|
249
281
|
return_value = nil
|
250
282
|
check_nothing_fails(true) do
|
@@ -396,7 +428,7 @@ EOM
|
|
396
428
|
|
397
429
|
different_error_class = Class.new(StandardError)
|
398
430
|
message = <<-EOM
|
399
|
-
<\#<Class:
|
431
|
+
<\#<Class:[xa-f\\d]+>\\("Error"\\)> exception expected but was
|
400
432
|
Class: <RuntimeError>
|
401
433
|
Message: <"Error">
|
402
434
|
EOM
|
@@ -446,8 +478,18 @@ EOM
|
|
446
478
|
check_fails(%Q{failed assert_instance_of.\n<"string"> expected to be an instance of\n<Hash> but was\n<String>.}) {
|
447
479
|
assert_instance_of(Hash, "string", "failed assert_instance_of")
|
448
480
|
}
|
481
|
+
|
482
|
+
check_nothing_fails do
|
483
|
+
assert_instance_of([Fixnum, NilClass], 100)
|
484
|
+
end
|
485
|
+
check_fails(%Q{<"string"> expected to be an instance of\n[<Fixnum>, <NilClass>] but was\n<String>.}) do
|
486
|
+
assert_instance_of([Fixnum, NilClass], "string")
|
487
|
+
end
|
488
|
+
check_fails(%Q{<100> expected to be an instance of\n[<Numeric>, <NilClass>] but was\n<Fixnum>.}) do
|
489
|
+
assert_instance_of([Numeric, NilClass], 100)
|
490
|
+
end
|
449
491
|
end
|
450
|
-
|
492
|
+
|
451
493
|
def test_assert_nil
|
452
494
|
check_nothing_fails {
|
453
495
|
assert_nil(nil)
|
@@ -486,14 +528,21 @@ EOM
|
|
486
528
|
check_nothing_fails {
|
487
529
|
assert_kind_of(Comparable, 1)
|
488
530
|
}
|
489
|
-
check_fails(%Q{<"string"
|
531
|
+
check_fails(%Q{<"string"> expected to be kind_of?\n<Class> but was\n<String>.}) {
|
490
532
|
assert_kind_of(Class, "string")
|
491
533
|
}
|
492
|
-
check_fails(%Q{failed assert_kind_of.\n<"string"
|
534
|
+
check_fails(%Q{failed assert_kind_of.\n<"string"> expected to be kind_of?\n<Class> but was\n<String>.}) {
|
493
535
|
assert_kind_of(Class, "string", "failed assert_kind_of")
|
494
536
|
}
|
537
|
+
|
538
|
+
check_nothing_fails do
|
539
|
+
assert_kind_of([Fixnum, NilClass], 100)
|
540
|
+
end
|
541
|
+
check_fails(%Q{<"string"> expected to be kind_of?\n[<Fixnum>, <NilClass>] but was\n<String>.}) do
|
542
|
+
assert_kind_of([Fixnum, NilClass], "string")
|
543
|
+
end
|
495
544
|
end
|
496
|
-
|
545
|
+
|
497
546
|
def test_assert_match
|
498
547
|
check_nothing_fails {
|
499
548
|
assert_match(/strin./, "string")
|
@@ -703,10 +752,13 @@ EOM
|
|
703
752
|
check_nothing_fails {
|
704
753
|
assert_respond_to("thing", "to_s", "message")
|
705
754
|
}
|
706
|
-
check_fails("<0.15
|
755
|
+
check_fails("<0.15>.kind_of?(Symbol) or\n" +
|
756
|
+
"<0.15>.respond_to?(:to_str) expected") {
|
707
757
|
assert_respond_to("thing", 0.15)
|
708
758
|
}
|
709
|
-
check_fails("message.\n
|
759
|
+
check_fails("message.\n" +
|
760
|
+
"<:symbol>.respond_to?(:non_existent) expected\n" +
|
761
|
+
"(Class: <Symbol>)") {
|
710
762
|
assert_respond_to(:symbol, :non_existent, "message")
|
711
763
|
}
|
712
764
|
end
|
@@ -728,10 +780,15 @@ EOM
|
|
728
780
|
check_fails("message.\n<0.5> and\n<0.4> expected to be within\n<0.05> of each other.") {
|
729
781
|
assert_in_delta(0.5, 0.4, 0.05, "message")
|
730
782
|
}
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
783
|
+
object = Object.new
|
784
|
+
check_fails("The arguments must respond to to_f; " +
|
785
|
+
"the first float did not.\n" +
|
786
|
+
"<#{object.inspect}>.respond_to?(:to_f) expected\n" +
|
787
|
+
"(Class: <Object>)") {
|
788
|
+
assert_in_delta(object, 0.4, 0.1)
|
789
|
+
}
|
790
|
+
check_fails("The delta should not be negative.\n" +
|
791
|
+
"<-0.1> expected to be\n>=\n<0.0>.") {
|
735
792
|
assert_in_delta(0.5, 0.4, -0.1, "message")
|
736
793
|
}
|
737
794
|
end
|
@@ -976,6 +1033,36 @@ EOM
|
|
976
1033
|
end
|
977
1034
|
end
|
978
1035
|
|
1036
|
+
def test_assert_predicate
|
1037
|
+
check_nothing_fails do
|
1038
|
+
assert_predicate([], :empty?)
|
1039
|
+
end
|
1040
|
+
|
1041
|
+
check_fails("<[1]>.empty? is true value expected but was\n<false>") do
|
1042
|
+
assert_predicate([1], :empty?)
|
1043
|
+
end
|
1044
|
+
|
1045
|
+
check_fails("<[1]>.respond_to?(:nonexistent?) expected\n" +
|
1046
|
+
"(Class: <Array>)") do
|
1047
|
+
assert_predicate([1], :nonexistent?)
|
1048
|
+
end
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
def test_assert_not_predicate
|
1052
|
+
check_nothing_fails do
|
1053
|
+
assert_not_predicate([1], :empty?)
|
1054
|
+
end
|
1055
|
+
|
1056
|
+
check_fails("<[]>.empty? is false value expected but was\n<true>") do
|
1057
|
+
assert_not_predicate([], :empty?)
|
1058
|
+
end
|
1059
|
+
|
1060
|
+
check_fails("<[]>.respond_to?(:nonexistent?) expected\n" +
|
1061
|
+
"(Class: <Array>)") do
|
1062
|
+
assert_not_predicate([], :nonexistent?)
|
1063
|
+
end
|
1064
|
+
end
|
1065
|
+
|
979
1066
|
private
|
980
1067
|
def add_failure(message, location=caller)
|
981
1068
|
unless @catch_assertions
|
@@ -993,4 +1080,3 @@ EOM
|
|
993
1080
|
end
|
994
1081
|
end
|
995
1082
|
end
|
996
|
-
p
|
@@ -4,7 +4,7 @@ class TestUnitUIMediator < Test::Unit::TestCase
|
|
4
4
|
def test_run_suite_with_interrupt_exception
|
5
5
|
test_case = Class.new(Test::Unit::TestCase) do
|
6
6
|
def test_raise_interrupt
|
7
|
-
raise Interrupt
|
7
|
+
raise Interrupt, "from test"
|
8
8
|
end
|
9
9
|
end
|
10
10
|
mediator = Test::Unit::UI::TestRunnerMediator.new(test_case.suite)
|
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.3
|
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:
|
13
|
+
date: 2009-07-19 00:00:00 +09:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -21,9 +21,15 @@ dependencies:
|
|
21
21
|
requirements:
|
22
22
|
- - ">="
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version:
|
24
|
+
version: 2.3.2
|
25
25
|
version:
|
26
|
-
description:
|
26
|
+
description: |-
|
27
|
+
Test::Unit 2.x - Improved version of Test::Unit bundled in
|
28
|
+
Ruby 1.8.x.
|
29
|
+
|
30
|
+
Ruby 1.9.x bundles miniunit not Test::Unit. Test::Unit
|
31
|
+
bundled in Ruby 1.8.x had not been improved but unbundled
|
32
|
+
Test::Unit (Test::Unit 2.x) will be improved actively.
|
27
33
|
email:
|
28
34
|
- kou@cozmixng.org
|
29
35
|
- ryand-ruby@zenspider.com
|
@@ -104,10 +110,10 @@ files:
|
|
104
110
|
- test/test-omission.rb
|
105
111
|
- test/test-pending.rb
|
106
112
|
- test/test-priority.rb
|
113
|
+
- test/test-testcase.rb
|
107
114
|
- test/test_assertions.rb
|
108
115
|
- test/test_error.rb
|
109
116
|
- test/test_failure.rb
|
110
|
-
- test/test_testcase.rb
|
111
117
|
- test/test_testresult.rb
|
112
118
|
- test/test_testsuite.rb
|
113
119
|
- test/testunit-test-util.rb
|
@@ -118,6 +124,8 @@ files:
|
|
118
124
|
- test/util/test_procwrapper.rb
|
119
125
|
has_rdoc: true
|
120
126
|
homepage: http://rubyforge.org/projects/test-unit/
|
127
|
+
licenses: []
|
128
|
+
|
121
129
|
post_install_message:
|
122
130
|
rdoc_options:
|
123
131
|
- --main
|
@@ -139,20 +147,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
147
|
requirements: []
|
140
148
|
|
141
149
|
rubyforge_project: test-unit
|
142
|
-
rubygems_version: 1.3.
|
150
|
+
rubygems_version: 1.3.4
|
143
151
|
signing_key:
|
144
|
-
specification_version:
|
152
|
+
specification_version: 3
|
145
153
|
summary: Test::Unit 2.x - Improved version of Test::Unit bundled in Ruby 1.8.x
|
146
154
|
test_files:
|
147
|
-
- test/test_testcase.rb
|
148
|
-
- test/test_failure.rb
|
149
|
-
- test/collector/test_objectspace.rb
|
150
155
|
- test/collector/test_dir.rb
|
151
|
-
- test/
|
156
|
+
- test/collector/test_objectspace.rb
|
157
|
+
- test/ui/test_testrunmediator.rb
|
152
158
|
- test/test_assertions.rb
|
153
|
-
- test/util/test_observable.rb
|
154
159
|
- test/util/test_procwrapper.rb
|
155
160
|
- test/util/test_backtracefilter.rb
|
156
|
-
- test/
|
161
|
+
- test/util/test_observable.rb
|
162
|
+
- test/test_failure.rb
|
163
|
+
- test/test_testsuite.rb
|
157
164
|
- test/test_testresult.rb
|
158
165
|
- test/test_error.rb
|