diff --git a/Library/Homebrew/test/utils/popen_spec.rb b/Library/Homebrew/test/utils/popen_spec.rb index c3f6027cf7..dcce91d8b4 100644 --- a/Library/Homebrew/test/utils/popen_spec.rb +++ b/Library/Homebrew/test/utils/popen_spec.rb @@ -26,11 +26,49 @@ describe Utils do end describe "::popen_write" do - it "with supports writing to a command's standard input" do + let(:foo) { mktmpdir/"foo" } + + before { foo.write "Foo\n" } + + it "supports writing to a command's standard input" do subject.popen_write("grep", "-q", "success") do |pipe| - pipe.write("success\n") + pipe.write "success\n" end expect($CHILD_STATUS).to be_a_success end + + it "returns the command's standard output before writing" do + child_stdout = subject.popen_write("cat", foo, "-") do |pipe| + pipe.write "Bar\n" + end + expect($CHILD_STATUS).to be_a_success + expect(child_stdout).to eq <<~EOS + Foo + Bar + EOS + end + + it "returns the command's standard output after writing" do + child_stdout = subject.popen_write("cat", "-", foo) do |pipe| + pipe.write "Bar\n" + end + expect($CHILD_STATUS).to be_a_success + expect(child_stdout).to eq <<~EOS + Bar + Foo + EOS + end + + it "supports interleaved writing between two reads" do + child_stdout = subject.popen_write("cat", foo, "-", foo) do |pipe| + pipe.write "Bar\n" + end + expect($CHILD_STATUS).to be_a_success + expect(child_stdout).to eq <<~EOS + Foo + Bar + Foo + EOS + end end end