Skip to content

Commit

Permalink
Use colors in output of Test() and some other tests
Browse files Browse the repository at this point in the history
... to make it easier to see and understand diffs.
  • Loading branch information
fingolfin committed Mar 4, 2021
1 parent 2ceb734 commit 273886a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 27 deletions.
5 changes: 3 additions & 2 deletions dev/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ do
# restore current directory before each test suite
cd "$BUILDDIR"

echo "Running test suite $TEST_SUITE"
case $TEST_SUITE in
testspecial | test-compile)
cd $SRCDIR/tst/$TEST_SUITE
Expand Down Expand Up @@ -97,9 +98,9 @@ GAPInput
Print("-----------------------------------------------------\n");
Print("Loading $pkg ... \n");
if LoadPackage("$pkg",false) = true then
Print("PASS: $pkg\n\n");
Print(TextAttr.2, "PASS: $pkg\n\n", TextAttr.reset);
else
Print("FAIL: $pkg\n\n");
Print(TextAttr.1, "FAIL: $pkg\n\n", TextAttr.reset);
AppendTo("fail.log", "Loading failed : ", "$pkg", "\n");
fi;
GAPInput
Expand Down
59 changes: 47 additions & 12 deletions lib/test.gi
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,44 @@ end);
## </ManSection>
## <#/GAPDoc>
##
DeclareGlobalName("TextAttr"); # from GAPDoc
DeclareGlobalName("DefaultReportDiffColors"); # initialized in Test() or by the user
BindGlobal("DefaultReportDiff", function(inp, expout, found, fnam, line, time)
if UserPreference("UseColorsInTerminal") = true then
Print(DefaultReportDiffColors.message);
Print("########> Diff in ");
if IsStream(fnam) then
Print("test stream, line ",line,":");
else
Print(fnam,":",line);
fi;
Print(TextAttr.reset, "\n", DefaultReportDiffColors.message);
Print("# Input is:", TextAttr.reset, "\n");
Print(DefaultReportDiffColors.input);
Print(inp);
Print(TextAttr.reset, TextAttr.delline, DefaultReportDiffColors.message);
Print("# Expected output:", TextAttr.reset, "\n");
Print(DefaultReportDiffColors.expected);
Print(expout);
Print(TextAttr.reset, TextAttr.delline, DefaultReportDiffColors.message);
Print("# But found:", TextAttr.reset, "\n");
Print(DefaultReportDiffColors.actual);
Print(found);
Print(TextAttr.reset, TextAttr.delline, DefaultReportDiffColors.message);
Print("########", TextAttr.reset, "\n");
else
Print("########> Diff in ");
if IsStream(fnam) then
Print("test stream, line ",line,":\n");
else
Print(fnam,":",line,"\n");
fi;
Print("# Input is:\n", inp);
Print("# Expected output:\n", expout);
Print("# But found:\n", found);
Print("########\n"); fi;
end);

InstallGlobalFunction("Test", function(arg)
local fnam, nopts, opts, size, full, pf, failures, lines, ign, new,
cT, ok, oldtimes, thr, delta, len, c, i, j, d, localdef, line;
Expand All @@ -510,6 +548,14 @@ InstallGlobalFunction("Test", function(arg)
else
nopts := rec();
fi;
if not IsBound(DefaultReportDiffColors) then
BindGlobal("DefaultReportDiffColors", rec(
message := TextAttr.4, # blue text
input := "",
expected := Concatenation(TextAttr.0, TextAttr.b2), # black text on green background
actual := Concatenation(TextAttr.7, TextAttr.b1), # white text on red background
));
fi;
opts := rec(
ignoreComments := true,
isStream := IsStream(fnam),
Expand Down Expand Up @@ -538,18 +584,7 @@ InstallGlobalFunction("Test", function(arg)
end,
rewriteToFile := false,
breakOnError := false,
reportDiff := function(inp, expout, found, fnam, line, time)
Print("########> Diff in ");
if IsStream(fnam) then
Print("test stream, line ",line,":\n");
else
Print(fnam,":",line,"\n");
fi;
Print("# Input is:\n", inp);
Print("# Expected output:\n", expout);
Print("# But found:\n", found);
Print("########\n");
end,
reportDiff := DefaultReportDiff,
subsWindowsLineBreaks := true,
returnNumFailures := false,
localdef := false,
Expand Down
15 changes: 3 additions & 12 deletions tst/testmanuals.g
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
ExamplesReportDiff := function(inp, expout, found, fnam, line, time)
local tstf, i, loc, res;

Print("########> Diff in ");
if IsStream(fnam) then
Print("test stream, line ",line,"\n");
else
if IsString(fnam) then
tstf := SplitString(StringFile(fnam), "\n");
i := line;
# Look for location marker
Expand All @@ -30,17 +27,11 @@ ExamplesReportDiff := function(inp, expout, found, fnam, line, time)
loc := InputTextString(Concatenation(tstf[i]{[6..Length(tstf[i])]}, ";"));
res := READ_COMMAND_REAL(loc, false);
if res[1] = true then
Print(res[2][1],":",res[2][2]);
fnam := Concatenation(fnam,res[2][1],":",res[2][2]);
fi;
Print(" (", fnam,":",line,")\n");
else # did not find a location marker
Print(fnam,":",line,"\n");
fi;
fi;
Print("# Input is:\n", inp);
Print("# Expected output:\n", expout);
Print("# But found:\n", found);
Print("########\n");
DefaultReportDiff(inp, expout, found, fnam, line, time);
end;

TestManualChapter := function(filename)
Expand Down
4 changes: 3 additions & 1 deletion tst/testspecial/run_gap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ gfile="$2"
# 4) Set lower and upper memory limits, for consistency
GAPROOT=$(cd ../..; pwd)
( echo "LogTo(\"${outfile}.tmp\");" ; cat "$gfile" ; echo "QUIT;" ) |
"$gap" -r -A -b -m 256m -o 512m -x 800 2>/dev/null >/dev/null
"$gap" -r -A -b -m 256m -o 512m -x 800 \
-c 'SetUserPreference("UseColorsInTerminal",false);' \
2>/dev/null >/dev/null
sed -E -e "s:${GAPROOT//:/\\:}:GAPROOT:g" -e "s;(GAPROOT(/[^/]+)+):[0-9]+;\1:LINE;g" < "${outfile}.tmp"
rm "${outfile}.tmp"

0 comments on commit 273886a

Please sign in to comment.