test-unit 3.4.2 → 3.4.6
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.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/Rakefile +0 -9
- data/doc/text/getting-started.md +1 -1
- data/doc/text/news.md +52 -0
- data/lib/test/unit/assertion-failed-error.rb +35 -0
- data/lib/test/unit/assertions.rb +206 -13
- data/lib/test/unit/autorunner.rb +13 -1
- data/lib/test/unit/collector/descendant.rb +1 -0
- data/lib/test/unit/collector/dir.rb +4 -2
- data/lib/test/unit/collector/load.rb +2 -0
- data/lib/test/unit/collector/objectspace.rb +1 -0
- data/lib/test/unit/collector.rb +31 -0
- data/lib/test/unit/testcase.rb +33 -2
- data/lib/test/unit/testsuite.rb +1 -1
- data/lib/test/unit/util/memory-usage.rb +47 -0
- data/lib/test/unit/version.rb +1 -1
- data/lib/test/unit.rb +4 -4
- metadata +6 -83
- data/test/collector/test-descendant.rb +0 -182
- data/test/collector/test-load.rb +0 -475
- data/test/collector/test_dir.rb +0 -407
- data/test/collector/test_objectspace.rb +0 -102
- data/test/fixtures/header-label.csv +0 -3
- data/test/fixtures/header-label.tsv +0 -3
- data/test/fixtures/header.csv +0 -3
- data/test/fixtures/header.tsv +0 -3
- data/test/fixtures/no-header.csv +0 -2
- data/test/fixtures/no-header.tsv +0 -2
- data/test/fixtures/plus.csv +0 -3
- data/test/run-test.rb +0 -22
- data/test/test-assertions.rb +0 -2187
- data/test/test-attribute-matcher.rb +0 -38
- data/test/test-attribute.rb +0 -123
- data/test/test-code-snippet.rb +0 -79
- data/test/test-color-scheme.rb +0 -123
- data/test/test-color.rb +0 -47
- data/test/test-data.rb +0 -419
- data/test/test-diff.rb +0 -518
- data/test/test-emacs-runner.rb +0 -60
- data/test/test-error.rb +0 -26
- data/test/test-failure.rb +0 -33
- data/test/test-fault-location-detector.rb +0 -163
- data/test/test-fixture.rb +0 -713
- data/test/test-notification.rb +0 -33
- data/test/test-omission.rb +0 -81
- data/test/test-pending.rb +0 -70
- data/test/test-priority.rb +0 -184
- data/test/test-test-case.rb +0 -1284
- data/test/test-test-result.rb +0 -113
- data/test/test-test-suite-creator.rb +0 -97
- data/test/test-test-suite.rb +0 -151
- data/test/testunit-test-util.rb +0 -33
- data/test/ui/test_testrunmediator.rb +0 -20
- data/test/util/test-method-owner-finder.rb +0 -38
- data/test/util/test-output.rb +0 -11
- data/test/util/test_backtracefilter.rb +0 -52
- data/test/util/test_observable.rb +0 -102
- data/test/util/test_procwrapper.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f8ed035b9be7e1b2a3c92d767c8007d46e867131d7385e54b2096170d658226
|
4
|
+
data.tar.gz: 426871e1614d48c08de963123fb36654da1abf611d1b3ca005a952fc4c4dd66b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ee530d7c01b91eee8ca71c62f6086ea3875c4fcf057ef5cd514896d633d4331f24ca5964a338622f7a80c747358cb85d4ae3996d30687b4f5f37d657d93f658
|
7
|
+
data.tar.gz: f0707e81dd0fa2f368759d0a61f1fae9dd764aeeb12e7e8c2cfd5b5f5fc0de76b13821154353fa1045b441a2a58f1d689a9530032c130ede1d3058d29f6d760b
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# test-unit
|
2
2
|
|
3
|
-
[](http://badge.fury.io/rb/test-unit)
|
4
|
+
[](https://github.com/test-unit/test-unit/actions/workflows/test.yml?query=branch%3Amaster+)
|
5
|
+
[](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
|
-
|
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
|
data/doc/text/getting-started.md
CHANGED
data/doc/text/news.md
CHANGED
@@ -1,5 +1,57 @@
|
|
1
1
|
# News
|
2
2
|
|
3
|
+
## 3.4.6 - 2021-09-11 {#version-3-4-6}
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* Added support for tests that use Ractor. Use
|
8
|
+
`Test::Unit::TestCase.ractor` to declare that these tests use
|
9
|
+
Ractor.
|
10
|
+
|
11
|
+
* Added `--debug-on-failure` option.
|
12
|
+
|
13
|
+
## 3.4.5 - 2021-09-04 {#version-3-4-5}
|
14
|
+
|
15
|
+
### Improvements
|
16
|
+
|
17
|
+
* Added more metadata to gemspec.
|
18
|
+
[GitHub#183][Patch by Kenichi Kamiya]
|
19
|
+
|
20
|
+
* Removed needless files from gem.
|
21
|
+
[GitHub#184][Patch by Kenichi Kamiya]
|
22
|
+
|
23
|
+
* Updated documents.
|
24
|
+
[GitHub#191][GitHub#192][GitHub#193][GitHub#199][GitHub#200]
|
25
|
+
[GitHub#201][Patch by Kenichi Kamiya]
|
26
|
+
|
27
|
+
* Added `assert_nothing_leaked_memory`.
|
28
|
+
|
29
|
+
### Fixes
|
30
|
+
|
31
|
+
* Fixed typos in documents.
|
32
|
+
[GitHub#189][GitHub#190][GitHub#195][GitHub#197][Patch by Kenichi Kamiya]
|
33
|
+
|
34
|
+
### Thanks
|
35
|
+
|
36
|
+
* Kenichi Kamiya
|
37
|
+
|
38
|
+
## 3.4.4 - 2021-06-04 {#version-3-4-4}
|
39
|
+
|
40
|
+
### Improvements
|
41
|
+
|
42
|
+
* Renamed `assert_all?` to `assert_all`. `assert_all?` is deprecated
|
43
|
+
but is available.
|
44
|
+
|
45
|
+
## 3.4.3 - 2021-06-04 {#version-3-4-3}
|
46
|
+
|
47
|
+
### Improvements
|
48
|
+
|
49
|
+
* Stopped to change result value of `Test::Unit::TestCase#include`.
|
50
|
+
|
51
|
+
* Added `assert_all?`.
|
52
|
+
|
53
|
+
* Added support for `assert_raise_with_message`.
|
54
|
+
|
3
55
|
## 3.4.2 - 2021-05-30 {#version-3-4-2}
|
4
56
|
|
5
57
|
### 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
|
+
class << self
|
13
|
+
@debug_on_failure = false
|
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
|
data/lib/test/unit/assertions.rb
CHANGED
@@ -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
|
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
|
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
|
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
|
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
|
-
#
|
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
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
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
|
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
|