diff --git a/build_tests/configure/custom_config_check.rb b/build_tests/configure/custom_config_check.rb index 769e510..a110626 100644 --- a/build_tests/configure/custom_config_check.rb +++ b/build_tests/configure/custom_config_check.rb @@ -17,6 +17,10 @@ configure do end op.complete(status, success_message: "good!", fail_message: fail_message, fail: should_fail) end + custom_check("Checking sed -E flag") do |op| + stdout, stderr, status = op.log_and_test_command(%w[sed -E -e s/ab+/rep/], stdin: "abbbc") + op.complete(stdout =~ /repc/ ? 0 : 1, success_message: "good", fail_message: "fail") + end end build do diff --git a/lib/rscons/configure_op.rb b/lib/rscons/configure_op.rb index 5fa57c8..986754d 100644 --- a/lib/rscons/configure_op.rb +++ b/lib/rscons/configure_op.rb @@ -280,12 +280,19 @@ module Rscons # Execute a test command and log the result. # + # @param command [Array] + # Command to execute. + # @param options [Hash] + # Optional arguments. + # @option options [String] :stdin + # Data to send to standard input stream of the executed command. + # # @return [String, String, Process::Status] # stdout, stderr, status - def log_and_test_command(command) + def log_and_test_command(command, options = {}) begin @log_fh.puts("Command: #{command.join(" ")}") - stdout, stderr, status = Open3.capture3(*command) + stdout, stderr, status = Open3.capture3(*command, stdin_data: options[:stdin]) @log_fh.puts("Exit status: #{status.to_i}") @log_fh.write(stdout) @log_fh.write(stderr) diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 11d5a38..09880f8 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -2189,6 +2189,14 @@ EOF expect(result.status).to eq 0 end end + + it "allows passing standard input data to the executed command" do + test_dir "configure" + result = run_rscons(rsconscript: "custom_config_check.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.stdout).to match /Checking sed -E flag\.\.\. good/ + expect(result.status).to eq 0 + end end end