From 3839a8fe79a3ec95ff9bf78ad1fd95953d600876 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 27 Jun 2021 21:13:37 +0900 Subject: [PATCH] Narrow the tracing of object allocations to during each test --- tool/lib/minitest/unit.rb | 56 +++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 28 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 - - 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 - - print "%.2f s = " % (Time.now - start_time) if @verbose - print result - puts if @verbose - $stdout.flush - - 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 - if ENV["LEAK_CHECKER_TRACE_OBJECT_ALLOCATION"] require "objspace" - ObjectSpace.trace_object_allocations(&continuation) - else - continuation.call + trace = true end + + 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 = + if trace + ObjectSpace.trace_object_allocations {inst.run self} + else + inst.run self + end + + print "%.2f s = " % (Time.now - start_time) if @verbose + print result + puts if @verbose + $stdout.flush + + 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 ##