Testing Fortran code
The course teaches the pieces: a hand-written assert
module and a driver with tolerances and exit codes
are two lessons of it, and coverage,
-fcheck and
valgrind are three more. This group is the layer above the
lessons: the module a project keeps, the comparison a test should use for reals, the coverage a suite does not
give, and the checked build that finds what a passing test hides.
Every output on these pages came from a run in this container, with the compiler and the machine named at the end
of the page. Four tools a Fortran team may know, pFUnit, test-drive, fortran-stdlib and fpm
test, are not installed here; the page about them says so and shows the real shell answer instead of
inventing their output.
Which tool when
| Job | Tool | Page |
|---|---|---|
| Check one value and print both | an assert module of your own | A reusable assert module |
| Fail the build when a check fails | ERROR STOP, a shell runner that keeps the status | A reusable assert module |
| Compare two reals | a relative tolerance; SPACING for ULPs | Comparing floating-point results |
| Find the code the tests never ran | gcov, --coverage | Coverage the tests do not give you |
| Catch a bad subscript, a NaN or a leak | -fcheck=all, -ffpe-trap, valgrind | The test build |
| Get a test framework | pFUnit, test-drive, fpm test | Not run here |
The order of the pages is the order a project meets them: assertions first, because a test needs something to compare with; tolerances next, because the second test of a numerical program compares two reals; coverage after that, because a suite that passes says nothing about the code it never calls; and the checked build last, because it is the one that turns a wrong answer into a failure.