Skip to content

Commit a310263

Browse files
author
Alexander Konovalov
committed
TestPackage function to run a standard test for a package
1 parent 4bae221 commit a310263

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/test.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ DeclareGlobalFunction("ParseTestFile");
1212
DeclareGlobalFunction("RunTests");
1313
DeclareGlobalFunction("Test");
1414
DeclareGlobalFunction("TestDirectory");
15+
DeclareGlobalFunction("TestPackage");
1516

lib/test.gi

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,3 +760,39 @@ InstallGlobalFunction( "TestDirectory", function(arg)
760760

761761
return testTotal;
762762
end);
763+
764+
765+
InstallGlobalFunction( "TestPackage", function(pkgname)
766+
local testfile, file, str;
767+
if not IsBound( GAPInfo.PackagesInfo.(pkgname) ) then
768+
Print("#I No package with the name ", pkgname, " is available\n");
769+
return;
770+
elif LoadPackage( pkgname ) = fail then
771+
Print( "#I ", pkgname, " package can not be loaded\n" );
772+
return;
773+
elif not IsBound( GAPInfo.PackagesInfo.(pkgname)[1].TestFile ) then
774+
Print("#I No standard tests specified in the installed version of the ", pkgname, " package\n");
775+
return;
776+
else
777+
testfile := GAPInfo.PackagesInfo.(pkgname)[1].TestFile;
778+
file:= Filename( DirectoriesPackageLibrary( pkgname, "" ), testfile );
779+
str:= StringFile( file );
780+
if not IsString( str ) then
781+
Print( "#I Test file `", testfile, "' for package `", pkgname, " is not readable\n" );
782+
return;
783+
fi;
784+
if PositionSublist( str, "gap> START_TEST(" ) = fail then
785+
if not READ( file ) then
786+
Print( "#I Test file `", testfile, "' for package `", pkgname, " is not readable\n" );
787+
fi;
788+
else
789+
if not Test( file, rec(compareFunction := "uptowhitespace") ) then
790+
Print( "#I Errors detected while testing package ", pkgname, "\n",
791+
"#I using the test file `", testfile, "'\n");
792+
else
793+
Print( "#I No errors detected while testing package ", pkgname, "\n",
794+
"#I using the test file `", testfile, "'\n");
795+
fi;
796+
fi;
797+
fi;
798+
end);

0 commit comments

Comments
 (0)