test-unit 3.3.5 → 3.4.0

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.
@@ -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
@@ -5,9 +5,25 @@ module Test
5
5
  class ColorScheme
6
6
  include Enumerable
7
7
 
8
+ TERM_256 = /
9
+ [+-]256color|
10
+ \A(?:
11
+ alacritty|
12
+ iTerm\s?\d*\.app|
13
+ kitty|
14
+ mintty|
15
+ ms-terminal|
16
+ nsterm-build\d+|
17
+ nsterm|
18
+ terminator|
19
+ terminology(?:-[0-9.]+)?|
20
+ termite|
21
+ vscode
22
+ )\z/x
23
+
8
24
  class << self
9
25
  def default
10
- if available_colors == 256
26
+ if available_colors >= 256
11
27
  default_for_256_colors
12
28
  else
13
29
  default_for_8_colors
@@ -140,7 +156,9 @@ module Test
140
156
 
141
157
  def guess_available_colors_from_term_env
142
158
  case ENV["TERM"]
143
- when /-256color\z/
159
+ when /[+-]direct/
160
+ 2**24
161
+ when TERM_256
144
162
  256
145
163
  else
146
164
  nil
@@ -3,9 +3,8 @@
3
3
  # Copyright (c) 2001-2008 Python Software Foundation; All Rights Reserved
4
4
  # Copyright (c) 2008-2011 Kouhei Sutou; All Rights Reserved
5
5
  #
6
- # It is free software, and is distributed under the Ruby license, the
7
- # PSF license and/or LGPLv2.1 or later. See the COPYING file, the PSFL
8
- # file and the LGPL file.
6
+ # It is free software, and is distributed under (the new Ruby license
7
+ # or BSDL) and the PSF license.
9
8
 
10
9
  module Test
11
10
  module Unit
@@ -1,21 +1,4 @@
1
1
  # Copyright (C) 2008-2017 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # License: Ruby OR LGPL-2.1+
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License as published by the Free Software Foundation; either
8
- # version 2.1 of the License, or (at your option) any later version.
9
- #
10
- # This library is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # Lesser General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Lesser General Public
16
- # License along with this library; if not, write to the Free Software
17
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
- # 02110-1301 USA
19
2
 
20
3
  module Test
21
4
  module Unit
@@ -47,8 +47,6 @@ module Test
47
47
  @progress_row_max ||= guess_progress_row_max
48
48
  @show_detail_immediately = @options[:show_detail_immediately]
49
49
  @show_detail_immediately = true if @show_detail_immediately.nil?
50
- @reverse_output = @options[:reverse_output]
51
- @reverse_output = @output.tty? if @reverse_output.nil?
52
50
  @already_outputted = false
53
51
  @indent = 0
54
52
  @top_level = true
@@ -184,29 +182,15 @@ module Test
184
182
  if fault.is_a?(Failure) and
185
183
  fault.inspected_expected and
186
184
  fault.inspected_actual
187
- if @reverse_output
188
- output_fault_backtrace(fault)
189
- output_failure_message(fault)
190
- output_single("#{fault.label}: ")
191
- output(fault.test_name, fault_color(fault))
192
- else
193
- output_single("#{fault.label}: ")
194
- output(fault.test_name, fault_color(fault))
195
- output_fault_backtrace(fault)
196
- output_failure_message(fault)
197
- end
185
+ output_single("#{fault.label}: ")
186
+ output(fault.test_name, fault_color(fault))
187
+ output_fault_backtrace(fault)
188
+ output_failure_message(fault)
198
189
  else
199
- if @reverse_output
200
- output_fault_backtrace(fault)
201
- output_single("#{fault.label}: ")
202
- output_single(fault.test_name, fault_color(fault))
203
- output_fault_message(fault)
204
- else
205
- output_single("#{fault.label}: ")
206
- output_single(fault.test_name, fault_color(fault))
207
- output_fault_message(fault)
208
- output_fault_backtrace(fault)
209
- end
190
+ output_single("#{fault.label}: ")
191
+ output_single(fault.test_name, fault_color(fault))
192
+ output_fault_message(fault)
193
+ output_fault_backtrace(fault)
210
194
  end
211
195
  end
212
196
 
@@ -244,19 +228,10 @@ module Test
244
228
  end
245
229
  end
246
230
 
247
- if @reverse_output
248
- backtrace.each_with_index.reverse_each do |entry, i|
249
- if i == code_snippet_backtrace_index
250
- output_code_snippet(code_snippet_lines, fault_color(fault))
251
- end
252
- output(entry)
253
- end
254
- else
255
- backtrace.each_with_index do |entry, i|
256
- output(entry)
257
- if i == code_snippet_backtrace_index
258
- output_code_snippet(code_snippet_lines, fault_color(fault))
259
- end
231
+ backtrace.each_with_index do |entry, i|
232
+ output(entry)
233
+ if i == code_snippet_backtrace_index
234
+ output_code_snippet(code_snippet_lines, fault_color(fault))
260
235
  end
261
236
  end
262
237
  end
@@ -336,17 +311,10 @@ module Test
336
311
  end
337
312
 
338
313
  def output_fault_in_short(fault)
339
- if @reverse_output
340
- output(fault.location.first)
341
- output_single("#{fault.label}: ")
342
- output_single(fault.message, fault_color(fault))
343
- output(" [#{fault.test_name}]")
344
- else
345
- output_single("#{fault.label}: ")
346
- output_single(fault.message, fault_color(fault))
347
- output(" [#{fault.test_name}]")
348
- output(fault.location.first)
349
- end
314
+ output_single("#{fault.label}: ")
315
+ output_single(fault.message, fault_color(fault))
316
+ output(" [#{fault.test_name}]")
317
+ output(fault.location.first)
350
318
  end
351
319
 
352
320
  def format_fault(fault)
@@ -540,13 +508,28 @@ module Test
540
508
  color("#{@result.status}-marker")
541
509
  end
542
510
 
511
+ TERM_COLOR_SUPPORT = /
512
+ color| # explicitly claims color support in the name
513
+ direct| # explicitly claims "direct color" (24 bit) support
514
+ #{ColorScheme::TERM_256}|
515
+ \Acygwin|
516
+ \Alinux|
517
+ \Ansterm-bce|
518
+ \Ansterm-c-|
519
+ \Aputty|
520
+ \Arxvt|
521
+ \Ascreen|
522
+ \Atmux|
523
+ \Axterm
524
+ /x
525
+
543
526
  def guess_color_availability
544
527
  return false unless @output.tty?
545
528
  return true if windows? and ruby_2_0_or_later?
546
529
  case ENV["TERM"]
547
530
  when /(?:term|screen)(?:-(?:256)?color)?\z/
548
531
  true
549
- when /\Arxvt/
532
+ when TERM_COLOR_SUPPORT
550
533
  true
551
534
  else
552
535
  return true if ENV["EMACS"] == "t"
@@ -1,5 +1,5 @@
1
1
  module Test
2
2
  module Unit
3
- VERSION = "3.3.5"
3
+ VERSION = "3.4.0"
4
4
  end
5
5
  end
@@ -0,0 +1,3 @@
1
+ if defined?(Warning) and Warning.respond_to?(:[]=)
2
+ Warning[:deprecated] = true
3
+ end
@@ -98,7 +98,7 @@ module Test
98
98
 
99
99
  def check_fail_exception(expected_message, options={}, &proc)
100
100
  normalizer = lambda do |actual_message|
101
- actual_message.gsub(/(^[^:\n]+:\d+:.+\n?)+\z/, "")
101
+ actual_message.gsub(/^(?:<internal:core> )?[^:\n]+:\d+:.+\n/, "")
102
102
  end
103
103
  check_assertions(true,
104
104
  options.merge(:expected_message => expected_message,
@@ -510,7 +510,8 @@ EOM
510
510
  message = <<-EOM.chomp
511
511
  failed assert_raise.
512
512
  <ArgumentError> exception expected but was
513
- <RuntimeError(<Error>)>.
513
+ <RuntimeError(<Error>)
514
+ >.
514
515
  EOM
515
516
  check_fail_exception(message) do
516
517
  assert_raise(ArgumentError, "failed assert_raise") do
@@ -571,7 +572,8 @@ EOM
571
572
  message = <<-EOM.chomp
572
573
  failed assert_raise.
573
574
  <[ArgumentError, TypeError]> exception expected but was
574
- <RuntimeError(<Error>)>.
575
+ <RuntimeError(<Error>)
576
+ >.
575
577
  EOM
576
578
  check_fail_exception(message) do
577
579
  assert_raise(ArgumentError, TypeError, "failed assert_raise") do
@@ -596,13 +598,8 @@ EOM
596
598
 
597
599
  message = <<-EOM.chomp
598
600
  <RuntimeError(<XXX>)> exception expected but was
599
- <RuntimeError(<Error>)>.
600
-
601
- diff:
602
- - RuntimeError(<XXX>)
603
- ? ^^^
604
- + RuntimeError(<Error>)
605
- ? ^^^^^
601
+ <RuntimeError(<Error>)
602
+ >.
606
603
  EOM
607
604
  check_fail_exception(message) do
608
605
  return_value = assert_raise(RuntimeError.new("XXX")) do
@@ -613,7 +610,8 @@ EOM
613
610
  different_error_class = Class.new(StandardError)
614
611
  message = <<-EOM.chomp
615
612
  <#{different_error_class.inspect}(<Error>)> exception expected but was
616
- <RuntimeError(<Error>)>.
613
+ <RuntimeError(<Error>)
614
+ >.
617
615
  EOM
618
616
  check_fail_exception(message) do
619
617
  assert_raise(different_error_class.new("Error")) do
@@ -627,7 +625,8 @@ EOM
627
625
  end
628
626
  message = <<-EOM.chomp
629
627
  <DifferentError: "Error"> exception expected but was
630
- <RuntimeError(<Error>)>.
628
+ <RuntimeError(<Error>)
629
+ >.
631
630
  EOM
632
631
  check_fail_exception(message) do
633
632
  assert_raise(different_error) do
@@ -645,7 +644,7 @@ EOM
645
644
  end
646
645
 
647
646
  def test_assert_raise_jruby
648
- omit("For JRuby") unless Object.const_defined?(:Java)
647
+ jruby_only_test
649
648
 
650
649
  exception = Java::JavaLang::StringIndexOutOfBoundsException
651
650
 
@@ -869,6 +868,7 @@ EOM
869
868
  expected_message = <<-EOM.chomp
870
869
  Exception raised:
871
870
  RuntimeError(<Error>)
871
+
872
872
  EOM
873
873
  check_fail_exception(expected_message) {
874
874
  assert_nothing_raised {
@@ -879,6 +879,7 @@ EOM
879
879
  failed assert_nothing_raised.
880
880
  Exception raised:
881
881
  RuntimeError(<Error>)
882
+
882
883
  EOM
883
884
  check_fail_exception(expected_message) {
884
885
  assert_nothing_raised("failed assert_nothing_raised") {
@@ -888,6 +889,7 @@ EOM
888
889
  expected_message = <<-EOM.chomp
889
890
  Exception raised:
890
891
  RuntimeError(<Error>)
892
+
891
893
  EOM
892
894
  check_fail_exception(expected_message) {
893
895
  assert_nothing_raised(StandardError, RuntimeError) {
@@ -954,16 +956,6 @@ EOM
954
956
  end
955
957
  end
956
958
 
957
- def test_assert_not_match_fail_not_regexp
958
- check_fail("<REGEXP> in assert_not_match(<REGEXP>, ...) " +
959
- "should be a Regexp.\n" +
960
- "<\"asdf\"> was expected to be instance_of?\n" +
961
- "<Regexp> but was\n" +
962
- "<String>.") do
963
- assert_not_match("asdf", "asdf")
964
- end
965
- end
966
-
967
959
  def test_assert_not_match_fail_match
968
960
  check_fail("</string/> was expected to not match\n" +
969
961
  "<\"string\">.") do
@@ -971,6 +963,13 @@ EOM
971
963
  end
972
964
  end
973
965
 
966
+ def test_assert_not_match_fail_match_string
967
+ check_fail("</asdf/> was expected to not match\n" +
968
+ "<\"asdf\">.") do
969
+ assert_not_match("asdf", "asdf")
970
+ end
971
+ end
972
+
974
973
  def test_assert_not_match_fail_match_with_message
975
974
  check_fail("message.\n" +
976
975
  "</string/> was expected to not match\n" +
@@ -1312,7 +1311,8 @@ EOM
1312
1311
 
1313
1312
  expected_message = <<-EOM.chomp
1314
1313
  <SystemCallError> family exception expected but was
1315
- <RuntimeError(<XXX>)>.
1314
+ <RuntimeError(<XXX>)
1315
+ >.
1316
1316
  EOM
1317
1317
  check_fail_exception(expected_message) do
1318
1318
  assert_raise_kind_of(SystemCallError) do