Skip to content

flap_test_utils ​

Utilities for FLAP test programs: assertions, output capture and self re-invocation.

Assertions end the program with error stop 1 on failure, so a failed check always gives a non-zero exit status.

Output capture: pass the unit returned by capture_open as usage_lun/error_lun/version_lun to cli%init, then read_back the text written to it.

Self re-invocation: reinvoke runs the calling program again in a child process with FLAP_TEST_CASE set, so the child knows (via child_case) which scenario to run. This is how a test exercises environment variables, standard input, exit statuses and the paths that end the program (--help, --version). It requires a POSIX sh and env.

Source: src/tests/flap_test_utils.F90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
CASE_ENVcharacter(len=*)parameterEnvironment variable selecting the child scenario.

Interfaces ​

assert_equal ​

Assert that an actual value equals the expected one.

Module procedures: assert_equal_character, assert_equal_logical, assert_equal_I4P, assert_equal_R8P, assert_equal_I4P_1d, assert_equal_R8P_1d

Subroutines ​

assert ​

Assert that a condition holds.

fortran
subroutine assert(condition, message)

Arguments

NameTypeIntentAttributesDescription
conditionlogicalinCondition to check.
messagecharacter(len=*)inDescription of the check.

Call graph

assert_contains ​

Assert that a text contains a substring.

fortran
subroutine assert_contains(text, substring, message)

Arguments

NameTypeIntentAttributesDescription
textcharacter(len=*)inText to search.
substringcharacter(len=*)inSubstring expected in the text.
messagecharacter(len=*)inDescription of the check.

Call graph

assert_equal_character ​

Assert that two strings are equal (Fortran comparison: trailing blanks are not significant).

fortran
subroutine assert_equal_character(actual, expected, message)

Arguments

NameTypeIntentAttributesDescription
actualcharacter(len=*)inActual value.
expectedcharacter(len=*)inExpected value.
messagecharacter(len=*)inDescription of the check.

Call graph

assert_equal_logical ​

Assert that two logicals are equal.

fortran
subroutine assert_equal_logical(actual, expected, message)

Arguments

NameTypeIntentAttributesDescription
actuallogicalinActual value.
expectedlogicalinExpected value.
messagecharacter(len=*)inDescription of the check.

Call graph

assert_equal_I4P ​

Assert that two integers are equal.

fortran
subroutine assert_equal_I4P(actual, expected, message)

Arguments

NameTypeIntentAttributesDescription
actualinteger(kind=I4P)inActual value.
expectedinteger(kind=I4P)inExpected value.
messagecharacter(len=*)inDescription of the check.

Call graph

assert_equal_R8P ​

Assert that two reals are equal, exactly or within an absolute tolerance.

fortran
subroutine assert_equal_R8P(actual, expected, message, tol)

Arguments

NameTypeIntentAttributesDescription
actualreal(kind=R8P)inActual value.
expectedreal(kind=R8P)inExpected value.
messagecharacter(len=*)inDescription of the check.
tolreal(kind=R8P)inoptionalAbsolute tolerance (default: exact comparison).

Call graph

assert_equal_I4P_1d ​

Assert that two integer arrays are equal.

fortran
subroutine assert_equal_I4P_1d(actual, expected, message)

Arguments

NameTypeIntentAttributesDescription
actualinteger(kind=I4P)inActual values.
expectedinteger(kind=I4P)inExpected values.
messagecharacter(len=*)inDescription of the check.

Call graph

assert_equal_R8P_1d ​

Assert that two real arrays are equal, exactly or within an absolute tolerance.

fortran
subroutine assert_equal_R8P_1d(actual, expected, message, tol)

Arguments

NameTypeIntentAttributesDescription
actualreal(kind=R8P)inActual values.
expectedreal(kind=R8P)inExpected values.
messagecharacter(len=*)inDescription of the check.
tolreal(kind=R8P)inoptionalAbsolute tolerance (default: exact comparison).

Call graph

capture_open ​

Open a scratch unit to capture output.

fortran
subroutine capture_open(lun)

Arguments

NameTypeIntentAttributesDescription
luninteger(kind=I4P)outCapture unit.

Call graph

capture_close ​

Close (and delete) a capture unit.

fortran
subroutine capture_close(lun)

Arguments

NameTypeIntentAttributesDescription
luninteger(kind=I4P)inCapture unit.

write_file ​

Write a text to a new file byte by byte (no newline added), replacing any existing one.

fortran
subroutine write_file(path, text)

Arguments

NameTypeIntentAttributesDescription
pathcharacter(len=*)inFile path.
textcharacter(len=*)inText to write, with its own new_line characters.

Call graph

delete_file ​

Delete a file.

fortran
subroutine delete_file(path)

Arguments

NameTypeIntentAttributesDescription
pathcharacter(len=*)inFile path.

Call graph

run_command ​

Run a shell command (by sh) and return its exit status and its standard output and error, merged.

fortran
subroutine run_command(cmd, exitstat, out)

Arguments

NameTypeIntentAttributesDescription
cmdcharacter(len=*)inShell command.
exitstatinteger(kind=I4P)outExit status of the command.
outcharacter(len=:)outallocatableStandard output and error of the command.

Call graph

reinvoke ​

Run the calling program again as a child process executing scenario case (read by the child with child_case).

The command line is env [env] FLAP_TEST_CASE=case 'self' [args] < stdin > out 2> err, run by sh: args and env are passed verbatim, so shell quoting is the caller's responsibility. env takes env operands with options first, e.g. '-u OLD NEW=value' unsets OLD and sets NEW. Without stdin the child reads from /dev/null.

fortran
subroutine reinvoke(case, exitstat, out, err, args, env, stdin)

Arguments

NameTypeIntentAttributesDescription
caseinteger(kind=I4P)inScenario run by the child.
exitstatinteger(kind=I4P)outExit status of the child.
outcharacter(len=:)outallocatableStandard output of the child.
errcharacter(len=:)outallocatableStandard error of the child.
argscharacter(len=*)inoptionalCommand line arguments for the child.
envcharacter(len=*)inoptionalExtra env operands, options first: '-u OLD NEW=value'.
stdincharacter(len=*)inoptionalStandard input for the child.

Call graph

fail ​

Report a failed check and end the program with a non-zero exit status.

fortran
subroutine fail(message)

Arguments

NameTypeIntentAttributesDescription
messagecharacter(len=*)inFailure description.

Call graph

Functions ​

read_back ​

Return the text written to a capture unit so far, then empty the unit: the next capture starts from scratch.

Returns: character(len=:)

fortran
function read_back(lun) result(text)

Arguments

NameTypeIntentAttributesDescription
luninteger(kind=I4P)inCapture unit.

Call graph

read_file ​

Return the whole content of a text file.

Returns: character(len=:)

fortran
function read_file(path) result(text)

Arguments

NameTypeIntentAttributesDescription
pathcharacter(len=*)inFile path.

Call graph

scratch_file ​

Path of a scratch file next to the running executable (a build directory, never the source tree).

Returns: character(len=:)

fortran
function scratch_file(name) result(path)

Arguments

NameTypeIntentAttributesDescription
namecharacter(len=*)inFile name suffix.

Call graph

child_case ​

Return the scenario requested by reinvoke, or 0 when the program was not re-invoked.

Returns: integer(kind=I4P)

fortran
function child_case() result(case)

Call graph

read_all ​

Read a formatted unit from its current position to the end; lines of any length are supported.

Returns: character(len=:)

fortran
function read_all(lun) result(text)

Arguments

NameTypeIntentAttributesDescription
luninteger(kind=I4P)inUnit to read.

Call graph

integer_to_string ​

Convert an integer to a string without blanks.

Attributes: pure

Returns: character(len=:)

fortran
function integer_to_string(n) result(string)

Arguments

NameTypeIntentAttributesDescription
ninteger(kind=I4P)inInteger to convert.

Call graph

real_to_string ​

Convert a real to a string in scientific notation, with enough digits to tell neighbouring values apart.

Attributes: pure

Returns: character(len=:)

fortran
function real_to_string(x) result(string)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inReal to convert.

Call graph

logical_to_string ​

Convert a logical to '.true.' or '.false.'.

Attributes: pure

Returns: character(len=:)

fortran
function logical_to_string(l) result(string)

Arguments

NameTypeIntentAttributesDescription
llogicalinLogical to convert.

Call graph

reals_match ​

Compare two reals, exactly or within an absolute tolerance.

Attributes: pure

Returns: logical

fortran
function reals_match(actual, expected, tol) result(match)

Arguments

NameTypeIntentAttributesDescription
actualreal(kind=R8P)inActual value.
expectedreal(kind=R8P)inExpected value.
tolreal(kind=R8P)inoptionalAbsolute tolerance (default: exact comparison).

Call graph