@@ -49,6 +49,7 @@ start(Options) ->
49
49
50
50
init (Options ) ->
51
51
St = # state {verbose = proplists :get_bool (verbose , Options )},
52
+ put (no_tty , proplists :get_bool (no_tty , Options )),
52
53
receive
53
54
{start , _Reference } ->
54
55
if St # state .verbose -> print_header ();
@@ -64,30 +65,30 @@ terminate({ok, Data}, St) ->
64
65
Cancel = proplists :get_value (cancel , Data , 0 ),
65
66
if Fail =:= 0 , Skip =:= 0 , Cancel =:= 0 ->
66
67
if Pass =:= 0 ->
67
- io : fwrite (" There were no tests to run.\n " );
68
+ fwrite (" There were no tests to run.\n " );
68
69
true ->
69
70
if St # state .verbose -> print_bar ();
70
71
true -> ok
71
72
end ,
72
73
if Pass =:= 1 ->
73
- io : fwrite (" Test passed.\n " );
74
+ fwrite (" Test passed.\n " );
74
75
true ->
75
- io : fwrite (" All ~w tests passed.\n " , [Pass ])
76
+ fwrite (" All ~w tests passed.\n " , [Pass ])
76
77
end
77
78
end ,
78
79
sync_end (ok );
79
80
true ->
80
81
print_bar (),
81
- io : fwrite (" Failed: ~w . Skipped: ~w . Passed: ~w .\n " ,
82
- [Fail , Skip , Pass ]),
82
+ fwrite (" Failed: ~w . Skipped: ~w . Passed: ~w .\n " ,
83
+ [Fail , Skip , Pass ]),
83
84
if Cancel =/= 0 ->
84
- io : fwrite (" One or more tests were cancelled.\n " );
85
+ fwrite (" One or more tests were cancelled.\n " );
85
86
true -> ok
86
87
end ,
87
88
sync_end (error )
88
89
end ;
89
90
terminate ({error , Reason }, _St ) ->
90
- io : fwrite (" Internal error: ~P .\n " , [Reason , 25 ]),
91
+ fwrite (" Internal error: ~P .\n " , [Reason , 25 ]),
91
92
sync_end (error ).
92
93
93
94
sync_end (Result ) ->
@@ -98,10 +99,10 @@ sync_end(Result) ->
98
99
end .
99
100
100
101
print_header () ->
101
- io : fwrite (" ======================== EUnit ========================\n " ).
102
+ fwrite (" ======================== EUnit ========================\n " ).
102
103
103
104
print_bar () ->
104
- io : fwrite (" =======================================================\n " ).
105
+ fwrite (" =======================================================\n " ).
105
106
106
107
107
108
handle_begin (group , Data , St ) ->
@@ -175,18 +176,18 @@ handle_cancel(test, Data, St) ->
175
176
176
177
177
178
indent (N ) when is_integer (N ), N >= 1 ->
178
- io : put_chars (lists :duplicate (N * 2 , $\s ));
179
+ fwrite (lists :duplicate (N * 2 , $\s ));
179
180
indent (_N ) ->
180
181
ok .
181
182
182
183
print_group_start (I , Desc ) ->
183
184
indent (I ),
184
- io : fwrite (" ~s \n " , [Desc ]).
185
+ fwrite (" ~s \n " , [Desc ]).
185
186
186
187
print_group_end (I , Time ) ->
187
188
if Time > 0 ->
188
189
indent (I ),
189
- io : fwrite (" [done in ~.3f s]\n " , [Time / 1000 ]);
190
+ fwrite (" [done in ~.3f s]\n " , [Time / 1000 ]);
190
191
true ->
191
192
ok
192
193
end .
@@ -203,46 +204,45 @@ print_test_begin(I, Data) ->
203
204
end ,
204
205
case proplists :get_value (source , Data ) of
205
206
{Module , Name , _Arity } ->
206
- io : fwrite (" ~s :~s ~s~s ..." , [Module , L , Name , D ]);
207
+ fwrite (" ~s :~s ~s~s ..." , [Module , L , Name , D ]);
207
208
_ ->
208
- io : fwrite (" ~s~s ..." , [L , D ])
209
+ fwrite (" ~s~s ..." , [L , D ])
209
210
end .
210
211
211
212
print_test_end (Data ) ->
212
213
Time = proplists :get_value (time , Data , 0 ),
213
214
T = if Time > 0 -> io_lib :fwrite (" [~.3f s] " , [Time / 1000 ]);
214
215
true -> " "
215
216
end ,
216
- io : fwrite (" ~s ok\n " , [T ]).
217
+ fwrite (" ~s ok\n " , [T ]).
217
218
218
219
print_test_error ({error , Exception }, Data ) ->
219
220
Output = proplists :get_value (output , Data ),
220
- io :fwrite (" *failed*\n ::~s " ,
221
- [eunit_lib :format_exception (Exception )]),
221
+ fwrite (" *failed*\n ::~s " , [eunit_lib :format_exception (Exception )]),
222
222
case Output of
223
223
<<>> ->
224
- io : put_chars (" \n\n " );
224
+ fwrite (" \n\n " );
225
225
<<Text :800 /binary , _ :1 /binary , _ /binary >> ->
226
- io : fwrite (" output:<<\" ~s \" >>...\n\n " , [Text ]);
226
+ fwrite (" output:<<\" ~s \" >>...\n\n " , [Text ]);
227
227
_ ->
228
- io : fwrite (" output:<<\" ~s \" >>\n\n " , [Output ])
228
+ fwrite (" output:<<\" ~s \" >>\n\n " , [Output ])
229
229
end ;
230
230
print_test_error ({skipped , Reason }, _ ) ->
231
- io : fwrite (" *did not run*\n ::~s \n " , [format_skipped (Reason )]).
231
+ fwrite (" *did not run*\n ::~s \n " , [format_skipped (Reason )]).
232
232
233
233
format_skipped ({module_not_found , M }) ->
234
- io_lib :format (" missing module: ~w " , [M ]);
234
+ io_lib :fwrite (" missing module: ~w " , [M ]);
235
235
format_skipped ({no_such_function , {M ,F ,A }}) ->
236
- io_lib :format (" no such function: ~w :~w /~w " , [M ,F ,A ]).
236
+ io_lib :fwrite (" no such function: ~w :~w /~w " , [M ,F ,A ]).
237
237
238
238
print_test_cancel (Reason ) ->
239
- io : fwrite (format_cancel (Reason )).
239
+ fwrite (format_cancel (Reason )).
240
240
241
241
print_group_cancel (_I , {blame , _ }) ->
242
242
ok ;
243
243
print_group_cancel (I , Reason ) ->
244
244
indent (I ),
245
- io : fwrite (format_cancel (Reason )).
245
+ fwrite (format_cancel (Reason )).
246
246
247
247
format_cancel (undefined ) ->
248
248
" *skipped*\n " ;
@@ -258,3 +258,12 @@ format_cancel({exit, Reason}) ->
258
258
[Reason , 15 ]);
259
259
format_cancel ({abort , Reason }) ->
260
260
eunit_lib :format_error (Reason ).
261
+
262
+ fwrite (String ) ->
263
+ fwrite (String , []).
264
+
265
+ fwrite (String , Args ) ->
266
+ case get (no_tty ) of
267
+ false -> io :fwrite (String , Args );
268
+ true -> ok
269
+ end .
0 commit comments