You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-18Lines changed: 36 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,7 @@
1
1
Assert
2
2
======
3
3
4
-
A simple assertion utility taking advantage of the Fortran 2018 standard's introduction of variable stop codes
5
-
and error termination inside pure procedures.
4
+
An assertion utility that combines variable stop codes and error termination in `pure` procedures to produce descriptive messages when a program detects violations of the requirements for correct execution.
6
5
7
6
Motivations
8
7
-----------
@@ -11,18 +10,37 @@ Motivations
11
10
12
11
Overview
13
12
--------
14
-
This assertion utility contains three public entities:
13
+
This assertion utility contains four public entities:
15
14
16
15
1. An `assert` subroutine,
17
16
2. A `characterizable_t` abstract type supporting `assert`, and
18
17
3. An `intrinsic_array_t` non-abstract type extending `characterizable_t`.
18
+
4. An `assert_macros.h` header file containing C-preprocessor macros.
19
19
20
20
The `assert` subroutine
21
-
22
-
* Error-terminates with a variable stop code when a user-defined logical assertion fails,
21
+
* Error-terminates with a variable stop code when a caller-provided logical assertion fails,
23
22
* Includes user-supplied diagnostic data in the output if provided by the calling procedure,
24
23
* Is callable inside `pure` procedures, and
25
-
* Can be eliminated during an optimizing compiler's dead-code removal phase based on a preprocessor macro: `-DUSE_ASSERTIONS=.false.`.
24
+
* Can be eliminated at compile-time, as controlled by the `ASSERTIONS` preprocessor define.
25
+
26
+
Assertion enforcement is controlled via the `ASSERTIONS` preprocessor macro,
27
+
which can be defined to non-zero or zero at compilation time to
28
+
respectively enable or disable run-time assertion enforcement.
29
+
30
+
When the `ASSERTIONS` preprocessor macro is not defined to any value,
31
+
the default is that assertions are *disabled* and will not check the condition.
32
+
33
+
To enable assertion enforcement (e.g., for a debug build), define the
34
+
preprocessor ASSERTIONS to non-zero, eg:
35
+
```
36
+
fpm build --flag "-DASSERTIONS"
37
+
```
38
+
The program [example/invoke-via-macro.F90] demonstrates the preferred way to invoke the `assert` subroutine via the three provided macros.
39
+
Invoking `assert` this way insures that `assert` invocations will be completely removed whenever the `ASSERTIONS` macro is undefined (or defined to zero) during compilation.
40
+
Due to a limitation of `fpm`, this approach works best if the project using Assert is also a `fpm` project.
41
+
If instead `fpm install` is used, then either the user must copy `include/assert_macros.h` to the installation directory (default: `~/.local/include`) or
42
+
the user must invoke `assert` directly (via `call assert(...)`).
43
+
In the latter approach when the assertions are disabled, the `assert` procedure will start and end with `if (.false.) then ... end if`, which might facilitate automatic removal of `assert` during the dead-code removal phase of optimizing compilers.
26
44
27
45
The `characterizable_t` type defines an `as_character()` deferred binding that produces `character` strings for use as diagnostic output from a user-defined derived type that extends `characterizable_t` and implements the deferred binding.
28
46
@@ -43,7 +61,7 @@ The requirements and assurances might be constraints of three kinds:
43
61
2.**Postconditions (assurances):** expressions that must evaluate to `.true.` when a procedure finishes execution, and
44
62
3.**Invariants:** universal pre- and postconditions that must always be true when all procedures in a class start or finish executing.
45
63
46
-
The [examples/README.md] file shows examples of writing constraints in notes on class diagrams using the formal syntax of the Object Constraint Language ([OCL]).
64
+
The [example/README.md] file shows examples of writing constraints in notes on class diagrams using the formal syntax of the Object Constraint Language ([OCL]).
47
65
48
66
Downloading, Building, and Running Examples
49
67
-------------------------------------------
@@ -58,14 +76,14 @@ cd assert
58
76
#### Single-image (serial) execution
59
77
The following command builds Assert and runs the full test suite in a single image:
60
78
```
61
-
fpm test --profile release
79
+
fpm test --profile release --flag "-ffree-line-length-0"
62
80
```
63
-
which builds the Assert library and runs the test suite.
81
+
which builds the Assert library (with the default of assertion enforcement disabled) and runs the test suite.
64
82
65
83
#### Multi-image (parallel) execution
66
84
With `gfortran` and OpenCoarrays installed,
67
85
```
68
-
fpm test --compiler caf --profile release --runner "cafrun -n 2"
0 commit comments