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,12 +165,14 @@ RSpec.configure do |config|
|
||||
|
||||
config.around do |example|
|
||||
def find_files
|
||||
return [] unless File.exist?(TEST_TMPDIR)
|
||||
|
||||
Find.find(TEST_TMPDIR)
|
||||
.reject { |f| File.basename(f) == ".DS_Store" }
|
||||
.reject { |f| TEST_DIRECTORIES.include?(Pathname(f)) }
|
||||
.map { |f| f.sub(TEST_TMPDIR, "") }
|
||||
end
|
||||
|
||||
begin
|
||||
Homebrew.raise_deprecation_exceptions = true
|
||||
|
||||
Formulary.clear_cache
|
||||
@ -193,6 +195,7 @@ RSpec.configure do |config|
|
||||
@__stdout = $stdout.clone
|
||||
@__stderr = $stderr.clone
|
||||
|
||||
begin
|
||||
if (example.metadata.keys & [:focus, :byebug]).empty? && !ENV.key?("VERBOSE_TESTS")
|
||||
$stdout.reopen(File::NULL)
|
||||
$stderr.reopen(File::NULL)
|
||||
@ -224,7 +227,7 @@ RSpec.configure do |config|
|
||||
Tab.clear_cache
|
||||
|
||||
FileUtils.rm_rf [
|
||||
TEST_DIRECTORIES.map(&:children),
|
||||
*TEST_DIRECTORIES,
|
||||
*Keg::MUST_EXIST_SUBDIRECTORIES,
|
||||
HOMEBREW_LINKED_KEGS,
|
||||
HOMEBREW_PINNED_KEGS,
|
||||
|
@ -281,5 +281,28 @@ describe SystemCommand do
|
||||
}.to raise_error.with_message(redacted_msg).and output(redacted_msg).to_stderr
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user