1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
program test_assert_macros
use assert_m
implicit none
print *
print '(a)',"The call_assert macro"
#undef ASSERTIONS
#define ASSERTIONS 1
#include "assert_macros.h"
call_assert(1==1)
print '(a)'," passes on not error-terminating when an assertion expression evaluating to .true. is the only argument"
#undef ASSERTIONS
#include "assert_macros.h"
call_assert(.false.)
print '(a)'," passes on being removed by the preprocessor when ASSERTIONS is undefined" // new_line('')
!------------------------------------------
print '(a)',"The call_assert_describe macro"
#undef ASSERTIONS
#define ASSERTIONS 1
#include "assert_macros.h"
call_assert_describe(.true., ".true.")
print '(a)'," passes on not error-terminating when assertion = .true. and a description is present"
#undef ASSERTIONS
#include "assert_macros.h"
call_assert_describe(.false., "")
print '(a)'," passes on being removed by the preprocessor when ASSERTIONS is undefined" // new_line('')
!------------------------------------------
#undef ASSERTIONS
#define ASSERTIONS 1
#include "assert_macros.h"
print '(a)',"The call_assert_* macros"
block
logical :: foo
foo = check_assert(.true.)
print '(a)'," pass on invocation from a pure function"
end block
!------------------------------------------
#undef ASSERTIONS
#define ASSERTIONS 1
#include "assert_macros.h"
! The following examples are taken from README.md and should be kept in sync with that document:
block
integer :: computed_checksum = 37, expected_checksum = 37
#if defined(_CRAYFTN) || defined(__LFORTRAN__)
! Cray Fortran uses different line continuations in macro invocations
call_assert_describe( computed_checksum == expected_checksum, &
"Checksum mismatch failure!" &
)
print *," passes with line breaks inside macro invocation"
call_assert_describe( computed_checksum == expected_checksum, & ! ensured since version 3.14
"Checksum mismatch failure!" & ! TODO: write a better message here
)
print *," passes with C block comments embedded in macro invocation"
#else
call_assert_describe( computed_checksum == expected_checksum, \
"Checksum mismatch failure!" \
)
print *," passes with line breaks inside macro invocation"
call_assert_describe( computed_checksum == expected_checksum, /* ensured since version 3.14 */ \
"Checksum mismatch failure!" /* TODO: write a better message here */ \
)
print *," passes with C block comments embedded in macro invocation"
#endif
end block
!------------------------------------------
contains
pure function check_assert(cond) result(ok)
logical, intent(in) :: cond
logical ok
call_assert(cond)
call_assert_describe(cond, "check_assert")
ok = .true.
end function
end program
|