Skip to content

Commit

Permalink
Emit non-fake shell name in TAP output
Browse files Browse the repository at this point in the history
  • Loading branch information
Håkan Mattsson committed Jul 21, 2021
1 parent d158bb7 commit 2a93d8f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 41 deletions.
7 changes: 3 additions & 4 deletions examples/require_fail.lux
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[doc Demonstrate an error]

[config require=MAKE]
[config require=YADA_MAKE]

[shell setup]
!$MAKE start

!${YADA_MAKE} start

[cleanup]
!$MAKE stop
!${YADA_MAKE} stop
8 changes: 4 additions & 4 deletions src/lux_case.erl
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ print_success(I, File) ->
success
end,
Results = [],
{ok, Outcome, File, FullLineNo, I#istate.case_log_dir,
{ok, Outcome, File, FullLineNo, no_shell, I#istate.case_log_dir,
RunWarnings, UnstableWarnings, Results,
<<>>, [{stopped_by_user, I#istate.stopped_by_user}]}.

Expand Down Expand Up @@ -642,7 +642,7 @@ print_fail(OldI0, NewI, File, Results,
[NewActual, lux_utils:to_string(NewRest)]),
Opaque = [{stopped_by_user,NewI#istate.stopped_by_user}],
NewResults = [Fail],
{ok, Outcome, File, FullLineNo, NewI#istate.case_log_dir,
{ok, Outcome, File, FullLineNo, ShellName, NewI#istate.case_log_dir,
RunWarnings, UnstableWarnings, NewResults,
FailBin, Opaque}.

Expand Down Expand Up @@ -719,7 +719,7 @@ filter_unstable(#istate{skip_skip = false, orig_file = File} = I,
false ->
false;
true ->
Format = "Fail but UNSTABLE as variable ~s is set",
Format = "FAIL but UNSTABLE as variable ~s is set",
Reason = format_val(Format, [Name], Val),
W = lux_utils:make_warning(File, FullLineNo, Reason),
progress_warnings(I, [W]),
Expand All @@ -731,7 +731,7 @@ filter_unstable(#istate{skip_skip = false, orig_file = File} = I,
true ->
false;
false ->
Format = "Fail but UNSTABLE as variable ~s is not set",
Format = "FAIL but UNSTABLE as variable ~s is not set",
Reason = format_val(Format, [Name], Val),
W = lux_utils:make_warning(File, FullLineNo, Reason),
progress_warnings(I, [W]),
Expand Down
15 changes: 11 additions & 4 deletions src/lux_log.erl
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,17 @@ pick_result(Results, Outcome) ->
end,
lists:foldl(Actual, Outcome, Events)
end,
[{Script, FullLineNo, Pick(Outcome, FailBin, Events)} ||
{ok, O, Script, FullLineNo, _LogDir,
Events, FailBin, _Opaque} <- Results,
O =:= Outcome].
MatchRes =
fun({ok, O, Script, FullLineNo, _S, _LD, Events, FailBin, _O}) ->
if
O =:= Outcome ->
{true, {Script, FullLineNo, Pick(O, FailBin, Events)}};
true ->
false
end
end,
OkRes = [R || R <- Results, element(1, R) =:= ok],
lists:zf(MatchRes, OkRes).

result_format(Progress, {IsTmp, Fd}, Format, Args) ->
IoList = ?FF(Format, Args),
Expand Down
82 changes: 53 additions & 29 deletions src/lux_suite.erl
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,8 @@ run_cases(R, [{SuiteFile, {error,Reason}, P, LenP}|Scripts],
?TRACE_ME(70, suite, 'case', SuiteFile, []),
tap_case_begin(R, SuiteFile),
?TRACE_ME(70, 'case', suite, error, [Reason]),
tap_case_end(R, R, CC, SuiteFile, P, LenP, Max, error, "0", Reason, Reason),
tap_case_end(R, R, CC, SuiteFile, P, LenP, Max, error,
"0", no_shell, Reason, Reason),
run_cases(R, Scripts, OldSummary, Results2, Max, CC+1, List, Opaque);
run_cases(OrigR, [{SuiteFile,{ok,Script}, P, LenP} | Scripts],
OldSummary, Results, Max, CC, List, Opaque) ->
Expand Down Expand Up @@ -640,16 +641,19 @@ run_cases(OrigR, [{SuiteFile,{ok,Script}, P, LenP} | Scripts],
Opts, Opaque),
SkipReason = "",
case Res of
{ok, Summary, _, FullLineNo, CaseLogDir,
{ok, Summary, _, FullLineNo, ShellName, CaseLogDir,
RunWarnings, UnstableWarnings, Events,
Details, NewOpaque} ->
NewRes = {ok, Summary, Script, FullLineNo,
CaseLogDir, Events, Details, Opaque},
NewRes = {ok, Summary, Script,
FullLineNo, ShellName,
CaseLogDir, Events,
Details, Opaque},
NewScripts = Scripts;
{error, MainFile, FullLineNo, CaseLogDir,
RunWarnings, UnstableWarnings, Details} ->
Summary = error,
NewOpaque = Opaque,
ShellName = no_shell,
NewRes = {error, MainFile, FullLineNo, Details},
NewScripts =
case Details of
Expand All @@ -666,7 +670,7 @@ run_cases(OrigR, [{SuiteFile,{ok,Script}, P, LenP} | Scripts],
NewR2 = NewR#rstate{warnings = AllWarnings},
tap_case_end(OrigR, NewR2, CC, Script,
P, LenP, Max, Summary,
FullLineNo, SkipReason, Details),
FullLineNo, ShellName, SkipReason, Details),
NewSummary = lux_utils:summary(OldSummary, Summary),
annotate_event_log(NewR2, Script, NewSummary,
CaseLogDir, Opts),
Expand Down Expand Up @@ -708,9 +712,10 @@ run_cases(OrigR, [{SuiteFile,{ok,Script}, P, LenP} | Scripts],
#cmd_pos{lineno = FullLineNo} = stack_error(ErrorStack, SkipReason),
tap_case_end(OrigR, NewR, CC, Script,
P, LenP, Max, Summary,
FullLineNo, ?b2l(SkipReason), <<>>),
FullLineNo, no_shell,
?b2l(SkipReason), <<>>),
NewSummary = lux_utils:summary(OldSummary, Summary),
Res = {ok, Summary, Script2, FullLineNo,
Res = {ok, Summary, Script2, FullLineNo, no_shell,
NewR#rstate.log_dir, [], SkipReason, []},
Results2 = [Res | Results],
ParseWarnings = NewR#rstate.warnings,
Expand Down Expand Up @@ -759,7 +764,7 @@ run_cases(OrigR, [{SuiteFile,{ok,Script}, P, LenP} | Scripts],
{ok, _} = lux_case:copy_orig(ErrR#rstate.log_dir, MainFile),
tap_case_end(OrigR, ErrR, CC, Script,
P, LenP, Max, Summary,
"0", ErrorBin, ErrorBin),
"0", no_shell, ErrorBin, ErrorBin),
NewWarnings = ErrR#rstate.warnings,
AllWarnings = OrigR#rstate.warnings ++ NewWarnings,
NewSummary = lux_utils:summary(OldSummary, Summary),
Expand Down Expand Up @@ -1306,14 +1311,14 @@ tap_case_begin(#rstate{}, _AbsScript) ->
tap_case_end(#rstate{},
#rstate{tap = undefined}, _CaseCount, _Script,
_P, _LenP, _Max,
_Result, _FullLineNo,
_Result, _FullLineNo, _ShellName,
_Reason, _Details) ->
ok;
tap_case_end(#rstate{warnings = OrigWarnings},
#rstate{tap = TAP, skip_skip = SkipSkip, warnings = Warnings},
CaseCount, _AbsScript,
P, LenP, Max,
Result, FullLineNo, Reason, Details) ->
Result, FullLineNo, ShellName, Reason, Details) ->
CaseCountStr = ?i2l(CaseCount),
PrefixLen = lists:min([4, 5-length(CaseCountStr)]),
Indent = lists:duplicate(PrefixLen, " "),
Expand All @@ -1335,28 +1340,47 @@ tap_case_end(#rstate{warnings = OrigWarnings},
end,
lux_tap:test(TAP, Outcome, Descr, Directive, Max-LenP),
NewWarnings = Warnings -- OrigWarnings,
lists:foreach(fun(W) -> tap_comment(TAP, W) end, NewWarnings),
case Details of
<<>> -> ignore;
_ -> tap_comment(TAP, {Result, dummy, FullLineNo, Details})
end.

tap_comment(TAP, #warning{file=File, lineno=FullLineNo, reason=Reason}) ->
Outcome = warning,
tap_comment(TAP, Outcome, File, FullLineNo, Reason);
tap_comment(TAP, {Outcome, _File, FullLineNo, Details}) ->
tap_comment(TAP, Outcome, _File, FullLineNo, Details).

tap_comment(TAP, Outcome, _File, FullLineNo, Details) ->
Prefix = ?b2l(?l2b([string:to_upper(?a2l(Outcome)),
" at line ", FullLineNo])),
TapComment =
fun(#warning{file=F, lineno=L, reason=R}) ->
tap_comment(TAP, prep, warning, F,
L, no_shell, R, [])
end,
lists:foreach(TapComment, NewWarnings),
tap_comment(TAP, final, Result, no_file,
FullLineNo, ShellName,
Details, Reason).

tap_comment(TAP, Context, Outcome, _File,
FullLineNo, OptShellName,
Details, Reason) ->
MakePrefix =
fun(O) ->
?b2l(?l2b([string:to_upper(?a2l(O)),
" at line ", FullLineNo]))
end,
case binary:split(Details, <<"\n">>, [global]) of
[<<>>] when Outcome =/= skip, Reason =/= "" ->
Prefix = MakePrefix(Outcome),
ok = lux_tap:diag(TAP, Prefix ++ " - " ++ Reason);
[<<>>] ->
ignore;
[Single] ->
Prefix = MakePrefix(Outcome),
ok = lux_tap:diag(TAP, Prefix ++ " - " ++ ?b2l(Single));
Multiline ->
ok = lux_tap:diag(TAP, Prefix ++ " - FAIL at line " ++
FullLineNo ++ " in shell ZZZ"),
[lux_tap:diag(TAP, ?b2l(D)) || D <- Multiline]
Multiline when Context =:= final ->
Suffix =
case OptShellName of
no_shell -> "";
ShellName -> " in shell " ++ ShellName
end,
NewOutcome =
case Outcome of
warning -> fail;
_ -> Outcome
end,
Prefix = MakePrefix(NewOutcome),
ok = lux_tap:diag(TAP, Prefix ++ Suffix),
[ok = lux_tap:diag(TAP, ?b2l(D)) || D <- Multiline]
end.

throw_error(File, Reason) ->
Expand Down

0 comments on commit 2a93d8f

Please sign in to comment.