Skip to content

Commit

Permalink
Merge pull request #4934 from reitermarkus/system_command-merged_output
Browse files Browse the repository at this point in the history
Add `SystemCommand::Result#merged_output`.
  • Loading branch information
reitermarkus committed Sep 19, 2018
2 parents f1a2fa5 + 91b0794 commit d8f5348
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
5 changes: 5 additions & 0 deletions Library/Homebrew/system_command.rb
Expand Up @@ -185,6 +185,11 @@ def stderr
.join
end

def merged_output
@merged_output ||= @output.map { |_, line| line }
.join
end

def success?
@exit_status.zero?
end
Expand Down
49 changes: 32 additions & 17 deletions Library/Homebrew/test/system_command_result_spec.rb
@@ -1,32 +1,47 @@
require "system_command"

describe SystemCommand::Result do
describe "#to_ary" do
let(:output) {
[
[:stdout, "output"],
[:stderr, "error"],
]
}
subject(:result) {
described_class.new([], output, instance_double(Process::Status, exitstatus: 0, success?: true))
}
let(:output_array) {
[
[:stdout, "output\n"],
[:stderr, "error\n"],
]
}
subject(:result) {
described_class.new([], output_array, instance_double(Process::Status, exitstatus: 0, success?: true))
}

describe "#to_ary" do
it "can be destructed like `Open3.capture3`" do
out, err, status = result

expect(out).to eq "output"
expect(err).to eq "error"
expect(out).to eq "output\n"
expect(err).to eq "error\n"
expect(status).to be_a_success
end
end

describe "#plist" do
subject {
described_class.new(command, [[:stdout, stdout]], instance_double(Process::Status, exitstatus: 0)).plist
}
describe "#stdout" do
it "returns the standard output" do
expect(result.stdout).to eq "output\n"
end
end

let(:command) { ["true"] }
describe "#stderr" do
it "returns the standard error output" do
expect(result.stderr).to eq "error\n"
end
end

describe "#merged_output" do
it "returns the combined standard and standard error output" do
expect(result.merged_output).to eq "output\nerror\n"
end
end

describe "#plist" do
subject { result.plist }
let(:output_array) { [[:stdout, stdout]] }
let(:garbage) {
<<~EOS
Hello there! I am in no way XML am I?!?!
Expand Down

0 comments on commit d8f5348

Please sign in to comment.