envutil.rb: improve assert_no_memory_leak

* test/ruby/envutil.rb (assert_no_memory_leak): allow envirionment
  variables keyword options.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-10-17 10:51:35 +00:00
Родитель ee4da732e3
Коммит 96399a0c5f
1 изменённых файлов: 4 добавлений и 2 удалений

Просмотреть файл

@ -334,23 +334,25 @@ eom
assert_warning(*args) {$VERBOSE = false; yield}
end
def assert_no_memory_leak(args, prepare, code, message=nil, limit: 1.5)
def assert_no_memory_leak(args, prepare, code, message=nil, limit: 1.5, **opt)
token = "\e[7;1m#{$$.to_s}:#{Time.now.strftime('%s.%L')}:#{rand(0x10000).to_s(16)}:\e[m"
token_dump = token.dump
token_re = Regexp.quote(token)
envs = args.shift if Array === args and Hash === args.first
args = [
"--disable=gems",
"-r", File.expand_path("../memory_status", __FILE__),
*args,
"-v", "-",
]
args.unshift(envs) if envs
cmd = [
'END {STDERR.puts '"#{token_dump}"'"FINAL=#{Memory::Status.new.size}"}',
prepare,
'STDERR.puts('"#{token_dump}"'"START=#{$initial_size = Memory::Status.new.size}")',
code,
].join("\n")
_, err, status = EnvUtil.invoke_ruby(args, cmd, true, true)
_, err, status = EnvUtil.invoke_ruby(args, cmd, true, true, **opt)
before = err.sub!(/^#{token_re}START=(\d+)\n/, '') && $1.to_i
after = err.sub!(/^#{token_re}FINAL=(\d+)\n/, '') && $1.to_i
assert_equal([true, ""], [status.success?, err], message)