From 13fe1584ff148802bf7844503ab7ec24e1a6a492 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Sat, 21 Sep 2024 00:47:12 -0400 Subject: [PATCH] Adapt "check" for tests as functions 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. --- M2/Macaulay2/m2/testing.m2 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/M2/Macaulay2/m2/testing.m2 b/M2/Macaulay2/m2/testing.m2 index 90447a84ee..d102b6c9f7 100644 --- a/M2/Macaulay2/m2/testing.m2 +++ b/M2/Macaulay2/m2/testing.m2 @@ -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 = () -> (