test-unit 3.4.1 → 3.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) 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 +49 -0
  6. data/lib/test/unit/assertions.rb +206 -13
  7. data/lib/test/unit/testcase.rb +3 -2
  8. data/lib/test/unit/testsuite.rb +1 -1
  9. data/lib/test/unit/ui/console/testrunner.rb +26 -0
  10. data/lib/test/unit/util/memory-usage.rb +47 -0
  11. data/lib/test/unit/version.rb +1 -1
  12. data/lib/test/unit.rb +4 -4
  13. metadata +6 -83
  14. data/test/collector/test-descendant.rb +0 -182
  15. data/test/collector/test-load.rb +0 -475
  16. data/test/collector/test_dir.rb +0 -407
  17. data/test/collector/test_objectspace.rb +0 -102
  18. data/test/fixtures/header-label.csv +0 -3
  19. data/test/fixtures/header-label.tsv +0 -3
  20. data/test/fixtures/header.csv +0 -3
  21. data/test/fixtures/header.tsv +0 -3
  22. data/test/fixtures/no-header.csv +0 -2
  23. data/test/fixtures/no-header.tsv +0 -2
  24. data/test/fixtures/plus.csv +0 -3
  25. data/test/run-test.rb +0 -22
  26. data/test/test-assertions.rb +0 -2187
  27. data/test/test-attribute-matcher.rb +0 -38
  28. data/test/test-attribute.rb +0 -123
  29. data/test/test-code-snippet.rb +0 -79
  30. data/test/test-color-scheme.rb +0 -123
  31. data/test/test-color.rb +0 -47
  32. data/test/test-data.rb +0 -419
  33. data/test/test-diff.rb +0 -518
  34. data/test/test-emacs-runner.rb +0 -60
  35. data/test/test-error.rb +0 -26
  36. data/test/test-failure.rb +0 -33
  37. data/test/test-fault-location-detector.rb +0 -163
  38. data/test/test-fixture.rb +0 -713
  39. data/test/test-notification.rb +0 -33
  40. data/test/test-omission.rb +0 -81
  41. data/test/test-pending.rb +0 -70
  42. data/test/test-priority.rb +0 -184
  43. data/test/test-test-case.rb +0 -1284
  44. data/test/test-test-result.rb +0 -113
  45. data/test/test-test-suite-creator.rb +0 -97
  46. data/test/test-test-suite.rb +0 -151
  47. data/test/testunit-test-util.rb +0 -33
  48. data/test/ui/test_testrunmediator.rb +0 -20
  49. data/test/util/test-method-owner-finder.rb +0 -38
  50. data/test/util/test-output.rb +0 -11
  51. data/test/util/test_backtracefilter.rb +0 -52
  52. data/test/util/test_observable.rb +0 -102
  53. data/test/util/test_procwrapper.rb +0 -36
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6a6de313462a0618acd2440bc3e639a59d616f6ff67d6d42cd301cdcbbdb2b6
4
- data.tar.gz: 59f68dc0e5c451d899f1cdd582c626e634a6b1fc7a45dde46312d33c6dd78104
3
+ metadata.gz: ddfd1116eddbfd3b3f9235d50e05f71c37b6327a4f3e79c549962f32b50f5075
4
+ data.tar.gz: 40c2137c8a8cf1b188a16bc1777456c2f418cbe2fb9af881b465f4a8e1b15625
5
5
  SHA512:
6
- metadata.gz: 4c73428a30c84ed9949fe37c29d969c830f4ab8bd534a9b72da145e2347f0c4d621f6dc88385f0e181de66b4206c26cc355b6454174f6d2c34aa3cebc5e602dc
7
- data.tar.gz: 30cf3e15384e3a0b32f15bafbbadbd22aa22dbdb74d87449e89fb682da398aee6d46555c2a9b7a30360bdff33524734617d78dc018f97b37725903bae312c338
6
+ metadata.gz: 7235989cdea7459d1e1f5a43c7c0a70d5b3deeae7efca4b0f804c23d8c50e76de4afb688487716e177d70b2972f49e9df1869dcc567085270f91976c636ff787
7
+ data.tar.gz: aba5319ba07fc555c698a4d68c702e01a4599f7ee84d4b15461438fec9b30cb265c2d38163e3f0af383c6f7c5c641fa1a03c02e0b33634fe10d7cf0fed3964fb
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # test-unit
2
2
 
3
- [![](https://badge.fury.io/rb/test-unit.svg)](http://badge.fury.io/rb/test-unit)
4
- [![](https://travis-ci.org/test-unit/test-unit.svg?branch=master)](https://travis-ci.org/test-unit/test-unit)
3
+ [![Gem Version](https://badge.fury.io/rb/test-unit.png)](http://badge.fury.io/rb/test-unit)
4
+ [![Build Status for Ruby 2.1+](https://github.com/test-unit/test-unit/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/test-unit/test-unit/actions/workflows/test.yml?query=branch%3Amaster+)
5
+ [![Build Status for Ruby 1.9 and 2.0](https://travis-ci.com/test-unit/test-unit.svg?branch=master)](https://travis-ci.com/test-unit/test-unit)
5
6
 
6
7
  * http://test-unit.github.io/
7
8
  * https://github.com/test-unit/test-unit
@@ -24,7 +25,7 @@ writing tests, checking results and automated testing in Ruby.
24
25
  to radically change very soon).
25
26
 
26
27
  * test-unit will be improved actively and may break
27
- compatiblity with test-unit 1.2.3. (We will not hope it
28
+ compatibility with test-unit 1.2.3. (We will not hope it
28
29
  if it isn't needed.)
29
30
 
30
31
  * Some features exist as separated gems like GUI test
data/Rakefile CHANGED
@@ -24,7 +24,6 @@ require "packnga"
24
24
  task :default => :test
25
25
 
26
26
  base_dir = File.dirname(__FILE__)
27
- html_base_dir = File.join(base_dir, "doc", "html")
28
27
 
29
28
  helper = Bundler::GemHelper.new(base_dir)
30
29
  def helper.version_tag
@@ -53,14 +52,6 @@ def rake(*arguments)
53
52
  ruby($0, *arguments)
54
53
  end
55
54
 
56
- namespace :html do
57
- desc "Publish HTML to Web site."
58
- task :publish do
59
- # FIXME Do nothing for now
60
- #rsync_to_rubyforge(spec, "#{html_base_dir}/", "")
61
- end
62
- end
63
-
64
55
  task :test do
65
56
  ruby("test/run-test.rb")
66
57
  end
@@ -239,7 +239,7 @@ module Sub
239
239
  end
240
240
  ~~~
241
241
 
242
- ## 7. For more inforomation
242
+ ## 7. For more information
243
243
 
244
244
  Let's read the official document.
245
245
 
data/doc/text/news.md CHANGED
@@ -1,5 +1,54 @@
1
1
  # News
2
2
 
3
+ ## 3.4.5 - 2021-09-04 {#version-3-4-5}
4
+
5
+ ### Improvements
6
+
7
+ * Added more metadata to gemspec.
8
+ [GitHub#183][Patch by Kenichi Kamiya]
9
+
10
+ * Removed needless files from gem.
11
+ [GitHub#184][Patch by Kenichi Kamiya]
12
+
13
+ * Updated documents.
14
+ [GitHub#191][GitHub#192][GitHub#193][GitHub#199][GitHub#200]
15
+ [GitHub#201][Patch by Kenichi Kamiya]
16
+
17
+ * Added `assert_nothing_leaked_memory`.
18
+
19
+ ### Fixes
20
+
21
+ * Fixed typos in documents.
22
+ [GitHub#189][GitHub#190][GitHub#195][GitHub#197][Patch by Kenichi Kamiya]
23
+
24
+ ### Thanks
25
+
26
+ * Kenichi Kamiya
27
+
28
+ ## 3.4.4 - 2021-06-04 {#version-3-4-4}
29
+
30
+ ### Improvements
31
+
32
+ * Renamed `assert_all?` to `assert_all`. `assert_all?` is deprecated
33
+ but is available.
34
+
35
+ ## 3.4.3 - 2021-06-04 {#version-3-4-3}
36
+
37
+ ### Improvements
38
+
39
+ * Stopped to change result value of `Test::Unit::TestCase#include`.
40
+
41
+ * Added `assert_all?`.
42
+
43
+ * Added support for `assert_raise_with_message`.
44
+
45
+ ## 3.4.2 - 2021-05-30 {#version-3-4-2}
46
+
47
+ ### Improvements
48
+
49
+ * [UI][console]: Improved diff readability for no color
50
+ case. Character based diff marks are always showed.
51
+
3
52
  ## 3.4.1 - 2021-04-19 {#version-3-4-1}
4
53
 
5
54
  ### Fixes
@@ -5,6 +5,7 @@
5
5
 
6
6
  require 'test/unit/assertion-failed-error'
7
7
  require 'test/unit/util/backtracefilter'
8
+ require 'test/unit/util/memory-usage'
8
9
  require 'test/unit/util/method-owner-finder'
9
10
  require 'test/unit/diff'
10
11
 
@@ -43,7 +44,7 @@ module Test
43
44
 
44
45
  ##
45
46
  # The assertion upon which all other assertions are based. Passes if the
46
- # block yields true.
47
+ # block yields not false nor nil.
47
48
  #
48
49
  # @example
49
50
  # assert_block "Couldn't do the thing" do
@@ -289,6 +290,71 @@ EOT
289
290
  # Just for minitest compatibility. :<
290
291
  alias_method :assert_raises, :assert_raise
291
292
 
293
+ # Passes if the block raises `expected_exception` with
294
+ # `expected_message`. `expected_message` can be a `String` or
295
+ # `Regexp`.
296
+ #
297
+ # @example Pass pattern: String
298
+ # assert_raise_with_message(RuntimeError, "Boom!!!") do
299
+ # raise "Boom!!!"
300
+ # end # -> pass
301
+ #
302
+ # @example Pass pattern: Regexp
303
+ # assert_raise_with_message(RuntimeError, /!!!/) do
304
+ # raise "Boom!!!"
305
+ # end # -> pass
306
+ #
307
+ # @example Failure pattern: Exception class isn't matched
308
+ # assert_raise_with_message(RuntimeError, "Boom!!!") do
309
+ # raise ArgumentError, "Boom!!!"
310
+ # end # -> failure
311
+ #
312
+ # @example Failure pattern: Exception message isn't matched
313
+ # assert_raise_with_message(RuntimeError, "Boom!!!") do
314
+ # raise "Hello"
315
+ # end # -> failure
316
+ #
317
+ # @since 3.4.3
318
+ def assert_raise_with_message(expected_exception_class,
319
+ expected_message,
320
+ message=nil,
321
+ &block)
322
+ assert_expected_exception = Proc.new do |*_args|
323
+ _message, assert_exception_helper, actual_exception = _args
324
+ diff = AssertionMessage.delayed_diff([
325
+ expected_exception_class,
326
+ expected_message,
327
+ ],
328
+ [
329
+ actual_exception.class,
330
+ actual_exception.message,
331
+ ])
332
+ full_message = build_message(message,
333
+ "<?>(<?>) exception expected but was\n" +
334
+ "<?>(<?>).?",
335
+ expected_exception_class,
336
+ expected_message,
337
+ actual_exception.class,
338
+ actual_exception.message,
339
+ diff)
340
+ begin
341
+ assert_block(full_message) do
342
+ assert_exception_helper.expected?(actual_exception) and
343
+ expected_message === actual_exception.message
344
+ end
345
+ rescue AssertionFailedError => failure
346
+ _set_failed_information(failure,
347
+ expected_exception_class,
348
+ actual_exception)
349
+ raise failure # For JRuby. :<
350
+ end
351
+ actual_exception
352
+ end
353
+ args = [expected_exception_class]
354
+ args << message if message
355
+ _assert_raise(assert_expected_exception, *args, &block)
356
+ end
357
+
292
358
  ##
293
359
  # Passes if the block raises one of the given
294
360
  # exceptions or sub exceptions of the given exceptions.
@@ -389,7 +455,7 @@ EOT
389
455
  alias_method :refute_instance_of, :assert_not_instance_of
390
456
 
391
457
  ##
392
- # Passes if `object` is nil.
458
+ # Passes if `object`.nil?.
393
459
  #
394
460
  # @example
395
461
  # assert_nil [1, 2].uniq!
@@ -562,7 +628,7 @@ EOT
562
628
  ##
563
629
  # Compares the `object1` with `object2` using `operator`.
564
630
  #
565
- # Passes if object1.__send__(operator, object2) is true.
631
+ # Passes if object1.__send__(operator, object2) is not false nor nil.
566
632
  #
567
633
  # @example
568
634
  # assert_operator 5, :>=, 4
@@ -582,7 +648,7 @@ EOT
582
648
  ##
583
649
  # Compares the `object1` with `object2` using `operator`.
584
650
  #
585
- # Passes if object1.__send__(operator, object2) is not true.
651
+ # Passes if object1.__send__(operator, object2) is false or nil.
586
652
  #
587
653
  # @example
588
654
  # assert_not_operator(5, :<, 4) # => pass
@@ -722,7 +788,7 @@ EOT
722
788
  alias_method :refute_match, :assert_not_match
723
789
 
724
790
  ##
725
- # Deprecated. Use #assert_not_match instead.
791
+ # @deprecated Use {#assert_not_match} instead.
726
792
  #
727
793
  # Passes if `regexp` !~ `string`
728
794
  #
@@ -1112,7 +1178,7 @@ EOT
1112
1178
 
1113
1179
  public
1114
1180
  ##
1115
- # Passes if the method send returns a true value.
1181
+ # Passes if the method `__send__` returns not false nor nil.
1116
1182
  #
1117
1183
  # `send_array` is composed of:
1118
1184
  # * A receiver
@@ -1152,7 +1218,7 @@ EOT
1152
1218
  end
1153
1219
 
1154
1220
  ##
1155
- # Passes if the method send doesn't return a true value.
1221
+ # Passes if the method `__send__` returns false or nil.
1156
1222
  #
1157
1223
  # `send_array` is composed of:
1158
1224
  # * A receiver
@@ -1202,7 +1268,7 @@ EOT
1202
1268
  assert_block(build_message(message,
1203
1269
  "<true> or <false> expected but was\n<?>",
1204
1270
  actual)) do
1205
- [true, false].include?(actual)
1271
+ true == actual || false == actual
1206
1272
  end
1207
1273
  end
1208
1274
  end
@@ -1218,7 +1284,7 @@ EOT
1218
1284
  assert_block(build_message(message,
1219
1285
  "<true> expected but was\n<?>",
1220
1286
  actual)) do
1221
- actual == true
1287
+ true == actual
1222
1288
  end
1223
1289
  end
1224
1290
  end
@@ -1234,14 +1300,14 @@ EOT
1234
1300
  assert_block(build_message(message,
1235
1301
  "<false> expected but was\n<?>",
1236
1302
  actual)) do
1237
- actual == false
1303
+ false == actual
1238
1304
  end
1239
1305
  end
1240
1306
  end
1241
1307
 
1242
1308
  ##
1243
1309
  # Passes if expression "`expected` `operator`
1244
- # `actual`" is true.
1310
+ # `actual`" is not false nor nil.
1245
1311
  #
1246
1312
  # @example
1247
1313
  # assert_compare(1, "<", 10) # -> pass
@@ -1370,7 +1436,7 @@ EOT
1370
1436
  end
1371
1437
 
1372
1438
  ##
1373
- # Passes if `object`.`predicate` is _true_.
1439
+ # Passes if `object`.`predicate` is not false nor nil.
1374
1440
  #
1375
1441
  # @example
1376
1442
  # assert_predicate([], :empty?) # -> pass
@@ -1392,7 +1458,7 @@ EOT
1392
1458
  end
1393
1459
 
1394
1460
  ##
1395
- # Passes if `object`.`predicate` is not _true_.
1461
+ # Passes if `object`.`predicate` is false or nil.
1396
1462
  #
1397
1463
  # @example
1398
1464
  # assert_not_predicate([1], :empty?) # -> pass
@@ -1612,6 +1678,133 @@ EOT
1612
1678
  # @since 3.0.0
1613
1679
  alias_method :refute_empty, :assert_not_empty
1614
1680
 
1681
+ # @overload assert_all(collection, message=nil, &block)
1682
+ #
1683
+ # Asserts that all `block.call(item)` where `item` is each
1684
+ # item in `collection` are not false nor nil.
1685
+ #
1686
+ # If `collection` is empty, this assertion is always passed
1687
+ # with any `block`.
1688
+ #
1689
+ # @example Pass patterns
1690
+ # assert_all([1, 2, 3]) {|item| item > 0} # => pass
1691
+ # assert_all([1, 2, 3], &:positive?) # => pass
1692
+ # assert_all([]) {|item| false} # => pass
1693
+ #
1694
+ # @example Failure pattern
1695
+ # assert_all([0, 1, 2], &:zero?) # => failure
1696
+ #
1697
+ # @param [#each] collection The check target.
1698
+ # @param [String] message The additional user message. It is
1699
+ # showed when the assertion is failed.
1700
+ # @yield [Object] Give each item in `collection` to the block.
1701
+ # @yieldreturn [Object] The checked object.
1702
+ # @return [void]
1703
+ #
1704
+ # @since 3.4.4
1705
+ def assert_all(collection, message=nil)
1706
+ _wrap_assertion do
1707
+ failed = false
1708
+ result = {}
1709
+ collection.each do |item|
1710
+ element_result = yield(item)
1711
+ failed = true unless element_result
1712
+ result[item] = element_result
1713
+ end
1714
+ format = <<-FORMAT
1715
+ <?> was expected to be all true values with the given block but was
1716
+ <?>
1717
+ FORMAT
1718
+ full_message = build_message(message,
1719
+ format,
1720
+ collection,
1721
+ result)
1722
+ assert_block(full_message) do
1723
+ not failed
1724
+ end
1725
+ end
1726
+ end
1727
+
1728
+ # Just for Ruby's tool/lib/test/unit compatibility.
1729
+ #
1730
+ # @since 3.4.3
1731
+ alias_method :assert_all?, :assert_all
1732
+
1733
+ # @overload assert_nothing_leaked_memory(max_increasable_size, target=:physical, message=nil, &block)
1734
+ #
1735
+ # Asserts that increased memory usage by `block.call` is less
1736
+ # than `max_increasable_size`. `GC.start` is called before and
1737
+ # after `block.call`.
1738
+ #
1739
+ # This assertion may be fragile. Because memory usage is
1740
+ # depends on the current Ruby process's memory
1741
+ # usage. Launching a new Ruby process for this will produce
1742
+ # more stable result but we need to specify target code as
1743
+ # `String` instead of block for the approach. We choose easy
1744
+ # to write API approach rather than more stable result
1745
+ # approach for this case.
1746
+ #
1747
+ # @example Pass pattern
1748
+ # require "objspace"
1749
+ # size_per_object = ObjectSpace.memsize_of("Hello")
1750
+ # # If memory isn't leaked, physical memory of almost created objects
1751
+ # # (1000 - 10 objects) must be freed.
1752
+ # assert_nothing_leaked_memory(size_per_object * 10) do
1753
+ # 1_000.times do
1754
+ # "Hello".dup
1755
+ # end
1756
+ # end # => pass
1757
+ #
1758
+ # @example Failure pattern
1759
+ # require "objspace"
1760
+ # size_per_object = ObjectSpace.memsize_of("Hello")
1761
+ # strings = []
1762
+ # assert_nothing_leaked_memory(size_per_object * 10) do
1763
+ # 10_000.times do
1764
+ # # Created objects aren't GC-ed because they are referred.
1765
+ # strings << "Hello".dup
1766
+ # end
1767
+ # end # => failure
1768
+ #
1769
+ # @param target [:physical, :virtual] which memory usage is
1770
+ # used for comparing. `:physical` means physical memory usage
1771
+ # also known as Resident Set Size (RSS). `:virtual` means
1772
+ # virtual memory usage.
1773
+ # @yield [] do anything you want to measure memory usage
1774
+ # in the block.
1775
+ # @yieldreturn [void]
1776
+ # @return [void]
1777
+ #
1778
+ # @since 3.4.5
1779
+ def assert_nothing_leaked_memory(max_increasable_size,
1780
+ target=:physical,
1781
+ message=nil)
1782
+ _wrap_assertion do
1783
+ GC.start
1784
+ before = Util::MemoryUsage.new
1785
+ unless before.collected?
1786
+ omit("memory usage collection isn't supported on this platform")
1787
+ end
1788
+ yield
1789
+ GC.start
1790
+ after = Util::MemoryUsage.new
1791
+ before_value = before.__send__(target)
1792
+ after_value = after.__send__(target)
1793
+ actual_increased_size = after_value - before_value
1794
+ template = <<-TEMPLATE
1795
+ <?> was expected to be less than
1796
+ <?>.
1797
+ TEMPLATE
1798
+ full_message = build_message(message,
1799
+ template,
1800
+ actual_increased_size,
1801
+ max_increasable_size)
1802
+ assert_block(full_message) do
1803
+ actual_increased_size < max_increasable_size
1804
+ end
1805
+ end
1806
+ end
1807
+
1615
1808
  ##
1616
1809
  # Builds a failure message. `user_message` is added before the
1617
1810
  # `template` and `arguments` replaces the '?'s positionally in
@@ -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 = {}
@@ -446,7 +447,7 @@ module Test
446
447
  # @private
447
448
  @@method_locations = {}
448
449
  # @private
449
- @@method_location_mutex = Mutex.new
450
+ @@method_location_mutex = Thread::Mutex.new
450
451
 
451
452
  # @private
452
453
  def method_locations