Skip to content

Commit 837947a

Browse files
committed
Compatibility with test-unit-ruby-core
1 parent 943b5f6 commit 837947a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

tool/lib/core_assertions.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,19 @@ def message msg = nil, ending = nil, &default
7474
module CoreAssertions
7575
require_relative 'envutil'
7676
require 'pp'
77-
require '-test-/sanitizers'
77+
begin
78+
require '-test-/sanitizers'
79+
rescue LoadError
80+
# in test-unit-ruby-core gem
81+
def sanitizers
82+
nil
83+
end
84+
else
85+
def sanitizers
86+
Test::Sanitizers
87+
end
88+
end
89+
module_function :sanitizers
7890

7991
nil.pretty_inspect
8092

@@ -159,7 +171,7 @@ def assert_no_memory_leak(args, prepare, code, message=nil, limit: 2.0, rss: fal
159171
pend 'assert_no_memory_leak may consider MJIT memory usage as leak' if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
160172
# ASAN has the same problem - its shadow memory greatly increases memory usage
161173
# (plus asan has better ways to detect memory leaks than this assertion)
162-
pend 'assert_no_memory_leak may consider ASAN memory usage as leak' if Test::Sanitizers.asan_enabled?
174+
pend 'assert_no_memory_leak may consider ASAN memory usage as leak' if sanitizers&.asan_enabled?
163175

164176
require_relative 'memory_status'
165177
raise Test::Unit::PendedError, "unsupported platform" unless defined?(Memory::Status)
@@ -329,7 +341,7 @@ def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **o
329341
args << "--debug" if RUBY_ENGINE == 'jruby' # warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
330342
stdout, stderr, status = EnvUtil.invoke_ruby(args, src, capture_stdout, true, **opt)
331343

332-
if Test::Sanitizers.lsan_enabled?
344+
if sanitizers&.lsan_enabled?
333345
# LSAN may output messages like the following line into stderr. We should ignore it.
334346
# ==276855==Running thread 276851 was not suspended. False leaks are possible.
335347
# See https://github.com/google/sanitizers/issues/1479

0 commit comments

Comments
 (0)