Use Open3
for integration tests instead of manually forking.
This commit is contained in:
parent
9aa4888d2b
commit
956daf37a0
@ -217,6 +217,10 @@ class Keg
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def require_relocation?
|
||||||
|
# no-op
|
||||||
|
end
|
||||||
|
|
||||||
def linked?
|
def linked?
|
||||||
linked_keg_record.symlink? &&
|
linked_keg_record.symlink? &&
|
||||||
linked_keg_record.directory? &&
|
linked_keg_record.directory? &&
|
||||||
|
@ -14,7 +14,7 @@ class IntegrationCommandTestBottle < IntegrationCommandTestCase
|
|||||||
FileUtils.ln_s "not-exist", "symlink"
|
FileUtils.ln_s "not-exist", "symlink"
|
||||||
end
|
end
|
||||||
assert_match(/testball-0\.1.*\.bottle\.tar\.gz/,
|
assert_match(/testball-0\.1.*\.bottle\.tar\.gz/,
|
||||||
cmd_output("bottle", "--no-rebuild", "testball"))
|
cmd("bottle", "--no-rebuild", "testball"))
|
||||||
ensure
|
ensure
|
||||||
FileUtils.rm_f Dir["testball-0.1*.bottle.tar.gz"]
|
FileUtils.rm_f Dir["testball-0.1*.bottle.tar.gz"]
|
||||||
end
|
end
|
||||||
|
@ -9,7 +9,7 @@ class IntegrationCommandTestOptions < IntegrationCommandTestCase
|
|||||||
EOS
|
EOS
|
||||||
|
|
||||||
assert_equal "--with-foo\n\tBuild with foo\n--without-bar\n\tBuild without bar support",
|
assert_equal "--with-foo\n\tBuild with foo\n--without-bar\n\tBuild without bar support",
|
||||||
cmd_output("options", "testball").chomp
|
cmd("options", "testball").chomp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ require "fileutils"
|
|||||||
require "pathname"
|
require "pathname"
|
||||||
require "formula"
|
require "formula"
|
||||||
require "test/support/helper/test_case"
|
require "test/support/helper/test_case"
|
||||||
|
require "open3"
|
||||||
|
|
||||||
class IntegrationCommandTestCase < Homebrew::TestCase
|
class IntegrationCommandTestCase < Homebrew::TestCase
|
||||||
def setup
|
def setup
|
||||||
@ -28,57 +29,34 @@ class IntegrationCommandTestCase < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def cmd_output(*args)
|
def cmd_output(*args)
|
||||||
# 1.8-compatible way of writing def cmd_output(*args, **env)
|
|
||||||
env = args.last.is_a?(Hash) ? args.pop : {}
|
env = args.last.is_a?(Hash) ? args.pop : {}
|
||||||
cmd_args = %W[
|
|
||||||
-W0
|
|
||||||
-I#{HOMEBREW_LIBRARY_PATH}/test/support/lib
|
|
||||||
-I#{HOMEBREW_LIBRARY_PATH}
|
|
||||||
-rconfig
|
|
||||||
]
|
|
||||||
if ENV["HOMEBREW_TESTS_COVERAGE"]
|
|
||||||
# This is needed only because we currently use a patched version of
|
|
||||||
# simplecov, and gems installed through git are not available without
|
|
||||||
# requiring bundler/setup first. See also the comment in test/Gemfile.
|
|
||||||
# Remove this line when we'll switch back to a stable simplecov release.
|
|
||||||
cmd_args << "-rbundler/setup"
|
|
||||||
cmd_args << "-rsimplecov"
|
|
||||||
end
|
|
||||||
cmd_args << "-rtest/support/helper/integration_mocks"
|
|
||||||
cmd_args << (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path.to_s
|
|
||||||
cmd_args += args
|
|
||||||
developer = ENV["HOMEBREW_DEVELOPER"]
|
|
||||||
Bundler.with_original_env do
|
|
||||||
ENV["HOMEBREW_BREW_FILE"] = HOMEBREW_PREFIX/"bin/brew"
|
|
||||||
ENV["HOMEBREW_INTEGRATION_TEST"] = cmd_id_from_args(args)
|
|
||||||
ENV["HOMEBREW_TEST_TMPDIR"] = TEST_TMPDIR
|
|
||||||
ENV["HOMEBREW_DEVELOPER"] = developer
|
|
||||||
env.each_pair do |k, v|
|
|
||||||
ENV[k] = v
|
|
||||||
end
|
|
||||||
|
|
||||||
read, write = IO.pipe
|
env.merge!(
|
||||||
begin
|
"HOMEBREW_BREW_FILE" => HOMEBREW_PREFIX/"bin/brew",
|
||||||
pid = fork do
|
"HOMEBREW_INTEGRATION_TEST" => cmd_id_from_args(args),
|
||||||
read.close
|
"HOMEBREW_TEST_TMPDIR" => TEST_TMPDIR,
|
||||||
$stdout.reopen(write)
|
"HOMEBREW_DEVELOPER" => ENV["HOMEBREW_DEVELOPER"]
|
||||||
$stderr.reopen(write)
|
)
|
||||||
write.close
|
|
||||||
exec RUBY_PATH, *cmd_args
|
ruby_args = [
|
||||||
end
|
"-W0",
|
||||||
write.close
|
"-I", "#{HOMEBREW_LIBRARY_PATH}/test/support/lib",
|
||||||
read.read.chomp
|
"-I", HOMEBREW_LIBRARY_PATH.to_s,
|
||||||
ensure
|
"-rconfig"
|
||||||
Process.wait(pid)
|
]
|
||||||
read.close
|
ruby_args << "-rsimplecov" if ENV["HOMEBREW_TESTS_COVERAGE"]
|
||||||
end
|
ruby_args << "-rtest/support/helper/integration_mocks"
|
||||||
|
ruby_args << (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path.to_s
|
||||||
|
|
||||||
|
Bundler.with_original_env do
|
||||||
|
output, status = Open3.capture2e(env, RUBY_PATH, *ruby_args, *args)
|
||||||
|
[output.chomp, status]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def cmd(*args)
|
def cmd(*args)
|
||||||
output = cmd_output(*args)
|
output, status = cmd_output(*args)
|
||||||
status = $?.exitstatus
|
assert status.success?, <<-EOS.undent
|
||||||
assert_equal 0, status, <<-EOS.undent
|
|
||||||
`brew #{args.join " "}` exited with non-zero status!
|
`brew #{args.join " "}` exited with non-zero status!
|
||||||
#{output}
|
#{output}
|
||||||
EOS
|
EOS
|
||||||
@ -86,9 +64,8 @@ class IntegrationCommandTestCase < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def cmd_fail(*args)
|
def cmd_fail(*args)
|
||||||
output = cmd_output(*args)
|
output, status = cmd_output(*args)
|
||||||
status = $?.exitstatus
|
refute status.success?, <<-EOS.undent
|
||||||
refute_equal 0, status, <<-EOS.undent
|
|
||||||
`brew #{args.join " "}` exited with zero status!
|
`brew #{args.join " "}` exited with zero status!
|
||||||
#{output}
|
#{output}
|
||||||
EOS
|
EOS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user