test-unit 3.4.5 → 3.4.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddfd1116eddbfd3b3f9235d50e05f71c37b6327a4f3e79c549962f32b50f5075
4
- data.tar.gz: 40c2137c8a8cf1b188a16bc1777456c2f418cbe2fb9af881b465f4a8e1b15625
3
+ metadata.gz: 381321596727dd997b6137fd59dc637ebb74ff6cb0a3f29465116d01c4ceebce
4
+ data.tar.gz: b18049275749a55cf6e89eeb74d95b21c5904bd46b9845c64b5564dc6e756946
5
5
  SHA512:
6
- metadata.gz: 7235989cdea7459d1e1f5a43c7c0a70d5b3deeae7efca4b0f804c23d8c50e76de4afb688487716e177d70b2972f49e9df1869dcc567085270f91976c636ff787
7
- data.tar.gz: aba5319ba07fc555c698a4d68c702e01a4599f7ee84d4b15461438fec9b30cb265c2d38163e3f0af383c6f7c5c641fa1a03c02e0b33634fe10d7cf0fed3964fb
6
+ metadata.gz: f384ac4b1a874f19602fd20bd3d1cda9ad0bff3012c9fafaefb35828b038ca9431b739e123d185927334dcbe63a79e377e2f91f9f9b542288a3e619a87e44baf
7
+ data.tar.gz: fe8e03f084c69bab668039fc94cdf84f54a6824f724e8528b28dbd21b9b4d1f62e64bf5cb60d64312fc5aded9cc5df20058d64db51b25d5d9fce10cdd89dd902
data/doc/text/news.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # News
2
2
 
3
+ ## 3.4.9 - 2021-10-18 {#version-3-4-9}
4
+
5
+ ### Improvements
6
+
7
+ * Added support for labeling each variable values by using `Hash`.
8
+
9
+ ## 3.4.8 - 2021-10-11 {#version-3-4-8}
10
+
11
+ ### Improvements
12
+
13
+ * Added support for omitting Ractor tests on Ruby 2.7 or earlier
14
+ automatically.
15
+
16
+ ## 3.4.7 - 2021-09-14 {#version-3-4-7}
17
+
18
+ ### Fixes
19
+
20
+ * Suppressed a warning on Ruby 2.
21
+ [GitHub#205][Patch by Kenichi Kamiya]
22
+
23
+ ### Thanks
24
+
25
+ * Kenichi Kamiya
26
+
27
+ ## 3.4.6 - 2021-09-11 {#version-3-4-6}
28
+
29
+ ### Improvements
30
+
31
+ * Added support for tests that use Ractor. Use
32
+ `Test::Unit::TestCase.ractor` to declare that these tests use
33
+ Ractor.
34
+
35
+ * Added `--debug-on-failure` option.
36
+
3
37
  ## 3.4.5 - 2021-09-04 {#version-3-4-5}
4
38
 
5
39
  ### Improvements
@@ -9,6 +9,17 @@ module Test
9
9
 
10
10
  # Thrown by Test::Unit::Assertions when an assertion fails.
11
11
  class AssertionFailedError < StandardError
12
+ @debug_on_failure = false
13
+ class << self
14
+ def debug_on_failure=(boolean)
15
+ @debug_on_failure = boolean
16
+ end
17
+
18
+ def debug_on_failure?
19
+ @debug_on_failure
20
+ end
21
+ end
22
+
12
23
  attr_accessor :expected, :actual, :user_message
13
24
  attr_accessor :inspected_expected, :inspected_actual
14
25
  def initialize(message=nil, options=nil)
@@ -19,6 +30,30 @@ module Test
19
30
  @inspected_actual = options[:inspected_actual]
20
31
  @user_message = options[:user_message]
21
32
  super(message)
33
+ debug_on_failure
34
+ end
35
+
36
+ private
37
+ def debug_on_failure
38
+ return unless self.class.debug_on_failure?
39
+
40
+ begin
41
+ require "debug"
42
+ rescue LoadError
43
+ return
44
+ end
45
+
46
+ return unless binding.respond_to?(:break)
47
+
48
+ frames = caller(0)
49
+ pre = nil
50
+ Util::BacktraceFilter.filter_backtrace(frames).each do |location|
51
+ frame_index = frames.index(location)
52
+ next if frame_index.nil?
53
+ pre = "frame #{frame_index}"
54
+ break
55
+ end
56
+ binding.break(pre: pre)
22
57
  end
23
58
  end
24
59
  end
@@ -1,10 +1,10 @@
1
1
  require "English"
2
+ require "optparse"
2
3
 
3
4
  require "test/unit/color-scheme"
4
5
  require "test/unit/priority"
5
6
  require "test/unit/attribute-matcher"
6
7
  require "test/unit/testcase"
7
- require "optparse"
8
8
 
9
9
  module Test
10
10
  module Unit
@@ -144,6 +144,7 @@ module Test
144
144
  attr_accessor :pattern, :exclude, :base, :workdir
145
145
  attr_accessor :color_scheme, :listeners
146
146
  attr_writer :stop_on_failure
147
+ attr_writer :debug_on_failure
147
148
  attr_writer :runner, :collector
148
149
 
149
150
  def initialize(standalone)
@@ -159,6 +160,7 @@ module Test
159
160
  @workdir = nil
160
161
  @listeners = []
161
162
  @stop_on_failure = false
163
+ @debug_on_failure = false
162
164
  config_file = "test-unit.yml"
163
165
  if File.exist?(config_file)
164
166
  load_config(config_file)
@@ -172,6 +174,10 @@ module Test
172
174
  @stop_on_failure
173
175
  end
174
176
 
177
+ def debug_on_failure?
178
+ @debug_on_failure
179
+ end
180
+
175
181
  def prepare
176
182
  PREPARE_HOOKS.each do |handler|
177
183
  handler.call(self)
@@ -381,6 +387,12 @@ module Test
381
387
  @stop_on_failure = boolean
382
388
  end
383
389
 
390
+ o.on("--[no-]debug-on-failure",
391
+ "Run debugger if available on failure",
392
+ "(#{AssertionFailedError.debug_on_failure?})") do |boolean|
393
+ AssertionFailedError.debug_on_failure = boolean
394
+ end
395
+
384
396
  ADDITIONAL_OPTIONS.each do |option_builder|
385
397
  option_builder.call(self, o)
386
398
  end
@@ -11,6 +11,7 @@ module Test
11
11
  def collect(name=NAME)
12
12
  suite = TestSuite.new(name)
13
13
  add_test_cases(suite, TestCase::DESCENDANTS)
14
+ adjust_ractor_tests(suite)
14
15
  suite
15
16
  end
16
17
  end
@@ -25,9 +25,9 @@ module Test
25
25
  basedir = @base
26
26
  $:.push(basedir) if basedir
27
27
  if(from.empty?)
28
- recursive_collect('.', find_test_cases)
28
+ suite = recursive_collect('.', find_test_cases)
29
29
  elsif(from.size == 1)
30
- recursive_collect(from.first, find_test_cases)
30
+ suite = recursive_collect(from.first, find_test_cases)
31
31
  else
32
32
  suites = []
33
33
  from.each do |f|
@@ -38,6 +38,8 @@ module Test
38
38
  sort(suites).each{|s| suite << s}
39
39
  suite
40
40
  end
41
+ adjust_ractor_tests(suite)
42
+ suite
41
43
  ensure
42
44
  $:.delete_at($:.rindex(basedir)) if basedir
43
45
  end
@@ -60,6 +60,8 @@ module Test
60
60
  test_suite = test_suites.first
61
61
  end
62
62
 
63
+ adjust_ractor_tests(test_suite)
64
+
63
65
  test_suite
64
66
  end
65
67
  end
@@ -26,6 +26,7 @@ module Test
26
26
  end
27
27
  end
28
28
  sort(sub_suites).each{|s| suite << s}
29
+ adjust_ractor_tests(suite)
29
30
  suite
30
31
  end
31
32
  end
@@ -68,6 +68,37 @@ module Test
68
68
  suite << sub_suite
69
69
  end
70
70
  end
71
+
72
+ def adjust_ractor_tests(suite)
73
+ return if suite.nil?
74
+ ractor_suites = extract_ractor_tests(suite)
75
+ ractor_suites.each do |ractor_suite|
76
+ suite << ractor_suite
77
+ end
78
+ end
79
+
80
+ def extract_ractor_tests(suite)
81
+ ractor_suites = []
82
+ ractor_tests = []
83
+ suite.tests.each do |test|
84
+ case test
85
+ when TestSuite
86
+ ractor_suites.concat(extract_ractor_tests(test))
87
+ else
88
+ next unless test[:ractor]
89
+ ractor_tests << test
90
+ end
91
+ end
92
+ unless ractor_tests.empty?
93
+ suite.delete_tests(ractor_tests)
94
+ ractor_suite = TestSuite.new(suite.name, suite.test_case)
95
+ ractor_tests.each do |ractor_test|
96
+ ractor_suite << ractor_test
97
+ end
98
+ ractor_suites << ractor_suite
99
+ end
100
+ ractor_suites
101
+ end
71
102
  end
72
103
  end
73
104
  end
@@ -88,9 +88,9 @@ module Test
88
88
  label = String.new
89
89
  label << "group: #{group.inspect}" unless group.nil?
90
90
  data = {}
91
- cell.each do |variable, pattern|
91
+ cell.each do |variable, pattern, pattern_label|
92
92
  label << ", " unless label.empty?
93
- label << "#{variable}: #{pattern.inspect}"
93
+ label << "#{variable}: #{pattern_label}"
94
94
  data[variable] = pattern
95
95
  end
96
96
  yield(label, data)
@@ -105,8 +105,14 @@ module Test
105
105
  variable
106
106
  end
107
107
  all_patterns = sorted_variables.collect do |(variable, patterns), _|
108
- patterns.collect do |pattern|
109
- [variable, pattern]
108
+ if patterns.is_a?(Hash)
109
+ patterns.collect do |pattern_label, pattern|
110
+ [variable, pattern, pattern_label]
111
+ end
112
+ else
113
+ patterns.collect do |pattern|
114
+ [variable, pattern, pattern.inspect]
115
+ end
110
116
  end
111
117
  end
112
118
  all_patterns[0].product(*all_patterns[1..-1], &block)
@@ -351,6 +351,36 @@ module Test
351
351
  attribute(:description, value, {}, *targets)
352
352
  end
353
353
 
354
+ # Declares that the following test uses Ractor.
355
+ #
356
+ # Tests that use Ractor are executed at the end. Because multi
357
+ # Ractor mode is enabled in the current process and it's not
358
+ # disabled even when only one Ractor is running after running
359
+ # a test that uses Ractor on Ruby 3.0. It will be solved in
360
+ # Ruby 3.1.
361
+ #
362
+ # This is implemented by setting the `:ractor` attribute of
363
+ # the test to `true`.
364
+ #
365
+ # @param options [Hash] See {Attribute::ClassMethods#attribute}
366
+ # for details.
367
+ #
368
+ # @return [void]
369
+ #
370
+ # @example Declares that test_do_something_with_ractor uses Ractor
371
+ #
372
+ # ractor
373
+ # def test_do_something_with_ractor
374
+ # Ractor.new do
375
+ # # ...
376
+ # end
377
+ # end
378
+ #
379
+ # @since 3.4.6
380
+ def ractor(options={})
381
+ attribute(:ractor, true, options)
382
+ end
383
+
354
384
  # Defines a sub test case.
355
385
  #
356
386
  # This is a syntax sugar. The both of the following codes are
@@ -821,6 +851,9 @@ module Test
821
851
  notify("<#{signature}> was redefined",
822
852
  :backtrace => redefined_info[:backtrace])
823
853
  end
854
+ if self[:ractor] and not defined?(::Ractor)
855
+ omit("<#{signature}> requires Ractor")
856
+ end
824
857
  if @internal_data.have_test_data?
825
858
  test_method = method(@method_name)
826
859
  arity = test_method.arity
@@ -1,5 +1,5 @@
1
1
  module Test
2
2
  module Unit
3
- VERSION = "3.4.5"
3
+ VERSION = "3.4.9"
4
4
  end
5
5
  end
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: 3.4.5
4
+ version: 3.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-09-03 00:00:00.000000000 Z
12
+ date: 2021-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: power_assert