-
-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove `#silence_build` method from `#exec.` * Tell the user what happened when a command fails. * Print both the command and error message for easier debugging. * Capture both STDOUT and STDERR in #exec. Commands may output important debugging information via either channel. Use `Open3.capture2e` instead of `Kernel.system`. It appears to be impossible to capture both `STDERR` and `STDOUT` simultaneously with the latter.
- Loading branch information
1 parent
87c65e3
commit f911bf0
Showing
4 changed files
with
76 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require "open3" | ||
|
||
module EmberCli | ||
class Runner | ||
def initialize(env: {}, out:, err:, options: {}) | ||
@env = env | ||
@out = out | ||
@err = err | ||
@options = options | ||
end | ||
|
||
def run!(command) | ||
output, status = Open3.capture2e(@env, command, @options) | ||
|
||
@out.write(output) | ||
|
||
unless status.success? | ||
@err.write <<-MSG.strip_heredoc | ||
ERROR: Failed command: `#{command}` | ||
OUTPUT: | ||
#{output} | ||
MSG | ||
|
||
exit 1 | ||
end | ||
|
||
true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require "ember_cli/runner" | ||
|
||
describe EmberCli::Runner do | ||
describe "#run!" do | ||
context "when the command fails" do | ||
it "writes STDERR and STDOUT to `err`" do | ||
out = StringIO.new | ||
err = StringIO.new | ||
runner = EmberCli::Runner.new(err: err, out: out) | ||
|
||
expect { runner.run!("echo 'out'; echo 'err' > /dev/stderr; exit 1") }. | ||
to raise_error(SystemExit) | ||
|
||
[err, out].each(&:rewind) | ||
|
||
expect(err.read).to match(/out\nerr/) | ||
expect(out.read).to eq("out\nerr\n") | ||
end | ||
end | ||
|
||
it "executes the command" do | ||
out = StringIO.new | ||
err = StringIO.new | ||
runner = EmberCli::Runner.new(err: err, out: out) | ||
|
||
runner.run!("echo 'out'") | ||
|
||
[err, out].each(&:rewind) | ||
|
||
expect(err.read).to be_empty | ||
expect(out.read).to eq("out\n") | ||
end | ||
end | ||
end |