Skip to content

Commit ee13db1

Browse files
committed
Fix remaining issues in test/ruby
1 parent 0d95446 commit ee13db1

6 files changed

Lines changed: 38 additions & 44 deletions

File tree

test/ruby/test_env.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,19 @@ def assert_invalid_env(msg = nil)
2323
end
2424

2525
def setup
26-
omit "unpredictable results" if multiple_ractors?
26+
@multiple_ractors = multiple_ractors? # save because test might mess with ENV
27+
omit "unpredictable results" if @multiple_ractors
2728
@verbose = $VERBOSE
2829
@backup = ENV.to_hash
2930
ENV.delete('test')
3031
ENV.delete('TEST')
3132
end
3233

3334
def teardown
34-
return if multiple_ractors?
35-
if @verbose
36-
$VERBOSE = @verbose
37-
ENV.clear
38-
@backup.each {|k, v| ENV[k] = v }
39-
end
35+
return if @multiple_ractors
36+
$VERBOSE = @verbose
37+
ENV.clear
38+
@backup.each {|k, v| ENV[k] = v }
4039
end
4140

4241
def test_bracket

test/ruby/test_exception.rb

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,32 +1069,31 @@ def test_message_of_name_error
10691069

10701070
def capture_warning_warn(category: false)
10711071
omit "global side effects" if multiple_ractors?
1072-
verbose = $VERBOSE
1073-
categories = Warning.categories.to_h {|cat| [cat, Warning[cat]]}
1074-
warning = []
1072+
begin
1073+
verbose = $VERBOSE
1074+
categories = Warning.categories.to_h {|cat| [cat, Warning[cat]]}
1075+
warning = []
10751076

1076-
::Warning.class_eval do
1077-
alias_method :warn2, :warn
1078-
remove_method :warn
1077+
::Warning.class_eval do
1078+
alias_method :warn2, :warn
1079+
remove_method :warn
10791080

1080-
if category
1081-
define_method(:warn) do |str, category: nil|
1082-
warning << [str, category]
1083-
end
1084-
else
1085-
define_method(:warn) do |str, category: nil|
1086-
warning << str
1081+
if category
1082+
define_method(:warn) do |str, category: nil|
1083+
warning << [str, category]
1084+
end
1085+
else
1086+
define_method(:warn) do |str, category: nil|
1087+
warning << str
1088+
end
10871089
end
10881090
end
1089-
end
1090-
1091-
$VERBOSE = true
1092-
Warning.categories.each {|cat| Warning[cat] = true}
1093-
yield
10941091

1095-
return warning
1096-
ensure
1097-
if verbose
1092+
$VERBOSE = true
1093+
Warning.categories.each {|cat| Warning[cat] = true}
1094+
yield
1095+
return warning
1096+
ensure
10981097
$VERBOSE = verbose
10991098
categories.each {|cat, flag| Warning[cat] = flag}
11001099

test/ruby/test_file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def test_realdirpath
317317
assert_equal(File.join(realdir, "foo"), File.realdirpath("foo", tst))
318318
if main_ractor?
319319
assert_equal(realdir, Dir.chdir(realdir) {File.realdirpath(".")})
320-
assert_equal(File.join(realdir, "foo"), Dir.chdir(realdir) {File.realdirpath("foo")}) if main
320+
assert_equal(File.join(realdir, "foo"), Dir.chdir(realdir) {File.realdirpath("foo")})
321321
end
322322
}
323323
begin

test/ruby/test_time_tz.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ def self.gen_variational_zdump_test(hint, data)
572572
}
573573
end
574574

575-
unless will_run_in_non_main_ractor?
575+
if will_run_in_main_ractor?
576576
# tzdata-2014g fixed the offset for lisbon from -0:36:32 to -0:36:45.
577577
# [ruby-core:65058] [Bug #10245]
578578
gen_variational_zdump_test "lisbon", <<'End' if has_lisbon_tz

tool/lib/core_assertions.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def assert_file
100100

101101
def assert_in_out_err(args, test_stdin = "", test_stdout = [], test_stderr = [], message = nil,
102102
success: nil, failed: nil, **opt)
103-
pend "#{__method__}" unless main_ractor?
103+
pend "#{__method__}" unless Test::Unit::TestCase.main_ractor?
104104
args = Array(args).dup
105105
args.insert((Hash === args[0] ? 1 : 0), '--disable=gems')
106106
stdout, stderr, status = EnvUtil.invoke_ruby(args, test_stdin, true, true, **opt)
@@ -157,7 +157,7 @@ def syntax_check(code, fname, line)
157157
end
158158

159159
def assert_no_memory_leak(args, prepare, code, message=nil, limit: 2.0, rss: false, **opt)
160-
omit "separate process" unless main_ractor?
160+
omit "separate process" unless Test::Unit::TestCase.main_ractor?
161161
# TODO: consider choosing some appropriate limit for RJIT and stop skipping this once it does not randomly fail
162162
pend 'assert_no_memory_leak may consider RJIT memory usage as leak' if defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?
163163
# For previous versions which implemented MJIT
@@ -274,7 +274,7 @@ def assert_valid_syntax(code, *args, **opt)
274274
end
275275

276276
def assert_normal_exit(testsrc, message = '', child_env: nil, **opt)
277-
pend "#{__method__}" unless main_ractor?
277+
pend "#{__method__}" unless Test::Unit::TestCase.main_ractor?
278278
assert_valid_syntax(testsrc, caller_locations(1, 1)[0])
279279
if child_env
280280
child_env = [child_env]
@@ -286,7 +286,7 @@ def assert_normal_exit(testsrc, message = '', child_env: nil, **opt)
286286
end
287287

288288
def assert_ruby_status(args, test_stdin="", message=nil, **opt)
289-
pend "#{__method__}" unless main_ractor?
289+
pend "#{__method__}" unless Test::Unit::TestCase.main_ractor?
290290
out, _, status = EnvUtil.invoke_ruby(args, test_stdin, true, :merge_to_stdout, **opt)
291291
desc = FailDesc[status, message, out]
292292
assert(!status.signaled?, desc)
@@ -310,7 +310,7 @@ def separated_runner(token, out = nil)
310310
end
311311

312312
def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **opt)
313-
pend "#{__method__}" unless main_ractor?
313+
pend "#{__method__}" unless Test::Unit::TestCase.main_ractor?
314314
unless file and line
315315
loc, = caller_locations(1,1)
316316
file ||= loc.path
@@ -508,7 +508,7 @@ def assert_raise_with_message(exception, expected, msg = nil, &block)
508508
assert = :assert_match
509509
end
510510
ex = m = nil
511-
if multiple_ractors?
511+
if Test::Unit::TestCase.multiple_ractors?
512512
ex = assert_raise(exception, msg || proc {"Exception(#{exception}) with message matches to #{expected.inspect}"}) do
513513
yield
514514
end
@@ -690,7 +690,7 @@ def assert_pattern_list(pattern_list, actual, message=nil)
690690

691691
def assert_warning(pat, msg = nil)
692692
result = nil
693-
if multiple_ractors?
693+
if Test::Unit::TestCase.multiple_ractors?
694694
stderr = EnvUtil.verbose_warning {
695695
result = yield
696696
}
@@ -873,7 +873,7 @@ def assert_all_assertions_foreach(msg = nil, *keys, &block)
873873
# :yield: each elements of +seq+.
874874
def assert_linear_performance(seq, rehearsal: nil, pre: ->(n) {n})
875875
pend "No PERFORMANCE_CLOCK found" unless defined?(PERFORMANCE_CLOCK)
876-
pend "Timeout" unless main_ractor?
876+
pend "Timeout" unless Test::Unit::TestCase.main_ractor?
877877

878878
# Timeout testing generally doesn't work when RJIT compilation happens.
879879
rjit_enabled = defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?

tool/lib/test/unit/testcase.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,9 @@ def multiple_ractors?
6363
ENV["RUBY_TESTS_WITH_RACTORS"].to_i > 1
6464
end
6565

66-
# In order to guard generating methods dynamically that will run inside a ractor
67-
def will_run_in_non_main_ractor?
68-
ENV["RUBY_TESTS_WITH_RACTORS"].to_i > 0
69-
end
70-
66+
# In order to guard generating methods dynamically that will run inside another ractor
7167
def will_run_in_main_ractor?
72-
not will_run_in_non_main_ractor?
68+
ENV["RUBY_TESTS_WITH_RACTORS"].to_i == 0
7369
end
7470
end
7571

0 commit comments

Comments
 (0)