From 59bb99f65378f9a153bcee0c8c33d831aa8b7cff Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 26 Sep 2023 21:31:19 +0200 Subject: [PATCH] Library: fix shortcoming with exception-expectations VERIFY_ERROR allows to check that an expected except is actually thrown. The implementation was lazy however; it just investigated the C-style error flag instead of *really* verifying that an *lumiera::Exception* with the expected flag was caught. This discrepancy can be a problem when there is a stray error flag set, or for some reason the error flag gets cleared before the exception reaches the top-level catch-block in the test. --- src/lib/test/test-helper.hpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/lib/test/test-helper.hpp b/src/lib/test/test-helper.hpp index 115a44919..20f2b0891 100644 --- a/src/lib/test/test-helper.hpp +++ b/src/lib/test/test-helper.hpp @@ -341,16 +341,24 @@ operator""_expect (const char* lit, size_t siz) * an assertion failure. In case of an exception, the #lumiera_error * state is checked, cleared and verified. */ -#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT) \ - try \ - { \ - ERRONEOUS_STATEMENT ; \ - NOTREACHED("expected '%s' failure in: %s", \ - #ERROR_ID, #ERRONEOUS_STATEMENT); \ - } \ - catch (...) \ - { \ - CHECK (lumiera_error_expect (LUMIERA_ERROR_##ERROR_ID));\ +#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT) \ + try \ + { \ + ERRONEOUS_STATEMENT ; \ + NOTREACHED("expected '%s' failure in: %s", \ + #ERROR_ID, #ERRONEOUS_STATEMENT); \ + } \ + catch (lumiera::Error& ex) \ + { \ + CHECK (ex.getID() \ + == lib::test::ExpectString{LUMIERA_ERROR_##ERROR_ID} );\ + lumiera_error(); \ + } \ + catch (...) \ + { \ + CHECK (lumiera_error_peek() \ + == lib::test::ExpectString{LUMIERA_ERROR_##ERROR_ID} ); \ + lumiera_error(); \ }