Skip to content

Commit

Permalink
TestDirectory reports number of failures and failed fails
Browse files Browse the repository at this point in the history
With this, you may get output like this, with the
relevant change in the "total" line near the end.

    gap> TestDirectory("misc");
    Architecture: x86_64-apple-darwin15.6.0-default64-kv5

    testing: misc/err.tst
           0 ms (0 ms GC) and 46.6KB allocated for err.tst
    testing: misc/foo.tst
    ########> Diff in misc/foo.tst:3
    # Input is:
    1+1;
    # Expected output:
    3
    # But found:
    2
    ########
           0 ms (0 ms GC) and 6.62KB allocated for foo.tst
    -----------------------------------
    total         0 ms (0 ms GC) and 53.2KB allocated, 1 failures in 1 out of 2 files

    #I  Errors detected while testing

    false
    gap>

Resolves #2861
  • Loading branch information
fingolfin committed Oct 5, 2018
1 parent 94e61ab commit f65d7e9
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions lib/test.gi
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ end;
## line breaks "\r\n" by UNIX style line breaks "\n" after reading the test
## file. (default is <K>true</K>).</Item>
## </List>
## <Mark><C>returnNumFailures</C></Mark>
## <Item>If this is <K>true</K> then &GAP; returns the number of input
## lines of the test file which had differences in their output, instead
## of returning <K>true</K> or <K>false</K>.</Item>
## </List>
##
## <Log><![CDATA[
## gap> tnam := Filename(DirectoriesLibrary(), "../doc/ref/demo.tst");;
Expand Down Expand Up @@ -324,7 +329,7 @@ end;
## <#/GAPDoc>
##
InstallGlobalFunction("Test", function(arg)
local fnam, nopts, opts, size, full, pf, ret, lines, ign, new, n,
local fnam, nopts, opts, size, full, pf, failures, lines, ign, new, n,
cT, ok, oldtimes, thr, delta, len, c, i, j, d;

# get arguments and set options
Expand Down Expand Up @@ -374,6 +379,7 @@ InstallGlobalFunction("Test", function(arg)
Print("########\n");
end,
subsWindowsLineBreaks := true,
returnNumFailures := false,
);
if not IS_OUTPUT_TTY() then
opts.showProgress := false;
Expand Down Expand Up @@ -432,12 +438,12 @@ InstallGlobalFunction("Test", function(arg)
SizeScreen(size);

# check for and report differences
ret := true;
failures := 0;
for i in [1..Length(pf[1])] do
if opts.compareFunction(pf[2][i], pf[4][i]) <> true then
if not opts.ignoreSTOP_TEST or
PositionSublist(pf[1][i], "STOP_TEST") <> 1 then
ret := false;
failures := failures + 1;
opts.reportDiff(pf[1][i], pf[2][i], pf[4][i], fnam, pf[3][i], pf[5][i]);
else
# print output of STOP_TEST
Expand Down Expand Up @@ -521,8 +527,13 @@ InstallGlobalFunction("Test", function(arg)
# store internal test data in TEST
TEST.lastTestData := pf;

# if requested, return number of failures
if opts.returnNumFailures then
return failures;
fi;

# return true/false
return ret;
return (failures = 0);
end);


Expand Down Expand Up @@ -575,14 +586,15 @@ end);
## </ManSection>
## <#/GAPDoc>
InstallGlobalFunction( "TestDirectory", function(arg)
local testTotal, totalTime, totalMem, STOP_TEST_CPY,
local testTotalFailures, testFailedFiles, totalTime, totalMem, STOP_TEST_CPY,
basedirs, nopts, opts, testOptions, earlyStop,
showProgress, suppressStatusMessage, exitGAP, c, files,
filetimes, filemems, recurseFiles, f, i, startTime,
startMem, testResult, time, mem, startGcTime, gctime,
totalGcTime, filegctimes, GcTime;

testTotal := true;
testTotalFailures := 0;
testFailedFiles := 0;
totalTime := 0;
totalMem := 0;
totalGcTime := 0;
Expand Down Expand Up @@ -621,7 +633,7 @@ InstallGlobalFunction( "TestDirectory", function(arg)
opts.(c) := nopts.(c);
od;
opts.exclude := Set(opts.exclude);

opts.testOptions.returnNumFailures := true;

if opts.exitGAP then
GAP_EXIT_CODE(1);
Expand Down Expand Up @@ -690,7 +702,7 @@ InstallGlobalFunction( "TestDirectory", function(arg)
opts.testOptions.rewriteToFile := files[i].name;
fi;
testResult := Test(files[i].name, opts.testOptions);
if not(testResult) and opts.earlyStop then
if (testResult <> 0) and opts.earlyStop then
STOP_TEST := STOP_TEST_CPY;
if not opts.suppressStatusMessage then
# Do not change the next line - it is needed for testing scrips
Expand All @@ -701,7 +713,10 @@ InstallGlobalFunction( "TestDirectory", function(arg)
fi;
return false;
fi;
testTotal := testTotal and testResult;
if testResult <> 0 then
testFailedFiles := testFailedFiles + 1;
fi;
testTotalFailures := testTotalFailures + testResult;

time := Runtime() - startTime;
mem := TotalMemoryAllocated() - startMem;
Expand All @@ -725,10 +740,13 @@ InstallGlobalFunction( "TestDirectory", function(arg)
Print("-----------------------------------\n");
Print( "total",
String( totalTime, 10 ), " ms (",String( totalGcTime )," ms GC) and ",
StringOfMemoryAmount( totalMem )," allocated\n\n" );
StringOfMemoryAmount( totalMem )," allocated, ",
testTotalFailures, " failures in ",
testFailedFiles, " of ", Length(files), " files",
"\n\n" );

if not opts.suppressStatusMessage then
if testTotal then
if testTotalFailures = 0 then
# Do not change the next line - it is needed for testing scrips
Print( "#I No errors detected while testing\n\n" );
else
Expand All @@ -738,14 +756,14 @@ InstallGlobalFunction( "TestDirectory", function(arg)
fi;

if opts.exitGAP then
if testTotal then
if testTotalFailures = 0 then
QUIT_GAP(0);
else
QUIT_GAP(1);
fi;
fi;

return testTotal;
return testTotalFailures = 0;
end);

#############################################################################
Expand Down

0 comments on commit f65d7e9

Please sign in to comment.