Skip to content

Commit df73e4a

Browse files
committed
CT: Add source filename in error output when possible
1 parent e8c5c86 commit df73e4a

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

lib/common_test/src/ct_framework.erl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,17 +1013,21 @@ error_notification(Mod,Func,_Args,{Error,Loc}) ->
10131013
%% if a function specified by all/0 does not exist, we
10141014
%% pick up undef here
10151015
[{LastMod,LastFunc}|_] when ErrorStr == "undef" ->
1016-
PrintError("~w:~tw could not be executed~nReason: ~ts",
1017-
[LastMod,LastFunc,ErrorStr]);
1016+
LastSource = error_notification_source_info(LastMod),
1017+
PrintError("~w:~tw at ~ts could not be executed~nReason: ~ts",
1018+
[LastMod,LastFunc,LastSource,ErrorStr]);
10181019

10191020
[{LastMod,LastFunc}|_] ->
1020-
PrintError("~w:~tw failed~nReason: ~ts", [LastMod,LastFunc,ErrorStr]);
1021+
LastSource = error_notification_source_info(LastMod),
1022+
PrintError("~w:~tw at ~ts failed~nReason: ~ts",
1023+
[LastMod,LastFunc,LastSource,ErrorStr]);
10211024

10221025
[{LastMod,LastFunc,LastLine}|_] ->
10231026
%% print error to console, we are only
10241027
%% interested in the last executed expression
1025-
PrintError("~w:~tw failed on line ~w~nReason: ~ts",
1026-
[LastMod,LastFunc,LastLine,ErrorStr]),
1028+
LastSource = error_notification_source_info(LastMod),
1029+
PrintError("~w:~tw at ~ts:~w failed~nReason: ~ts",
1030+
[LastMod,LastFunc,LastSource,LastLine,ErrorStr]),
10271031

10281032
case ct_util:read_suite_data({seq,Mod,Func}) of
10291033
undefined ->
@@ -1035,6 +1039,16 @@ error_notification(Mod,Func,_Args,{Error,Loc}) ->
10351039
end,
10361040
ok.
10371041

1042+
error_notification_source_info(Mod) ->
1043+
maybe
1044+
{Mod, Beam, _} ?= code:get_object_code(Mod),
1045+
{ok, {Mod, [{abstract_code, {_, Forms}}]}} ?= beam_lib:chunks(Beam, [abstract_code]),
1046+
[{attribute, _, file, {File, _}}|_] ?= Forms,
1047+
File
1048+
else
1049+
_ -> atom_to_list(Mod) ++ ".erl"
1050+
end.
1051+
10381052
%% cases in seq that have already run
10391053
mark_as_failed(Seq,Mod,Func,[Func|TCs]) ->
10401054
mark_as_failed1(Seq,Mod,Func,TCs);

0 commit comments

Comments
 (0)