Skip to content

Commit ee9a568

Browse files
authored
Merge pull request #42 from bonachea/auto-desc
Auto description
2 parents 6047dd8 + d1fcd76 commit ee9a568

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

example/invoke-via-macro.F90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ program invoke_via_macro
2828
print *,'Here comes the expected assertion failure:'
2929
print *
3030
#endif
31+
!call_assert(1+1>2)
32+
!call_assert_describe(1+1>2, "Mathematics is broken!")
3133
call_assert_diagnose(1+1>2, "example with array diagnostic data" , intrinsic_array_t([1,1,2])) ! false assertion
3234

3335
end program invoke_via_macro

include/assert_macros.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@
1111
#define ASSERTIONS 0
1212
#endif
1313

14+
! Deal with stringification issues:
15+
! https://gcc.gnu.org/legacy-ml/fortran/2009-06/msg00131.html
16+
#ifndef STRINGIFY
17+
# ifdef __GFORTRAN__
18+
# define STRINGIFY(x) "x"
19+
# else
20+
# define STRINGIFY(x) #x
21+
# endif
22+
#endif
23+
1424
#if ASSERTIONS
15-
# define call_assert(assertion) call assert(assertion, "No description provided (see file " // __FILE__ // ", line " // string(__LINE__) // ")")
16-
# define call_assert_describe(assertion, description) call assert(assertion, description // " in file " // __FILE__ // ", line " // string(__LINE__) // ": " )
17-
# define call_assert_diagnose(assertion, description, diagnostic_data) call assert(assertion, "file " // __FILE__ // ", line " // string(__LINE__) // ": " // description, diagnostic_data)
25+
# define call_assert(assertion) call assert(assertion, "call_assert(" // STRINGIFY(assertion) // ") in file " // __FILE__ // ", line " // string(__LINE__))
26+
# define call_assert_describe(assertion, description) call assert(assertion, description // " in file " // __FILE__ // ", line " // string(__LINE__))
27+
# define call_assert_diagnose(assertion, description, diagnostic_data) call assert(assertion, description // " in file " // __FILE__ // ", line " // string(__LINE__), diagnostic_data)
1828
#else
1929
# define call_assert(assertion)
2030
# define call_assert_describe(assertion, description)

src/assert/assert_subroutine_s.F90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
represent_diagnostics_as_string: &
3232
if (.not. present(diagnostic_data)) then
3333

34-
trailer = "(none provided)"
34+
trailer = ""
3535

3636
else
3737

@@ -51,10 +51,11 @@
5151
class default
5252
trailer = "of unsupported type."
5353
end select
54+
trailer = ' with diagnostic data "' // trailer // '"'
5455

5556
end if represent_diagnostics_as_string
5657

57-
error stop header // ' with diagnostic data "' // trailer // '"'
58+
error stop header // trailer
5859

5960
end if check_assertion
6061

0 commit comments

Comments
 (0)