envutil.rb: keyword arguments
* test/ruby/envutil.rb (invoke_ruby, assert_normal_exit), (assert_in_out_err, assert_ruby_status, assert_separately): use keyword arguments so that optional parameters can be omitted. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d7167e852a
commit
05dd6b194c
@ -29,20 +29,18 @@ module EnvUtil
|
|||||||
|
|
||||||
LANG_ENVS = %w"LANG LC_ALL LC_CTYPE"
|
LANG_ENVS = %w"LANG LC_ALL LC_CTYPE"
|
||||||
|
|
||||||
def invoke_ruby(args, stdin_data="", capture_stdout=false, capture_stderr=false, opt={})
|
def invoke_ruby(args, stdin_data = "", capture_stdout = false, capture_stderr = false,
|
||||||
|
encoding: nil, timeout: 10, reprieve: 1, **opt)
|
||||||
in_c, in_p = IO.pipe
|
in_c, in_p = IO.pipe
|
||||||
out_p, out_c = IO.pipe if capture_stdout
|
out_p, out_c = IO.pipe if capture_stdout
|
||||||
err_p, err_c = IO.pipe if capture_stderr && capture_stderr != :merge_to_stdout
|
err_p, err_c = IO.pipe if capture_stderr && capture_stderr != :merge_to_stdout
|
||||||
opt = opt.dup
|
|
||||||
opt[:in] = in_c
|
opt[:in] = in_c
|
||||||
opt[:out] = out_c if capture_stdout
|
opt[:out] = out_c if capture_stdout
|
||||||
opt[:err] = capture_stderr == :merge_to_stdout ? out_c : err_c if capture_stderr
|
opt[:err] = capture_stderr == :merge_to_stdout ? out_c : err_c if capture_stderr
|
||||||
if enc = opt.delete(:encoding)
|
if encoding
|
||||||
out_p.set_encoding(enc) if out_p
|
out_p.set_encoding(encoding) if out_p
|
||||||
err_p.set_encoding(enc) if err_p
|
err_p.set_encoding(encoding) if err_p
|
||||||
end
|
end
|
||||||
timeout = opt.delete(:timeout) || 10
|
|
||||||
reprieve = opt.delete(:reprieve) || 1
|
|
||||||
c = "C"
|
c = "C"
|
||||||
child_env = {}
|
child_env = {}
|
||||||
LANG_ENVS.each {|lc| child_env[lc] = c}
|
LANG_ENVS.each {|lc| child_env[lc] = c}
|
||||||
@ -50,7 +48,7 @@ module EnvUtil
|
|||||||
child_env.update(args.shift)
|
child_env.update(args.shift)
|
||||||
end
|
end
|
||||||
args = [args] if args.kind_of?(String)
|
args = [args] if args.kind_of?(String)
|
||||||
pid = spawn(child_env, EnvUtil.rubybin, *args, opt)
|
pid = spawn(child_env, EnvUtil.rubybin, *args, **opt)
|
||||||
in_c.close
|
in_c.close
|
||||||
out_c.close if capture_stdout
|
out_c.close if capture_stdout
|
||||||
err_c.close if capture_stderr && capture_stderr != :merge_to_stdout
|
err_c.close if capture_stderr && capture_stderr != :merge_to_stdout
|
||||||
@ -209,11 +207,10 @@ module Test
|
|||||||
$VERBOSE = verbose
|
$VERBOSE = verbose
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_normal_exit(testsrc, message = '', opt = {})
|
def assert_normal_exit(testsrc, message = '', child_env: nil, **opt)
|
||||||
assert_valid_syntax(testsrc, caller_locations(1, 1)[0])
|
assert_valid_syntax(testsrc, caller_locations(1, 1)[0])
|
||||||
if opt.include?(:child_env)
|
if child_env
|
||||||
opt = opt.dup
|
child_env = [child_env]
|
||||||
child_env = [opt.delete(:child_env)] || []
|
|
||||||
else
|
else
|
||||||
child_env = []
|
child_env = []
|
||||||
end
|
end
|
||||||
@ -247,7 +244,7 @@ module Test
|
|||||||
faildesc
|
faildesc
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_in_out_err(args, test_stdin = "", test_stdout = [], test_stderr = [], message = nil, opt={})
|
def assert_in_out_err(args, test_stdin = "", test_stdout = [], test_stderr = [], message = nil, **opt)
|
||||||
stdout, stderr, status = EnvUtil.invoke_ruby(args, test_stdin, true, true, opt)
|
stdout, stderr, status = EnvUtil.invoke_ruby(args, test_stdin, true, true, opt)
|
||||||
if block_given?
|
if block_given?
|
||||||
raise "test_stdout ignored, use block only or without block" if test_stdout != []
|
raise "test_stdout ignored, use block only or without block" if test_stdout != []
|
||||||
@ -272,7 +269,7 @@ module Test
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_ruby_status(args, test_stdin="", message=nil, opt={})
|
def assert_ruby_status(args, test_stdin="", message=nil, **opt)
|
||||||
out, _, status = EnvUtil.invoke_ruby(args, test_stdin, true, :merge_to_stdout, opt)
|
out, _, status = EnvUtil.invoke_ruby(args, test_stdin, true, :merge_to_stdout, opt)
|
||||||
assert(!status.signaled?, FailDesc[status, message, out])
|
assert(!status.signaled?, FailDesc[status, message, out])
|
||||||
message ||= "ruby exit status is not success:"
|
message ||= "ruby exit status is not success:"
|
||||||
@ -281,7 +278,7 @@ module Test
|
|||||||
|
|
||||||
ABORT_SIGNALS = Signal.list.values_at(*%w"ILL ABRT BUS SEGV")
|
ABORT_SIGNALS = Signal.list.values_at(*%w"ILL ABRT BUS SEGV")
|
||||||
|
|
||||||
def assert_separately(args, file = nil, line = nil, src, **opt)
|
def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **opt)
|
||||||
unless file and line
|
unless file and line
|
||||||
loc, = caller_locations(1,1)
|
loc, = caller_locations(1,1)
|
||||||
file ||= loc.path
|
file ||= loc.path
|
||||||
@ -298,7 +295,6 @@ module Test
|
|||||||
eom
|
eom
|
||||||
args = args.dup
|
args = args.dup
|
||||||
args.insert((Hash === args.first ? 1 : 0), *$:.map {|l| "-I#{l}"})
|
args.insert((Hash === args.first ? 1 : 0), *$:.map {|l| "-I#{l}"})
|
||||||
ignore_stderr = opt.delete(:ignore_stderr)
|
|
||||||
stdout, stderr, status = EnvUtil.invoke_ruby(args, src, true, true, opt)
|
stdout, stderr, status = EnvUtil.invoke_ruby(args, src, true, true, opt)
|
||||||
abort = status.coredump? || (status.signaled? && ABORT_SIGNALS.include?(status.termsig))
|
abort = status.coredump? || (status.signaled? && ABORT_SIGNALS.include?(status.termsig))
|
||||||
assert(!abort, FailDesc[status, stderr])
|
assert(!abort, FailDesc[status, stderr])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user