Allow passing spawn options to sh - close #153

This commit is contained in:
Josh Holtrop 2022-02-06 14:02:26 -05:00
parent 8b2387f7a3
commit 6d5f44d4e5
6 changed files with 18 additions and 6 deletions

View File

@ -0,0 +1,3 @@
default do
sh "pwd", chdir: "src"
end

View File

@ -211,6 +211,7 @@ module Rscons
if command.last.is_a?(Hash)
options = command.slice!(-1)
end
continue = options.delete(:continue)
if command.size == 1 && command[0].is_a?(Array)
command = command[0]
end
@ -222,10 +223,10 @@ module Rscons
end
end
begin
system(*command, exception: true)
system(*command, options.merge(exception: true))
rescue StandardError => e
message = "#{e.backtrace[2]}: #{e.message}"
if options[:continue]
if continue
Ansi.write($stderr, :red, message, :reset, "\n")
else
raise RsconsError.new(message)

View File

@ -2789,7 +2789,7 @@ EOF
context "sh method" do
it "executes the command given" do
test_dir "sh"
test_dir "typical"
result = run_rscons(args: %w[-f sh.rb])
expect(result.stderr).to eq ""
expect(result.status).to eq 0
@ -2799,8 +2799,16 @@ EOF
])
end
it "changes directory to execute the requested command" do
test_dir "typical"
result = run_rscons(args: %w[-f sh_chdir.rb])
expect(result.stderr).to eq ""
expect(result.status).to eq 0
expect(result.stdout).to match %r{/src$}
end
it "prints the command when executing verbosely" do
test_dir "sh"
test_dir "typical"
result = run_rscons(args: %w[-f sh.rb -v])
expect(result.stderr).to eq ""
expect(result.status).to eq 0
@ -2813,7 +2821,7 @@ EOF
end
it "terminates execution on failure" do
test_dir "sh"
test_dir "typical"
result = run_rscons(args: %w[-f sh_fail.rb])
expect(result.stderr).to match /sh_fail\.rb:2:.*foobar42/
expect(result.status).to_not eq 0
@ -2821,7 +2829,7 @@ EOF
end
it "continues execution on failure when :continue option is set" do
test_dir "sh"
test_dir "typical"
result = run_rscons(args: %w[-f sh_fail_continue.rb])
expect(result.stderr).to match /sh_fail_continue\.rb:2:.*foobar42/
expect(result.status).to eq 0