aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/utils/popen_spec.rb
blob: e3704a876ad8e6433289c348ba86390c2bbf3dc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require "utils/popen"

describe Utils do
  describe "::popen_read" do
    it "reads the standard output of a given command" do
      expect(subject.popen_read("sh", "-c", "echo success").chomp).to eq("success")
      expect($?).to be_a_success
    end

    it "can be given a block to manually read from the pipe" do
      expect(
        subject.popen_read("sh", "-c", "echo success") do |pipe|
          pipe.read.chomp
        end,
      ).to eq("success")
      expect($?).to be_a_success
    end
  end

  describe "::popen_write" do
    it "with supports writing to a command's standard input" do
      subject.popen_write("grep", "-q", "success") do |pipe|
        pipe.write("success\n")
      end
      expect($?).to be_a_success
    end
  end
end