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.

Test A reusable assert module The module a Fortran project writes once: counters, four assertions, a suite of test procedures called through procedure pointers, TAP lines and a status a runner can read. Open Test Comparing floating-point results Absolute, relative and ULP distance on real pairs from this machine, the function a test should use, and the case where the reference value is zero. Open Test Coverage the tests do not give you gcov over a module with a branch the tests never take, the listing that names the line, and a shell gate that fails when the covered fraction drops. Open Test The test build: -fcheck, -ffpe-trap, valgrind One program with three bugs and three tools: an out-of-bounds read, a division by zero and a leak, each found by the build that is looking for it. Open Test pFUnit, test-drive and fpm: not run here The frameworks a Fortran team may install, what each one gives, the real commands that show they are absent, and what the image has instead. Open

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.