test-unit 3.3.1 → 3.3.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.
- checksums.yaml +4 -4
- data/doc/text/news.md +67 -0
- data/lib/test/unit.rb +171 -157
- data/lib/test/unit/assertions.rb +52 -52
- data/lib/test/unit/autorunner.rb +55 -23
- data/lib/test/unit/code-snippet-fetcher.rb +4 -2
- data/lib/test/unit/collector/load.rb +1 -3
- data/lib/test/unit/data.rb +2 -2
- data/lib/test/unit/notification.rb +9 -7
- data/lib/test/unit/omission.rb +34 -31
- data/lib/test/unit/pending.rb +12 -11
- data/lib/test/unit/priority.rb +7 -3
- data/lib/test/unit/testcase.rb +138 -123
- data/lib/test/unit/util/observable.rb +2 -2
- data/lib/test/unit/util/output.rb +5 -4
- data/lib/test/unit/version.rb +1 -1
- data/test/collector/test-load.rb +35 -2
- data/test/test-assertions.rb +10 -5
- data/test/test-priority.rb +19 -8
- metadata +33 -34
@@ -31,9 +31,11 @@ module Test
|
|
31
31
|
break if first_line.nil?
|
32
32
|
encoding = detect_encoding(first_line) || Encoding::UTF_8
|
33
33
|
first_line.force_encoding(encoding)
|
34
|
-
file.set_encoding(encoding)
|
35
34
|
lines << first_line
|
36
|
-
|
35
|
+
file.each_line do |line|
|
36
|
+
line.force_encoding(encoding)
|
37
|
+
lines << line
|
38
|
+
end
|
37
39
|
end
|
38
40
|
lines
|
39
41
|
end
|
@@ -111,7 +111,7 @@ module Test
|
|
111
111
|
return if @program_file == expanded_path.to_s
|
112
112
|
add_load_path(expanded_path.dirname) do
|
113
113
|
begin
|
114
|
-
require(
|
114
|
+
require(expanded_path.to_s)
|
115
115
|
rescue LoadError
|
116
116
|
@require_failed_infos << {:path => expanded_path, :exception => $!}
|
117
117
|
end
|
@@ -131,8 +131,6 @@ module Test
|
|
131
131
|
return yield if path.nil?
|
132
132
|
|
133
133
|
path = path.to_s
|
134
|
-
return yield if $LOAD_PATH.index(path)
|
135
|
-
|
136
134
|
begin
|
137
135
|
$LOAD_PATH.unshift(path)
|
138
136
|
yield
|
data/lib/test/unit/data.rb
CHANGED
@@ -187,7 +187,7 @@ module Test
|
|
187
187
|
#
|
188
188
|
# @param [String] file_name full path to test data file.
|
189
189
|
# File format is automatically detected from filename extension.
|
190
|
-
# @raise [ArgumentError] if
|
190
|
+
# @raise [ArgumentError] if `file_name` is not supported file format.
|
191
191
|
# @see Loader#load
|
192
192
|
#
|
193
193
|
# @example Load data from CSV file
|
@@ -211,7 +211,7 @@ module Test
|
|
211
211
|
#
|
212
212
|
# @param [String] file_name full path to test data file.
|
213
213
|
# File format is automatically detected from filename extension.
|
214
|
-
# @raise [ArgumentError] if
|
214
|
+
# @raise [ArgumentError] if `file_name` is not supported file format.
|
215
215
|
# @see #load_csv
|
216
216
|
# @see #load_tsv
|
217
217
|
# @api private
|
@@ -65,15 +65,17 @@ module Test
|
|
65
65
|
# Notify some information.
|
66
66
|
#
|
67
67
|
# Example:
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
68
|
+
#
|
69
|
+
# def test_notification
|
70
|
+
# notify("I'm here!")
|
71
|
+
# # Reached here
|
72
|
+
# notify("Special!") if special_case?
|
73
|
+
# # Reached here too
|
74
|
+
# end
|
74
75
|
#
|
75
76
|
# options:
|
76
|
-
#
|
77
|
+
#
|
78
|
+
# :backtrace override backtrace.
|
77
79
|
def notify(message, options={}, &block)
|
78
80
|
backtrace = filter_backtrace(options[:backtrace] || caller)
|
79
81
|
notification = Notification.new(name, backtrace, message,
|
data/lib/test/unit/omission.rb
CHANGED
@@ -65,17 +65,18 @@ module Test
|
|
65
65
|
# Omit the test or part of the test.
|
66
66
|
#
|
67
67
|
# Example:
|
68
|
-
# def test_omission
|
69
|
-
# omit
|
70
|
-
# # Not reached here
|
71
|
-
# end
|
72
68
|
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
# # Not
|
69
|
+
# def test_omission
|
70
|
+
# omit
|
71
|
+
# # Not reached here
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# def test_omission_with_here
|
75
|
+
# omit do
|
76
|
+
# # Not ran here
|
77
|
+
# end
|
78
|
+
# # Reached here
|
76
79
|
# end
|
77
|
-
# # Reached here
|
78
|
-
# end
|
79
80
|
def omit(message=nil, &block)
|
80
81
|
message ||= "omitted."
|
81
82
|
if block_given?
|
@@ -91,20 +92,21 @@ module Test
|
|
91
92
|
# true.
|
92
93
|
#
|
93
94
|
# Example:
|
94
|
-
# def test_omission
|
95
|
-
# omit_if("".empty?)
|
96
|
-
# # Not reached here
|
97
|
-
# end
|
98
95
|
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
# # Not
|
96
|
+
# def test_omission
|
97
|
+
# omit_if("".empty?)
|
98
|
+
# # Not reached here
|
102
99
|
# end
|
103
|
-
#
|
104
|
-
#
|
100
|
+
#
|
101
|
+
# def test_omission_with_here
|
102
|
+
# omit_if(true) do
|
103
|
+
# # Not ran here
|
104
|
+
# end
|
105
|
+
# omit_if(false) do
|
106
|
+
# # Reached here
|
107
|
+
# end
|
108
|
+
# # Reached here too
|
105
109
|
# end
|
106
|
-
# # Reached here too
|
107
|
-
# end
|
108
110
|
def omit_if(condition, *args, &block)
|
109
111
|
if condition
|
110
112
|
omit(*args, &block)
|
@@ -117,20 +119,21 @@ module Test
|
|
117
119
|
# not true.
|
118
120
|
#
|
119
121
|
# Example:
|
120
|
-
# def test_omission
|
121
|
-
# omit_unless("string".empty?)
|
122
|
-
# # Not reached here
|
123
|
-
# end
|
124
122
|
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
# #
|
123
|
+
# def test_omission
|
124
|
+
# omit_unless("string".empty?)
|
125
|
+
# # Not reached here
|
128
126
|
# end
|
129
|
-
#
|
130
|
-
#
|
127
|
+
#
|
128
|
+
# def test_omission_with_here
|
129
|
+
# omit_unless(true) do
|
130
|
+
# # Reached here
|
131
|
+
# end
|
132
|
+
# omit_unless(false) do
|
133
|
+
# # Not ran here
|
134
|
+
# end
|
135
|
+
# # Reached here too
|
131
136
|
# end
|
132
|
-
# # Reached here too
|
133
|
-
# end
|
134
137
|
def omit_unless(condition, *args, &block)
|
135
138
|
if condition
|
136
139
|
block.call if block
|
data/lib/test/unit/pending.rb
CHANGED
@@ -65,19 +65,20 @@ module Test
|
|
65
65
|
# Marks the test or part of the test is pending.
|
66
66
|
#
|
67
67
|
# Example:
|
68
|
-
# def test_pending
|
69
|
-
# pend
|
70
|
-
# # Not reached here
|
71
|
-
# end
|
72
68
|
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
# #
|
76
|
-
#
|
77
|
-
#
|
69
|
+
# def test_pending
|
70
|
+
# pend
|
71
|
+
# # Not reached here
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# def test_pending_with_here
|
75
|
+
# pend do
|
76
|
+
# # Ran here
|
77
|
+
# # Fails if the block doesn't raise any error.
|
78
|
+
# # Because it means the block is passed unexpectedly.
|
79
|
+
# end
|
80
|
+
# # Reached here
|
78
81
|
# end
|
79
|
-
# # Reached here
|
80
|
-
# end
|
81
82
|
def pend(message=nil, &block)
|
82
83
|
message ||= "pended."
|
83
84
|
if block_given?
|
data/lib/test/unit/priority.rb
CHANGED
@@ -148,15 +148,19 @@ module Test
|
|
148
148
|
end
|
149
149
|
|
150
150
|
def escape_class_name(class_name)
|
151
|
-
class_name
|
151
|
+
escape_name(class_name)
|
152
152
|
end
|
153
153
|
|
154
154
|
def escaped_method_name
|
155
|
-
@test.method_name.to_s
|
155
|
+
escape_name(@test.method_name.to_s)
|
156
|
+
end
|
157
|
+
|
158
|
+
def escape_name(name)
|
159
|
+
name.gsub(/(?:[: \/!?=])/) do |matched|
|
156
160
|
case matched
|
157
161
|
when ":"
|
158
162
|
"_colon_"
|
159
|
-
when " "
|
163
|
+
when " ", "/"
|
160
164
|
"_"
|
161
165
|
when "!"
|
162
166
|
".destructive"
|
data/lib/test/unit/testcase.rb
CHANGED
@@ -186,27 +186,29 @@ module Test
|
|
186
186
|
# scope.
|
187
187
|
#
|
188
188
|
# Here is an example test case:
|
189
|
-
#
|
190
|
-
# class
|
191
|
-
#
|
192
|
-
#
|
189
|
+
#
|
190
|
+
# class TestMyClass < Test::Unit::TestCase
|
191
|
+
# class << self
|
192
|
+
# def startup
|
193
|
+
# ...
|
194
|
+
# end
|
193
195
|
# end
|
194
|
-
# end
|
195
196
|
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
197
|
+
# def setup
|
198
|
+
# ...
|
199
|
+
# end
|
199
200
|
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
201
|
+
# def test_my_class1
|
202
|
+
# ...
|
203
|
+
# end
|
203
204
|
#
|
204
|
-
#
|
205
|
-
#
|
205
|
+
# def test_my_class2
|
206
|
+
# ...
|
207
|
+
# end
|
206
208
|
# end
|
207
|
-
# end
|
208
209
|
#
|
209
210
|
# Here is a call order:
|
211
|
+
#
|
210
212
|
# * startup
|
211
213
|
# * setup
|
212
214
|
# * test_my_class1 (or test_my_class2)
|
@@ -222,27 +224,29 @@ module Test
|
|
222
224
|
# down fixture information used in test case scope.
|
223
225
|
#
|
224
226
|
# Here is an example test case:
|
225
|
-
#
|
226
|
-
# class
|
227
|
-
#
|
228
|
-
#
|
227
|
+
#
|
228
|
+
# class TestMyClass < Test::Unit::TestCase
|
229
|
+
# class << self
|
230
|
+
# def shutdown
|
231
|
+
# ...
|
232
|
+
# end
|
229
233
|
# end
|
230
|
-
# end
|
231
234
|
#
|
232
|
-
#
|
233
|
-
#
|
234
|
-
#
|
235
|
+
# def teardown
|
236
|
+
# ...
|
237
|
+
# end
|
235
238
|
#
|
236
|
-
#
|
237
|
-
#
|
238
|
-
#
|
239
|
+
# def test_my_class1
|
240
|
+
# ...
|
241
|
+
# end
|
239
242
|
#
|
240
|
-
#
|
241
|
-
#
|
243
|
+
# def test_my_class2
|
244
|
+
# ...
|
245
|
+
# end
|
242
246
|
# end
|
243
|
-
# end
|
244
247
|
#
|
245
248
|
# Here is a call order:
|
249
|
+
#
|
246
250
|
# * test_my_class1 (or test_my_class2)
|
247
251
|
# * teardown
|
248
252
|
# * test_my_class2 (or test_my_class1)
|
@@ -257,7 +261,7 @@ module Test
|
|
257
261
|
@@test_orders = {}
|
258
262
|
|
259
263
|
# Returns the current test order. This returns
|
260
|
-
#
|
264
|
+
# `:alphabetic` by default.
|
261
265
|
def test_order
|
262
266
|
ancestors.each do |ancestor|
|
263
267
|
order = @@test_orders[ancestor]
|
@@ -269,12 +273,15 @@ module Test
|
|
269
273
|
# Sets the current test order.
|
270
274
|
#
|
271
275
|
# Here are the available _order_:
|
272
|
-
#
|
273
|
-
#
|
274
|
-
#
|
275
|
-
#
|
276
|
-
#
|
277
|
-
#
|
276
|
+
#
|
277
|
+
# :alphabetic
|
278
|
+
# : Default. Tests are sorted in alphabetic order.
|
279
|
+
#
|
280
|
+
# :random
|
281
|
+
# : Tests are sorted in random order.
|
282
|
+
#
|
283
|
+
# :defined
|
284
|
+
# : Tests are sorted in defined order.
|
278
285
|
def test_order=(order)
|
279
286
|
@@test_orders[self] = order
|
280
287
|
end
|
@@ -285,22 +292,22 @@ module Test
|
|
285
292
|
# In declarative syntax usage, the following two
|
286
293
|
# test definitions are the almost same:
|
287
294
|
#
|
288
|
-
#
|
289
|
-
#
|
290
|
-
#
|
291
|
-
#
|
295
|
+
# description "register user"
|
296
|
+
# def test_register_user
|
297
|
+
# ...
|
298
|
+
# end
|
292
299
|
#
|
293
|
-
#
|
294
|
-
#
|
295
|
-
#
|
300
|
+
# test "register user" do
|
301
|
+
# ...
|
302
|
+
# end
|
296
303
|
#
|
297
304
|
# In test method mark usage, the "my_test_method" is
|
298
305
|
# treated as a test method:
|
299
306
|
#
|
300
|
-
#
|
301
|
-
#
|
302
|
-
#
|
303
|
-
#
|
307
|
+
# test
|
308
|
+
# def my_test_method
|
309
|
+
# assert_equal("call me", ...)
|
310
|
+
# end
|
304
311
|
def test(*test_description_or_targets, &block)
|
305
312
|
if block_given?
|
306
313
|
test_description = test_description_or_targets.first
|
@@ -334,10 +341,10 @@ module Test
|
|
334
341
|
# normal user" description with "test_register"
|
335
342
|
# test.
|
336
343
|
#
|
337
|
-
#
|
338
|
-
#
|
339
|
-
#
|
340
|
-
#
|
344
|
+
# description "register a normal user"
|
345
|
+
# def test_register
|
346
|
+
# ...
|
347
|
+
# end
|
341
348
|
def description(value, target=nil)
|
342
349
|
targets = [target].compact
|
343
350
|
attribute(:description, value, {}, *targets)
|
@@ -349,20 +356,22 @@ module Test
|
|
349
356
|
# the same in meaning:
|
350
357
|
#
|
351
358
|
# Standard:
|
352
|
-
#
|
353
|
-
# class
|
354
|
-
#
|
359
|
+
#
|
360
|
+
# class TestParent < Test::Unit::TestCase
|
361
|
+
# class TestChild < self
|
362
|
+
# def test_in_child
|
363
|
+
# end
|
355
364
|
# end
|
356
365
|
# end
|
357
|
-
# end
|
358
366
|
#
|
359
367
|
# Syntax sugar:
|
360
|
-
#
|
361
|
-
#
|
362
|
-
#
|
368
|
+
#
|
369
|
+
# class TestParent < Test::Unit::TestCase
|
370
|
+
# sub_test_case("TestChild") do
|
371
|
+
# def test_in_child
|
372
|
+
# end
|
363
373
|
# end
|
364
374
|
# end
|
365
|
-
# end
|
366
375
|
#
|
367
376
|
# The difference of them are the following:
|
368
377
|
#
|
@@ -559,35 +568,37 @@ module Test
|
|
559
568
|
#
|
560
569
|
# You can add additional setup tasks by the following
|
561
570
|
# code:
|
562
|
-
# class TestMyClass < Test::Unit::TestCase
|
563
|
-
# def setup
|
564
|
-
# ...
|
565
|
-
# end
|
566
571
|
#
|
567
|
-
#
|
568
|
-
#
|
569
|
-
#
|
570
|
-
#
|
572
|
+
# class TestMyClass < Test::Unit::TestCase
|
573
|
+
# def setup
|
574
|
+
# ...
|
575
|
+
# end
|
571
576
|
#
|
572
|
-
#
|
573
|
-
#
|
574
|
-
#
|
577
|
+
# setup
|
578
|
+
# def my_setup1
|
579
|
+
# ...
|
580
|
+
# end
|
575
581
|
#
|
576
|
-
#
|
577
|
-
#
|
578
|
-
#
|
579
|
-
# end
|
582
|
+
# setup do
|
583
|
+
# ... # setup callback1
|
584
|
+
# end
|
580
585
|
#
|
581
|
-
#
|
582
|
-
#
|
583
|
-
#
|
586
|
+
# setup
|
587
|
+
# def my_setup2
|
588
|
+
# ...
|
589
|
+
# end
|
590
|
+
#
|
591
|
+
# setup do
|
592
|
+
# ... # setup callback2
|
593
|
+
# end
|
584
594
|
#
|
585
|
-
#
|
586
|
-
#
|
595
|
+
# def test_my_class
|
596
|
+
# ...
|
597
|
+
# end
|
587
598
|
# end
|
588
|
-
# end
|
589
599
|
#
|
590
600
|
# Here is a call order:
|
601
|
+
#
|
591
602
|
# * setup
|
592
603
|
# * my_setup1
|
593
604
|
# * setup callback1
|
@@ -604,35 +615,37 @@ module Test
|
|
604
615
|
#
|
605
616
|
# You can add additional cleanup tasks by the following
|
606
617
|
# code:
|
607
|
-
# class TestMyClass < Test::Unit::TestCase
|
608
|
-
# def cleanup
|
609
|
-
# ...
|
610
|
-
# end
|
611
618
|
#
|
612
|
-
#
|
613
|
-
#
|
614
|
-
#
|
615
|
-
#
|
619
|
+
# class TestMyClass < Test::Unit::TestCase
|
620
|
+
# def cleanup
|
621
|
+
# ...
|
622
|
+
# end
|
616
623
|
#
|
617
|
-
#
|
618
|
-
#
|
619
|
-
#
|
624
|
+
# cleanup
|
625
|
+
# def my_cleanup1
|
626
|
+
# ...
|
627
|
+
# end
|
620
628
|
#
|
621
|
-
#
|
622
|
-
#
|
623
|
-
#
|
624
|
-
# end
|
629
|
+
# cleanup do
|
630
|
+
# ... # cleanup callback1
|
631
|
+
# end
|
625
632
|
#
|
626
|
-
#
|
627
|
-
#
|
628
|
-
#
|
633
|
+
# cleanup
|
634
|
+
# def my_cleanup2
|
635
|
+
# ...
|
636
|
+
# end
|
629
637
|
#
|
630
|
-
#
|
631
|
-
#
|
638
|
+
# cleanup do
|
639
|
+
# ... # cleanup callback2
|
640
|
+
# end
|
641
|
+
#
|
642
|
+
# def test_my_class
|
643
|
+
# ...
|
644
|
+
# end
|
632
645
|
# end
|
633
|
-
# end
|
634
646
|
#
|
635
647
|
# Here is a call order:
|
648
|
+
#
|
636
649
|
# * test_my_class
|
637
650
|
# * cleanup callback2
|
638
651
|
# * my_cleanup2
|
@@ -647,35 +660,37 @@ module Test
|
|
647
660
|
#
|
648
661
|
# You can add additional teardown tasks by the following
|
649
662
|
# code:
|
650
|
-
# class TestMyClass < Test::Unit::TestCase
|
651
|
-
# def teardown
|
652
|
-
# ...
|
653
|
-
# end
|
654
663
|
#
|
655
|
-
#
|
656
|
-
#
|
657
|
-
#
|
658
|
-
#
|
664
|
+
# class TestMyClass < Test::Unit::TestCase
|
665
|
+
# def teardown
|
666
|
+
# ...
|
667
|
+
# end
|
659
668
|
#
|
660
|
-
#
|
661
|
-
#
|
662
|
-
#
|
669
|
+
# teardown
|
670
|
+
# def my_teardown1
|
671
|
+
# ...
|
672
|
+
# end
|
663
673
|
#
|
664
|
-
#
|
665
|
-
#
|
666
|
-
#
|
667
|
-
# end
|
674
|
+
# teardown do
|
675
|
+
# ... # teardown callback1
|
676
|
+
# end
|
668
677
|
#
|
669
|
-
#
|
670
|
-
#
|
671
|
-
#
|
678
|
+
# teardown
|
679
|
+
# def my_teardown2
|
680
|
+
# ...
|
681
|
+
# end
|
682
|
+
#
|
683
|
+
# teardown do
|
684
|
+
# ... # teardown callback2
|
685
|
+
# end
|
672
686
|
#
|
673
|
-
#
|
674
|
-
#
|
687
|
+
# def test_my_class
|
688
|
+
# ...
|
689
|
+
# end
|
675
690
|
# end
|
676
|
-
# end
|
677
691
|
#
|
678
692
|
# Here is a call order:
|
693
|
+
#
|
679
694
|
# * test_my_class
|
680
695
|
# * teardown callback2
|
681
696
|
# * my_teardown2
|
@@ -695,13 +710,13 @@ module Test
|
|
695
710
|
|
696
711
|
# Returns a label of test data for the test. If the
|
697
712
|
# test isn't associated with any test data, it returns
|
698
|
-
#
|
713
|
+
# `nil`.
|
699
714
|
def data_label
|
700
715
|
@internal_data.test_data_label
|
701
716
|
end
|
702
717
|
|
703
718
|
# Returns test data for the test. If the test isn't associated
|
704
|
-
# with any test data, it returns
|
719
|
+
# with any test data, it returns `nil`.
|
705
720
|
def data
|
706
721
|
@internal_data.test_data
|
707
722
|
end
|