From 0bb885dab2c64dc1dec40b0f1f898b141a7e65d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Mon, 15 Nov 2021 17:04:37 +0100 Subject: [PATCH] Bring soltestAssert() up to date with solAssert() - Allow omitting description. - Provide a default description. - Use a custom exception type derived from util::Exception rather than std::exception. --- test/libsolidity/util/SoltestErrors.h | 29 ++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/test/libsolidity/util/SoltestErrors.h b/test/libsolidity/util/SoltestErrors.h index e223f714b..849a8b34e 100644 --- a/test/libsolidity/util/SoltestErrors.h +++ b/test/libsolidity/util/SoltestErrors.h @@ -15,20 +15,35 @@ #pragma once #include +#include #include #include +#include +#include +#include + namespace solidity::frontend::test { -#define soltestAssert(CONDITION, DESCRIPTION) \ - do \ - { \ - if (!(CONDITION)) \ - BOOST_THROW_EXCEPTION(std::runtime_error(DESCRIPTION)); \ - } \ - while (false) +struct InternalSoltestError: virtual util::Exception {}; +#if !BOOST_PP_VARIADICS_MSVC +#define soltestAssert(...) BOOST_PP_OVERLOAD(soltestAssert_,__VA_ARGS__)(__VA_ARGS__) +#else +#define soltestAssert(...) BOOST_PP_CAT(BOOST_PP_OVERLOAD(soltestAssert_,__VA_ARGS__)(__VA_ARGS__),BOOST_PP_EMPTY()) +#endif + +#define soltestAssert_1(CONDITION) \ + soltestAssert_2((CONDITION), "") + +#define soltestAssert_2(CONDITION, DESCRIPTION) \ + assertThrowWithDefaultDescription( \ + (CONDITION), \ + ::solidity::frontend::test::InternalSoltestError, \ + (DESCRIPTION), \ + "Soltest assertion failed" \ + ) class TestParserError: virtual public util::Exception {