test-unit 3.3.3 → 3.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -171,7 +171,7 @@ module Test
171
171
  end
172
172
  end
173
173
 
174
- # Asserts that +object+ is false or nil.
174
+ # Asserts that `object` is false or nil.
175
175
  #
176
176
  # @note Just for minitest compatibility. :<
177
177
  #
@@ -213,7 +213,7 @@ module Test
213
213
  end
214
214
 
215
215
  ##
216
- # Passes if +expected+ == +actual+.
216
+ # Passes if `expected` == `actual`.
217
217
  #
218
218
  # Note that the ordering of arguments is important, since a helpful
219
219
  # error message is generated when this one fails that tells you the
@@ -314,7 +314,7 @@ EOT
314
314
 
315
315
 
316
316
  ##
317
- # Passes if +object+.instance_of?(+klass+). When +klass+ is
317
+ # Passes if `object`.instance_of?(`klass`). When `klass` is
318
318
  # an array of classes, it passes if any class
319
319
  # satisfies +object.instance_of?(class).
320
320
  #
@@ -348,8 +348,8 @@ EOT
348
348
  end
349
349
 
350
350
  ##
351
- # Passes if +object+.instance_of?(+klass+) does not hold.
352
- # When +klass+ is an array of classes, it passes if no class
351
+ # Passes if `object`.instance_of?(`klass`) does not hold.
352
+ # When `klass` is an array of classes, it passes if no class
353
353
  # satisfies +object.instance_of?(class).
354
354
  #
355
355
  # @example
@@ -389,7 +389,7 @@ EOT
389
389
  alias_method :refute_instance_of, :assert_not_instance_of
390
390
 
391
391
  ##
392
- # Passes if +object+ is nil.
392
+ # Passes if `object` is nil.
393
393
  #
394
394
  # @example
395
395
  # assert_nil [1, 2].uniq!
@@ -401,7 +401,7 @@ EOT
401
401
  end
402
402
 
403
403
  ##
404
- # Passes if +object+.kind_of?(+klass+). When +klass+ is
404
+ # Passes if `object`.kind_of?(`klass`). When `klass` is
405
405
  # an array of classes or modules, it passes if any
406
406
  # class or module satisfies +object.kind_of?(class_or_module).
407
407
  #
@@ -437,8 +437,8 @@ EOT
437
437
  end
438
438
 
439
439
  ##
440
- # Passes if +object+.kind_of?(+klass+) does not hold.
441
- # When +klass+ is an array of classes or modules, it passes only if all
440
+ # Passes if `object`.kind_of?(`klass`) does not hold.
441
+ # When `klass` is an array of classes or modules, it passes only if all
442
442
  # classes (and modules) do not satisfy +object.kind_of?(class_or_module).
443
443
  #
444
444
  # @example
@@ -478,7 +478,7 @@ EOT
478
478
  alias_method :refute_kind_of, :assert_not_kind_of
479
479
 
480
480
  ##
481
- # Passes if +object+ .respond_to? +method+
481
+ # Passes if `object` .respond_to? `method`
482
482
  #
483
483
  # @example
484
484
  # assert_respond_to 'bugbear', :slice
@@ -500,7 +500,7 @@ EOT
500
500
  end
501
501
 
502
502
  ##
503
- # Passes if +object+ does not .respond_to? +method+.
503
+ # Passes if `object` does not .respond_to? `method`.
504
504
  #
505
505
  # @example
506
506
  # assert_not_respond_to('bugbear', :nonexistence) # -> pass
@@ -528,7 +528,7 @@ EOT
528
528
  alias_method :refute_respond_to, :assert_not_respond_to
529
529
 
530
530
  ##
531
- # Passes if +pattern+ =~ +string+.
531
+ # Passes if `pattern` =~ `string`.
532
532
  #
533
533
  # @example
534
534
  # assert_match(/\d+/, 'five, 6, seven')
@@ -548,7 +548,7 @@ EOT
548
548
  end
549
549
 
550
550
  ##
551
- # Passes if +actual+ .equal? +expected+ (i.e. they are the same
551
+ # Passes if `actual` .equal? `expected` (i.e. they are the same
552
552
  # instance).
553
553
  #
554
554
  # @example
@@ -565,7 +565,7 @@ EOT
565
565
  end
566
566
 
567
567
  ##
568
- # Compares the +object1+ with +object2+ using +operator+.
568
+ # Compares the `object1` with `object2` using `operator`.
569
569
  #
570
570
  # Passes if object1.__send__(operator, object2) is true.
571
571
  #
@@ -585,7 +585,7 @@ EOT
585
585
  end
586
586
 
587
587
  ##
588
- # Compares the +object1+ with +object2+ using +operator+.
588
+ # Compares the `object1` with `object2` using `operator`.
589
589
  #
590
590
  # Passes if object1.__send__(operator, object2) is not true.
591
591
  #
@@ -652,7 +652,7 @@ EOT
652
652
  end
653
653
 
654
654
  ##
655
- # Passes if ! +actual+ .equal? +expected+
655
+ # Passes if ! `actual` .equal? `expected`
656
656
  #
657
657
  # @example
658
658
  # assert_not_same Object.new, Object.new
@@ -672,7 +672,7 @@ EOT
672
672
  alias_method :refute_same, :assert_not_same
673
673
 
674
674
  ##
675
- # Passes if +expected+ != +actual+
675
+ # Passes if `expected` != `actual`
676
676
  #
677
677
  # @example
678
678
  # assert_not_equal 'some string', 5
@@ -689,7 +689,7 @@ EOT
689
689
  alias_method :refute_equal, :assert_not_equal
690
690
 
691
691
  ##
692
- # Passes if ! +object+ .nil?
692
+ # Passes if ! `object` .nil?
693
693
  #
694
694
  # @example
695
695
  # assert_not_nil '1 two 3'.sub!(/two/, '2')
@@ -706,7 +706,7 @@ EOT
706
706
  alias_method :refute_nil, :assert_not_nil
707
707
 
708
708
  ##
709
- # Passes if +regexp+ !~ +string+
709
+ # Passes if `regexp` !~ `string`
710
710
  #
711
711
  # @example
712
712
  # assert_not_match(/two/, 'one 2 three') # -> pass
@@ -731,7 +731,7 @@ EOT
731
731
  ##
732
732
  # Deprecated. Use #assert_not_match instead.
733
733
  #
734
- # Passes if +regexp+ !~ +string+
734
+ # Passes if `regexp` !~ `string`
735
735
  #
736
736
  # @example
737
737
  # assert_no_match(/two/, 'one 2 three') # -> pass
@@ -789,7 +789,7 @@ EOT
789
789
  end
790
790
 
791
791
  ##
792
- # Passes if the block throws +expected_object+
792
+ # Passes if the block throws `expected_object`
793
793
  #
794
794
  # @example
795
795
  # assert_throw(:done) do
@@ -860,8 +860,8 @@ EOT
860
860
  end
861
861
 
862
862
  ##
863
- # Passes if +expected_float+ and +actual_float+ are equal
864
- # within +delta+ tolerance.
863
+ # Passes if `expected_float` and `actual_float` are equal
864
+ # within `delta` tolerance.
865
865
  #
866
866
  # @example
867
867
  # assert_in_delta 0.05, (50000.0 / 10**6), 0.00001
@@ -881,8 +881,8 @@ EOT
881
881
  end
882
882
 
883
883
  ##
884
- # Passes if +expected_float+ and +actual_float+ are
885
- # not equal within +delta+ tolerance.
884
+ # Passes if `expected_float` and `actual_float` are
885
+ # not equal within `delta` tolerance.
886
886
  #
887
887
  # @example
888
888
  # assert_not_in_delta(0.05, (50000.0 / 10**6), 0.00002) # -> pass
@@ -981,8 +981,8 @@ EOT
981
981
 
982
982
  public
983
983
  ##
984
- # Passes if +expected_float+ and +actual_float+ are equal
985
- # within +epsilon+ relative error of +expected_float+.
984
+ # Passes if `expected_float` and `actual_float` are equal
985
+ # within `epsilon` relative error of `expected_float`.
986
986
  #
987
987
  # @example
988
988
  # assert_in_epsilon(10000.0, 9900.0, 0.1) # -> pass
@@ -1011,9 +1011,9 @@ EOT
1011
1011
  end
1012
1012
 
1013
1013
  ##
1014
- # Passes if +expected_float+ and +actual_float+ are
1015
- # not equal within +epsilon+ relative error of
1016
- # +expected_float+.
1014
+ # Passes if `expected_float` and `actual_float` are
1015
+ # not equal within `epsilon` relative error of
1016
+ # `expected_float`.
1017
1017
  #
1018
1018
  # @example
1019
1019
  # assert_not_in_epsilon(10000.0, 9900.0, 0.1) # -> fail
@@ -1121,7 +1121,7 @@ EOT
1121
1121
  ##
1122
1122
  # Passes if the method send returns a true value.
1123
1123
  #
1124
- # +send_array+ is composed of:
1124
+ # `send_array` is composed of:
1125
1125
  # * A receiver
1126
1126
  # * A method
1127
1127
  # * Arguments to the method
@@ -1161,7 +1161,7 @@ EOT
1161
1161
  ##
1162
1162
  # Passes if the method send doesn't return a true value.
1163
1163
  #
1164
- # +send_array+ is composed of:
1164
+ # `send_array` is composed of:
1165
1165
  # * A receiver
1166
1166
  # * A method
1167
1167
  # * Arguments to the method
@@ -1199,7 +1199,7 @@ EOT
1199
1199
  end
1200
1200
 
1201
1201
  ##
1202
- # Passes if +actual+ is a boolean value.
1202
+ # Passes if `actual` is a boolean value.
1203
1203
  #
1204
1204
  # @example
1205
1205
  # assert_boolean(true) # -> pass
@@ -1215,7 +1215,7 @@ EOT
1215
1215
  end
1216
1216
 
1217
1217
  ##
1218
- # Passes if +actual+ is true.
1218
+ # Passes if `actual` is true.
1219
1219
  #
1220
1220
  # @example
1221
1221
  # assert_true(true) # -> pass
@@ -1231,7 +1231,7 @@ EOT
1231
1231
  end
1232
1232
 
1233
1233
  ##
1234
- # Passes if +actual+ is false.
1234
+ # Passes if `actual` is false.
1235
1235
  #
1236
1236
  # @example
1237
1237
  # assert_false(false) # -> pass
@@ -1247,8 +1247,8 @@ EOT
1247
1247
  end
1248
1248
 
1249
1249
  ##
1250
- # Passes if expression "+expected+ +operator+
1251
- # +actual+" is true.
1250
+ # Passes if expression "`expected` `operator`
1251
+ # `actual`" is true.
1252
1252
  #
1253
1253
  # @example
1254
1254
  # assert_compare(1, "<", 10) # -> pass
@@ -1303,7 +1303,7 @@ EOT
1303
1303
 
1304
1304
  ##
1305
1305
  # Passes if an exception is raised in block and its
1306
- # message is +expected+.
1306
+ # message is `expected`.
1307
1307
  #
1308
1308
  # @example
1309
1309
  # assert_raise_message("exception") {raise "exception"} # -> pass
@@ -1343,7 +1343,7 @@ EOT
1343
1343
  end
1344
1344
 
1345
1345
  ##
1346
- # Passes if +object+.const_defined?(+constant_name+)
1346
+ # Passes if `object`.const_defined?(`constant_name`)
1347
1347
  #
1348
1348
  # @example
1349
1349
  # assert_const_defined(Test, :Unit) # -> pass
@@ -1360,7 +1360,7 @@ EOT
1360
1360
  end
1361
1361
 
1362
1362
  ##
1363
- # Passes if !+object+.const_defined?(+constant_name+)
1363
+ # Passes if !`object`.const_defined?(`constant_name`)
1364
1364
  #
1365
1365
  # @example
1366
1366
  # assert_not_const_defined(Object, :Nonexistent) # -> pass
@@ -1377,7 +1377,7 @@ EOT
1377
1377
  end
1378
1378
 
1379
1379
  ##
1380
- # Passes if +object+.+predicate+ is _true_.
1380
+ # Passes if `object`.`predicate` is _true_.
1381
1381
  #
1382
1382
  # @example
1383
1383
  # assert_predicate([], :empty?) # -> pass
@@ -1399,7 +1399,7 @@ EOT
1399
1399
  end
1400
1400
 
1401
1401
  ##
1402
- # Passes if +object+.+predicate+ is not _true_.
1402
+ # Passes if `object`.`predicate` is not _true_.
1403
1403
  #
1404
1404
  # @example
1405
1405
  # assert_not_predicate([1], :empty?) # -> pass
@@ -1426,8 +1426,8 @@ EOT
1426
1426
  alias_method :refute_predicate, :assert_not_predicate
1427
1427
 
1428
1428
  ##
1429
- # Passes if +object+#+alias_name+ is an alias method of
1430
- # +object+#+original_name+.
1429
+ # Passes if `object`#`alias_name` is an alias method of
1430
+ # `object`#`original_name`.
1431
1431
  #
1432
1432
  # @example
1433
1433
  # assert_alias_method([], :length, :size) # -> pass
@@ -1474,7 +1474,7 @@ EOT
1474
1474
  end
1475
1475
 
1476
1476
  ##
1477
- # Passes if +path+ exists.
1477
+ # Passes if `path` exists.
1478
1478
  #
1479
1479
  # @example
1480
1480
  # assert_path_exist("/tmp") # -> pass
@@ -1492,7 +1492,7 @@ EOT
1492
1492
  end
1493
1493
 
1494
1494
  ##
1495
- # Passes if +path+ doesn't exist.
1495
+ # Passes if `path` doesn't exist.
1496
1496
  #
1497
1497
  # @example
1498
1498
  # assert_path_not_exist("/nonexistent") # -> pass
@@ -1510,7 +1510,7 @@ EOT
1510
1510
  end
1511
1511
 
1512
1512
  ##
1513
- # Passes if +collection+ includes +object+.
1513
+ # Passes if `collection` includes `object`.
1514
1514
  #
1515
1515
  # @example
1516
1516
  # assert_include([1, 10], 1) # -> pass
@@ -1537,7 +1537,7 @@ EOT
1537
1537
  alias_method :assert_includes, :assert_include
1538
1538
 
1539
1539
  ##
1540
- # Passes if +collection+ doesn't include +object+.
1540
+ # Passes if `collection` doesn't include `object`.
1541
1541
  #
1542
1542
  # @example
1543
1543
  # assert_not_include([1, 10], 5) # -> pass
@@ -1569,7 +1569,7 @@ EOT
1569
1569
  alias_method :refute_includes, :assert_not_include
1570
1570
 
1571
1571
  ##
1572
- # Passes if +object+ is empty.
1572
+ # Passes if `object` is empty.
1573
1573
  #
1574
1574
  # @example
1575
1575
  # assert_empty("") # -> pass
@@ -1592,7 +1592,7 @@ EOT
1592
1592
  end
1593
1593
 
1594
1594
  ##
1595
- # Passes if +object+ is not empty.
1595
+ # Passes if `object` is not empty.
1596
1596
  #
1597
1597
  # @example
1598
1598
  # assert_not_empty(" ") # -> pass
@@ -1620,8 +1620,8 @@ EOT
1620
1620
  alias_method :refute_empty, :assert_not_empty
1621
1621
 
1622
1622
  ##
1623
- # Builds a failure message. +user_message+ is added before the
1624
- # +template+ and +arguments+ replaces the '?'s positionally in
1623
+ # Builds a failure message. `user_message` is added before the
1624
+ # `template` and `arguments` replaces the '?'s positionally in
1625
1625
  # the template.
1626
1626
  def build_message(user_message, template=nil, *arguments)
1627
1627
  template &&= template.chomp
@@ -2121,7 +2121,14 @@ EOT
2121
2121
 
2122
2122
  def inspect
2123
2123
  if default_inspect?
2124
- "#{@exception.class.inspect}(<#{@exception.message}>)"
2124
+ inspected = "#{@exception.class.inspect}(<#{@exception.message}>)"
2125
+ unless (@exception.backtrace || []).empty?
2126
+ inspected += "\n"
2127
+ @exception.backtrace.each do |trace|
2128
+ inspected << "#{trace}\n"
2129
+ end
2130
+ end
2131
+ inspected
2125
2132
  else
2126
2133
  @exception.inspect
2127
2134
  end
@@ -246,54 +246,61 @@ module Test
246
246
 
247
247
  o.on("-n", "--name=NAME", String,
248
248
  "Runs tests matching NAME.",
249
- "Use '/PATTERN/' for NAME to use regular expression.") do |name|
250
- name = (%r{\A/(.*)/\Z} =~ name ? Regexp.new($1) : name)
249
+ "Use '/PATTERN/' for NAME to use regular expression.",
250
+ "Regular expression accepts options.",
251
+ "Example: '/taRget/i' matches 'target' and 'TARGET'") do |name|
252
+ name = prepare_name(name)
251
253
  @filters << lambda do |test|
252
- return true if name === test.method_name
253
- return true if name === test.local_name
254
- false
254
+ match_test_name(test, name)
255
255
  end
256
256
  end
257
257
 
258
258
  o.on("--ignore-name=NAME", String,
259
259
  "Ignores tests matching NAME.",
260
- "Use '/PATTERN/' for NAME to use regular expression.") do |n|
261
- n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n)
262
- case n
263
- when Regexp
264
- @filters << proc {|t| n =~ t.method_name ? false : true}
265
- else
266
- @filters << proc {|t| n != t.method_name}
260
+ "Use '/PATTERN/' for NAME to use regular expression.",
261
+ "Regular expression accepts options.",
262
+ "Example: '/taRget/i' matches 'target' and 'TARGET'") do |name|
263
+ name = prepare_name(name)
264
+ @filters << lambda do |test|
265
+ not match_test_name(test, name)
267
266
  end
268
267
  end
269
268
 
270
269
  o.on("-t", "--testcase=TESTCASE", String,
271
270
  "Runs tests in TestCases matching TESTCASE.",
272
- "Use '/PATTERN/' for TESTCASE to use regular expression.") do |n|
273
- n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n)
271
+ "Use '/PATTERN/' for TESTCASE to use regular expression.",
272
+ "Regular expression accepts options.",
273
+ "Example: '/taRget/i' matches 'target' and 'TARGET'") do |name|
274
+ name = prepare_name(name)
274
275
  @filters << lambda do |test|
275
- match_test_case_name(test, n)
276
+ match_test_case_name(test, name)
276
277
  end
277
278
  end
278
279
 
279
280
  o.on("--ignore-testcase=TESTCASE", String,
280
281
  "Ignores tests in TestCases matching TESTCASE.",
281
- "Use '/PATTERN/' for TESTCASE to use regular expression.") do |n|
282
- n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n)
282
+ "Use '/PATTERN/' for TESTCASE to use regular expression.",
283
+ "Regular expression accepts options.",
284
+ "Example: '/taRget/i' matches 'target' and 'TARGET'") do |name|
285
+ name = prepare_name(name)
283
286
  @filters << lambda do |test|
284
- not match_test_case_name(test, n)
287
+ not match_test_case_name(test, name)
285
288
  end
286
289
  end
287
290
 
288
291
  o.on("--location=LOCATION", String,
289
292
  "Runs tests that defined in LOCATION.",
290
- "LOCATION is one of PATH:LINE, PATH or LINE") do |location|
291
- if /\A\d+\z/ =~ location
293
+ "LOCATION is one of PATH:LINE, PATH or LINE.") do |location|
294
+ case location
295
+ when /\A(\d+)\z/
292
296
  path = nil
293
- line = location.to_i
297
+ line = $1.to_i
298
+ when /:(\d+)\z/
299
+ path = $PREMATCH
300
+ line = $1.to_i
294
301
  else
295
- path, line, = location.split(/:(\d+)/, 2)
296
- line = line.to_i unless line.nil?
302
+ path = location
303
+ line = nil
297
304
  end
298
305
  add_location_filter(path, line)
299
306
  end
@@ -349,7 +356,7 @@ module Test
349
356
  end
350
357
 
351
358
  o.on("--config=FILE",
352
- "Use YAML fomat FILE content as configuration file.") do |file|
359
+ "Use YAML format FILE content as configuration file.") do |file|
353
360
  load_config(file)
354
361
  end
355
362
 
@@ -456,7 +463,7 @@ module Test
456
463
  if key == :arguments
457
464
  @default_arguments.concat(value.split)
458
465
  else
459
- runner_options[key.to_sym] = value
466
+ runner_options[key] = value
460
467
  end
461
468
  end
462
469
  @runner_options = @runner_options.merge(runner_options)
@@ -496,6 +503,31 @@ module Test
496
503
  end
497
504
  end
498
505
 
506
+ def prepare_name(name)
507
+ case name
508
+ when /\A\/(.*)\/([imx]*)\z/
509
+ pattern = $1
510
+ options_raw = $2
511
+ options = 0
512
+ options |= Regexp::IGNORECASE if options_raw.include?("i")
513
+ options |= Regexp::MULTILINE if options_raw.include?("m")
514
+ options |= Regexp::EXTENDED if options_raw.include?("x")
515
+ Regexp.new(pattern, options)
516
+ else
517
+ name
518
+ end
519
+ end
520
+
521
+ def match_test_name(test, pattern)
522
+ return true if pattern === test.method_name
523
+ return true if pattern === test.local_name
524
+ if pattern.is_a?(String)
525
+ return true if pattern === "#{test.class}##{test.method_name}"
526
+ return true if pattern === "#{test.class}##{test.local_name}"
527
+ end
528
+ false
529
+ end
530
+
499
531
  def match_test_case_name(test, pattern)
500
532
  test.class.ancestors.each do |test_class|
501
533
  break if test_class == TestCase