Skip to content

Commit

Permalink
Adapt "check" for tests as functions
Browse files Browse the repository at this point in the history
We call each test, and if it returns a string, then it's a traditional test
that we should try to capture.  Otherwise, we're done!

A couple things:

- Tests run this way don't produce any output, so debugging is harder.  In
  particular, Verbose => true doesn't do anything.
- We print "calling" *after* we're done running the test, since we don't know
  if it returns a string or not.
  • Loading branch information
d-torrance committed Sep 21, 2024
1 parent 6977699 commit 13fe158
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions M2/Macaulay2/m2/testing.m2
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,21 @@ check(List, Package) := opts -> (L, pkg) -> (
--
errorList := for k in testKeys list (
if not inputs#?k then error(pkg, " has no test #", k);
teststring := inputs#k#"code";
desc := "check(" | toString k | ", " | format pkg#"pkgname" | ")";
ret := elapsedTime captureTestResult(desc, teststring, pkg, usermode);
if not ret then (k, temporaryFilenameCounter - 2) else continue);
elapsedTime (
try teststring := inputs#k() then (
if instance(teststring, String) then (
if captureTestResult(desc, teststring, pkg, usermode)
then continue
else (k, temporaryFilenameCounter - 2))
else (checkmsg("calling", desc); continue))
else (checkmsg("calling", desc); (k, null))));
outfile := errfile -> temporaryDirectory() | errfile | ".tmp";
if #errorList > 0 then (
if opts.Verbose then apply(errorList, (k, errfile) -> (
stderr << locate inputs#k << " error:" << endl;
printerr getErrors(outfile errfile)));
if errfile =!= null then (
stderr << locate inputs#k << " error:" << endl;
printerr getErrors(outfile errfile))));
error("test(s) #", demark(", ", toString \ first \ errorList), " of package ", toString pkg, " failed.")))

checkAllPackages = () -> (
Expand Down

0 comments on commit 13fe158

Please sign in to comment.