@@ -278,6 +278,10 @@ end;
278278# # <Item>If this is <K>true</K> then &GAP; substitutes DOS/Windows style
279279# # line breaks "\r\n" by UNIX style line breaks "\n" after reading the test
280280# # file. (default is <K>true</K>).</Item>
281+ # # <Mark><C>returnNumFailures</C></Mark>
282+ # # <Item>If this is <K>true</K> then &GAP; returns the number of input
283+ # # lines of the test file which had differences in their output, instead
284+ # # of returning <K>true</K> or <K>false</K>.</Item>
281285# # </List>
282286# #
283287# # <Log><![CDATA[
330334# # <#/GAPDoc>
331335# #
332336InstallGlobalFunction(" Test" , function (arg )
333- local fnam, nopts, opts, size, full, pf, ret , lines, ign, new, n,
337+ local fnam, nopts, opts, size, full, pf, failures , lines, ign, new, n,
334338 cT, ok, oldtimes, thr, delta, len, c, i, j, d;
335339
336340 # get arguments and set options
@@ -380,6 +384,7 @@ InstallGlobalFunction("Test", function(arg)
380384 Print(" ########\n " );
381385 end ,
382386 subsWindowsLineBreaks := true ,
387+ returnNumFailures := false ,
383388 );
384389 if not IS_OUTPUT_TTY() then
385390 opts.showProgress := false ;
@@ -438,12 +443,12 @@ InstallGlobalFunction("Test", function(arg)
438443 SizeScreen(size);
439444
440445 # check for and report differences
441- ret := true ;
446+ failures := 0 ;
442447 for i in [ 1 .. Length(pf[ 1 ] )] do
443448 if opts.compareFunction(pf[ 2 ][ i] , pf[ 4 ][ i] ) <> true then
444449 if not opts.ignoreSTOP_TEST or
445450 PositionSublist(pf[ 1 ][ i] , " STOP_TEST" ) <> 1 then
446- ret := false ;
451+ failures := failures + 1 ;
447452 opts.reportDiff(pf[ 1 ][ i] , pf[ 2 ][ i] , pf[ 4 ][ i] , fnam, pf[ 3 ][ i] , pf[ 5 ][ i] );
448453 else
449454 # print output of STOP_TEST
@@ -527,8 +532,13 @@ InstallGlobalFunction("Test", function(arg)
527532 # store internal test data in TEST
528533 TEST.lastTestData := pf;
529534
535+ # if requested, return number of failures
536+ if opts.returnNumFailures then
537+ return failures;
538+ fi ;
539+
530540 # return true/false
531- return ret ;
541+ return (failures = 0 ) ;
532542end );
533543
534544
@@ -581,14 +591,15 @@ end);
581591# # </ManSection>
582592# # <#/GAPDoc>
583593InstallGlobalFunction( " TestDirectory" , function (arg )
584- local testTotal, totalTime, totalMem, STOP_TEST_CPY,
594+ local testTotalFailures, testFailedFiles, totalTime, totalMem, STOP_TEST_CPY,
585595 basedirs, nopts, opts, testOptions, earlyStop,
586596 showProgress, suppressStatusMessage, exitGAP, c, files,
587597 filetimes, filemems, recurseFiles, f, i, startTime,
588598 startMem, testResult, time, mem, startGcTime, gctime,
589599 totalGcTime, filegctimes, GcTime;
590600
591- testTotal := true ;
601+ testTotalFailures := 0 ;
602+ testFailedFiles := 0 ;
592603 totalTime := 0 ;
593604 totalMem := 0 ;
594605 totalGcTime := 0 ;
@@ -627,7 +638,7 @@ InstallGlobalFunction( "TestDirectory", function(arg)
627638 opts.(c) := nopts.(c);
628639 od ;
629640 opts.exclude := Set(opts.exclude);
630-
641+ opts.testOptions.returnNumFailures := true ;
631642
632643 if opts.exitGAP then
633644 GAP_EXIT_CODE(1 );
@@ -696,7 +707,7 @@ InstallGlobalFunction( "TestDirectory", function(arg)
696707 opts.testOptions.rewriteToFile := files[ i] .name;
697708 fi ;
698709 testResult := Test(files[ i] .name, opts.testOptions);
699- if not (testResult) and opts.earlyStop then
710+ if (testResult <> 0 ) and opts.earlyStop then
700711 STOP_TEST := STOP_TEST_CPY;
701712 if not opts.suppressStatusMessage then
702713 # Do not change the next line - it is needed for testing scrips
@@ -707,7 +718,10 @@ InstallGlobalFunction( "TestDirectory", function(arg)
707718 fi ;
708719 return false ;
709720 fi ;
710- testTotal := testTotal and testResult;
721+ if testResult <> 0 then
722+ testFailedFiles := testFailedFiles + 1 ;
723+ fi ;
724+ testTotalFailures := testTotalFailures + testResult;
711725
712726 time := Runtime() - startTime;
713727 mem := TotalMemoryAllocated() - startMem;
@@ -731,10 +745,15 @@ InstallGlobalFunction( "TestDirectory", function(arg)
731745 Print(" -----------------------------------\n " );
732746 Print( " total" ,
733747 String( totalTime, 10 ), " ms (" ,String( totalGcTime )," ms GC) and " ,
734- StringOfMemoryAmount( totalMem )," allocated\n\n " );
748+ StringOfMemoryAmount( totalMem )," allocated\n " );
749+ Print( " " , String( testTotalFailures, 10 ), " failures in " );
750+ if testTotalFailures > 0 then
751+ Print( testFailedFiles, " of " );
752+ fi ;
753+ Print( Length(files), " files\n\n " );
735754
736755 if not opts.suppressStatusMessage then
737- if testTotal then
756+ if testTotalFailures = 0 then
738757 # Do not change the next line - it is needed for testing scrips
739758 Print( " #I No errors detected while testing\n\n " );
740759 else
@@ -744,14 +763,14 @@ InstallGlobalFunction( "TestDirectory", function(arg)
744763 fi ;
745764
746765 if opts.exitGAP then
747- if testTotal then
766+ if testTotalFailures = 0 then
748767 QUIT_GAP(0 );
749768 else
750769 QUIT_GAP(1 );
751770 fi ;
752771 fi ;
753772
754- return testTotal ;
773+ return testTotalFailures = 0 ;
755774end );
756775
757776# ############################################################################
0 commit comments