piko-max-mod 0.0.1

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.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/piko-max-mod.gemspec +12 -0
  3. data/test-unit-3.7.8/BSDL +24 -0
  4. data/test-unit-3.7.8/COPYING +64 -0
  5. data/test-unit-3.7.8/PSFL +271 -0
  6. data/test-unit-3.7.8/README.md +108 -0
  7. data/test-unit-3.7.8/Rakefile +74 -0
  8. data/test-unit-3.7.8/bin/test-unit +5 -0
  9. data/test-unit-3.7.8/doc/text/getting-started.md +120 -0
  10. data/test-unit-3.7.8/doc/text/how-to.md +90 -0
  11. data/test-unit-3.7.8/doc/text/news.md +2070 -0
  12. data/test-unit-3.7.8/lib/test/unit/assertion-failed-error.rb +60 -0
  13. data/test-unit-3.7.8/lib/test/unit/assertions.rb +2536 -0
  14. data/test-unit-3.7.8/lib/test/unit/attribute-matcher.rb +26 -0
  15. data/test-unit-3.7.8/lib/test/unit/attribute.rb +228 -0
  16. data/test-unit-3.7.8/lib/test/unit/auto-runner-loader.rb +17 -0
  17. data/test-unit-3.7.8/lib/test/unit/autorunner.rb +654 -0
  18. data/test-unit-3.7.8/lib/test/unit/code-snippet-fetcher.rb +58 -0
  19. data/test-unit-3.7.8/lib/test/unit/collector/descendant.rb +20 -0
  20. data/test-unit-3.7.8/lib/test/unit/collector/dir.rb +110 -0
  21. data/test-unit-3.7.8/lib/test/unit/collector/load.rb +201 -0
  22. data/test-unit-3.7.8/lib/test/unit/collector/objectspace.rb +35 -0
  23. data/test-unit-3.7.8/lib/test/unit/collector/xml.rb +249 -0
  24. data/test-unit-3.7.8/lib/test/unit/collector.rb +104 -0
  25. data/test-unit-3.7.8/lib/test/unit/color-scheme.rb +225 -0
  26. data/test-unit-3.7.8/lib/test/unit/color.rb +134 -0
  27. data/test-unit-3.7.8/lib/test/unit/data-sets.rb +127 -0
  28. data/test-unit-3.7.8/lib/test/unit/data.rb +371 -0
  29. data/test-unit-3.7.8/lib/test/unit/diff.rb +745 -0
  30. data/test-unit-3.7.8/lib/test/unit/error.rb +158 -0
  31. data/test-unit-3.7.8/lib/test/unit/exception-handler.rb +82 -0
  32. data/test-unit-3.7.8/lib/test/unit/failure.rb +169 -0
  33. data/test-unit-3.7.8/lib/test/unit/fault-location-detector.rb +104 -0
  34. data/test-unit-3.7.8/lib/test/unit/fixture.rb +304 -0
  35. data/test-unit-3.7.8/lib/test/unit/notification.rb +138 -0
  36. data/test-unit-3.7.8/lib/test/unit/omission.rb +198 -0
  37. data/test-unit-3.7.8/lib/test/unit/pending.rb +155 -0
  38. data/test-unit-3.7.8/lib/test/unit/priority.rb +194 -0
  39. data/test-unit-3.7.8/lib/test/unit/process-test-result.rb +55 -0
  40. data/test-unit-3.7.8/lib/test/unit/process-worker.rb +87 -0
  41. data/test-unit-3.7.8/lib/test/unit/runner/console.rb +86 -0
  42. data/test-unit-3.7.8/lib/test/unit/runner/emacs.rb +8 -0
  43. data/test-unit-3.7.8/lib/test/unit/runner/xml.rb +15 -0
  44. data/test-unit-3.7.8/lib/test/unit/sub-test-result.rb +59 -0
  45. data/test-unit-3.7.8/lib/test/unit/test-process-run-context.rb +21 -0
  46. data/test-unit-3.7.8/lib/test/unit/test-run-context.rb +16 -0
  47. data/test-unit-3.7.8/lib/test/unit/test-suite-creator.rb +103 -0
  48. data/test-unit-3.7.8/lib/test/unit/test-suite-process-runner.rb +205 -0
  49. data/test-unit-3.7.8/lib/test/unit/test-suite-runner.rb +132 -0
  50. data/test-unit-3.7.8/lib/test/unit/test-suite-thread-runner.rb +96 -0
  51. data/test-unit-3.7.8/lib/test/unit/test-thread-run-context.rb +23 -0
  52. data/test-unit-3.7.8/lib/test/unit/testcase.rb +1058 -0
  53. data/test-unit-3.7.8/lib/test/unit/testresult.rb +132 -0
  54. data/test-unit-3.7.8/lib/test/unit/testsuite.rb +133 -0
  55. data/test-unit-3.7.8/lib/test/unit/ui/console/outputlevel.rb +15 -0
  56. data/test-unit-3.7.8/lib/test/unit/ui/console/testrunner.rb +891 -0
  57. data/test-unit-3.7.8/lib/test/unit/ui/emacs/testrunner.rb +49 -0
  58. data/test-unit-3.7.8/lib/test/unit/ui/testrunner.rb +53 -0
  59. data/test-unit-3.7.8/lib/test/unit/ui/testrunnermediator.rb +131 -0
  60. data/test-unit-3.7.8/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  61. data/test-unit-3.7.8/lib/test/unit/ui/xml/testrunner.rb +225 -0
  62. data/test-unit-3.7.8/lib/test/unit/util/backtracefilter.rb +65 -0
  63. data/test-unit-3.7.8/lib/test/unit/util/memory-usage.rb +47 -0
  64. data/test-unit-3.7.8/lib/test/unit/util/method-owner-finder.rb +28 -0
  65. data/test-unit-3.7.8/lib/test/unit/util/observable.rb +86 -0
  66. data/test-unit-3.7.8/lib/test/unit/util/output.rb +32 -0
  67. data/test-unit-3.7.8/lib/test/unit/util/procwrapper.rb +48 -0
  68. data/test-unit-3.7.8/lib/test/unit/version.rb +5 -0
  69. data/test-unit-3.7.8/lib/test/unit/warning.rb +3 -0
  70. data/test-unit-3.7.8/lib/test/unit/worker-context.rb +20 -0
  71. data/test-unit-3.7.8/lib/test/unit.rb +521 -0
  72. data/test-unit-3.7.8/lib/test-unit.rb +19 -0
  73. data/test-unit-3.7.8/sample/adder.rb +13 -0
  74. data/test-unit-3.7.8/sample/subtracter.rb +12 -0
  75. data/test-unit-3.7.8/sample/test_adder.rb +20 -0
  76. data/test-unit-3.7.8/sample/test_subtracter.rb +20 -0
  77. data/test-unit-3.7.8/sample/test_user.rb +23 -0
  78. metadata +117 -0
@@ -0,0 +1,1058 @@
1
+ #--
2
+ #
3
+ # Author:: Nathaniel Talbott.
4
+ # Copyright::
5
+ # * Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
6
+ # * Copyright (c) 2008-2012 Kouhei Sutou <tt><kou@clear-code.com></tt>
7
+ # License:: Ruby license.
8
+
9
+ require_relative 'attribute'
10
+ require_relative 'fixture'
11
+ require_relative 'exception-handler'
12
+ require_relative 'assertions'
13
+ require_relative 'failure'
14
+ require_relative 'error'
15
+ require_relative 'pending'
16
+ require_relative 'omission'
17
+ require_relative 'notification'
18
+ require_relative 'priority'
19
+ require_relative 'data'
20
+ require_relative 'testsuite'
21
+ require_relative 'test-suite-creator'
22
+ require_relative 'assertion-failed-error'
23
+ require_relative 'auto-runner-loader'
24
+ require_relative 'util/backtracefilter'
25
+ require_relative 'util/output'
26
+ require_relative 'util/method-owner-finder'
27
+
28
+ module Test
29
+ module Unit
30
+
31
+ # Ties everything together. If you subclass and add your own
32
+ # test methods, it takes care of making them into tests and
33
+ # wrapping those tests into a suite. It also does the
34
+ # nitty-gritty of actually running an individual test and
35
+ # collecting its results into a Test::Unit::TestResult object.
36
+ #
37
+ # You can run two hooks before/after a TestCase run.
38
+ #
39
+ # Example:
40
+ #
41
+ # class TestMyClass < Test::Unit::TestCase
42
+ # class << self
43
+ # def startup
44
+ # ...
45
+ # end
46
+ #
47
+ # def shutdown
48
+ # ...
49
+ # end
50
+ # end
51
+ #
52
+ # def setup
53
+ # ...
54
+ # end
55
+ #
56
+ # def cleanup
57
+ # ...
58
+ # end
59
+ #
60
+ # def teardown
61
+ # ...
62
+ # end
63
+ #
64
+ # def test_my_method1
65
+ # ...
66
+ # end
67
+ #
68
+ # def test_my_method2
69
+ # ...
70
+ # end
71
+ # end
72
+ #
73
+ # Here is a call order:
74
+ #
75
+ # 1. startup
76
+ # 1. setup
77
+ # 1. test_my_method1
78
+ # 1. cleanup
79
+ # 1. teardown
80
+ # 1. setup
81
+ # 1. test_my_method2
82
+ # 1. cleanup
83
+ # 1. teardown
84
+ # 1. shutdown
85
+ #
86
+ # You can set an attribute to each test.
87
+ #
88
+ # Example:
89
+ #
90
+ # class TestMyClass < Test::Unit::TestCase
91
+ # attribute :speed, :fast
92
+ # def test_my_fast_method
93
+ # # You can get the attribute via `self[]`
94
+ # self[:speed] # => :fast
95
+ # ...
96
+ # end
97
+ #
98
+ # attribute :speed, :slow
99
+ # def test_my_slow_method
100
+ # self[:speed] # => :slow
101
+ # ...
102
+ # end
103
+ # end
104
+ class TestCase
105
+ include Attribute
106
+ include Fixture
107
+ include ExceptionHandler
108
+ include ErrorHandler
109
+ include FailureHandler
110
+ include TestCasePendingSupport
111
+ include TestCaseOmissionSupport
112
+ include TestCaseNotificationSupport
113
+ include Priority
114
+ include Data
115
+ include Assertions
116
+ include Util::BacktraceFilter
117
+ include Util::Output
118
+
119
+ STARTED = name + "::STARTED" # :nodoc:
120
+ FINISHED = name + "::FINISHED" # :nodoc:
121
+ STARTED_OBJECT = name + "::STARTED::OBJECT" # :nodoc:
122
+ FINISHED_OBJECT = name + "::FINISHED::OBJECT" # :nodoc:
123
+
124
+ DESCENDANTS = [] # :nodoc:
125
+ AVAILABLE_ORDERS = [:alphabetic, :random, :defined] # :nodoc:
126
+
127
+ class << self
128
+ # Indicates whether the test is parallel safe.
129
+ #
130
+ # Tests that this method returns `false` are executed sequentially
131
+ # before parallel safe tests run. This only works when the `--parallel`
132
+ # option is specified.
133
+ #
134
+ # @example Indicates that test_parallel_unsafe is parallel unsafe
135
+ #
136
+ # class TestMyClass < Test::Unit::TestCase
137
+ # class << self
138
+ # def parallel_safe?
139
+ # false
140
+ # end
141
+ # end
142
+ #
143
+ # def test_parallel_unsafe
144
+ # # ...
145
+ # end
146
+ # end
147
+ #
148
+ # @since 3.6.3
149
+ def parallel_safe?
150
+ true
151
+ end
152
+
153
+ def inherited(sub_class) # :nodoc:
154
+ DESCENDANTS << sub_class
155
+ super
156
+ end
157
+
158
+ def include(*modules, &block) # :nodoc:
159
+ result = super
160
+ modules.each do |mod|
161
+ mod.public_instance_methods(false).each do |method_name|
162
+ AutoRunnerLoader.check(self, method_name.to_s)
163
+ end
164
+ end
165
+ result
166
+ end
167
+
168
+ @@added_method_names = {}
169
+ def method_added(name) # :nodoc:
170
+ super
171
+ added_method_names = (@@added_method_names[self] ||= {})
172
+ stringified_name = name.to_s
173
+ if added_method_names.key?(stringified_name)
174
+ attribute(:redefined, {:backtrace => caller}, {}, stringified_name)
175
+ end
176
+ source_location = find_attribute(stringified_name, :source_location)
177
+ if source_location
178
+ path, line = source_location
179
+ elsif respond_to?(:caller_locations, true)
180
+ location = caller_locations(1, 1)[0]
181
+ path = location.absolute_path || location.path
182
+ line = location.lineno
183
+ else
184
+ # TODO: Remove me when Ruby 1.9 support is dropped
185
+ path, line, = caller[0].split(/:(\d+)/, 2)
186
+ line = line.to_i if line
187
+ end
188
+ location = {
189
+ :method_name => stringified_name,
190
+ :path => File.expand_path(path),
191
+ :line => line,
192
+ }
193
+ add_method_location(location)
194
+ added_method_names[stringified_name] = true
195
+ AutoRunnerLoader.check(self, stringified_name)
196
+ end
197
+
198
+ def added_method_names # :nodoc:
199
+ (@@added_method_names[self] ||= {}).keys
200
+ end
201
+
202
+ # Rolls up all of the test* methods in the fixture into
203
+ # one suite, creating a new instance of the fixture for
204
+ # each method.
205
+ def suite
206
+ suite_creator = TestSuiteCreator.new(self)
207
+ suite_creator.create
208
+ end
209
+
210
+ # Called before every test case runs. Can be used
211
+ # to set up fixture information used in test case
212
+ # scope.
213
+ #
214
+ # Here is an example test case:
215
+ #
216
+ # class TestMyClass < Test::Unit::TestCase
217
+ # class << self
218
+ # def startup
219
+ # ...
220
+ # end
221
+ # end
222
+ #
223
+ # def setup
224
+ # ...
225
+ # end
226
+ #
227
+ # def test_my_class1
228
+ # ...
229
+ # end
230
+ #
231
+ # def test_my_class2
232
+ # ...
233
+ # end
234
+ # end
235
+ #
236
+ # Here is a call order:
237
+ #
238
+ # * startup
239
+ # * setup
240
+ # * test_my_class1 (or test_my_class2)
241
+ # * setup
242
+ # * test_my_class2 (or test_my_class1)
243
+ #
244
+ # Note that you should not assume test order. Tests
245
+ # should be worked in any order.
246
+ def startup
247
+ end
248
+
249
+ # Called after every test case runs. Can be used to tear
250
+ # down fixture information used in test case scope.
251
+ #
252
+ # Here is an example test case:
253
+ #
254
+ # class TestMyClass < Test::Unit::TestCase
255
+ # class << self
256
+ # def shutdown
257
+ # ...
258
+ # end
259
+ # end
260
+ #
261
+ # def teardown
262
+ # ...
263
+ # end
264
+ #
265
+ # def test_my_class1
266
+ # ...
267
+ # end
268
+ #
269
+ # def test_my_class2
270
+ # ...
271
+ # end
272
+ # end
273
+ #
274
+ # Here is a call order:
275
+ #
276
+ # * test_my_class1 (or test_my_class2)
277
+ # * teardown
278
+ # * test_my_class2 (or test_my_class1)
279
+ # * teardown
280
+ # * shutdown
281
+ #
282
+ # Note that you should not assume test order. Tests
283
+ # should be worked in any order.
284
+ def shutdown
285
+ end
286
+
287
+ @@test_orders = {}
288
+
289
+ # Returns the current test order. This returns
290
+ # `:alphabetic` by default.
291
+ def test_order
292
+ ancestors.each do |ancestor|
293
+ order = @@test_orders[ancestor]
294
+ return order if order
295
+ end
296
+ AVAILABLE_ORDERS.first
297
+ end
298
+
299
+ # Sets the current test order.
300
+ #
301
+ # Here are the available _order_:
302
+ #
303
+ # :alphabetic
304
+ # : Default. Tests are sorted in alphabetic order.
305
+ #
306
+ # :random
307
+ # : Tests are sorted in random order.
308
+ #
309
+ # :defined
310
+ # : Tests are sorted in defined order.
311
+ def test_order=(order)
312
+ @@test_orders[self] = order
313
+ end
314
+
315
+ # Defines a test in declarative syntax or marks
316
+ # following method as a test method.
317
+ #
318
+ # In declarative syntax usage, the following two
319
+ # test definitions are the almost same:
320
+ #
321
+ # description "register user"
322
+ # def test_register_user
323
+ # ...
324
+ # end
325
+ #
326
+ # test "register user" do
327
+ # ...
328
+ # end
329
+ #
330
+ # In test method mark usage, the "my_test_method" is
331
+ # treated as a test method:
332
+ #
333
+ # test
334
+ # def my_test_method
335
+ # assert_equal("call me", ...)
336
+ # end
337
+ def test(*test_description_or_targets, &block)
338
+ if block_given?
339
+ test_description = test_description_or_targets.first
340
+ if test_description.nil?
341
+ raise ArgumentError, "test description is missing"
342
+ end
343
+ n_arguments = test_description_or_targets.size
344
+ if n_arguments > 1
345
+ message = "wrong number of arguments (#{n_arguments} for 1)"
346
+ raise ArgumentError, message
347
+ end
348
+ method_name = "test: #{test_description}"
349
+ description(test_description, method_name)
350
+ attribute(:test, true, {}, method_name)
351
+ if block.respond_to?(:source_location)
352
+ attribute(:source_location, block.source_location, {}, method_name)
353
+ end
354
+ define_method(method_name, &block)
355
+ else
356
+ targets = test_description_or_targets
357
+ attribute(:test, true, {}, *targets)
358
+ targets.each do |target|
359
+ AutoRunnerLoader.check(self, target)
360
+ end
361
+ end
362
+ end
363
+
364
+ # Describes a test.
365
+ #
366
+ # The following example associates "register a
367
+ # normal user" description with "test_register"
368
+ # test.
369
+ #
370
+ # description "register a normal user"
371
+ # def test_register
372
+ # ...
373
+ # end
374
+ def description(value, target=nil)
375
+ targets = [target].compact
376
+ attribute(:description, value, {}, *targets)
377
+ end
378
+
379
+ # Declares that the following test uses Ractor.
380
+ #
381
+ # Tests that use Ractor are executed at the end. Because multi
382
+ # Ractor mode is enabled in the current process and it's not
383
+ # disabled even when only one Ractor is running after running
384
+ # a test that uses Ractor on Ruby 3.0. It will be solved in
385
+ # the future.
386
+ #
387
+ # This is implemented by setting the `:ractor` attribute of
388
+ # the test to `true`.
389
+ #
390
+ # @param options [Hash] See {Attribute::ClassMethods#attribute}
391
+ # for details.
392
+ #
393
+ # @return [void]
394
+ #
395
+ # @example Declares that test_do_something_with_ractor uses Ractor
396
+ #
397
+ # ractor
398
+ # def test_do_something_with_ractor
399
+ # Ractor.new do
400
+ # # ...
401
+ # end
402
+ # end
403
+ #
404
+ # @example Declares that test_do_something_with_ractor uses Ractor in one line
405
+ #
406
+ # ractor def test_do_something_with_ractor
407
+ # Ractor.new do
408
+ # # ...
409
+ # end
410
+ # end
411
+ #
412
+ # @since 3.4.6
413
+ def ractor(options={})
414
+ attribute(:ractor, true, options)
415
+ end
416
+
417
+ # Defines a sub test case.
418
+ #
419
+ # This is a syntax sugar. The both of the following codes are
420
+ # the same in meaning:
421
+ #
422
+ # Standard:
423
+ #
424
+ # class TestParent < Test::Unit::TestCase
425
+ # class TestChild < self
426
+ # def test_in_child
427
+ # end
428
+ # end
429
+ # end
430
+ #
431
+ # Syntax sugar:
432
+ #
433
+ # class TestParent < Test::Unit::TestCase
434
+ # sub_test_case("TestChild") do
435
+ # def test_in_child
436
+ # end
437
+ # end
438
+ # end
439
+ #
440
+ # The difference of them are the following:
441
+ #
442
+ # * Test case created by {sub_test_case} is backed by an anonymous class,
443
+ # but it is assigned to an auto generated constant. So it can be referred
444
+ # to by name (e.g. for `Marshal.dump` and across process use).
445
+ # * The class name of class style must follow
446
+ # constant naming rule in Ruby. But the name of test case
447
+ # created by {sub_test_case} doesn't need to follow the rule.
448
+ # For example, you can use a space in name such as "child test".
449
+ #
450
+ # @param name [String] The name of newly created sub test case.
451
+ # @yield
452
+ # The block is evaluated under the newly created sub test
453
+ # case class context.
454
+ # @return [Test::Unit::TestCase] Created sub test case class.
455
+ def sub_test_case(name, &block)
456
+ sub_test_case = sub_test_case_class(name)
457
+ sub_test_case.class_eval(&block)
458
+ sub_test_case
459
+ end
460
+
461
+ # Checks whether a test that is matched the query is
462
+ # defined.
463
+ #
464
+ # @option query [String] :path (nil)
465
+ # the path where a test is defined in.
466
+ # @option query [Numeric] :line (nil)
467
+ # the line number where a test is defined at.
468
+ # @option query [String] :method_name (nil)
469
+ # the method name for a test.
470
+ def test_defined?(query)
471
+ locations = find_locations(query)
472
+ not locations.empty?
473
+ end
474
+
475
+ def find_locations(query)
476
+ query_path = query[:path]
477
+ query_line = query[:line]
478
+ query_method_name = query[:method_name]
479
+
480
+ available_locations = target_method_locations(query_path)
481
+ if query_line
482
+ available_locations = available_locations.sort_by do |location|
483
+ -location[:line]
484
+ end
485
+ available_location = available_locations.find do |location|
486
+ query_line >= location[:line]
487
+ end
488
+ return [] if available_location.nil?
489
+ return [] if available_location[:test_case] != self
490
+ available_locations = [available_location]
491
+ end
492
+ if query_method_name
493
+ available_location = available_locations.find do |location|
494
+ location[:test_case] == self and
495
+ query_method_name == location[:method_name]
496
+ end
497
+ return [] if available_location.nil?
498
+ available_locations = [available_location]
499
+ end
500
+
501
+ available_locations
502
+ end
503
+
504
+ # Returns a current worker ID for the test case. This return depends on
505
+ # how tests are run:
506
+ #
507
+ # * Sequential: always returns `0`
508
+ #
509
+ # * Parallel: returns a one-based to the number of workers.
510
+ #
511
+ # @return [Integer]
512
+ #
513
+ # @since 3.7.4
514
+ def worker_id
515
+ @worker_id || 0
516
+ end
517
+
518
+ def worker_id=(worker_id) # :nodoc:
519
+ @worker_id = worker_id
520
+ end
521
+
522
+ private
523
+ # @private
524
+ @@method_locations = {}
525
+ # @private
526
+ @@method_location_mutex = Thread::Mutex.new
527
+
528
+ # @private
529
+ def method_locations
530
+ @@method_locations[self] ||= []
531
+ end
532
+
533
+ # @private
534
+ def add_method_location(location)
535
+ @@method_location_mutex.synchronize do
536
+ method_locations << location
537
+ end
538
+ end
539
+
540
+ # @private
541
+ def target_method_locations(path)
542
+ @@method_location_mutex.synchronize do
543
+ if path.nil?
544
+ self_location = method_locations.first
545
+ path = self_location[:path] if self_location
546
+ end
547
+ return [] if path.nil?
548
+
549
+ target_locations = []
550
+ @@method_locations.each do |test_case, locations|
551
+ locations.each do |location|
552
+ absolete_path = File.expand_path(path)
553
+ location_path = location[:path]
554
+ location_basename = File.basename(location_path)
555
+ if location_path == absolete_path or location_basename == path
556
+ target_locations << location.merge(:test_case => test_case)
557
+ end
558
+ end
559
+ end
560
+ target_locations
561
+ end
562
+ end
563
+
564
+ # @private
565
+ def sub_test_case_class(name)
566
+ parent_test_case = self
567
+ sub_test_case = Class.new(self) do
568
+ singleton_class = class << self; self; end
569
+ singleton_class.__send__(:define_method, :name) do
570
+ [parent_test_case.name, name].compact.join("::")
571
+ end
572
+ end
573
+ # Give the anonymous class a unique, Base64 encoded constant
574
+ # name. So it becomes a named class that `Marshal` can
575
+ # safely dump even across processes.
576
+ #
577
+ # We can't use "\n", "=", "+" and "/" in base64 as class name.
578
+ encoded_name = [sub_test_case.name].pack("m").delete("\n=+/")
579
+ const_set(:"TEST_#{encoded_name}", sub_test_case)
580
+ sub_test_case
581
+ end
582
+ end
583
+
584
+ attr_reader :method_name
585
+
586
+ # Creates a new instance of the fixture for running the
587
+ # test represented by test_method_name.
588
+ def initialize(test_method_name)
589
+ @method_name = test_method_name
590
+ @internal_data = InternalData.new
591
+ end
592
+
593
+ # Assigns test data to the test. It is used in internal.
594
+ def assign_test_data(label, data) # :nodoc:
595
+ @internal_data.assign_test_data(label, data)
596
+ end
597
+
598
+ # Returns the test is valid test. It is used in internal.
599
+ def valid? # :nodoc:
600
+ return false unless respond_to?(@method_name)
601
+ test_method = method(@method_name)
602
+ unless @internal_data.have_test_data?
603
+ return false unless test_method.arity <= 0
604
+ end
605
+ owner = Util::MethodOwnerFinder.find(self, @method_name)
606
+ if owner.class != Module and self.class != owner
607
+ return false
608
+ end
609
+ true
610
+ end
611
+
612
+ # Runs the individual test method represented by this
613
+ # instance of the fixture, collecting statistics, failures
614
+ # and errors in result.
615
+ def run(worker_context)
616
+ begin
617
+ unless worker_context.is_a?(WorkerContext)
618
+ result = worker_context
619
+ worker_context = WorkerContext.new(nil, nil, result)
620
+ end
621
+ result = worker_context.result
622
+ @_result = result
623
+ instance_variables_before = instance_variables
624
+ @internal_data.run_context = worker_context.run_context
625
+ @internal_data.worker_id = worker_context.id
626
+ @internal_data.test_started
627
+ yield(STARTED, name)
628
+ yield(STARTED_OBJECT, self)
629
+ processed_exception_in_setup = false
630
+ begin
631
+ catch do |tag|
632
+ run_setup do
633
+ begin
634
+ run_test
635
+ run_cleanup
636
+ add_pass
637
+ rescue Exception => e
638
+ @internal_data.interrupted
639
+ unless handle_exception(e)
640
+ processed_exception_in_setup = true
641
+ raise
642
+ end
643
+ throw(tag)
644
+ end
645
+ end
646
+ end
647
+ rescue Exception => e
648
+ if processed_exception_in_setup
649
+ raise
650
+ else
651
+ @internal_data.interrupted
652
+ raise unless handle_exception(e)
653
+ end
654
+ ensure
655
+ begin
656
+ run_teardown
657
+ rescue Exception => e
658
+ raise unless handle_exception(e)
659
+ end
660
+ end
661
+ @internal_data.test_finished
662
+ result.add_run
663
+ yield(FINISHED, name)
664
+ yield(FINISHED_OBJECT, self)
665
+ ensure
666
+ # @_result = nil # For test-spec's after_all :<
667
+ (instance_variables - instance_variables_before).each do |name|
668
+ remove_instance_variable(name)
669
+ end
670
+ end
671
+ end
672
+
673
+ # Called before every test method runs. Can be used
674
+ # to set up fixture information.
675
+ #
676
+ # You can add additional setup tasks by the following
677
+ # code:
678
+ #
679
+ # class TestMyClass < Test::Unit::TestCase
680
+ # def setup
681
+ # ...
682
+ # end
683
+ #
684
+ # setup
685
+ # def my_setup1
686
+ # ...
687
+ # end
688
+ #
689
+ # setup do
690
+ # ... # setup callback1
691
+ # end
692
+ #
693
+ # setup
694
+ # def my_setup2
695
+ # ...
696
+ # end
697
+ #
698
+ # setup do
699
+ # ... # setup callback2
700
+ # end
701
+ #
702
+ # def test_my_class
703
+ # ...
704
+ # end
705
+ # end
706
+ #
707
+ # Here is a call order:
708
+ #
709
+ # * setup
710
+ # * my_setup1
711
+ # * setup callback1
712
+ # * my_setup2
713
+ # * setup callback2
714
+ # * test_my_class
715
+ def setup
716
+ end
717
+
718
+ # Called after every test method runs but the test
719
+ # method isn't marked as 'passed'. Can be used to
720
+ # clean up and/or verify tested condition.
721
+ # e.g. Can be used to verify mock.
722
+ #
723
+ # You can add additional cleanup tasks by the following
724
+ # code:
725
+ #
726
+ # class TestMyClass < Test::Unit::TestCase
727
+ # def cleanup
728
+ # ...
729
+ # end
730
+ #
731
+ # cleanup
732
+ # def my_cleanup1
733
+ # ...
734
+ # end
735
+ #
736
+ # cleanup do
737
+ # ... # cleanup callback1
738
+ # end
739
+ #
740
+ # cleanup
741
+ # def my_cleanup2
742
+ # ...
743
+ # end
744
+ #
745
+ # cleanup do
746
+ # ... # cleanup callback2
747
+ # end
748
+ #
749
+ # def test_my_class
750
+ # ...
751
+ # end
752
+ # end
753
+ #
754
+ # Here is a call order:
755
+ #
756
+ # * test_my_class
757
+ # * cleanup callback2
758
+ # * my_cleanup2
759
+ # * cleanup callback1
760
+ # * my_cleanup1
761
+ # * cleanup
762
+ def cleanup
763
+ end
764
+
765
+ # Called after every test method runs. Can be used to tear
766
+ # down fixture information.
767
+ #
768
+ # You can add additional teardown tasks by the following
769
+ # code:
770
+ #
771
+ # class TestMyClass < Test::Unit::TestCase
772
+ # def teardown
773
+ # ...
774
+ # end
775
+ #
776
+ # teardown
777
+ # def my_teardown1
778
+ # ...
779
+ # end
780
+ #
781
+ # teardown do
782
+ # ... # teardown callback1
783
+ # end
784
+ #
785
+ # teardown
786
+ # def my_teardown2
787
+ # ...
788
+ # end
789
+ #
790
+ # teardown do
791
+ # ... # teardown callback2
792
+ # end
793
+ #
794
+ # def test_my_class
795
+ # ...
796
+ # end
797
+ # end
798
+ #
799
+ # Here is a call order:
800
+ #
801
+ # * test_my_class
802
+ # * teardown callback2
803
+ # * my_teardown2
804
+ # * teardown callback1
805
+ # * my_teardown1
806
+ # * teardown
807
+ def teardown
808
+ end
809
+
810
+ def default_test
811
+ flunk("No tests were specified")
812
+ end
813
+
814
+ def size
815
+ 1
816
+ end
817
+
818
+ # Returns a current worker ID for the test. See {TestCase.worker_id}
819
+ # for details.
820
+ #
821
+ # @return [Integer]
822
+ #
823
+ # @since 3.7.4
824
+ def worker_id
825
+ @internal_data.worker_id || 0
826
+ end
827
+
828
+ # Returns a label of test data for the test. If the
829
+ # test isn't associated with any test data, it returns
830
+ # `nil`.
831
+ def data_label
832
+ @internal_data.test_data_label
833
+ end
834
+
835
+ # Returns test data for the test. If the test isn't associated
836
+ # with any test data, it returns `nil`.
837
+ def data
838
+ @internal_data.test_data
839
+ end
840
+
841
+ # Returns a human-readable name for the specific test that
842
+ # this instance of TestCase represents.
843
+ def name
844
+ "#{local_name}(#{self.class.name})"
845
+ end
846
+
847
+ # Returns a human-readable name for the specific test that this
848
+ # instance of TestCase represents.
849
+ #
850
+ # `#local_name` doesn't include class name. `#name` includes
851
+ # class name.
852
+ def local_name
853
+ if @internal_data.have_test_data?
854
+ "#{@method_name}[#{data_label}]"
855
+ else
856
+ @method_name.to_s
857
+ end
858
+ end
859
+
860
+ # Returns a description for the test. A description
861
+ # will be associated by Test::Unit::TestCase.test or
862
+ # Test::Unit::TestCase.description.
863
+ #
864
+ # Returns a name for the test for no description test.
865
+ def description
866
+ self[:description] || name
867
+ end
868
+
869
+ # Overridden to return #name.
870
+ def to_s
871
+ name
872
+ end
873
+
874
+ # It's handy to be able to compare TestCase instances.
875
+ def ==(other)
876
+ return false unless other.kind_of?(self.class)
877
+ return false unless @method_name == other.method_name
878
+ return false unless data_label == other.data_label
879
+ self.class == other.class
880
+ end
881
+
882
+ # Returns a Time at the test was started.
883
+ def start_time
884
+ @internal_data.start_time
885
+ end
886
+
887
+ # Returns elapsed time for the test was ran.
888
+ def elapsed_time
889
+ @internal_data.elapsed_time
890
+ end
891
+
892
+ # Returns whether the test is interrupted.
893
+ def interrupted?
894
+ @internal_data.interrupted?
895
+ end
896
+
897
+ # Returns whether this individual test passed or
898
+ # not. Primarily for use in teardown so that artifacts
899
+ # can be left behind if the test fails.
900
+ def passed?
901
+ @internal_data.passed?
902
+ end
903
+
904
+ # Notify that a problem is occurred in the test. It means that
905
+ # the test is a failed test. If any failed tests exist in test
906
+ # suites, the test process exits with failure exit status.
907
+ #
908
+ # This is a public API for developers who extend test-unit.
909
+ #
910
+ # @return [void]
911
+ def problem_occurred
912
+ @internal_data.problem_occurred
913
+ end
914
+
915
+ # Returns test suite runner class for easy to test.
916
+ def runner_class
917
+ @internal_data.run_context.runner_class
918
+ end
919
+
920
+ # Notify that the test is passed. Normally, it is not needed
921
+ # because #run calls it automatically. If you want to override
922
+ # #run, it is not a good idea. Please contact test-unit
923
+ # developers. We will help you without your custom #run. For
924
+ # example, we may add a new hook in #run.
925
+ #
926
+ # This is a public API for developers who extend test-unit.
927
+ #
928
+ # @return [void]
929
+ def add_pass
930
+ current_result.add_pass
931
+ end
932
+
933
+ def marshal_dump
934
+ {
935
+ method_name: @method_name,
936
+ internal_data: @internal_data,
937
+ }
938
+ end
939
+
940
+ def marshal_load(data)
941
+ @method_name = data[:method_name]
942
+ @internal_data = data[:internal_data]
943
+ end
944
+
945
+ private
946
+ def current_result
947
+ @_result
948
+ end
949
+
950
+ def run_test
951
+ signature = "#{self.class}\##{@method_name}"
952
+ redefined_info = self[:redefined]
953
+ if redefined_info
954
+ notify("<#{signature}> was redefined",
955
+ :backtrace => redefined_info[:backtrace])
956
+ end
957
+ if self[:ractor] and not defined?(::Ractor)
958
+ omit("<#{signature}> requires Ractor")
959
+ end
960
+ if @internal_data.have_test_data?
961
+ test_method = method(@method_name)
962
+ arity = test_method.arity
963
+ if arity.zero?
964
+ __send__(@method_name)
965
+ else
966
+ __send__(@method_name, @internal_data.test_data)
967
+ end
968
+ else
969
+ __send__(@method_name)
970
+ end
971
+ end
972
+
973
+ def handle_exception(exception)
974
+ self.class.exception_handlers.each do |handler|
975
+ if handler.respond_to?(:call)
976
+ handled = handler.call(self, exception)
977
+ else
978
+ handled = __send__(handler, exception)
979
+ end
980
+ return true if handled
981
+ end
982
+ false
983
+ end
984
+
985
+ def add_assertion
986
+ current_result.add_assertion
987
+ end
988
+
989
+ class InternalData
990
+ attr_reader :start_time, :elapsed_time
991
+ attr_reader :test_data_label, :test_data
992
+ attr_accessor :run_context
993
+ attr_accessor :worker_id
994
+ def initialize
995
+ @start_time = nil
996
+ @elapsed_time = nil
997
+ @passed = true
998
+ @interrupted = false
999
+ @test_data_label = nil
1000
+ @test_data = nil
1001
+ @run_context = nil
1002
+ @worker_id = nil
1003
+ end
1004
+
1005
+ def passed?
1006
+ @passed
1007
+ end
1008
+
1009
+ def interrupted?
1010
+ @interrupted
1011
+ end
1012
+
1013
+ def assign_test_data(label, data)
1014
+ @test_data_label = label
1015
+ @test_data = data
1016
+ end
1017
+
1018
+ def have_test_data?
1019
+ not @test_data_label.nil?
1020
+ end
1021
+
1022
+ def test_started
1023
+ @start_time = Time.now
1024
+ end
1025
+
1026
+ def test_finished
1027
+ @elapsed_time = Time.now - @start_time
1028
+ end
1029
+
1030
+ def problem_occurred
1031
+ @passed = false
1032
+ end
1033
+
1034
+ def interrupted
1035
+ @interrupted = true
1036
+ end
1037
+
1038
+ def marshal_dump
1039
+ {
1040
+ start_time: @start_time,
1041
+ elapsed_time: @elapsed_time,
1042
+ passed: @passed,
1043
+ interrupted: @interrupted,
1044
+ test_data_label: @test_data_label,
1045
+ }
1046
+ end
1047
+
1048
+ def marshal_load(data)
1049
+ @start_time = data[:start_time]
1050
+ @elapsed_time = data[:elapsed_time]
1051
+ @passed = data[:passed]
1052
+ @interrupted = data[:interrupted]
1053
+ @test_data_label = data[:test_data_label]
1054
+ end
1055
+ end
1056
+ end
1057
+ end
1058
+ end