Skip to content

Commit ceb08f5

Browse files
author
Damian Rouson
authored
Merge pull request #2 from sourceryinstitute/update-docs
Update documentation
2 parents 7a056f5 + c68befc commit ceb08f5

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

README.md

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Assert
22
======
33

4-
A simple assertion utility taking advantage of the Fortran 2018 standard's introduction of variable stop codes and error termination inside pure procedures.
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.
56

67
Motivations
78
-----------
@@ -10,22 +11,68 @@ Motivations
1011

1112
Overview
1213
--------
13-
This assertion utility contains just one public procedure: an `assert` subroutine that
14+
This assertion utility contains one public procedure and one public abstract type: `assert` and `characterizable_t`, respectively.
15+
The `assert` subroutine
1416

1517
1. error-terminates with a variable stop code when a user-defined logical assertion fails,
1618
2. includes user-supplied diagnostic data in the output if provided by the calling procedure,
1719
3. is callable inside `pure` procedures, and
18-
4. can be eliminated by an optimizing compiler through the use of a preprocessor macro: `-DUSE_ASSERTIONS=.false.`.
20+
4. can be eliminated during an optimizing compiler's dead-code removal phase based on a preprocessor macro: `-DUSE_ASSERTIONS=.false.`.
1921

20-
The intended uses cases are twofold: (1) enforcing programming contracts throughout a project
21-
and (2) providing a convenient way to get temporarily produce output for debugging purposes.o
22+
The `characterizable_t` abstract derived type provides a mechanism for obtaining diagnostic data from a user-defined derived type that implements the `characterizable_t`'s `as_character()` deferred binding.
2223

23-
Contracts enforce
24+
Use Cases
25+
---------
26+
1. [Enforcing programming contracts] throughout a project via runtime checks.
27+
2. Produce output in `pure` procedures for debugging purposes.
28+
29+
### Enforcing programming contracts
2430

2531
1. Preconditions (requirements): `logical` expressions that must evaluate to `.true.` when a procedure starts execution,
2632
2. Postconditions (assurances): expressions that must evaluate to `.false.`
2733
3. Invariants: universal pre- and postconditions that must always be true when all procedures in a class or package start or finish executing.
2834

29-
Examples
30-
--------
31-
See [./examples](./examples).
35+
### Examples
36+
See the [./example](./example) subdirectory.
37+
38+
Downloading, Building, and Running Examples
39+
-------------------------------------------
40+
Prerequisites:
41+
1. A Fortran 2018 compiler (recent Cray, Intel, GNU, and NAG compiler versions suffice).
42+
2. The [Fortran Package Manager](https://github.com/fortran-lang/fpm).
43+
3. _Optional_: [OpenCoarrays] for parallel execution with the GNU Fortran compiler.
44+
45+
### Single-image execution
46+
```
47+
git clone [email protected]:sourceryinstitute/assert
48+
cd assert
49+
fpm run --example simple_assertions
50+
fpm run --example derived_type_diagnostic
51+
```
52+
where the `fpm run` automatically invokes `fpm build` if necessary, .e.g., the `fpm` source has
53+
changed since the most recent build. If `assert` is working correctly, the first `fpm run` above
54+
will error-terminate with the character stop code
55+
```
56+
Assertion "x > 0" failed on image 1 with diagnostic data "-1.00000000"
57+
```
58+
and the second `fpm run` above will error-terminate with the character stop code
59+
```
60+
Assertion "stuff_t%z(): self%defined()" failed on image 1 with diagnostic data "(none provided)"
61+
```
62+
63+
### Multi-image execution with `gfortran` and OpenCoarrays
64+
```
65+
git clone [email protected]/sourceryinstitute/assert
66+
cd assert
67+
fpm run --compiler caf --runner "cafrun -n 2" --example simple_assertions
68+
fpm run --compiler caf --runner "cafrun -n 2" --example derived_type_diagnostic
69+
```
70+
Replace either instance of `2` above with the desired number of images to run for parallel execution.
71+
If `assert` is working correctly, both of the latter `fpm run` commands will error-terminate with one
72+
or more images providing stop codes analogous to those quoted in the [Single-image execution] section.
73+
74+
[Hyperlinks]:#
75+
[OpenCoarrays]: https://github.com/sourceryinstitute/opencoarrays
76+
[Enforcing programming contracts]: #enforcing-programming-contracts
77+
[Single-image execution]: #single-image-execution
78+

example/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
![Classes involved in [derived_type_diagnostic.f90](./derived_type_diagnostic.f90)](https://user-images.githubusercontent.com/13108868/130385757-6b79e5f1-5dec-440c-98f5-0f659c538754.png)

0 commit comments

Comments
 (0)