summaryrefslogtreecommitdiff
path: root/tool/lib/minitest
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-06-27 21:13:37 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-06-27 21:13:51 +0900
commit3839a8fe79a3ec95ff9bf78ad1fd95953d600876 (patch)
treed43a9d89a533a8e0904c2b8a410eb5e452aa8cb4 /tool/lib/minitest
parent13939d61b4b69bd109c5f41303c79868d639fa44 (diff)
Narrow the tracing of object allocations to during each test
Diffstat (limited to 'tool/lib/minitest')
-rw-r--r--tool/lib/minitest/unit.rb50
1 files changed, 25 insertions, 25 deletions
diff --git a/tool/lib/minitest/unit.rb b/tool/lib/minitest/unit.rb
index ec6d6357b0..2cda29ad7d 100644
--- a/tool/lib/minitest/unit.rb
+++ b/tool/lib/minitest/unit.rb
@@ -961,37 +961,37 @@ module MiniTest
}
leakchecker = LeakChecker.new
+ if ENV["LEAK_CHECKER_TRACE_OBJECT_ALLOCATION"]
+ require "objspace"
+ trace = true
+ end
- continuation = proc do
- assertions = filtered_test_methods.map { |method|
- inst = suite.new method
- inst._assertions = 0
-
- print "#{suite}##{method} = " if @verbose
-
- start_time = Time.now if @verbose
- result = inst.run self
+ assertions = filtered_test_methods.map { |method|
+ inst = suite.new method
+ inst._assertions = 0
- print "%.2f s = " % (Time.now - start_time) if @verbose
- print result
- puts if @verbose
- $stdout.flush
+ print "#{suite}##{method} = " if @verbose
- unless defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # compiler process is wrongly considered as leak
- leakchecker.check("#{inst.class}\##{inst.__name__}")
+ start_time = Time.now if @verbose
+ result =
+ if trace
+ ObjectSpace.trace_object_allocations {inst.run self}
+ else
+ inst.run self
end
- inst._assertions
- }
- return assertions.size, assertions.inject(0) { |sum, n| sum + n }
- end
+ print "%.2f s = " % (Time.now - start_time) if @verbose
+ print result
+ puts if @verbose
+ $stdout.flush
- if ENV["LEAK_CHECKER_TRACE_OBJECT_ALLOCATION"]
- require "objspace"
- ObjectSpace.trace_object_allocations(&continuation)
- else
- continuation.call
- end
+ unless defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # compiler process is wrongly considered as leak
+ leakchecker.check("#{inst.class}\##{inst.__name__}")
+ end
+
+ inst._assertions
+ }
+ return assertions.size, assertions.inject(0) { |sum, n| sum + n }
end
##