-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return errors on missing commands rather than raise
This makes it possible for the caller to decide whether a missing command should crash. This is different from the semantics of System.cmd/3 and MuonTrap.cmd/3, but it's so convenient so long as we don't run into a command that does useful work and returns failure exit statuses. To help prevent that, the exit status on missing command is 256 which should be unusual. This also adds tests and documentation for posterity.
- Loading branch information
Showing
2 changed files
with
57 additions
and
17 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,25 @@ | ||
defmodule VintageNet.CommandTest do | ||
use ExUnit.Case | ||
doctest VintageNet.Command | ||
alias VintageNet.Command | ||
|
||
# See test/fixtures/root for what commands are available | ||
|
||
test "cmd" do | ||
assert {"hello\n", 0} = Command.cmd("echo", ["hello"]) | ||
assert {"", 1} = Command.cmd("false", []) | ||
assert {_reason, 256} = Command.cmd("missing_command", []) | ||
end | ||
|
||
test "muon_cmd" do | ||
assert {"hello\n", 0} = Command.muon_cmd("echo", ["hello"]) | ||
assert {"", 1} = Command.muon_cmd("false", []) | ||
assert {_reason, 256} = Command.cmd("missing_command", []) | ||
end | ||
|
||
test "PATH overridden with VintageNet's version" do | ||
expected_path = Application.get_env(:vintage_net, :path) | ||
assert {expected_path <> "\n", 0} == Command.cmd("sh", ["-c", "echo $PATH"]) | ||
assert {expected_path <> "\n", 0} == Command.muon_cmd("sh", ["-c", "echo $PATH"]) | ||
end | ||
end |