@@ -5,7 +5,6 @@ defmodule Benchee.SystemTest do
55 import Benchee.System
66
77 alias Benchee.Suite
8- alias Benchee.System
98 alias Benchee.Utility.ErlangVersion
109
1110 test ".system adds the content to a given suite" do
@@ -104,20 +103,32 @@ defmodule Benchee.SystemTest do
104103 assert rest =~ ~r/ GB/
105104 end
106105
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
109109
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
114118
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
117123
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
121132 end
122133
123134 describe "all_protocols_consolidated?/1" do
@@ -157,7 +168,7 @@ defmodule Benchee.SystemTest do
157168 end
158169 end
159170
160- @ system % System {
171+ @ system % Benchee. System{
161172 elixir: "1.4.0" ,
162173 erlang: "19.1" ,
163174 jit_enabled?: false ,
0 commit comments