Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,4 @@ jobs:
run: |
set -x
( set +e ; fpm run --example false-assertion ${FPM_FLAGS} --flag "$FFLAGS" ; test $? = $ERROR_STOP_CODE )
( set +e ; fpm run --example invoke-via-macro ${FPM_FLAGS} --flag "$FFLAGS" ; test $? = $ERROR_STOP_CODE )
4 changes: 2 additions & 2 deletions include/assert_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#endif

#if ASSERTIONS
# define call_assert(assertion) call assert_always(assertion, "call_assert(" // CPP_STRINGIFY_SOURCE(assertion) // ") in file " // __FILE__ // ", line " // fortran_stringify_integer(__LINE__))
# define call_assert_describe(assertion, description) call assert_always(assertion, description // " in file " // __FILE__ // ", line " // fortran_stringify_integer(__LINE__))
# define call_assert(assertion) call assert_always(assertion, "call_assert(" // CPP_STRINGIFY_SOURCE(assertion) // ")", __FILE__, __LINE__)
# define call_assert_describe(assertion, description) call assert_always(assertion, description, __FILE__, __LINE__)
#else
# define call_assert(assertion)
# define call_assert_describe(assertion, description)
Expand Down
42 changes: 35 additions & 7 deletions src/assert/assert_subroutine_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -87,38 +87,66 @@ pure subroutine assert(assertion, description)

end subroutine

pure subroutine assert_always(assertion, description)
pure subroutine assert_always(assertion, description, file, line)
!! Same as above but always enforces the assertion (regardless of ASSERTIONS)
implicit none
logical, intent(in) :: assertion
character(len=*), intent(in) :: description
character(len=*), intent(in), optional :: file
integer, intent(in), optional :: line
character(len=:), allocatable :: message
character(len=:), allocatable :: location
integer me

check_assertion: &
if (.not. assertion) then
! Avoid harmless warnings from Cray Fortran:
allocate(character(len=0)::message)
allocate(character(len=0)::location)

! format source location, if known
location = ''
if (present(file)) then
location = ' at ' // file // ':'
if (present(line)) then ! only print line number if file is also known
block
character(len=128) line_str
write(line_str, '(i0)') line
location = location // trim(adjustl(line_str))
end block
else
location = location // '<unknown>'
endif
endif

#if ASSERT_MULTI_IMAGE
# if ASSERT_PARALLEL_CALLBACKS
me = assert_this_image()
if (associated(assert_this_image)) then
me = assert_this_image()
else
me = 0
endif
# else
me = this_image()
# endif
block
character(len=128) image_number
write(image_number, *) me
message = 'Assertion failure on image ' // trim(adjustl(image_number)) // ':' // description
message = 'Assertion failure on image ' // trim(adjustl(image_number)) // location // ': ' // description
end block
#else
message = 'Assertion failure: ' // description
message = 'Assertion failure' // location // ': ' // description
me = 0 ! avoid a harmless warning
#endif

#if ASSERT_PARALLEL_CALLBACKS
call assert_error_stop(message)
#else
error stop message, QUIET=.false.
if (associated(assert_this_image)) then
call assert_error_stop(message)
else
; ! deliberate fall-thru
endif
#endif
error stop message, QUIET=.false.

end if check_assertion

Expand Down
16 changes: 0 additions & 16 deletions src/assert/fortran_stringify_integer_m.f90

This file was deleted.

8 changes: 0 additions & 8 deletions src/assert_m.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,5 @@ module assert_m
!! Public interface
use assert_subroutine_m ! DO NOT PLACE AN ONLY CLAUSE HERE!
! All public members of assert_subroutine_m are exported

! The function below is public only to support automated
! invocation via `assert_macros.h`. For a more broadly useful
! function to convert numeric data to string format, please
! consider using the functions that can be accessed via the
! `string_t` generic interface in the Julienne framework at
! https://go.lbl.gov/julienne.
use fortran_stringify_integer_m, only : fortran_stringify_integer
implicit none
end module