From 1dfa6375599309b03fadb830fce055625f5f53e2 Mon Sep 17 00:00:00 2001 From: Dan Bonachea Date: Thu, 3 Oct 2024 17:17:20 -0700 Subject: [PATCH 1/3] Add automated description generation Also reformat description arguments for uniformity --- include/assert_macros.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/include/assert_macros.h b/include/assert_macros.h index c1b4872..a51a55d 100644 --- a/include/assert_macros.h +++ b/include/assert_macros.h @@ -11,10 +11,20 @@ #define ASSERTIONS 0 #endif +! Deal with Fortran's stringification debacle: +! 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) From 7d19a9d95462a51bcdf82a9fba2d88ccde10211b Mon Sep 17 00:00:00 2001 From: Dan Bonachea Date: Thu, 3 Oct 2024 17:21:21 -0700 Subject: [PATCH 2/3] Remove nusiance output Stop printing: ``` with diagnostic data "(none provided)" ``` at the end of every assertion failure that didn't provide diagnostic data. It's pedantic and redundant. --- example/invoke-via-macro.F90 | 2 ++ src/assert/assert_subroutine_s.F90 | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/example/invoke-via-macro.F90 b/example/invoke-via-macro.F90 index b89df91..12212f1 100644 --- a/example/invoke-via-macro.F90 +++ b/example/invoke-via-macro.F90 @@ -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 diff --git a/src/assert/assert_subroutine_s.F90 b/src/assert/assert_subroutine_s.F90 index 203c279..157b962 100644 --- a/src/assert/assert_subroutine_s.F90 +++ b/src/assert/assert_subroutine_s.F90 @@ -31,7 +31,7 @@ represent_diagnostics_as_string: & if (.not. present(diagnostic_data)) then - trailer = "(none provided)" + trailer = "" else @@ -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 From d1fcd76ff45e81ab92c211c6eaddfc20da4ee0ef Mon Sep 17 00:00:00 2001 From: Dan Bonachea Date: Fri, 4 Oct 2024 15:16:55 -0400 Subject: [PATCH 3/3] Update include/assert_macros.h Co-authored-by: Damian Rouson --- include/assert_macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/assert_macros.h b/include/assert_macros.h index a51a55d..f53bb81 100644 --- a/include/assert_macros.h +++ b/include/assert_macros.h @@ -11,7 +11,7 @@ #define ASSERTIONS 0 #endif -! Deal with Fortran's stringification debacle: +! Deal with stringification issues: ! https://gcc.gnu.org/legacy-ml/fortran/2009-06/msg00131.html #ifndef STRINGIFY # ifdef __GFORTRAN__