Skip to content

Commit

Permalink
Use assert_crash_report in test_crash_report_pipe
Browse files Browse the repository at this point in the history
Instead of using `assert_in_out_err` directly.
  • Loading branch information
nobu committed Mar 12, 2024
1 parent 2af6bc2 commit ad2aa6d
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions test/ruby/test_rubyoptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ module SEGVTest
KILL_SELF = "Process.kill :SEGV, $$"
end

def assert_segv(args, message=nil, list: SEGVTest::ExpectedStderrList, **opt)
def assert_segv(args, message=nil, list: SEGVTest::ExpectedStderrList, **opt, &block)
# We want YJIT to be enabled in the subprocess if it's enabled for us
# so that the Ruby description matches.
env = Hash === args.first ? args.shift : {}
Expand All @@ -867,9 +867,10 @@ def assert_segv(args, message=nil, list: SEGVTest::ExpectedStderrList, **opt)
args.unshift(env)

test_stdin = ""
tests = [//, list] unless block

assert_in_out_err(args, test_stdin, //, list, encoding: "ASCII-8BIT",
**SEGVTest::ExecOptions, **opt)
assert_in_out_err(args, test_stdin, *tests, encoding: "ASCII-8BIT",
**SEGVTest::ExecOptions, **opt, &block)
end

def test_segv_test
Expand Down Expand Up @@ -897,7 +898,7 @@ def test_segv_setproctitle
}
end

def assert_crash_report(path, cmd = nil)
def assert_crash_report(path, cmd = nil, &block)
Dir.mktmpdir("ruby_crash_report") do |dir|
list = SEGVTest::ExpectedStderrList
if cmd
Expand All @@ -908,7 +909,8 @@ def assert_crash_report(path, cmd = nil)
else
cmd = ['-e', SEGVTest::KILL_SELF]
end
status = assert_segv([{"RUBY_CRASH_REPORT"=>path}, *cmd], list: [], chdir: dir)
status = assert_segv([{"RUBY_CRASH_REPORT"=>path}, *cmd], list: [], chdir: dir, &block)
next if block
reports = Dir.glob("*.log", File::FNM_DOTMATCH, base: dir)
assert_equal(1, reports.size)
assert_pattern_list(list, File.read(File.join(dir, reports.first)))
Expand Down Expand Up @@ -945,12 +947,8 @@ def test_crash_report_pipe
else
omit "/bin/echo not found"
end
env = {"RUBY_CRASH_REPORT"=>"| #{echo} %e:%f:%p", "RUBY_ON_BUG"=>nil}
assert_in_out_err([env], SEGVTest::KILL_SELF,
encoding: "ASCII-8BIT",
**SEGVTest::ExecOptions) do |stdout, stderr, status|
assert_empty(stderr)
assert_equal(["#{File.basename(EnvUtil.rubybin)}:-:#{status.pid}"], stdout)
assert_crash_report("| #{echo} %e:%f:%p") do |stdin, stdout, status|
assert_equal(["#{File.basename(EnvUtil.rubybin)}:-e:#{status.pid}"], stdin)
end
end

Expand Down

0 comments on commit ad2aa6d

Please sign in to comment.