aboutsummaryrefslogtreecommitdiffstats
path: root/lib/test_server/src/test_server.erl
diff options
context:
space:
mode:
authorPeter Andersson <[email protected]>2016-03-08 01:40:19 +0100
committerPeter Andersson <[email protected]>2016-03-08 09:36:20 +0100
commit9b9879b1ccbeff9ec87494ba7ed59273d679740e (patch)
tree605c8edf298887a7eb36b57468f2a97fe84bdf4c /lib/test_server/src/test_server.erl
parent7a05d84c9d6664573a34485e3441b3c9542ed25b (diff)
downloadotp-9b9879b1ccbeff9ec87494ba7ed59273d679740e.tar.gz
otp-9b9879b1ccbeff9ec87494ba7ed59273d679740e.tar.bz2
otp-9b9879b1ccbeff9ec87494ba7ed59273d679740e.zip
Fix problems with formatted test_server printouts
Diffstat (limited to 'lib/test_server/src/test_server.erl')
-rw-r--r--lib/test_server/src/test_server.erl109
1 files changed, 58 insertions, 51 deletions
diff --git a/lib/test_server/src/test_server.erl b/lib/test_server/src/test_server.erl
index 538f8abbae..67c3eff440 100644
--- a/lib/test_server/src/test_server.erl
+++ b/lib/test_server/src/test_server.erl
@@ -732,15 +732,10 @@ do_call_end_conf(Starter,Mod,Func,Data,Conf,TVal) ->
try apply(Mod,end_per_testcase,[Func,Conf]) of
_ -> ok
catch
- _:Why ->
+ _:Error ->
timer:sleep(1),
- WhyStr = test_server_ctrl:escape_chars(
- io_lib:format("~tp", [Why])),
- group_leader() ! {printout,12,
- "WARNING! "
- "~w:end_per_testcase(~w, ~p)"
- " crashed!\n\tReason: ~ts\n",
- [Mod,Func,Conf,WhyStr]}
+ print_end_conf_result(Mod,Func,Conf,
+ "crashed",Error)
end,
Supervisor ! {self(),end_conf}
end,
@@ -749,12 +744,7 @@ do_call_end_conf(Starter,Mod,Func,Data,Conf,TVal) ->
{Pid,end_conf} ->
Starter ! {self(),{call_end_conf,Data,ok}};
{'EXIT',Pid,Reason} ->
- ReasonStr = test_server_ctrl:escape_chars(
- io_lib:format("~tp", [Reason])),
- group_leader() ! {printout,12,
- "WARNING! ~w:end_per_testcase(~w, ~p)"
- " failed!\n\tReason: ~ts\n",
- [Mod,Func,Conf,ReasonStr]},
+ print_end_conf_result(Mod,Func,Conf,"failed",Reason),
Starter ! {self(),{call_end_conf,Data,{error,Reason}}};
{'EXIT',_OtherPid,Reason} ->
%% Probably the parent - not much to do about that
@@ -763,6 +753,22 @@ do_call_end_conf(Starter,Mod,Func,Data,Conf,TVal) ->
end,
spawn_link(EndConfProc).
+print_end_conf_result(Mod,Func,Conf,Cause,Error) ->
+ Str2Print =
+ fun(NoHTML) when NoHTML == stdout; NoHTML == major ->
+ io_lib:format("WARNING! "
+ "~w:end_per_testcase(~w, ~tp)"
+ " ~s!\n\tReason: ~tp\n",
+ [Mod,Func,Conf,Cause,Error]);
+ (minor) ->
+ ErrorStr = test_server_ctrl:escape_chars(Error),
+ io_lib:format("WARNING! "
+ "~w:end_per_testcase(~w, ~tp)"
+ " ~s!\n\tReason: ~ts\n",
+ [Mod,Func,Conf,Cause,ErrorStr])
+ end,
+ group_leader() ! {printout,12,Str2Print}.
+
spawn_fw_call(Mod,{init_per_testcase,Func},CurrConf,Pid,
{timetrap_timeout,TVal}=Why,
Loc,SendTo) ->
@@ -1203,11 +1209,9 @@ do_init_per_testcase(Mod, Args) ->
[] ->
{ok,NewConf};
Bad ->
- ErrorStr =
- test_server_ctrl:escape_chars(
- io_lib:format("ERROR! init_per_testcase has returned "
- "bad elements in Config: ~p\n",[Bad])),
- group_leader() ! {printout,12,ErrorStr,[]},
+ group_leader() ! {printout,12,
+ "ERROR! init_per_testcase has returned "
+ "bad elements in Config: ~tp\n",[Bad]},
{skip,{failed,{Mod,init_per_testcase,bad_return}}}
end;
{fail,_Reason}=Res ->
@@ -1225,31 +1229,33 @@ do_init_per_testcase(Mod, Args) ->
throw:Other ->
set_loc(erlang:get_stacktrace()),
Line = get_loc(),
- FormattedLoc = test_server_sup:format_loc(Line),
- ReasonStr =
- test_server_ctrl:escape_chars(io_lib:format("~tp", [Other])),
- ErrorStr =
- io_lib:format("ERROR! init_per_testcase thrown!\n"
- "\tLocation: ~ts\n\tReason: ~ts\n",
- [FormattedLoc,ReasonStr]),
- group_leader() ! {printout,12,ErrorStr,[]},
+ print_init_conf_result(Line,"thrown",Other),
{skip,{failed,{Mod,init_per_testcase,Other}}};
_:Reason0 ->
Stk = erlang:get_stacktrace(),
Reason = {Reason0,Stk},
set_loc(Stk),
Line = get_loc(),
- FormattedLoc = test_server_sup:format_loc(Line),
- ReasonStr =
- test_server_ctrl:escape_chars(io_lib:format("~tp", [Reason])),
- ErrorStr =
- io_lib:format("ERROR! init_per_testcase crashed!\n"
- "\tLocation: ~ts\n\tReason: ~ts\n",
- [FormattedLoc,ReasonStr]),
- group_leader() ! {printout,12,ErrorStr,[]},
+ print_init_conf_result(Line,"crashed",Reason),
{skip,{failed,{Mod,init_per_testcase,Reason}}}
end.
+print_init_conf_result(Line,Cause,Reason) ->
+ FormattedLoc = test_server_sup:format_loc(Line),
+ Str2Print =
+ fun(NoHTML) when NoHTML == stdout; NoHTML == major ->
+ io_lib:format("ERROR! init_per_testcase ~s!\n"
+ "\tLocation: ~p\n\tReason: ~tp\n",
+ [Cause,Line,Reason]);
+ (minor) ->
+ ReasonStr = test_server_ctrl:escape_chars(Reason),
+ io_lib:format("ERROR! init_per_testcase ~s!\n"
+ "\tLocation: ~ts\n\tReason: ~ts\n",
+ [Cause,FormattedLoc,ReasonStr])
+ end,
+ group_leader() ! {printout,12,Str2Print}.
+
+
end_per_testcase(Mod, Func, Conf) ->
case erlang:function_exported(Mod,end_per_testcase,2) of
true ->
@@ -1284,14 +1290,7 @@ do_end_per_testcase(Mod,EndFunc,Func,Conf) ->
comment(io_lib:format("~ts<font color=\"red\">"
"WARNING: ~w thrown!"
"</font>\n",[Comment0,EndFunc])),
- ReasonStr =
- test_server_ctrl:escape_chars(io_lib:format("~tp", [Other])),
- group_leader() ! {printout,12,
- "WARNING: ~w thrown!\n"
- "Reason: ~ts\n"
- "Line: ~ts\n",
- [EndFunc, ReasonStr,
- test_server_sup:format_loc(get_loc())]},
+ print_end_tc_warning(EndFunc,Other,"thrown",get_loc()),
{failed,{Mod,end_per_testcase,Other}};
Class:Reason ->
Stk = erlang:get_stacktrace(),
@@ -1308,17 +1307,25 @@ do_end_per_testcase(Mod,EndFunc,Func,Conf) ->
comment(io_lib:format("~ts<font color=\"red\">"
"WARNING: ~w crashed!"
"</font>\n",[Comment0,EndFunc])),
- ReasonStr =
- test_server_ctrl:escape_chars(io_lib:format("~tp", [Reason])),
- group_leader() ! {printout,12,
- "WARNING: ~w crashed!\n"
- "Reason: ~ts\n"
- "Line: ~ts\n",
- [EndFunc, ReasonStr,
- test_server_sup:format_loc(get_loc())]},
+ print_end_tc_warning(EndFunc,Reason,"crashed",get_loc()),
{failed,{Mod,end_per_testcase,Why}}
end.
+print_end_tc_warning(EndFunc,Reason,Cause,Loc) ->
+ FormattedLoc = test_server_sup:format_loc(Loc),
+ Str2Print =
+ fun(NoHTML) when NoHTML == stdout; NoHTML == major ->
+ io_lib:format("WARNING: ~w ~s!\n"
+ "Reason: ~tp\nLine: ~p\n",
+ [EndFunc,Cause,Reason,Loc]);
+ (minor) ->
+ ReasonStr = test_server_ctrl:escape_chars(Reason),
+ io_lib:format("WARNING: ~w ~s!\n"
+ "Reason: ~ts\nLine: ~ts\n",
+ [EndFunc,Cause,ReasonStr,FormattedLoc])
+ end,
+ group_leader() ! {printout,12,Str2Print}.
+
get_loc() ->
get(test_server_loc).