Skip to content

Commit 52f5efe

Browse files
authored
Merge pull request #3 from rouson/fix-test
Fix test
2 parents aed8470 + f6e1671 commit 52f5efe

3 files changed

Lines changed: 50 additions & 87 deletions

File tree

src/assert/assert_subroutine_m.F90

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
!
88
#include "assert_macros.h"
99

10+
#include "assert_features.h"
11+
1012
module assert_subroutine_m
1113
!! summary: Utility for runtime enforcement of logical assertions.
1214
!! usage: error-terminate if the assertion fails:
@@ -66,25 +68,61 @@ pure subroutine assert_error_stop_interface(stop_code_char)
6668
#endif
6769
logical, parameter :: enforce_assertions=USE_ASSERTIONS
6870

69-
interface
7071

71-
pure module subroutine assert(assertion, description)
72+
contains
73+
74+
pure subroutine assert(assertion, description)
7275
!! If assertion is .false. and enforcement is enabled (e.g. via -DASSERTIONS=1),
7376
!! then error-terminate with a character stop code that contains the description argument if present
7477
implicit none
7578
logical, intent(in) :: assertion
7679
!! Most assertions will be expressions such as i>0
7780
character(len=*), intent(in) :: description
7881
!! A brief statement of what is being asserted such as "i>0" or "positive i"
79-
end subroutine
8082

81-
pure module subroutine assert_always(assertion, description)
83+
toggle_assertions: &
84+
if (enforce_assertions) then
85+
call assert_always(assertion, description)
86+
end if toggle_assertions
87+
88+
end subroutine
89+
90+
pure subroutine assert_always(assertion, description)
8291
!! Same as above but always enforces the assertion (regardless of ASSERTIONS)
8392
implicit none
8493
logical, intent(in) :: assertion
8594
character(len=*), intent(in) :: description
86-
end subroutine
95+
character(len=:), allocatable :: message
96+
integer me
8797

88-
end interface
98+
check_assertion: &
99+
if (.not. assertion) then
100+
101+
#if ASSERT_MULTI_IMAGE
102+
# if ASSERT_PARALLEL_CALLBACKS
103+
me = assert_this_image()
104+
# else
105+
me = this_image()
106+
# endif
107+
block
108+
character(len=128) image_number
109+
write(image_number, *) me
110+
message = 'Assertion failure on image ' // trim(adjustl(image_number)) // ':' // description
111+
end block
112+
#else
113+
message = 'Assertion failure: ' // description
114+
me = 0 ! avoid a harmless warning
115+
#endif
116+
117+
#if ASSERT_PARALLEL_CALLBACKS
118+
call assert_error_stop(message)
119+
#else
120+
error stop message, QUIET=.false.
121+
#endif
122+
123+
end if check_assertion
124+
125+
end subroutine
89126

90127
end module assert_subroutine_m
128+

src/assert/assert_subroutine_s.F90

Lines changed: 0 additions & 79 deletions
This file was deleted.

test/test-assert-subroutine-error-termination.F90

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ program test_assert_subroutine_error_termination
2727
#elif _CRAYFTN
2828
command = "fpm run --example false-assertion --profile release --compiler crayftn.sh --flag '-DASSERTIONS' > /dev/null 2>&1", &
2929
#else
30-
command = "echo 'example/false_assertion.F90: unsupported compiler' && exit 1", &
30+
! For all other compilers, we assume that the default fpm command works
31+
command = "fpm run --example false-assertion --profile release --flag '-DASSERTIONS -ffree-line-length-0' > /dev/null 2>&1", &
3132
#endif
3233
wait = .true., &
3334
exitstat = exit_status &
@@ -47,15 +48,18 @@ program test_assert_subroutine_error_termination
4748
end if
4849
end if
4950
end block
51+
#else
52+
#ifdef __LFORTRAN__
53+
print *,trim(merge("passes","FAILS ",exit_status/=0)) // " on error-terminating when assertion = .false."
5054
#else
5155
block
5256
integer unit
5357
open(newunit=unit, file="build/exit_status", status="old")
5458
read(unit,*) exit_status
55-
print *,trim(merge("passes","FAILS ",exit_status/=0)) // " on error-terminating when assertion = .false."
5659
close(unit)
5760
end block
5861
#endif
62+
#endif
5963

6064
contains
6165

0 commit comments

Comments
 (0)