@@ -5,7 +5,6 @@ defmodule Benchee.SystemTest do
5
5
import Benchee.System
6
6
7
7
alias Benchee.Suite
8
- alias Benchee.System
9
8
alias Benchee.Utility.ErlangVersion
10
9
11
10
test ".system adds the content to a given suite" do
@@ -104,20 +103,32 @@ defmodule Benchee.SystemTest do
104
103
assert rest =~ ~r/ GB/
105
104
end
106
105
107
- test ".system_cmd handles errors gracefully" do
108
- system_func = fn _ , _ -> { "ERROR" , 1 } end
106
+ describe ".system_cmd/3" do
107
+ test "handles error return values gracefully" do
108
+ system_func = fn _ , _ -> { "ERROR" , 1 } end
109
109
110
- captured_io =
111
- capture_io ( fn ->
112
- system_cmd ( "cat" , "dev/null" , system_func )
113
- end )
110
+ captured_io =
111
+ capture_io ( fn ->
112
+ system_cmd ( "cat" , "dev/null" , system_func ) == "N/A"
113
+ end )
114
+
115
+ assert captured_io =~ "Something went wrong"
116
+ assert captured_io =~ "ERROR"
117
+ end
114
118
115
- assert captured_io =~ "Something went wrong"
116
- assert captured_io =~ "ERROR"
119
+ # programs might not be installed or deprecated, see https://github.com/bencheeorg/benchee/issues/442
120
+ test "handles exceptions gracefully" do
121
+ # this raises an ERlang error: :enoent - but in case that changes I wanted to trigger it directly
122
+ system_func = fn _ , _ -> System . cmd ( "definitely-not-existing-command32832" , [ "bogus" ] ) end
117
123
118
- capture_io ( fn ->
119
- assert system_cmd ( "cat" , "dev/null" , system_func ) == "N/A"
120
- end )
124
+ captured_io =
125
+ capture_io ( fn ->
126
+ system_cmd ( "does" , "not/matter" , system_func ) == "N/A"
127
+ end )
128
+
129
+ assert captured_io =~ "Something went wrong"
130
+ assert captured_io =~ "enoent"
131
+ end
121
132
end
122
133
123
134
describe "all_protocols_consolidated?/1" do
@@ -157,7 +168,7 @@ defmodule Benchee.SystemTest do
157
168
end
158
169
end
159
170
160
- @ system % System {
171
+ @ system % Benchee. System{
161
172
elixir: "1.4.0" ,
162
173
erlang: "19.1" ,
163
174
jit_enabled?: false ,
0 commit comments