From 5df28a47b77d93164b18ea7599b089b521a80a10 Mon Sep 17 00:00:00 2001 From: Leif Gensert Date: Fri, 21 Feb 2025 09:36:31 -0800 Subject: [PATCH] Fix the stderr test The `BackticksRunner` and `PopenRunner` do not support outputs on `stderr`, therefore the spec that verifies whether large output on `stderr` hangs or not, doesn't make sense for these runners. The only reason it works on MRI is because the way the spec is written, selects the `ProcessRunner`. On JRuby the `ProcessRunner` is not supported, so it falls back to the `BackticksRunner` and then makes the spec fail. --- spec/support/nonblocking_examples.rb | 20 +++++++++---------- .../runners/backticks_runner_spec.rb | 2 +- .../command_line/runners/popen_runner_spec.rb | 2 +- .../runners/process_runner_spec.rb | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/spec/support/nonblocking_examples.rb b/spec/support/nonblocking_examples.rb index 4d1996b..46eb33b 100644 --- a/spec/support/nonblocking_examples.rb +++ b/spec/support/nonblocking_examples.rb @@ -1,15 +1,13 @@ -shared_examples_for "a command that does not block" do - it "does not block if the command output a lot on stderr" do - cmd = Terrapin::CommandLine.new( - "ruby", - "-e '$stdout.puts %{hello}; $stderr.puts %{goodbye}*10_000'", - :swallow_stderr => false - ) - Timeout.timeout(5) do - cmd.run +shared_examples_for "a command that does not block" do |opts = {}| + if opts[:supports_stderr] + it "does not block if the command output a lot on stderr" do + Timeout.timeout(5) do + output = subject.call("ruby -e '$stdout.puts %{hello}; $stderr.puts %{goodbye}*10_000'") + + expect(output.output).to eq "hello\n" + expect(output.error_output).to eq "#{"goodbye" * 10_000}\n" + end end - expect(cmd.command_output).to eq "hello\n" - expect(cmd.command_error_output).to eq "#{"goodbye" * 10_000}\n" end it 'does not block if the command outputs a lot of data' do diff --git a/spec/terrapin/command_line/runners/backticks_runner_spec.rb b/spec/terrapin/command_line/runners/backticks_runner_spec.rb index dea9a25..cced409 100644 --- a/spec/terrapin/command_line/runners/backticks_runner_spec.rb +++ b/spec/terrapin/command_line/runners/backticks_runner_spec.rb @@ -2,7 +2,7 @@ describe Terrapin::CommandLine::BackticksRunner do if Terrapin::CommandLine::BackticksRunner.supported? - it_behaves_like 'a command that does not block' + it_behaves_like 'a command that does not block', { :supports_stderr => false } it 'runs the command given and captures the output in an Output' do output = subject.call("echo hello") diff --git a/spec/terrapin/command_line/runners/popen_runner_spec.rb b/spec/terrapin/command_line/runners/popen_runner_spec.rb index 8e5d993..0b5ebec 100644 --- a/spec/terrapin/command_line/runners/popen_runner_spec.rb +++ b/spec/terrapin/command_line/runners/popen_runner_spec.rb @@ -2,7 +2,7 @@ describe Terrapin::CommandLine::PopenRunner do if Terrapin::CommandLine::PopenRunner.supported? - it_behaves_like 'a command that does not block' + it_behaves_like 'a command that does not block', { :supports_stderr => false } it 'runs the command given and captures the output in an Output' do output = subject.call("echo hello") diff --git a/spec/terrapin/command_line/runners/process_runner_spec.rb b/spec/terrapin/command_line/runners/process_runner_spec.rb index 91dfa0e..02945f9 100644 --- a/spec/terrapin/command_line/runners/process_runner_spec.rb +++ b/spec/terrapin/command_line/runners/process_runner_spec.rb @@ -2,7 +2,7 @@ describe Terrapin::CommandLine::ProcessRunner do if Terrapin::CommandLine::ProcessRunner.supported? - it_behaves_like "a command that does not block" + it_behaves_like "a command that does not block", { :supports_stderr => true } it 'runs the command given and captures the output' do output = subject.call("echo hello")