test-unit 3.4.2 → 3.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -3
  3. data/Rakefile +0 -9
  4. data/doc/text/getting-started.md +1 -1
  5. data/doc/text/news.md +52 -0
  6. data/lib/test/unit/assertion-failed-error.rb +35 -0
  7. data/lib/test/unit/assertions.rb +206 -13
  8. data/lib/test/unit/autorunner.rb +13 -1
  9. data/lib/test/unit/collector/descendant.rb +1 -0
  10. data/lib/test/unit/collector/dir.rb +4 -2
  11. data/lib/test/unit/collector/load.rb +2 -0
  12. data/lib/test/unit/collector/objectspace.rb +1 -0
  13. data/lib/test/unit/collector.rb +31 -0
  14. data/lib/test/unit/testcase.rb +33 -2
  15. data/lib/test/unit/testsuite.rb +1 -1
  16. data/lib/test/unit/util/memory-usage.rb +47 -0
  17. data/lib/test/unit/version.rb +1 -1
  18. data/lib/test/unit.rb +4 -4
  19. metadata +6 -83
  20. data/test/collector/test-descendant.rb +0 -182
  21. data/test/collector/test-load.rb +0 -475
  22. data/test/collector/test_dir.rb +0 -407
  23. data/test/collector/test_objectspace.rb +0 -102
  24. data/test/fixtures/header-label.csv +0 -3
  25. data/test/fixtures/header-label.tsv +0 -3
  26. data/test/fixtures/header.csv +0 -3
  27. data/test/fixtures/header.tsv +0 -3
  28. data/test/fixtures/no-header.csv +0 -2
  29. data/test/fixtures/no-header.tsv +0 -2
  30. data/test/fixtures/plus.csv +0 -3
  31. data/test/run-test.rb +0 -22
  32. data/test/test-assertions.rb +0 -2187
  33. data/test/test-attribute-matcher.rb +0 -38
  34. data/test/test-attribute.rb +0 -123
  35. data/test/test-code-snippet.rb +0 -79
  36. data/test/test-color-scheme.rb +0 -123
  37. data/test/test-color.rb +0 -47
  38. data/test/test-data.rb +0 -419
  39. data/test/test-diff.rb +0 -518
  40. data/test/test-emacs-runner.rb +0 -60
  41. data/test/test-error.rb +0 -26
  42. data/test/test-failure.rb +0 -33
  43. data/test/test-fault-location-detector.rb +0 -163
  44. data/test/test-fixture.rb +0 -713
  45. data/test/test-notification.rb +0 -33
  46. data/test/test-omission.rb +0 -81
  47. data/test/test-pending.rb +0 -70
  48. data/test/test-priority.rb +0 -184
  49. data/test/test-test-case.rb +0 -1284
  50. data/test/test-test-result.rb +0 -113
  51. data/test/test-test-suite-creator.rb +0 -97
  52. data/test/test-test-suite.rb +0 -151
  53. data/test/testunit-test-util.rb +0 -33
  54. data/test/ui/test_testrunmediator.rb +0 -20
  55. data/test/util/test-method-owner-finder.rb +0 -38
  56. data/test/util/test-output.rb +0 -11
  57. data/test/util/test_backtracefilter.rb +0 -52
  58. data/test/util/test_observable.rb +0 -102
  59. data/test/util/test_procwrapper.rb +0 -36
@@ -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
@@ -131,12 +131,13 @@ module Test
131
131
  end
132
132
 
133
133
  def include(*modules, &block) # :nodoc:
134
- super
134
+ result = super
135
135
  modules.each do |mod|
136
136
  mod.public_instance_methods(false).each do |method_name|
137
137
  AutoRunnerLoader.check(self, method_name.to_s)
138
138
  end
139
139
  end
140
+ result
140
141
  end
141
142
 
142
143
  @@added_method_names = {}
@@ -350,6 +351,36 @@ module Test
350
351
  attribute(:description, value, {}, *targets)
351
352
  end
352
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
+
353
384
  # Defines a sub test case.
354
385
  #
355
386
  # This is a syntax sugar. The both of the following codes are
@@ -446,7 +477,7 @@ module Test
446
477
  # @private
447
478
  @@method_locations = {}
448
479
  # @private
449
- @@method_location_mutex = Mutex.new
480
+ @@method_location_mutex = Thread::Mutex.new
450
481
 
451
482
  # @private
452
483
  def method_locations
@@ -77,7 +77,7 @@ module Test
77
77
  @tests -= tests
78
78
  end
79
79
 
80
- # Retuns the rolled up number of tests in this suite;
80
+ # Returns the rolled up number of tests in this suite;
81
81
  # i.e. if the suite contains other suites, it counts the
82
82
  # tests within those suites, not the suites themselves.
83
83
  def size
@@ -0,0 +1,47 @@
1
+ module Test
2
+ module Unit
3
+ module Util
4
+ class MemoryUsage
5
+ attr_reader :virtual
6
+ attr_reader :physical
7
+ def initialize
8
+ @virtual = nil
9
+ @physical = nil
10
+ collect_data
11
+ end
12
+
13
+ def collected?
14
+ return false if @virtual.nil?
15
+ return false if @physical.nil?
16
+ true
17
+ end
18
+
19
+ private
20
+ def collect_data
21
+ collect_data_proc
22
+ end
23
+
24
+ def collect_data_proc
25
+ status_file = "/proc/self/status"
26
+ return false unless File.exist?(status_file)
27
+
28
+ data = File.binread(status_file)
29
+ data.each_line do |line|
30
+ case line
31
+ when /\AVm(Size|RSS):\s*(\d+)\s*kB/
32
+ name = $1
33
+ value = Integer($2, 10) * 1024
34
+ case name
35
+ when "Size"
36
+ @virtual = value
37
+ when "RSS"
38
+ @physical = value
39
+ end
40
+ end
41
+ end
42
+ collected?
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
1
  module Test
2
2
  module Unit
3
- VERSION = "3.4.2"
3
+ VERSION = "3.4.6"
4
4
  end
5
5
  end
data/lib/test/unit.rb CHANGED
@@ -324,14 +324,14 @@ module Test # :nodoc:
324
324
  # Set true when Test::Unit has run. If set to true Test::Unit
325
325
  # will not automatically run at exit.
326
326
  #
327
- # @deprecated Use Test::Unit::AutoRunner.need_auto_run= instead.
327
+ # @deprecated Use {Test::Unit::AutoRunner.need_auto_run=} instead.
328
328
  def run=(have_run)
329
329
  AutoRunner.need_auto_run = (not have_run)
330
330
  end
331
331
 
332
332
  # Already tests have run?
333
333
  #
334
- # @deprecated Use Test::Unit::AutoRunner.need_auto_run? instead.
334
+ # @deprecated Use {Test::Unit::AutoRunner.need_auto_run?} instead.
335
335
  def run?
336
336
  not AutoRunner.need_auto_run?
337
337
  end
@@ -339,7 +339,7 @@ module Test # :nodoc:
339
339
  # @api private
340
340
  @@at_start_hooks = []
341
341
 
342
- # Regsiter a hook that is run before running tests.
342
+ # Register a hook that is run before running tests.
343
343
  # To register multiple hooks, call this method multiple times.
344
344
  #
345
345
  # Here is an example test case:
@@ -425,7 +425,7 @@ module Test # :nodoc:
425
425
  # @api private
426
426
  @@at_exit_hooks = []
427
427
 
428
- # Regsiter a hook that is run after running tests.
428
+ # Register a hook that is run after running tests.
429
429
  # To register multiple hooks, call this method multiple times.
430
430
  #
431
431
  # Here is an example test case:
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.2
4
+ version: 3.4.6
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-05-29 00:00:00.000000000 Z
12
+ date: 2021-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: power_assert
@@ -159,6 +159,7 @@ files:
159
159
  - lib/test/unit/ui/testrunnerutilities.rb
160
160
  - lib/test/unit/ui/xml/testrunner.rb
161
161
  - lib/test/unit/util/backtracefilter.rb
162
+ - lib/test/unit/util/memory-usage.rb
162
163
  - lib/test/unit/util/method-owner-finder.rb
163
164
  - lib/test/unit/util/observable.rb
164
165
  - lib/test/unit/util/output.rb
@@ -170,46 +171,6 @@ files:
170
171
  - sample/test_adder.rb
171
172
  - sample/test_subtracter.rb
172
173
  - sample/test_user.rb
173
- - test/collector/test-descendant.rb
174
- - test/collector/test-load.rb
175
- - test/collector/test_dir.rb
176
- - test/collector/test_objectspace.rb
177
- - test/fixtures/header-label.csv
178
- - test/fixtures/header-label.tsv
179
- - test/fixtures/header.csv
180
- - test/fixtures/header.tsv
181
- - test/fixtures/no-header.csv
182
- - test/fixtures/no-header.tsv
183
- - test/fixtures/plus.csv
184
- - test/run-test.rb
185
- - test/test-assertions.rb
186
- - test/test-attribute-matcher.rb
187
- - test/test-attribute.rb
188
- - test/test-code-snippet.rb
189
- - test/test-color-scheme.rb
190
- - test/test-color.rb
191
- - test/test-data.rb
192
- - test/test-diff.rb
193
- - test/test-emacs-runner.rb
194
- - test/test-error.rb
195
- - test/test-failure.rb
196
- - test/test-fault-location-detector.rb
197
- - test/test-fixture.rb
198
- - test/test-notification.rb
199
- - test/test-omission.rb
200
- - test/test-pending.rb
201
- - test/test-priority.rb
202
- - test/test-test-case.rb
203
- - test/test-test-result.rb
204
- - test/test-test-suite-creator.rb
205
- - test/test-test-suite.rb
206
- - test/testunit-test-util.rb
207
- - test/ui/test_testrunmediator.rb
208
- - test/util/test-method-owner-finder.rb
209
- - test/util/test-output.rb
210
- - test/util/test_backtracefilter.rb
211
- - test/util/test_observable.rb
212
- - test/util/test_procwrapper.rb
213
174
  homepage: http://test-unit.github.io/
214
175
  licenses:
215
176
  - Ruby
@@ -217,6 +178,8 @@ licenses:
217
178
  - PSFL
218
179
  metadata:
219
180
  source_code_uri: https://github.com/test-unit/test-unit
181
+ documentation_uri: https://test-unit.github.io/test-unit/en/
182
+ bug_tracker_uri: https://github.com/test-unit/test-unit/issues
220
183
  post_install_message:
221
184
  rdoc_options: []
222
185
  require_paths:
@@ -236,44 +199,4 @@ rubygems_version: 3.3.0.dev
236
199
  signing_key:
237
200
  specification_version: 4
238
201
  summary: An xUnit family unit testing framework for Ruby.
239
- test_files:
240
- - test/collector/test-descendant.rb
241
- - test/collector/test-load.rb
242
- - test/collector/test_dir.rb
243
- - test/collector/test_objectspace.rb
244
- - test/fixtures/header-label.csv
245
- - test/fixtures/header-label.tsv
246
- - test/fixtures/header.csv
247
- - test/fixtures/header.tsv
248
- - test/fixtures/no-header.csv
249
- - test/fixtures/no-header.tsv
250
- - test/fixtures/plus.csv
251
- - test/run-test.rb
252
- - test/test-assertions.rb
253
- - test/test-attribute-matcher.rb
254
- - test/test-attribute.rb
255
- - test/test-code-snippet.rb
256
- - test/test-color-scheme.rb
257
- - test/test-color.rb
258
- - test/test-data.rb
259
- - test/test-diff.rb
260
- - test/test-emacs-runner.rb
261
- - test/test-error.rb
262
- - test/test-failure.rb
263
- - test/test-fault-location-detector.rb
264
- - test/test-fixture.rb
265
- - test/test-notification.rb
266
- - test/test-omission.rb
267
- - test/test-pending.rb
268
- - test/test-priority.rb
269
- - test/test-test-case.rb
270
- - test/test-test-result.rb
271
- - test/test-test-suite-creator.rb
272
- - test/test-test-suite.rb
273
- - test/testunit-test-util.rb
274
- - test/ui/test_testrunmediator.rb
275
- - test/util/test-method-owner-finder.rb
276
- - test/util/test-output.rb
277
- - test/util/test_backtracefilter.rb
278
- - test/util/test_observable.rb
279
- - test/util/test_procwrapper.rb
202
+ test_files: []
@@ -1,182 +0,0 @@
1
- require 'test/unit'
2
- require 'test/unit/collector/descendant'
3
-
4
- class TestUnitCollectorDescendant < Test::Unit::TestCase
5
- def setup
6
- @previous_descendants = Test::Unit::TestCase::DESCENDANTS.dup
7
- Test::Unit::TestCase::DESCENDANTS.clear
8
- end
9
-
10
- def teardown
11
- Test::Unit::TestCase::DESCENDANTS.replace(@previous_descendants)
12
- end
13
-
14
- private
15
- def assert_collect(expected, *collect_args)
16
- collector = Test::Unit::Collector::Descendant.new
17
- yield(collector) if block_given?
18
- assert_equal(expected, collector.send(:collect, *collect_args))
19
- end
20
-
21
- def default_name
22
- Test::Unit::Collector::Descendant::NAME
23
- end
24
-
25
- def empty_suite(name=nil)
26
- Test::Unit::TestSuite.new(name || default_name)
27
- end
28
-
29
- class TestCollect < self
30
- def setup
31
- super
32
-
33
- @test_case1 = Class.new(Test::Unit::TestCase) do
34
- self.test_order = :alphabetic
35
-
36
- def self.name
37
- "test-case1"
38
- end
39
-
40
- def test_1
41
- end
42
-
43
- def test_2
44
- end
45
- end
46
-
47
- @test_case2 = Class.new(Test::Unit::TestCase) do
48
- self.test_order = :alphabetic
49
-
50
- def self.name
51
- "test-case2"
52
- end
53
-
54
- def test_0
55
- end
56
- end
57
-
58
- @no_test_case = Class.new do
59
- def self.name
60
- "no-test-case"
61
- end
62
-
63
- def test_4
64
- end
65
- end
66
- end
67
-
68
- def test_basic
69
- assert_collect(full_suite("name"), "name")
70
-
71
- assert_collect(full_suite("name"), "name") do |collector|
72
- collector.filter = []
73
- end
74
- end
75
-
76
- def test_filtered
77
- assert_collect(empty_suite) do |collector|
78
- collector.filter = Proc.new {false}
79
- end
80
-
81
- assert_collect(full_suite) do |collector|
82
- collector.filter = Proc.new {true}
83
- end
84
-
85
- assert_collect(full_suite) do |collector|
86
- collector.filter = Proc.new {nil}
87
- end
88
-
89
- assert_collect(empty_suite) do |collector|
90
- collector.filter = [Proc.new {false}, Proc.new {true}]
91
- end
92
-
93
- assert_collect(empty_suite) do |collector|
94
- collector.filter = [Proc.new {true}, Proc.new {false}]
95
- end
96
-
97
- assert_collect(empty_suite) do |collector|
98
- collector.filter = [Proc.new {nil}, Proc.new {false}]
99
- end
100
-
101
- assert_collect(full_suite) do |collector|
102
- collector.filter = [Proc.new {nil}, Proc.new {true}]
103
- end
104
-
105
- expected = empty_suite
106
- suite1 = Test::Unit::TestSuite.new(@test_case1.name)
107
- suite1 << @test_case1.new("test_1")
108
- suite2 = Test::Unit::TestSuite.new(@test_case2.name)
109
- suite2 << @test_case2.new("test_0")
110
- expected << suite1 << suite2
111
- assert_collect(expected) do |collector|
112
- collector.filter = Proc.new do |test|
113
- ['test_1', 'test_0'].include?(test.method_name)
114
- end
115
- end
116
-
117
- suite1 = Test::Unit::TestSuite.new(@test_case1.name)
118
- suite1 << @test_case1.new("test_1")
119
- suite2 = Test::Unit::TestSuite.new(@test_case2.name)
120
- suite2 << @test_case2.new("test_0")
121
- assert_collect(empty_suite) do |collector|
122
- filters = [Proc.new {|test| test.method_name == 'test_1' ? true : nil},
123
- Proc.new {|test| test.method_name == 'test_0' ? true : nil},
124
- Proc.new {false}]
125
- collector.filter = filters
126
- end
127
- end
128
-
129
- private
130
- def full_suite(name=nil)
131
- sub_suite1 = Test::Unit::TestSuite.new(@test_case1.name)
132
- sub_suite1 << @test_case1.new('test_1')
133
- sub_suite1 << @test_case1.new('test_2')
134
-
135
- sub_suite2 = Test::Unit::TestSuite.new(@test_case2.name)
136
- sub_suite2 << @test_case2.new('test_0')
137
-
138
- suite = empty_suite(name)
139
- suite << sub_suite1
140
- suite << sub_suite2
141
- suite
142
- end
143
- end
144
-
145
- class TestModule < self
146
- def test_included_in_child
147
- tests = Module.new do
148
- def test_in_module
149
- end
150
- end
151
-
152
- parent_test_case = Class.new(Test::Unit::TestCase) do
153
- class << self
154
- def name
155
- "Parent"
156
- end
157
- end
158
- end
159
-
160
- child_test_case = Class.new(parent_test_case) do
161
- include tests
162
-
163
- class << self
164
- def name
165
- "Child"
166
- end
167
- end
168
- end
169
-
170
- child_suite = Test::Unit::TestSuite.new(child_test_case.name)
171
- child_suite << child_test_case.new("test_in_module")
172
-
173
- parent_suite = Test::Unit::TestSuite.new(parent_test_case.name)
174
- parent_suite << child_suite
175
-
176
- suite = empty_suite("all")
177
- suite << parent_suite
178
-
179
- assert_collect(suite, "all")
180
- end
181
- end
182
- end