-
Notifications
You must be signed in to change notification settings - Fork 45
/
errors_test.exs
71 lines (56 loc) · 1.93 KB
/
errors_test.exs
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
defmodule PorcelainTest.ErrorsTest do
use ExUnit.Case
import Porcelain, only: [shell: 2, exec: 2]
alias Porcelain.Result
test "bad option" do
:ok = Porcelain.reinit(Porcelain.Driver.Basic)
msg = "Invalid options: [option: \"value\"]"
assert_raise Porcelain.UsageError, msg, fn ->
shell("whatever", option: "value")
end
msg = "Invalid options: [in: :receive]"
assert_raise Porcelain.UsageError, msg, fn ->
shell("whatever", in: :receive)
end
end
@tag :posix
test "non-existent program [basic, shell]" do
:ok = Porcelain.reinit(Porcelain.Driver.Basic)
result = shell("whatever", err: :out)
assert %Result{err: :out, out: <<_::binary>>, status: 127}
= result
assert result.out =~ ~r/whatever: .*?not found/
end
test "non-existent program [basic, noshell]" do
assert exec("whatever", [])
== {:error, "Command not found: whatever"}
assert Porcelain.spawn("whatever", [])
== {:error, "Command not found: whatever"}
end
@tag :posix
@tag :goon
test "non-existent program [goon, shell, redirect]" do
:ok = Porcelain.reinit(Porcelain.Driver.Goon)
result = shell("whatever", err: :out)
assert %Result{err: :out, out: <<_::binary>>, status: 127}
= result
assert result.out =~ ~r/whatever: .*?not found/
end
@tag :posix
@tag :goon
test "non-existent program [goon, shell]" do
:ok = Porcelain.reinit(Porcelain.Driver.Goon)
result = shell("whatever", err: :string)
assert %Result{err: <<_::binary>>, out: "", status: 127}
= result
assert result.err =~ ~r/whatever: .*?not found/
end
@tag :goon
test "non-existent program [goon, noshell]" do
:ok = Porcelain.reinit(Porcelain.Driver.Goon)
assert exec("whatever", [])
== {:error, "Command not found: whatever"}
assert Porcelain.spawn("whatever", [])
== {:error, "Command not found: whatever"}
end
end