Improve negative assertions by checking the actual exceptions' content.

This commit is contained in:
hashlag
2026-08-02 03:06:27 +03:00
parent 8b9b67aa0c
commit c03b392bcc
8 changed files with 247 additions and 46 deletions
+34
View File
@@ -0,0 +1,34 @@
#ifndef CHAOSTESTS_TESTHELPERS_ASSERTTHROWEX_HPP
#define CHAOSTESTS_TESTHELPERS_ASSERTTHROWEX_HPP
#include <gtest/gtest.h>
#define ASSERT_THROW_EX(statement, expected_exception_type, assertions) \
do \
{ \
bool ASSERT_THROW_EX_expectedExceptionThrown = false; \
\
try \
{ \
statement; \
} \
catch (const expected_exception_type & ex) \
{ \
ASSERT_THROW_EX_expectedExceptionThrown = true; \
assertions; \
} \
catch (...) \
{ \
FAIL() << "Expected: " << #statement << " throws an exception of type " \
<< #expected_exception_type << ".\n Actual: it throws a different type."; \
} \
\
if (!ASSERT_THROW_EX_expectedExceptionThrown) \
{ \
FAIL() << "Expected: " << #statement << " throws an exception of type " \
<< #expected_exception_type << ".\n Actual: it throws nothing."; \
} \
} \
while (false)
#endif // CHAOSTESTS_TESTHELPERS_ASSERTTHROWEX_HPP