Skip to content

Commit b830e2d

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

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,3 +760,42 @@ InstallGlobalFunction( "TestDirectory", function(arg)
760760

761761
return testTotal;
762762
end);
763+
764+
765+
InstallGlobalFunction( "TestPackage", function(pkgname)
766+
local testfile, 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 ", pkgname, " package, version ",
775+
GAPInfo.PackagesInfo.(pkgname)[1].Version, "\n");
776+
return;
777+
else
778+
testfile := Filename( DirectoriesPackageLibrary( pkgname, "" ),
779+
GAPInfo.PackagesInfo.(pkgname)[1].TestFile );
780+
str:= StringFile( testfile );
781+
if not IsString( str ) then
782+
Print( "#I Test file `", testfile, "' for package `", pkgname,
783+
" version ", GAPInfo.PackagesInfo.(pkgname)[1].Version, " is not readable\n" );
784+
return;
785+
fi;
786+
if EndsWith(testfile,".tst") then
787+
if Test( testfile, rec(compareFunction := "uptowhitespace") ) then
788+
Print( "#I No errors detected while testing package ", pkgname,
789+
" version ", GAPInfo.PackagesInfo.(pkgname)[1].Version,
790+
"\n#I using the test file `", testfile, "'\n");
791+
else
792+
Print( "#I Errors detected while testing package ", pkgname,
793+
" version ", GAPInfo.PackagesInfo.(pkgname)[1].Version,
794+
"\n#I using the test file `", testfile, "'\n");
795+
fi;
796+
elif not READ( testfile ) then
797+
Print( "#I Test file `", testfile, "' for package `", pkgname,
798+
" version ", GAPInfo.PackagesInfo.(pkgname)[1].Version, " is not readable\n" );
799+
fi;
800+
fi;
801+
end);

0 commit comments

Comments
 (0)