diff --git a/build_tests/sh/sh.rb b/build_tests/typical/sh.rb similarity index 100% rename from build_tests/sh/sh.rb rename to build_tests/typical/sh.rb diff --git a/build_tests/typical/sh_chdir.rb b/build_tests/typical/sh_chdir.rb new file mode 100644 index 0000000..c177a0b --- /dev/null +++ b/build_tests/typical/sh_chdir.rb @@ -0,0 +1,3 @@ +default do + sh "pwd", chdir: "src" +end diff --git a/build_tests/sh/sh_fail.rb b/build_tests/typical/sh_fail.rb similarity index 100% rename from build_tests/sh/sh_fail.rb rename to build_tests/typical/sh_fail.rb diff --git a/build_tests/sh/sh_fail_continue.rb b/build_tests/typical/sh_fail_continue.rb similarity index 100% rename from build_tests/sh/sh_fail_continue.rb rename to build_tests/typical/sh_fail_continue.rb diff --git a/lib/rscons/script.rb b/lib/rscons/script.rb index fc68cda..5bd85db 100644 --- a/lib/rscons/script.rb +++ b/lib/rscons/script.rb @@ -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) diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index b453fd5..7bb34d4 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -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