test-unit 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +26 -0
- data/README.txt +2 -0
- data/lib/test/unit.rb +3 -2
- data/lib/test/unit/assertions.rb +62 -2
- data/lib/test/unit/collector/load.rb +2 -3
- data/lib/test/unit/omission.rb +47 -3
- data/lib/test/unit/testcase.rb +42 -0
- data/lib/test/unit/version.rb +1 -1
- data/test/test-omission.rb +1 -1
- data/test/test-testcase.rb +27 -0
- data/test/test_assertions.rb +71 -0
- metadata +3 -3
data/History.txt
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
=== 2.0.6 / 2010-01-09
|
2
|
+
|
3
|
+
* 3 major enhancements
|
4
|
+
* [#27380] Declarative syntax? [Daniel Berger]
|
5
|
+
support declarative syntax:
|
6
|
+
|
7
|
+
test "test description in natural language" do
|
8
|
+
...
|
9
|
+
end
|
10
|
+
* support test description:
|
11
|
+
description "test description in natural language"
|
12
|
+
def test_my_test
|
13
|
+
...
|
14
|
+
end
|
15
|
+
* make max diff target string size customizable by
|
16
|
+
TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE environment variable.
|
17
|
+
|
18
|
+
* 2 bug fixes
|
19
|
+
* [#27374] omit_if unexpected behavior [David MARCHALAND]
|
20
|
+
* fix a bug that tests in sub directories aren't load with --basedir.
|
21
|
+
[Daniel Berger]
|
22
|
+
|
23
|
+
* Thanks
|
24
|
+
* David MARCHALAND
|
25
|
+
* Daniel Berger
|
26
|
+
|
1
27
|
=== 2.0.5 / 2009-10-18
|
2
28
|
|
3
29
|
* 1 bug fixes
|
data/README.txt
CHANGED
data/lib/test/unit.rb
CHANGED
@@ -303,12 +303,13 @@ module Test # :nodoc:
|
|
303
303
|
#
|
304
304
|
|
305
305
|
module Unit
|
306
|
-
#
|
306
|
+
# Set true when Test::Unit has run. If set to true Test::Unit
|
307
|
+
# will not automatically run at exit.
|
307
308
|
def self.run=(flag)
|
308
309
|
@run = flag
|
309
310
|
end
|
310
311
|
|
311
|
-
#
|
312
|
+
# Already tests have run?
|
312
313
|
def self.run?
|
313
314
|
@run ||= false
|
314
315
|
end
|
data/lib/test/unit/assertions.rb
CHANGED
@@ -798,6 +798,54 @@ EOT
|
|
798
798
|
end
|
799
799
|
end
|
800
800
|
|
801
|
+
##
|
802
|
+
# Passes if +object+#+alias_name+ is an alias method of
|
803
|
+
# +object+#+original_name+.
|
804
|
+
#
|
805
|
+
# Example:
|
806
|
+
# assert_alias_method([], :length, :size) # -> pass
|
807
|
+
# assert_alias_method([], :size, :length) # -> pass
|
808
|
+
# assert_alias_method([], :each, :size) # -> fail
|
809
|
+
def assert_alias_method(object, alias_name, original_name, message=nil)
|
810
|
+
_wrap_assertion do
|
811
|
+
find_method_failure_message = Proc.new do |method_name|
|
812
|
+
build_message(message,
|
813
|
+
"<?>.? doesn't exist\n" +
|
814
|
+
"(Class: <?>)",
|
815
|
+
object,
|
816
|
+
AssertionMessage.literal(method_name),
|
817
|
+
object.class)
|
818
|
+
end
|
819
|
+
|
820
|
+
alias_method = original_method = nil
|
821
|
+
assert_block(find_method_failure_message.call(alias_name)) do
|
822
|
+
begin
|
823
|
+
alias_method = object.method(alias_name)
|
824
|
+
true
|
825
|
+
rescue NameError
|
826
|
+
false
|
827
|
+
end
|
828
|
+
end
|
829
|
+
assert_block(find_method_failure_message.call(original_name)) do
|
830
|
+
begin
|
831
|
+
original_method = object.method(original_name)
|
832
|
+
true
|
833
|
+
rescue NameError
|
834
|
+
false
|
835
|
+
end
|
836
|
+
end
|
837
|
+
|
838
|
+
full_message = build_message(message,
|
839
|
+
"<?> is alias of\n" +
|
840
|
+
"<?> expected",
|
841
|
+
alias_method,
|
842
|
+
original_method)
|
843
|
+
assert_block(full_message) do
|
844
|
+
alias_method == original_method
|
845
|
+
end
|
846
|
+
end
|
847
|
+
end
|
848
|
+
|
801
849
|
##
|
802
850
|
# Builds a failure message. +head+ is added before the +template+ and
|
803
851
|
# +arguments+ replaces the '?'s positionally in the template.
|
@@ -890,11 +938,23 @@ EOT
|
|
890
938
|
end
|
891
939
|
|
892
940
|
MAX_DIFF_TARGET_STRING_SIZE = 1000
|
941
|
+
def max_diff_target_string_size
|
942
|
+
size = ENV["TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"]
|
943
|
+
if size
|
944
|
+
begin
|
945
|
+
size = Integer(size)
|
946
|
+
rescue ArgumentError
|
947
|
+
size = nil
|
948
|
+
end
|
949
|
+
end
|
950
|
+
size || MAX_DIFF_TARGET_STRING_SIZE
|
951
|
+
end
|
952
|
+
|
893
953
|
def diff_target_string?(string)
|
894
954
|
if string.respond_to?(:bytesize)
|
895
|
-
string.bytesize <
|
955
|
+
string.bytesize < max_diff_target_string_size
|
896
956
|
else
|
897
|
-
string.size <
|
957
|
+
string.size < max_diff_target_string_size
|
898
958
|
end
|
899
959
|
end
|
900
960
|
|
@@ -29,7 +29,7 @@ module Test
|
|
29
29
|
add_load_path(@base) do
|
30
30
|
froms = ["."] if froms.empty?
|
31
31
|
test_suites = froms.collect do |from|
|
32
|
-
test_suite = collect_recursive(from, find_test_cases)
|
32
|
+
test_suite = collect_recursive(resolve_path(from), find_test_cases)
|
33
33
|
test_suite = nil if test_suite.tests.empty?
|
34
34
|
test_suite
|
35
35
|
end.compact
|
@@ -56,10 +56,9 @@ module Test
|
|
56
56
|
end
|
57
57
|
|
58
58
|
private
|
59
|
-
def collect_recursive(
|
59
|
+
def collect_recursive(path, already_gathered)
|
60
60
|
sub_test_suites = []
|
61
61
|
|
62
|
-
path = resolve_path(name)
|
63
62
|
if path.directory?
|
64
63
|
directories, files = path.children.partition do |child|
|
65
64
|
child.directory?
|
data/lib/test/unit/omission.rb
CHANGED
@@ -56,7 +56,7 @@ module Test
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
# Omit the test
|
59
|
+
# Omit the test or part of the test.
|
60
60
|
#
|
61
61
|
# Example:
|
62
62
|
# def test_omission
|
@@ -80,12 +80,56 @@ module Test
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
# Omit the test or part of the test if _condition_ is
|
84
|
+
# true.
|
85
|
+
#
|
86
|
+
# Example:
|
87
|
+
# def test_omission
|
88
|
+
# omit_if("".empty?)
|
89
|
+
# # Not reached here
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# def test_omission_with_here
|
93
|
+
# omit_if(true) do
|
94
|
+
# # Not ran here
|
95
|
+
# end
|
96
|
+
# omit_if(false) do
|
97
|
+
# # Reached here
|
98
|
+
# end
|
99
|
+
# # Reached here too
|
100
|
+
# end
|
83
101
|
def omit_if(condition, *args, &block)
|
84
|
-
|
102
|
+
if condition
|
103
|
+
omit(*args, &block)
|
104
|
+
else
|
105
|
+
block.call if block
|
106
|
+
end
|
85
107
|
end
|
86
108
|
|
109
|
+
# Omit the test or part of the test if _condition_ is
|
110
|
+
# not true.
|
111
|
+
#
|
112
|
+
# Example:
|
113
|
+
# def test_omission
|
114
|
+
# omit_unless("string".empty?)
|
115
|
+
# # Not reached here
|
116
|
+
# end
|
117
|
+
#
|
118
|
+
# def test_omission_with_here
|
119
|
+
# omit_unless(true) do
|
120
|
+
# # Reached here
|
121
|
+
# end
|
122
|
+
# omit_unless(false) do
|
123
|
+
# # Not ran here
|
124
|
+
# end
|
125
|
+
# # Reached here too
|
126
|
+
# end
|
87
127
|
def omit_unless(condition, *args, &block)
|
88
|
-
|
128
|
+
if condition
|
129
|
+
block.call if block
|
130
|
+
else
|
131
|
+
omit(*args, &block)
|
132
|
+
end
|
89
133
|
end
|
90
134
|
|
91
135
|
private
|
data/lib/test/unit/testcase.rb
CHANGED
@@ -212,6 +212,39 @@ module Test
|
|
212
212
|
@@test_order = order
|
213
213
|
end
|
214
214
|
|
215
|
+
# Defines a test in declarative syntax.
|
216
|
+
#
|
217
|
+
# The following two test definitions are the same:
|
218
|
+
#
|
219
|
+
# description "register user"
|
220
|
+
# def test_register_user
|
221
|
+
# ...
|
222
|
+
# end
|
223
|
+
#
|
224
|
+
# test "register user" do
|
225
|
+
# ...
|
226
|
+
# end
|
227
|
+
def test(test_description, &block)
|
228
|
+
normalized_description = test_description.gsub(/[^a-zA-Z\d_]+/, '_')
|
229
|
+
method_name = "test_#{normalized_description}".to_sym
|
230
|
+
define_method(method_name, &block)
|
231
|
+
description(test_description, method_name)
|
232
|
+
end
|
233
|
+
|
234
|
+
# Describes a test.
|
235
|
+
#
|
236
|
+
# The following example associates "register a
|
237
|
+
# normal user" description with "test_register"
|
238
|
+
# test.
|
239
|
+
#
|
240
|
+
# description "register a normal user"
|
241
|
+
# def test_register
|
242
|
+
# ...
|
243
|
+
# end
|
244
|
+
def description(value, target=nil)
|
245
|
+
attribute(:description, value, {}, target || [])
|
246
|
+
end
|
247
|
+
|
215
248
|
# :stopdoc:
|
216
249
|
private
|
217
250
|
def collect_test_names
|
@@ -374,6 +407,15 @@ module Test
|
|
374
407
|
"#{@method_name}(#{self.class.name})"
|
375
408
|
end
|
376
409
|
|
410
|
+
# Returns a description for the test. A description
|
411
|
+
# will be associated by Test::Unit::TestCase.test or
|
412
|
+
# Test::Unit::TestCase.description.
|
413
|
+
#
|
414
|
+
# Returns a name for the test for no description test.
|
415
|
+
def description
|
416
|
+
self[:description] || name
|
417
|
+
end
|
418
|
+
|
377
419
|
# Overridden to return #name.
|
378
420
|
def to_s
|
379
421
|
name
|
data/lib/test/unit/version.rb
CHANGED
data/test/test-omission.rb
CHANGED
@@ -68,7 +68,7 @@ class TestUnitOmission < Test::Unit::TestCase
|
|
68
68
|
|
69
69
|
def test_omit_with_condition_and_block
|
70
70
|
result = _run_test("test_omit_with_block_and_condition")
|
71
|
-
assert_equal("1 tests,
|
71
|
+
assert_equal("1 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, " \
|
72
72
|
"1 omissions, 0 notifications",
|
73
73
|
result.to_s)
|
74
74
|
assert_fault_messages(["Should omit."], result.omissions)
|
data/test/test-testcase.rb
CHANGED
@@ -490,6 +490,33 @@ module Test
|
|
490
490
|
end
|
491
491
|
end
|
492
492
|
|
493
|
+
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
|
498
|
+
|
499
|
+
test "include parenthesis" do
|
500
|
+
end
|
501
|
+
|
502
|
+
test "1 + 2 = 3" do
|
503
|
+
end
|
504
|
+
end
|
505
|
+
|
506
|
+
test_case.test_order = :defined
|
507
|
+
|
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})
|
512
|
+
|
513
|
+
assert_equal(["declarative style test definition",
|
514
|
+
"include parenthesis",
|
515
|
+
"1 + 2 = 3"],
|
516
|
+
test_case.suite.tests.collect {|test| test.description})
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
493
520
|
private
|
494
521
|
def check(message, passed)
|
495
522
|
add_assertion
|
data/test/test_assertions.rb
CHANGED
@@ -275,6 +275,42 @@ EOM
|
|
275
275
|
end
|
276
276
|
end
|
277
277
|
|
278
|
+
def test_assert_equal_with_max_diff_target_string_size
|
279
|
+
key = "TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"
|
280
|
+
before_value = ENV[key]
|
281
|
+
ENV[key] = "100"
|
282
|
+
begin
|
283
|
+
message = <<-EOM.chomp
|
284
|
+
<#{("a\n" + "x" * 97).inspect}> expected but was
|
285
|
+
<#{"x".inspect}>.
|
286
|
+
|
287
|
+
diff:
|
288
|
+
+ x
|
289
|
+
- a
|
290
|
+
- #{"x" * 97}
|
291
|
+
|
292
|
+
folded diff:
|
293
|
+
+ x
|
294
|
+
- a
|
295
|
+
#{(["- " + ("x" * 78)]).join("\n")}
|
296
|
+
- #{"x" * 19}
|
297
|
+
EOM
|
298
|
+
check_fails(message) do
|
299
|
+
assert_equal("a\n" + "x" * 97, "x")
|
300
|
+
end
|
301
|
+
|
302
|
+
message = <<-EOM.chomp
|
303
|
+
<#{("a\n" + "x" * 98).inspect}> expected but was
|
304
|
+
<#{"x".inspect}>.
|
305
|
+
EOM
|
306
|
+
check_fails(message) do
|
307
|
+
assert_equal("a\n" + "x" * 98, "x")
|
308
|
+
end
|
309
|
+
ensure
|
310
|
+
ENV[key] = before_value
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
278
314
|
def test_assert_raise_success
|
279
315
|
return_value = nil
|
280
316
|
check_nothing_fails(true) do
|
@@ -1061,6 +1097,41 @@ EOM
|
|
1061
1097
|
end
|
1062
1098
|
end
|
1063
1099
|
|
1100
|
+
def test_assert_alias_method
|
1101
|
+
object = Object.new
|
1102
|
+
class << object
|
1103
|
+
def original_method
|
1104
|
+
end
|
1105
|
+
alias_method :alias_method, :original_method
|
1106
|
+
|
1107
|
+
def other
|
1108
|
+
end
|
1109
|
+
end
|
1110
|
+
|
1111
|
+
check_nothing_fails do
|
1112
|
+
assert_alias_method(object, :alias_method, :original_method)
|
1113
|
+
end
|
1114
|
+
|
1115
|
+
check_nothing_fails do
|
1116
|
+
assert_alias_method(object, :original_method, :alias_method)
|
1117
|
+
end
|
1118
|
+
|
1119
|
+
check_fails("<#{object.method(:other).inspect}> is alias of\n" +
|
1120
|
+
"<#{object.method(:original_method).inspect}> expected") do
|
1121
|
+
assert_alias_method(object, :other, :original_method)
|
1122
|
+
end
|
1123
|
+
|
1124
|
+
check_fails("<#{object.inspect}>.nonexistent doesn't exist\n" +
|
1125
|
+
"(Class: <Object>)") do
|
1126
|
+
assert_alias_method(object, :nonexistent, :original_method)
|
1127
|
+
end
|
1128
|
+
|
1129
|
+
check_fails("<#{object.inspect}>.nonexistent doesn't exist\n" +
|
1130
|
+
"(Class: <Object>)") do
|
1131
|
+
assert_alias_method(object, :alias_method, :nonexistent)
|
1132
|
+
end
|
1133
|
+
end
|
1134
|
+
|
1064
1135
|
private
|
1065
1136
|
def add_failure(message, location=caller, options=nil)
|
1066
1137
|
unless @catch_assertions
|
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.6
|
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: 2010-01-09 00:00:00 +09:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
requirements:
|
22
22
|
- - ">="
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: 2.
|
24
|
+
version: 2.4.0
|
25
25
|
version:
|
26
26
|
description: |-
|
27
27
|
Test::Unit 2.x - Improved version of Test::Unit bundled in
|