I have been using PlUnit for years to grade students’ projects.
On feature that I always wanted is to (1) run a test battery and (2) check the results afterward. Alas, as with many unit test libraries in several languages, PLUnit is a “my report is a bunch of printouts” beast.
I finally bit the bullet and delved deeply in PlUnit’s guts and wrenched out the necessary information. Now I can write
testing_run :- writeln('>>> Starting testing run.'), run_tests_and_report(report(Passed, Failed, FailedAssertions, Blocked, STO)), writeln('>>> Finished testing run.'), testing_run_report(Passed, Failed, FailedAssertions, Blocked, STO).
testing_run_report that just does some computation and other stuff, the new predicate is
run_tests_and_report/1, which is a counterpart to
run_tests/0. As you can see it unifies a
report/5 term with the nice information that PlUnit does compute internally. The predicate always succeeds (modulo catastrophic errors), unlike
run_tests, which may fails if some test fails; this is key to allow post processing of the overall test results by the user.
Now I can do post processing.
I am attaching a file with the relevant code. I am not well versed in SWI structured comments or conventions, so it will need some polishing. Of course, I’d lobby for inclusion of these entry points in PlUnit.
I can generate a pull request, once the code has been vetted by someone more expert… You-know-who-you-are
It has been fun.
All the best
plunit_reporting.pl (5.2 KB)