mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
test_timeout_scale_from_env uses assert_separately, which the test-unit gem runner does not provide. ruby/ruby gets it from tool/lib/test/unit.rb. https://github.com/ruby/test-unit-ruby-core/commit/b5da68b6fd Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.1 KiB
Ruby
48 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "test/unit"
|
|
require "envutil"
|
|
require "core_assertions"
|
|
|
|
class TestEnvUtil < Test::Unit::TestCase
|
|
include Test::Unit::CoreAssertions
|
|
|
|
def test_rubybin_points_to_a_ruby_executable
|
|
assert(File.executable?(EnvUtil.rubybin))
|
|
end
|
|
|
|
def test_apply_timeout_scale
|
|
original_scale = EnvUtil.timeout_scale
|
|
EnvUtil.timeout_scale = 2.5
|
|
|
|
assert_equal(5.0, EnvUtil.apply_timeout_scale(2))
|
|
ensure
|
|
EnvUtil.timeout_scale = original_scale
|
|
end
|
|
|
|
def test_timeout_scale_from_env
|
|
assert_separately([{"RUBY_TEST_TIMEOUT_SCALE" => "2.5"}], "assert_equal(2.5, EnvUtil.timeout_scale)")
|
|
end
|
|
|
|
def test_invoke_ruby_captures_output_and_status
|
|
stdout, stderr, status = EnvUtil.invoke_ruby(
|
|
["-e", "STDOUT.print('out'); STDERR.print('err')"],
|
|
"", true, true
|
|
)
|
|
|
|
assert_equal("out", stdout)
|
|
assert_equal("err", stderr)
|
|
assert_predicate(status, :success?)
|
|
end
|
|
|
|
def test_terminate_reaps_exited_child
|
|
r, w = IO.pipe
|
|
pid = spawn(EnvUtil.rubybin, "-e", "", out: w)
|
|
w.close
|
|
r.read
|
|
r.close
|
|
|
|
assert_equal(pid, EnvUtil.terminate(pid).pid)
|
|
end
|
|
end
|