Skip to content

Commit

Permalink
Merge pull request BerkeleyLab#42 from bonachea/auto-desc
Browse files Browse the repository at this point in the history
Auto description
  • Loading branch information
rouson authored Oct 4, 2024
2 parents 6047dd8 + d1fcd76 commit ee9a568
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions example/invoke-via-macro.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ program invoke_via_macro
print *,'Here comes the expected assertion failure:'
print *
#endif
!call_assert(1+1>2)
!call_assert_describe(1+1>2, "Mathematics is broken!")
call_assert_diagnose(1+1>2, "example with array diagnostic data" , intrinsic_array_t([1,1,2])) ! false assertion

end program invoke_via_macro
16 changes: 13 additions & 3 deletions include/assert_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@
#define ASSERTIONS 0
#endif

! Deal with stringification issues:
! https://gcc.gnu.org/legacy-ml/fortran/2009-06/msg00131.html
#ifndef STRINGIFY
# ifdef __GFORTRAN__
# define STRINGIFY(x) "x"
# else
# define STRINGIFY(x) #x
# endif
#endif

#if ASSERTIONS
# define call_assert(assertion) call assert(assertion, "No description provided (see file " // __FILE__ // ", line " // string(__LINE__) // ")")
# define call_assert_describe(assertion, description) call assert(assertion, description // " in file " // __FILE__ // ", line " // string(__LINE__) // ": " )
# define call_assert_diagnose(assertion, description, diagnostic_data) call assert(assertion, "file " // __FILE__ // ", line " // string(__LINE__) // ": " // description, diagnostic_data)
# define call_assert(assertion) call assert(assertion, "call_assert(" // STRINGIFY(assertion) // ") in file " // __FILE__ // ", line " // string(__LINE__))
# define call_assert_describe(assertion, description) call assert(assertion, description // " in file " // __FILE__ // ", line " // string(__LINE__))
# define call_assert_diagnose(assertion, description, diagnostic_data) call assert(assertion, description // " in file " // __FILE__ // ", line " // string(__LINE__), diagnostic_data)
#else
# define call_assert(assertion)
# define call_assert_describe(assertion, description)
Expand Down
5 changes: 3 additions & 2 deletions src/assert/assert_subroutine_s.F90
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
represent_diagnostics_as_string: &
if (.not. present(diagnostic_data)) then

trailer = "(none provided)"
trailer = ""

else

Expand All @@ -51,10 +51,11 @@
class default
trailer = "of unsupported type."
end select
trailer = ' with diagnostic data "' // trailer // '"'

end if represent_diagnostics_as_string

error stop header // ' with diagnostic data "' // trailer // '"'
error stop header // trailer

end if check_assertion

Expand Down

0 comments on commit ee9a568

Please sign in to comment.