Skip to content

Commit b081f9d

Browse files
committed
Merge pull request #647 from alex-konovalov/test-one-package
TestPackage function and 'testpackage' make target
2 parents c61aa0a + 070357d commit b081f9d

File tree

6 files changed

+121
-3
lines changed

6 files changed

+121
-3
lines changed

Makefile.in

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,33 @@ testpackages:
274274
( chmod 777 testpackages.in; ./testpackages.in; rm testpackages.in )
275275
( rm wsp.g )
276276

277+
testpackage:
278+
mkdir -p dev/log
279+
( echo 'SetAssertionLevel( 2 ); ReadGapRoot( "tst/testutil.g" ); \
280+
SaveWorkspace( "wsp.g" );' | $(TESTGAP) )
281+
( echo 'CreatePackageTestsInput( "testpackage.in", \
282+
"dev/log/testpackage1", \
283+
"$(TESTGAP) -L wsp.g", "false", "$(PKGNAME)" );'\
284+
| $(TESTGAP) -L wsp.g > /dev/null )
285+
( chmod 777 testpackage.in; ./testpackage.in; rm testpackage.in )
286+
( rm wsp.g )
287+
( echo 'SetAssertionLevel( 2 ); ReadGapRoot( "tst/testutil.g" ); \
288+
SaveWorkspace( "wsp.g" );' | $(TESTGAPauto) )
289+
( echo 'CreatePackageTestsInput( "testpackage.in", \
290+
"dev/log/testpackageA", \
291+
"$(TESTGAPauto) -L wsp.g", "auto", "$(PKGNAME)" );'\
292+
| $(TESTGAPauto) -L wsp.g > /dev/null )
293+
( chmod 777 testpackage.in; ./testpackage.in; rm testpackage.in )
294+
( rm wsp.g )
295+
( echo 'SetAssertionLevel( 2 ); ReadGapRoot( "tst/testutil.g" ); \
296+
SaveWorkspace( "wsp.g" );' | $(TESTGAP) )
297+
( echo 'CreatePackageTestsInput( "testpackage.in", \
298+
"dev/log/testpackage2", \
299+
"$(TESTGAP) -L wsp.g", "true", "$(PKGNAME)" );'\
300+
| $(TESTGAP) -L wsp.g > /dev/null )
301+
( chmod 777 testpackage.in; ./testpackage.in; rm testpackage.in )
302+
( rm wsp.g )
303+
277304
testpackagesload:
278305
mkdir -p dev/log
279306
( echo 'ReadGapRoot( "tst/testutil.g" ); \

doc/ref/debug.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,9 @@ gaussian.tst 0 10
769769

770770
<#Include Label="Test">
771771
<#Include Label="TestDirectory">
772+
773+
See also <Ref Func="TestPackage"/> for the information on running standard
774+
tests for &GAP; packages.
772775
</Section>
773776

774777

doc/ref/gappkg.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ package and not by users of a package.
9595

9696
<#Include Label="ReadPackage">
9797
<#Include Label="TestPackageAvailability">
98+
<#Include Label="TestPackage">
9899
<#Include Label="InstalledPackageVersion">
99100
<#Include Label="DirectoriesPackageLibrary">
100101
<#Include Label="DirectoriesPackagePrograms">

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

761761
return testTotal;
762762
end);
763+
764+
#############################################################################
765+
##
766+
## TestPackage( <pkgname> )
767+
##
768+
## <#GAPDoc Label="TestPackage">
769+
## <ManSection>
770+
## <Func Name="TestPackage" Arg='pkgname'/>
771+
## <Description>
772+
## It is recommended that a &GAP; package specifies a standard test in its
773+
## <F>PackageInfo.g</F> file. If <A>pkgname</A> is a string with the name of
774+
## a &GAP; package, then <C>TestDirectory(pkgname)</C> will check if this
775+
## package is loadable and has the standard test, and will run this test in
776+
## the current &GAP; session.<P/>
777+
##
778+
## The output of the test depends on the particular package, and it also
779+
## may depend on the current &GAP; session (loaded packages, state of the
780+
## random sources, defined global variables etc.). If you would like to
781+
## run the test for the same package in the same setting that is used
782+
## for the testing of &GAP; releases, you have to call
783+
##
784+
## <Log><![CDATA[
785+
## make testpackage PKGNAME=pkgname
786+
## ]]></Log>
787+
##
788+
## in the UNIX shell (without quotes around <A>pkgname</A>). This will run
789+
## the standard test for the package <A>pkgname</A> three times in different
790+
## settings, and will write test output to three files in the <F>dev/log</F>
791+
## directory. These output files will be named in the format
792+
## <F>testpackageX_timestamp.pkgname</F>, where <C>X=A</C> for the test
793+
## with packages loaded by default, <C>X=1</C> for the test without other
794+
## packages (i.e. when &GAP; is started with <C>-A</C> command line option),
795+
## and <C>X=2</C> when the test is run with all packages loaded.
796+
## </Description>
797+
## </ManSection>
798+
## <#/GAPDoc>
799+
##
800+
InstallGlobalFunction( "TestPackage", function(pkgname)
801+
local testfile, str;
802+
if not IsBound( GAPInfo.PackagesInfo.(pkgname) ) then
803+
Print("#I No package with the name ", pkgname, " is available\n");
804+
return;
805+
elif LoadPackage( pkgname ) = fail then
806+
Print( "#I ", pkgname, " package can not be loaded\n" );
807+
return;
808+
elif not IsBound( GAPInfo.PackagesInfo.(pkgname)[1].TestFile ) then
809+
Print("#I No standard tests specified in ", pkgname, " package, version ",
810+
GAPInfo.PackagesInfo.(pkgname)[1].Version, "\n");
811+
return;
812+
else
813+
testfile := Filename( DirectoriesPackageLibrary( pkgname, "" ),
814+
GAPInfo.PackagesInfo.(pkgname)[1].TestFile );
815+
str:= StringFile( testfile );
816+
if not IsString( str ) then
817+
Print( "#I Test file `", testfile, "' for package `", pkgname,
818+
" version ", GAPInfo.PackagesInfo.(pkgname)[1].Version, " is not readable\n" );
819+
return;
820+
fi;
821+
if EndsWith(testfile,".tst") then
822+
if Test( testfile, rec(compareFunction := "uptowhitespace") ) then
823+
Print( "#I No errors detected while testing package ", pkgname,
824+
" version ", GAPInfo.PackagesInfo.(pkgname)[1].Version,
825+
"\n#I using the test file `", testfile, "'\n");
826+
else
827+
Print( "#I Errors detected while testing package ", pkgname,
828+
" version ", GAPInfo.PackagesInfo.(pkgname)[1].Version,
829+
"\n#I using the test file `", testfile, "'\n");
830+
fi;
831+
elif not READ( testfile ) then
832+
Print( "#I Test file `", testfile, "' for package `", pkgname,
833+
" version ", GAPInfo.PackagesInfo.(pkgname)[1].Version, " is not readable\n" );
834+
fi;
835+
fi;
836+
end);

tst/testutil.g

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,28 @@ end;
7676
## is actually managed in the Makefile, and is passed to this function
7777
## just to be printed in the information messages.
7878
##
79-
BindGlobal( "CreatePackageTestsInput", function( scriptfile, outfile, gap, other )
80-
local result, name, entry, pair, testfile;
79+
BindGlobal( "CreatePackageTestsInput", function( scriptfile, outfile, gap, other, pkgname... )
80+
local result, name, entry, pair, testfile, packages;
8181

8282
SizeScreen( [ 1000 ] );
8383
InitializePackagesInfoRecords( false );
8484
result:= "";
8585

8686
Append( result, "TIMESTAMP=`date -u +_%Y-%m-%d-%H-%M`\n" );
8787

88-
for name in SortedList(ShallowCopy(RecNames(GAPInfo.PackagesInfo))) do
88+
if Length(pkgname)=0 then
89+
packages := SortedList(ShallowCopy(RecNames(GAPInfo.PackagesInfo)));
90+
else
91+
packages := pkgname;
92+
if Length(packages) <> 1 or Length(packages[1]) = 0 then
93+
Error("Usage: make testpackage PKGNAME=pkgname");
94+
fi;
95+
if not pkgname[1] in RecNames(GAPInfo.PackagesInfo) then
96+
Error("There is no package with the name ", pkgname[1], " installed\n");
97+
fi;
98+
fi;
99+
100+
for name in packages do
89101
for entry in GAPInfo.PackagesInfo.( name ) do
90102
if IsBound( entry.InstallationPath ) and IsBound( entry.TestFile ) then
91103
testfile := Filename( DirectoriesPackageLibrary( name, "" ), entry.TestFile );

0 commit comments

Comments
 (0)