-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdev-pkg.g
111 lines (104 loc) · 3.84 KB
/
dev-pkg.g
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Functions to test package
#
# Getting package name from its PackageInfo.g file
#
# Borrowed from `ValidatePackageInfo` in GAP's lib/package.gi
GetNameFromPackageInfo := function(info)
local record, pkgdir, i;
if IsString( info ) then
if IsReadableFile( info ) then
Unbind( GAPInfo.PackageInfoCurrent );
Read( info );
if IsBound( GAPInfo.PackageInfoCurrent ) then
record:= GAPInfo.PackageInfoCurrent;
Unbind( GAPInfo.PackageInfoCurrent );
else
Error( "the file <info> is not a `PackageInfo.g' file" );
fi;
pkgdir:= "./";
for i in Reversed( [ 1 .. Length( info ) ] ) do
if info[i] = '/' then
pkgdir:= info{ [ 1 .. i ] };
break;
fi;
od;
else
Error( "<info> is not the name of a readable file" );
fi;
elif IsRecord( info ) then
pkgdir:= fail;
record:= info;
else
Error( "<info> must be either a record or a filename" );
fi;
return record.PackageName;
end;
# Running standard test for the package
#
TestOnePackage := function(pkgname)
local testfile, str;
if not IsBound( GAPInfo.PackagesInfo.(pkgname) ) then
Print("#I No package with the name ", pkgname, " is available\n");
return fail;
elif LoadPackage( pkgname ) = fail then
Print( "#I ", pkgname, " package can not be loaded\n" );
return fail;
elif not IsBound( GAPInfo.PackagesInfo.(pkgname)[1].TestFile ) then
Print("#I No standard tests specified in ", pkgname, " package, version ",
GAPInfo.PackagesInfo.(pkgname)[1].Version, "\n");
return fail;
else
testfile := Filename( DirectoriesPackageLibrary( pkgname, "" ),
GAPInfo.PackagesInfo.(pkgname)[1].TestFile );
str:= StringFile( testfile );
if not IsString( str ) then
Print( "#I Test file `", testfile, "' for package `", pkgname,
" version ", GAPInfo.PackagesInfo.(pkgname)[1].Version, " is not readable\n" );
return fail;
fi;
if EndsWith(testfile,".tst") then
if Test( testfile, rec(compareFunction := "uptowhitespace") ) then
Print( "#I No errors detected while testing package ", pkgname,
" version ", GAPInfo.PackagesInfo.(pkgname)[1].Version,
"\n#I using the test file `", testfile, "'\n");
return true;
else
Print( "#I Errors detected while testing package ", pkgname,
" version ", GAPInfo.PackagesInfo.(pkgname)[1].Version,
"\n#I using the test file `", testfile, "'\n");
return false;
fi;
elif not READ( testfile ) then
Print( "#I Test file `", testfile, "' for package `", pkgname,
" version ", GAPInfo.PackagesInfo.(pkgname)[1].Version, " is not readable\n" );
return fail;
else
# At this point, the READ succeeded, but we have no idea what the
# outcome of that test was. Hopefully, that file printed a message of
# its own and then terminated GAP with a suitable error code (e.g. by
# using TestDirectory with exitGAP:=true); in that case we never get
# here an all is fine.
return "UNKNOWN";
fi;
fi;
end;
PreparePackageInDir := function(path)
local pkg, pkginfo;
pkg := LowercaseString(GetNameFromPackageInfo("PackageInfo.g"));
if IsPackageMarkedForLoading(pkg, "") then
# verify the right version of the package was loaded
pkginfo := GAPInfo.PackagesInfo.(pkg);
if Length(pkginfo) > 1 then
Print("#I Found ", Length(pkginfo), " copies of package ", pkg, "\n");
fi;
if pkginfo[1].InstallationPath <> path then
Error("Package ", pkg, " already loaded from bad path '",
pkginfo[1].InstallationPath, "' instead of the expected path '",
path, "'");
fi;
else
# ensure the right version of the package gets loaded later on
SetPackagePath(pkg, path);
fi;
return pkg;
end;