An inline if paired with error stop aborts the program when a result is wrong, otherwise execution falls through.

Program

Play the program to verify a double_value function and confirm all checks pass.

assertion.f90
program assertion_demo
    implicit none
    integer :: result_

    result_ = double_value(2)
    if (result_ /= 4) error stop "double(2) failed"

    result_ = double_value(0)
    if (result_ /= 0) error stop "double(0) failed"

    print '(A)', "all checks passed"
contains
    function double_value(n) result(out)
        integer, intent(in) :: n
        integer :: out
        out = n * 2
    end function double_value
end program assertion_demo
inline if `if (cond) stmt` is the single-statement if form.
error stop `error stop "msg"` aborts the program with a non-zero status.
function check A small function plus checks demonstrates the test pattern without a test harness.