Fortran Carpentries

Durham HPC Days 2026

Connor Aird

University College London

2026-06-16

TL;DR

  • The problem: Scientific Fortran codes often don’t have unit tests.
  • Therefore, I have written a Unit Testing in Fortran workshop in the carpentries style to teach pFUnit.
  • I will be running these workshops over the next 12 months.
  • Other Fortran carpentries workshops are also in development.

What is pFUnit

Overview of pFUnit

The Parallel Fortran Unit Testing Framework (pFUnit) is a framework for unit testing Fortran.

  • Created by developers from NASA.
  • Open source on GitHub and accepting contributions - Goddard-Fortran-Ecosystem/pFUnit
  • Availale under a NASA OPEN SOURCE AGREEMENT VERSION 1.3 licence
    • Permissive license similar to MIT and BSD but there are differences.
  • Uses a preprocessor to convert .pf files to .f90.
  • Follows the style of JUnit. i.e. Directives (annotations in JUnit) label code sections for the preprocessor.
  • F2003 object oriented features and some F2008 features, thus requires more recent versions of compilers.

Syntax

.pf syntax is similar to .f90 with preprocessor directives, such as @Test and @assertEqual.

module test_something
    use maths_operations, only : double_int
    use funit
    implicit none

contains

    @Test
    subroutine test_double_int_1()
        integer :: input, actual_output

        input = 1

        call double_int(input, actual_output)

        @assertEqual(2, actual_output, "Unexpected output from double_int")
    end subroutine test_double_int_1
end module test_something

The preprocessor

  • Written in Python.
  • Converts .pf with directives into .f90.
  • Called automatically when building with Make or CMake.
  • Directives exist for the following tasks
    • Labeling subroutines as tests.
    • Parameterising tests.
    • Labelling subroutines as setup and teardown steps.
    • Specifying assertions.

Assert preprocessor directives

Software carpentries

The Carpentries teaches foundational coding and data science skills to researchers worldwide.

Carpentries and the incubator

  • Carpentries lessons are small, volunteer-led, hands on workshops.
  • The incubator is a space to host lessons that are still in-development.
  • Lessons can remain in the incubator for years.
  • Incubator lessons can still be taught.
  • Lessons move through the lesson life cycle.

Workshop material

  • A Fortran curriculum is in-development.
  • Further lessons are planned

flowchart TD
    accTitle: Learner Pathways for the Introduction to Modern Fortran Course
    accDescr {This diagram shows the possible learning pathways after completing the Introduction to Modern Fortran course.
    The Intermediate and Advanced Topics in Modern Fortran courses are in the pre-alpha stage.
    The MPI and OpenMP courses are from ARCHER2, the UK's national supercomputing facility, courses.}
    A("Introduction to Modern Fortran") --> B
    B(Intermediate Modern Fortran) --> C & D & E
    C(Advanced Topics<br>in Modern Fortran)
    D(Message-passing<br>Programming with MPI)
    E(Shared Memory<br>Programming with OpenMP)
    F(Making Legacy Fortran Sustainable) --> G
    B --> G(Unit Testing in Fortran)

    linkStyle default stroke:#000,stroke-width:2px
    classDef archer2 fill:#201f5e,stroke:#fff,stroke-width:1px,color:#fff
    classDef default fill:#ddd,stroke:#000,stroke-width:1px,color:#000
    classDef existing fill:#ddd,stroke:#000,stroke-width:1px,color:#2a78dd
    class D,E archer2
    class A,G existing
    click A href "https://carpentries-incubator.github.io/intro-to-modern-fortran/" "Link to the Introduction to modern Fortran Course"
    click G href "https://carpentries-incubator.github.io/fortran-unit-testing/" "Link to the Unit Testing in Fortran Course"
    click D href "https://www.archer2.ac.uk/training/courses/#message-passing-programming-with-mpi" "Link to the MPI Archer2 Course"
    click E href "https://www.archer2.ac.uk/training/courses/#shared-memory-programming-with-openmp" "Link to the OpenMP Archer2 Course"

Get involved

Acknowledgements

Thank you

Scan to view the slides

QR code linking to this talk's web page.