-
Notifications
You must be signed in to change notification settings - Fork 11
Assertion chores, fixes, documentation and new test #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
60a4f46
d8563b7
0d7794d
88b5780
17fdf41
f3b749d
849721a
bdb6d47
209b957
4b6f19e
655e848
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| name = "julienne" | ||
|
|
||
| [dependencies] | ||
| assert = {git = "https://github.com/berkeleylab/assert", tag = "3.0.0"} | ||
| assert = {git = "https://github.com/berkeleylab/assert", tag = "3.0.2"} | ||
|
|
||
| [install] | ||
| library = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| ! Copyright (c) 2024-2025, The Regents of the University of California and Sourcery Institute | ||
| ! Terms of use are as specified in LICENSE.txt | ||
|
|
||
| module julienne_assert_m | ||
| !! Define interfaces for writing assertions | ||
| use julienne_test_diagnosis_m, only : test_diagnosis_t | ||
| implicit none | ||
|
|
||
| private | ||
| public :: call_julienne_assert_ | ||
| public :: julienne_assert | ||
|
|
||
| interface call_julienne_assert_ | ||
|
|
||
| pure module subroutine julienne_assert(test_diagnosis, file, line) | ||
| !! This subroutine wraps the Assert library's `assert` subroutine. | ||
| !! | ||
| !! Use Cases | ||
| !! --------- | ||
| !! 1. Invoke julienne_assert via the generic interface `call_julienne_assert` to | ||
| !! facilitate complete removal when compiling without the flag `-DASSERTIONS`. | ||
| !! 2. Invoke julienne_assert via direct procedure call to guarantee execution. | ||
| !! | ||
| !! Usage | ||
| !! ----- | ||
| !! Make the only actual argument an expression containing `test_diagnosis_t` defined | ||
| !! operations, such as `x .approximates. y .within. tolerance`. The expression | ||
| !! result will be a `test_diagnosis_t` object on which `julienne_assert` will invoke | ||
| !! the `diagnostics_string()` type-bound procedure, the result of which julienne_assert | ||
| !! will include in the stop code of an `error stop` if the expresssion is untrue. | ||
| !! The resulting stop code will contain such information as the operand values and | ||
| !! roles (expected value, actual value, tolerance value). In use case 1, compiling | ||
| !! with `-DASSERTIONS` will cause the preprocessor to insert the corresponding | ||
| !! invocations's line number and the encompassing file's name as the `file` and `line` | ||
| !! arguments, respectively, which `julienne_assert` will include in the stop code. | ||
| !! Most compilers will write the stop code to `error_unit`. | ||
| !! | ||
| !! If a literal reproduction of the test expression suffices, such as when the | ||
| !! expression is `allocated(a)`, then instead invoke the Assert library's `assert` | ||
| !! subroutine by that library's `call_assert` macro or by direct call. | ||
| !! When invoking via the macro, make the only actual argument, `assertion`, a | ||
| !! `logical` expression. Then if compiling with `-DASSERTIONS` and if the assertion | ||
| !! evaluates to `.false.`, the stop code will include the text of the expression | ||
| !! argument, the file name, and the line number of the `call_assert` macro invocation. | ||
| implicit none | ||
| type(test_diagnosis_t), intent(in) :: test_diagnosis | ||
| character(len=*), intent(in), optional :: file | ||
| integer, intent(in), optional :: line | ||
| end subroutine | ||
|
|
||
| end interface | ||
|
|
||
| end module julienne_assert_m |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| ! Copyright (c) 2024-2025, The Regents of the University of California and Sourcery Institute | ||
| ! Terms of use are as specified in LICENSE.txt | ||
|
|
||
| submodule(julienne_assert_m) julienne_assert_s | ||
| use assert_m, only : assert_always | ||
| use julienne_m, only : string_t | ||
| implicit none | ||
|
|
||
| contains | ||
|
|
||
| module procedure julienne_assert | ||
| character(len=:), allocatable :: diagnostics_string | ||
| diagnostics_string = test_diagnosis%diagnostics_string() | ||
| if (present(file)) diagnostics_string = diagnostics_string // " in file " // file | ||
| if (present(line)) diagnostics_string = diagnostics_string // " at line " // string_t(line) | ||
| call assert_always(test_diagnosis%test_passed(), diagnostics_string) | ||
| end procedure | ||
|
Comment on lines
+11
to
+17
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because you are using Assert 3+, this procedure could more simply and efficiently be written as: In addition to simplicity, this also has the significant advantage to skipping most of the string-handling overhead for the common case when the assertion is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bonachea nice! I'll try this solution. |
||
|
|
||
| end submodule julienne_assert_s | ||
Uh oh!
There was an error while loading. Please reload this page.