mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Add test for SystemCommand
with SIGINT
handler.
This commit is contained in:
parent
3db55d13d6
commit
2dd40720f0
@ -165,34 +165,37 @@ RSpec.configure do |config|
|
|||||||
|
|
||||||
config.around do |example|
|
config.around do |example|
|
||||||
def find_files
|
def find_files
|
||||||
|
return [] unless File.exist?(TEST_TMPDIR)
|
||||||
|
|
||||||
Find.find(TEST_TMPDIR)
|
Find.find(TEST_TMPDIR)
|
||||||
.reject { |f| File.basename(f) == ".DS_Store" }
|
.reject { |f| File.basename(f) == ".DS_Store" }
|
||||||
|
.reject { |f| TEST_DIRECTORIES.include?(Pathname(f)) }
|
||||||
.map { |f| f.sub(TEST_TMPDIR, "") }
|
.map { |f| f.sub(TEST_TMPDIR, "") }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Homebrew.raise_deprecation_exceptions = true
|
||||||
|
|
||||||
|
Formulary.clear_cache
|
||||||
|
Tap.clear_cache
|
||||||
|
DependencyCollector.clear_cache
|
||||||
|
Formula.clear_cache
|
||||||
|
Keg.clear_cache
|
||||||
|
Tab.clear_cache
|
||||||
|
FormulaInstaller.clear_attempted
|
||||||
|
FormulaInstaller.clear_installed
|
||||||
|
|
||||||
|
TEST_DIRECTORIES.each(&:mkpath)
|
||||||
|
|
||||||
|
@__homebrew_failed = Homebrew.failed?
|
||||||
|
|
||||||
|
@__files_before_test = find_files
|
||||||
|
|
||||||
|
@__env = ENV.to_hash # dup doesn't work on ENV
|
||||||
|
|
||||||
|
@__stdout = $stdout.clone
|
||||||
|
@__stderr = $stderr.clone
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Homebrew.raise_deprecation_exceptions = true
|
|
||||||
|
|
||||||
Formulary.clear_cache
|
|
||||||
Tap.clear_cache
|
|
||||||
DependencyCollector.clear_cache
|
|
||||||
Formula.clear_cache
|
|
||||||
Keg.clear_cache
|
|
||||||
Tab.clear_cache
|
|
||||||
FormulaInstaller.clear_attempted
|
|
||||||
FormulaInstaller.clear_installed
|
|
||||||
|
|
||||||
TEST_DIRECTORIES.each(&:mkpath)
|
|
||||||
|
|
||||||
@__homebrew_failed = Homebrew.failed?
|
|
||||||
|
|
||||||
@__files_before_test = find_files
|
|
||||||
|
|
||||||
@__env = ENV.to_hash # dup doesn't work on ENV
|
|
||||||
|
|
||||||
@__stdout = $stdout.clone
|
|
||||||
@__stderr = $stderr.clone
|
|
||||||
|
|
||||||
if (example.metadata.keys & [:focus, :byebug]).empty? && !ENV.key?("VERBOSE_TESTS")
|
if (example.metadata.keys & [:focus, :byebug]).empty? && !ENV.key?("VERBOSE_TESTS")
|
||||||
$stdout.reopen(File::NULL)
|
$stdout.reopen(File::NULL)
|
||||||
$stderr.reopen(File::NULL)
|
$stderr.reopen(File::NULL)
|
||||||
@ -224,7 +227,7 @@ RSpec.configure do |config|
|
|||||||
Tab.clear_cache
|
Tab.clear_cache
|
||||||
|
|
||||||
FileUtils.rm_rf [
|
FileUtils.rm_rf [
|
||||||
TEST_DIRECTORIES.map(&:children),
|
*TEST_DIRECTORIES,
|
||||||
*Keg::MUST_EXIST_SUBDIRECTORIES,
|
*Keg::MUST_EXIST_SUBDIRECTORIES,
|
||||||
HOMEBREW_LINKED_KEGS,
|
HOMEBREW_LINKED_KEGS,
|
||||||
HOMEBREW_PINNED_KEGS,
|
HOMEBREW_PINNED_KEGS,
|
||||||
|
@ -281,5 +281,28 @@ describe SystemCommand do
|
|||||||
}.to raise_error.with_message(redacted_msg).and output(redacted_msg).to_stderr
|
}.to raise_error.with_message(redacted_msg).and output(redacted_msg).to_stderr
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when a `SIGINT` handler is set in the parent process" do
|
||||||
|
it "is not interrupted" do
|
||||||
|
start_time = Time.now
|
||||||
|
|
||||||
|
pid = fork do
|
||||||
|
trap("INT") do
|
||||||
|
# Ignore SIGINT.
|
||||||
|
end
|
||||||
|
|
||||||
|
described_class.run! "sleep", args: [5]
|
||||||
|
|
||||||
|
exit!
|
||||||
|
end
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
Process.kill("INT", pid)
|
||||||
|
|
||||||
|
Process.waitpid(pid)
|
||||||
|
|
||||||
|
expect(Time.now - start_time).to be >= 5
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user