null+****@clear*****
null+****@clear*****
2010年 11月 23日 (火) 17:16:47 JST
Kouhei Sutou 2010-11-23 08:16:47 +0000 (Tue, 23 Nov 2010)
New Revision: a18c4df69353c59488d2e90efe19cd24d0096552
Log:
cleanup.
Modified files:
test/unit/lib/ruby/groonga-test-utils.rb
Modified: test/unit/lib/ruby/groonga-test-utils.rb (+26 -17)
===================================================================
--- test/unit/lib/ruby/groonga-test-utils.rb 2010-11-22 07:52:40 +0000 (a5c8d7f)
+++ test/unit/lib/ruby/groonga-test-utils.rb 2010-11-23 08:16:47 +0000 (ba1228b)
@@ -145,13 +145,18 @@ module GroongaTestUtils
LANG_ENVS = %w"LANG LC_ALL LC_CTYPE"
- def invoke_groonga(args, stdin_data="", capture_stdout=false, capture_stderr=false, opt={})
+ def invoke_groonga(*args)
+ options = args.last.is_a?(Hash) ? args.pop : {}
+ input_data = options[:input] || ""
+ capture_output = options[:capture_output]
+ capture_output = true if capture_output.nil?
+ capture_error = options[:capture_error]
@groonga ||= guess_groonga_path
args = [args] unless args.kind_of?(Array)
begin
in_child, in_parent = IO.pipe
- out_parent, out_child = IO.pipe if capture_stdout
- err_parent, err_child = IO.pipe if capture_stderr
+ out_parent, out_child = IO.pipe if capture_output
+ err_parent, err_child = IO.pipe if capture_error
pid = fork do
c = "C"
LANG_ENVS.each {|lc| ENV[lc] = c}
@@ -161,11 +166,11 @@ module GroongaTestUtils
end
STDIN.reopen(in_child)
in_parent.close
- if capture_stdout
+ if capture_output
STDOUT.reopen(out_child)
out_parent.close
end
- if capture_stderr
+ if capture_error
STDERR.reopen(err_child)
err_parent.close
end
@@ -173,15 +178,16 @@ module GroongaTestUtils
exec(@groonga, *args)
end
in_child.close
- out_child.close if capture_stdout
- err_child.close if capture_stderr
- th_stdout = Thread.new { out_parent.read } if capture_stdout
- th_stderr = Thread.new { err_parent.read } if capture_stderr
- in_parent.write stdin_data.to_str
+ out_child.close if capture_output
+ err_child.close if capture_error
+ th_stdout = Thread.new { out_parent.read } if capture_output
+ th_stderr = Thread.new { err_parent.read } if capture_error
+ in_parent.write(input_data.to_str)
in_parent.close
- if (!capture_stdout || th_stdout.join(10)) && (!capture_stderr || th_stderr.join(10))
- stdout = th_stdout.value if capture_stdout
- stderr = th_stderr.value if capture_stderr
+ if (!capture_output || th_stdout.join(10)) &&
+ (!capture_error || th_stderr.join(10))
+ stdout = th_stdout.value if capture_output
+ stderr = th_stderr.value if capture_error
else
raise Timeout::Error
end
@@ -200,17 +206,20 @@ module GroongaTestUtils
def assert_run_groonga(test_stdout, test_stderr, args, *rest)
argnum = rest.size + 3
- opt = (Hash === rest.last ? rest.pop : {})
+ options = (Hash === rest.last ? rest.pop : {})
message = (rest.pop if String === rest.last)
if String === rest.last
- stdin = rest.pop
+ input = rest.pop
else
- stdin = opt.delete(:stdin) || ""
+ input = options.delete(:input) || ""
end
unless rest.empty?
raise ArgumentError, "wrong number of arguments (#{argnum} for 3)"
end
- stdout, stderr, status = invoke_groonga(args, stdin, true, true, opt)
+ args << options.merge(:input => stdin,
+ :capture_output => true,
+ :capture_error => true)
+ stdout, stderr, status = invoke_groonga(*args)
assert_not_predicate(status, :signaled?)
if block_given?
yield(stdout, stderr)