From 02841b66c13c730e212132cbb9633c4a8447fefd Mon Sep 17 00:00:00 2001 From: NMuleo Date: Mon, 4 Nov 2024 11:34:03 +0100 Subject: [PATCH 01/21] implement snitch_disable feature change snitch disable configuration template modified: include/snitch/snitch_config.hpp.config disable public API macros (if snitch is disabled) modified: include/snitch/snitch_macros_check.hpp modified: include/snitch/snitch_macros_check_base.hpp modified: include/snitch/snitch_macros_consteval.hpp modified: include/snitch/snitch_macros_constexpr.hpp modified: include/snitch/snitch_macros_exceptions.hpp modified: include/snitch/snitch_macros_misc.hpp modified: include/snitch/snitch_macros_reporter.hpp modified: include/snitch/snitch_macros_test_case.hpp modified: include/snitch/snitch_macros_utility.hpp provide empty class 'registry' declaration and implementation modified: include/snitch/snitch_registry.hpp modified: src/snitch_registry.cpp added option for disabling snitch modified: CMakeLists.txt disable CLI functions modified: src/snitch_cli.cpp added maybe_unused in append helper functions declaration modified: tests/runtime_tests/check.cpp README update --- CMakeLists.txt | 1 + README.md | 1 + include/snitch/snitch_config.hpp.config | 3 + include/snitch/snitch_macros_check.hpp | 166 ++++++++------- include/snitch/snitch_macros_check_base.hpp | 4 +- include/snitch/snitch_macros_consteval.hpp | 76 ++++--- include/snitch/snitch_macros_constexpr.hpp | 121 ++++++----- include/snitch/snitch_macros_exceptions.hpp | 211 +++++++++++--------- include/snitch/snitch_macros_misc.hpp | 24 ++- include/snitch/snitch_macros_reporter.hpp | 17 +- include/snitch/snitch_macros_test_case.hpp | 94 ++++++--- include/snitch/snitch_macros_utility.hpp | 16 +- include/snitch/snitch_registry.hpp | 161 ++++++++++++++- src/snitch_cli.cpp | 26 ++- src/snitch_registry.cpp | 203 ++++++++++++++++--- tests/runtime_tests/check.cpp | 6 + 16 files changed, 785 insertions(+), 345 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 36033218..017b315b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ set(SNITCH_MAX_PATH_LENGTH 1024 CACHE STRING "Maximum length of a file set(SNITCH_MAX_REPORTER_SIZE_BYTES 128 CACHE STRING "Maximum size (in bytes) of a reporter object.") # Feature toggles. +set(SNITCH_DISABLE OFF CACHE BOOL "Disable Snitch at build time") set(SNITCH_DEFINE_MAIN ON CACHE BOOL "Define main() in snitch -- disable to provide your own main() function.") set(SNITCH_WITH_EXCEPTIONS ON CACHE BOOL "Use exceptions in snitch implementation -- will be forced OFF if exceptions are not available.") set(SNITCH_WITH_MULTITHREADING ON CACHE BOOL "Make the testing framework thread-safe -- disable if multithreading is not needed.") diff --git a/README.md b/README.md index 43816f77..f18b0dcb 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ The goal of _snitch_ is to be a simple, cheap, non-invasive, and user-friendly t - Additional API not in _Catch2_, or different from _Catch2_: - Matchers use a different API (see [Matchers](#matchers) below). - Additional macros for testing [`constexpr`](#run-time-and-compile-time) and [`consteval`](#compile-time) expressions. +- Can be disabled at build time. As a side effect, this will reduce the size of the executable, as most, if not all, the Snitch symbols will be removed by the compiler and/or linker (especially when LTO is enabled). If you need features that are not in the list above, please use _Catch2_ or _doctest_. diff --git a/include/snitch/snitch_config.hpp.config b/include/snitch/snitch_config.hpp.config index 337ef072..30048ad1 100644 --- a/include/snitch/snitch_config.hpp.config +++ b/include/snitch/snitch_config.hpp.config @@ -89,6 +89,9 @@ #if !defined(SNITCH_SHARED_LIBRARY) #cmakedefine01 SNITCH_SHARED_LIBRARY #endif +#if !defined(SNITCH_DISABLE) +#cmakedefine01 SNITCH_DISABLE +#endif // clang-format on #if defined(_MSC_VER) diff --git a/include/snitch/snitch_macros_check.hpp b/include/snitch/snitch_macros_check.hpp index d9817839..e7195bba 100644 --- a/include/snitch/snitch_macros_check.hpp +++ b/include/snitch/snitch_macros_check.hpp @@ -4,97 +4,119 @@ #include "snitch/snitch_config.hpp" #include "snitch/snitch_expression.hpp" #include "snitch/snitch_macros_check_base.hpp" +#include "snitch/snitch_macros_utility.hpp" #include "snitch/snitch_macros_warnings.hpp" #include "snitch/snitch_matcher.hpp" #include "snitch/snitch_registry.hpp" #include "snitch/snitch_test_data.hpp" -#define SNITCH_REQUIRE_IMPL(CHECK, EXPECTED, MAYBE_ABORT, ...) \ - do { \ - auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ - SNITCH_WARNING_PUSH \ - SNITCH_WARNING_DISABLE_PARENTHESES \ - SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON \ - if constexpr (SNITCH_IS_DECOMPOSABLE(__VA_ARGS__)) { \ - SNITCH_EXPR(CHECK, EXPECTED, __VA_ARGS__); \ - SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ - } else { \ - const auto SNITCH_CURRENT_EXPRESSION = snitch::impl::expression{ \ - CHECK, #__VA_ARGS__, {}, static_cast(__VA_ARGS__) == EXPECTED}; \ - SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ - } \ - SNITCH_WARNING_POP \ - } while (0) +#if !(SNITCH_DISABLE) + +# define SNITCH_REQUIRE_IMPL(CHECK, EXPECTED, MAYBE_ABORT, ...) \ + do { \ + auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ + SNITCH_WARNING_PUSH \ + SNITCH_WARNING_DISABLE_PARENTHESES \ + SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON \ + if constexpr (SNITCH_IS_DECOMPOSABLE(__VA_ARGS__)) { \ + SNITCH_EXPR(CHECK, EXPECTED, __VA_ARGS__); \ + SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ + } else { \ + const auto SNITCH_CURRENT_EXPRESSION = snitch::impl::expression{ \ + CHECK, #__VA_ARGS__, {}, static_cast(__VA_ARGS__) == EXPECTED}; \ + SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ + } \ + SNITCH_WARNING_POP \ + } while (0) // clang-format off -#define SNITCH_REQUIRE(...) SNITCH_REQUIRE_IMPL("REQUIRE", true, SNITCH_TESTING_ABORT, __VA_ARGS__) -#define SNITCH_CHECK(...) SNITCH_REQUIRE_IMPL("CHECK", true, (void)0, __VA_ARGS__) -#define SNITCH_REQUIRE_FALSE(...) SNITCH_REQUIRE_IMPL("REQUIRE_FALSE", false, SNITCH_TESTING_ABORT, __VA_ARGS__) -#define SNITCH_CHECK_FALSE(...) SNITCH_REQUIRE_IMPL("CHECK_FALSE", false, (void)0, __VA_ARGS__) +# define SNITCH_REQUIRE(...) SNITCH_REQUIRE_IMPL("REQUIRE", true, SNITCH_TESTING_ABORT, __VA_ARGS__) +# define SNITCH_CHECK(...) SNITCH_REQUIRE_IMPL("CHECK", true, (void)0, __VA_ARGS__) +# define SNITCH_REQUIRE_FALSE(...) SNITCH_REQUIRE_IMPL("REQUIRE_FALSE", false, SNITCH_TESTING_ABORT, __VA_ARGS__) +# define SNITCH_CHECK_FALSE(...) SNITCH_REQUIRE_IMPL("CHECK_FALSE", false, (void)0, __VA_ARGS__) // clang-format on -#define SNITCH_SUCCEED(MESSAGE) \ - do { \ - auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ - snitch::registry::report_assertion(true, (MESSAGE)); \ - } while (0) - -#define SNITCH_FAIL(MESSAGE) \ - do { \ - auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ - snitch::registry::report_assertion(false, (MESSAGE)); \ - SNITCH_TESTING_ABORT; \ - } while (0) - -#define SNITCH_FAIL_CHECK(MESSAGE) \ - do { \ - auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ - snitch::registry::report_assertion(false, (MESSAGE)); \ - } while (0) - -#define SNITCH_SKIP(MESSAGE) \ - do { \ - auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ - snitch::registry::report_skipped((MESSAGE)); \ - SNITCH_TESTING_ABORT; \ - } while (0) - -#define SNITCH_SKIP_CHECK(MESSAGE) \ - do { \ - auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ - snitch::registry::report_skipped((MESSAGE)); \ - } while (0) - -#define SNITCH_REQUIRE_THAT_IMPL(CHECK, MAYBE_ABORT, EXPR, ...) \ - do { \ - auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ - const auto SNITCH_TEMP_RESULT = snitch::impl::match(EXPR, __VA_ARGS__); \ - const auto SNITCH_CURRENT_EXPRESSION = snitch::impl::expression{ \ - CHECK, #EXPR ", " #__VA_ARGS__, \ - snitch::resize_or_truncate(SNITCH_TEMP_RESULT.second), \ - SNITCH_TEMP_RESULT.first}; \ - SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ - } while (0) +# define SNITCH_SUCCEED(MESSAGE) \ + do { \ + auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ + snitch::registry::report_assertion(true, (MESSAGE)); \ + } while (0) + +# define SNITCH_FAIL(MESSAGE) \ + do { \ + auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ + snitch::registry::report_assertion(false, (MESSAGE)); \ + SNITCH_TESTING_ABORT; \ + } while (0) + +# define SNITCH_FAIL_CHECK(MESSAGE) \ + do { \ + auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ + snitch::registry::report_assertion(false, (MESSAGE)); \ + } while (0) + +# define SNITCH_SKIP(MESSAGE) \ + do { \ + auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ + snitch::registry::report_skipped((MESSAGE)); \ + SNITCH_TESTING_ABORT; \ + } while (0) + +# define SNITCH_SKIP_CHECK(MESSAGE) \ + do { \ + auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ + snitch::registry::report_skipped((MESSAGE)); \ + } while (0) + +# define SNITCH_REQUIRE_THAT_IMPL(CHECK, MAYBE_ABORT, EXPR, ...) \ + do { \ + auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ + const auto SNITCH_TEMP_RESULT = snitch::impl::match(EXPR, __VA_ARGS__); \ + const auto SNITCH_CURRENT_EXPRESSION = snitch::impl::expression{ \ + CHECK, #EXPR ", " #__VA_ARGS__, \ + snitch::resize_or_truncate(SNITCH_TEMP_RESULT.second), \ + SNITCH_TEMP_RESULT.first}; \ + SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ + } while (0) // clang-format off -#define SNITCH_REQUIRE_THAT(EXPR, ...) SNITCH_REQUIRE_THAT_IMPL("REQUIRE_THAT", SNITCH_TESTING_ABORT, EXPR, __VA_ARGS__) -#define SNITCH_CHECK_THAT(EXPR, ...) SNITCH_REQUIRE_THAT_IMPL("CHECK_THAT", (void)0, EXPR, __VA_ARGS__) +# define SNITCH_REQUIRE_THAT(EXPR, ...) SNITCH_REQUIRE_THAT_IMPL("REQUIRE_THAT", SNITCH_TESTING_ABORT, EXPR, __VA_ARGS__) +# define SNITCH_CHECK_THAT(EXPR, ...) SNITCH_REQUIRE_THAT_IMPL("CHECK_THAT", (void)0, EXPR, __VA_ARGS__) // clang-format on +#else // SNITCH_DISABLE // clang-format off +# define SNITCH_REQUIRE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CHECK(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_REQUIRE_FALSE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CHECK_FALSE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) + +# define SNITCH_SUCCEED(MESSAGE) SNITCH_VOID_STATEMENT +# define SNITCH_FAIL(MESSAGE) SNITCH_VOID_STATEMENT +# define SNITCH_FAIL_CHECK(MESSAGE) SNITCH_VOID_STATEMENT +# define SNITCH_SKIP(MESSAGE) SNITCH_VOID_STATEMENT +# define SNITCH_SKIP_CHECK(MESSAGE) SNITCH_VOID_STATEMENT + +# define SNITCH_REQUIRE_THAT(EXPR, ...) SNITCH_DISCARD_ARGS(EXPR, __VA_ARGS__) +# define SNITCH_CHECK_THAT(EXPR, ...) SNITCH_DISCARD_ARGS(EXPR, __VA_ARGS__) +// clang-format on + +#endif // SNITCH_DISABLE + +// clang-format on #if SNITCH_WITH_SHORTHAND_MACROS -# define SUCCEED(MESSAGE) SNITCH_SUCCEED(MESSAGE) -# define FAIL(MESSAGE) SNITCH_FAIL(MESSAGE) +# define SUCCEED(MESSAGE) SNITCH_SUCCEED(MESSAGE) +# define FAIL(MESSAGE) SNITCH_FAIL(MESSAGE) # define FAIL_CHECK(MESSAGE) SNITCH_FAIL_CHECK(MESSAGE) -# define SKIP(MESSAGE) SNITCH_SKIP(MESSAGE) +# define SKIP(MESSAGE) SNITCH_SKIP(MESSAGE) # define SKIP_CHECK(MESSAGE) SNITCH_SKIP_CHECK(MESSAGE) -# define REQUIRE(...) SNITCH_REQUIRE(__VA_ARGS__) -# define CHECK(...) SNITCH_CHECK(__VA_ARGS__) -# define REQUIRE_FALSE(...) SNITCH_REQUIRE_FALSE(__VA_ARGS__) -# define CHECK_FALSE(...) SNITCH_CHECK_FALSE(__VA_ARGS__) +# define REQUIRE(...) SNITCH_REQUIRE(__VA_ARGS__) +# define CHECK(...) SNITCH_CHECK(__VA_ARGS__) +# define REQUIRE_FALSE(...) SNITCH_REQUIRE_FALSE(__VA_ARGS__) +# define CHECK_FALSE(...) SNITCH_CHECK_FALSE(__VA_ARGS__) # define REQUIRE_THAT(EXP, ...) SNITCH_REQUIRE_THAT(EXP, __VA_ARGS__) -# define CHECK_THAT(EXP, ...) SNITCH_CHECK_THAT(EXP, __VA_ARGS__) +# define CHECK_THAT(EXP, ...) SNITCH_CHECK_THAT(EXP, __VA_ARGS__) #endif // clang-format on diff --git a/include/snitch/snitch_macros_check_base.hpp b/include/snitch/snitch_macros_check_base.hpp index 43201282..0ae78ebd 100644 --- a/include/snitch/snitch_macros_check_base.hpp +++ b/include/snitch/snitch_macros_check_base.hpp @@ -15,7 +15,9 @@ #endif #define SNITCH_NEW_CHECK \ - snitch::impl::scoped_test_check { SNITCH_CURRENT_LOCATION } + snitch::impl::scoped_test_check { \ + SNITCH_CURRENT_LOCATION \ + } #define SNITCH_EXPR(TYPE, EXPECTED, ...) \ auto SNITCH_CURRENT_EXPRESSION = \ diff --git a/include/snitch/snitch_macros_consteval.hpp b/include/snitch/snitch_macros_consteval.hpp index 8e52e340..8dac0cd5 100644 --- a/include/snitch/snitch_macros_consteval.hpp +++ b/include/snitch/snitch_macros_consteval.hpp @@ -4,51 +4,67 @@ #include "snitch/snitch_config.hpp" #include "snitch/snitch_expression.hpp" #include "snitch/snitch_macros_check_base.hpp" +#include "snitch/snitch_macros_utility.hpp" #include "snitch/snitch_macros_warnings.hpp" #include "snitch/snitch_matcher.hpp" #include "snitch/snitch_registry.hpp" #include "snitch/snitch_test_data.hpp" -#define SNITCH_CONSTEVAL_REQUIRE_IMPL(CHECK, EXPECTED, MAYBE_ABORT, ...) \ - do { \ - auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ - SNITCH_WARNING_PUSH \ - SNITCH_WARNING_DISABLE_PARENTHESES \ - SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON \ - if constexpr (SNITCH_IS_DECOMPOSABLE(__VA_ARGS__)) { \ - constexpr SNITCH_EXPR(CHECK, EXPECTED, __VA_ARGS__); \ - SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ - } else { \ +#if !(SNITCH_DISABLE) + +# define SNITCH_CONSTEVAL_REQUIRE_IMPL(CHECK, EXPECTED, MAYBE_ABORT, ...) \ + do { \ + auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ + SNITCH_WARNING_PUSH \ + SNITCH_WARNING_DISABLE_PARENTHESES \ + SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON \ + if constexpr (SNITCH_IS_DECOMPOSABLE(__VA_ARGS__)) { \ + constexpr SNITCH_EXPR(CHECK, EXPECTED, __VA_ARGS__); \ + SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ + } else { \ + constexpr auto SNITCH_CURRENT_EXPRESSION = snitch::impl::expression{ \ + CHECK, #__VA_ARGS__, {}, static_cast(__VA_ARGS__) == EXPECTED}; \ + SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ + } \ + SNITCH_WARNING_POP \ + } while (0) + +// clang-format off +# define SNITCH_CONSTEVAL_REQUIRE(...) SNITCH_CONSTEVAL_REQUIRE_IMPL("CONSTEVAL_REQUIRE", true, SNITCH_TESTING_ABORT, __VA_ARGS__) +# define SNITCH_CONSTEVAL_CHECK(...) SNITCH_CONSTEVAL_REQUIRE_IMPL("CONSTEVAL_CHECK", true, (void)0, __VA_ARGS__) +# define SNITCH_CONSTEVAL_REQUIRE_FALSE(...) SNITCH_CONSTEVAL_REQUIRE_IMPL("CONSTEVAL_REQUIRE_FALSE", false, SNITCH_TESTING_ABORT, __VA_ARGS__) +# define SNITCH_CONSTEVAL_CHECK_FALSE(...) SNITCH_CONSTEVAL_REQUIRE_IMPL("CONSTEVAL_CHECK_FALSE", false, (void)0, __VA_ARGS__) +// clang-format on + +# define SNITCH_CONSTEVAL_REQUIRE_THAT_IMPL(CHECK, MAYBE_ABORT, EXPR, ...) \ + do { \ + auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ + constexpr auto SNITCH_TEMP_RESULT = snitch::impl::match(EXPR, __VA_ARGS__); \ constexpr auto SNITCH_CURRENT_EXPRESSION = snitch::impl::expression{ \ - CHECK, #__VA_ARGS__, {}, static_cast(__VA_ARGS__) == EXPECTED}; \ + CHECK, #EXPR ", " #__VA_ARGS__, \ + snitch::resize_or_truncate(SNITCH_TEMP_RESULT.second), \ + SNITCH_TEMP_RESULT.first}; \ SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ - } \ - SNITCH_WARNING_POP \ - } while (0) + } while (0) // clang-format off -#define SNITCH_CONSTEVAL_REQUIRE(...) SNITCH_CONSTEVAL_REQUIRE_IMPL("CONSTEVAL_REQUIRE", true, SNITCH_TESTING_ABORT, __VA_ARGS__) -#define SNITCH_CONSTEVAL_CHECK(...) SNITCH_CONSTEVAL_REQUIRE_IMPL("CONSTEVAL_CHECK", true, (void)0, __VA_ARGS__) -#define SNITCH_CONSTEVAL_REQUIRE_FALSE(...) SNITCH_CONSTEVAL_REQUIRE_IMPL("CONSTEVAL_REQUIRE_FALSE", false, SNITCH_TESTING_ABORT, __VA_ARGS__) -#define SNITCH_CONSTEVAL_CHECK_FALSE(...) SNITCH_CONSTEVAL_REQUIRE_IMPL("CONSTEVAL_CHECK_FALSE", false, (void)0, __VA_ARGS__) +# define SNITCH_CONSTEVAL_REQUIRE_THAT(EXPR, ...) SNITCH_CONSTEVAL_REQUIRE_THAT_IMPL("CONSTEVAL_REQUIRE_THAT", SNITCH_TESTING_ABORT, EXPR, __VA_ARGS__) +# define SNITCH_CONSTEVAL_CHECK_THAT(EXPR, ...) SNITCH_CONSTEVAL_REQUIRE_THAT_IMPL("CONSTEVAL_CHECK_THAT", (void)0, EXPR, __VA_ARGS__) // clang-format on -#define SNITCH_CONSTEVAL_REQUIRE_THAT_IMPL(CHECK, MAYBE_ABORT, EXPR, ...) \ - do { \ - auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ - constexpr auto SNITCH_TEMP_RESULT = snitch::impl::match(EXPR, __VA_ARGS__); \ - constexpr auto SNITCH_CURRENT_EXPRESSION = snitch::impl::expression{ \ - CHECK, #EXPR ", " #__VA_ARGS__, \ - snitch::resize_or_truncate(SNITCH_TEMP_RESULT.second), \ - SNITCH_TEMP_RESULT.first}; \ - SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ - } while (0) +#else // SNITCH_DISABLE // clang-format off -#define SNITCH_CONSTEVAL_REQUIRE_THAT(EXPR, ...) SNITCH_CONSTEVAL_REQUIRE_THAT_IMPL("CONSTEVAL_REQUIRE_THAT", SNITCH_TESTING_ABORT, EXPR, __VA_ARGS__) -#define SNITCH_CONSTEVAL_CHECK_THAT(EXPR, ...) SNITCH_CONSTEVAL_REQUIRE_THAT_IMPL("CONSTEVAL_CHECK_THAT", (void)0, EXPR, __VA_ARGS__) +# define SNITCH_CONSTEVAL_REQUIRE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEVAL_CHECK(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEVAL_REQUIRE_FALSE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEVAL_CHECK_FALSE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEVAL_REQUIRE_THAT(EXPR, ...) SNITCH_DISCARD_ARGS(EXPR, __VA_ARGS__) +# define SNITCH_CONSTEVAL_CHECK_THAT(EXPR, ...) SNITCH_DISCARD_ARGS(EXPR, __VA_ARGS__) // clang-format on +#endif // SNITCH_DISABLE + // clang-format off #if SNITCH_WITH_SHORTHAND_MACROS # define CONSTEVAL_REQUIRE(...) SNITCH_CONSTEVAL_REQUIRE(__VA_ARGS__) diff --git a/include/snitch/snitch_macros_constexpr.hpp b/include/snitch/snitch_macros_constexpr.hpp index b67d6e95..b1479734 100644 --- a/include/snitch/snitch_macros_constexpr.hpp +++ b/include/snitch/snitch_macros_constexpr.hpp @@ -4,79 +4,96 @@ #include "snitch/snitch_config.hpp" #include "snitch/snitch_expression.hpp" #include "snitch/snitch_macros_check_base.hpp" +#include "snitch/snitch_macros_utility.hpp" #include "snitch/snitch_macros_warnings.hpp" #include "snitch/snitch_matcher.hpp" #include "snitch/snitch_registry.hpp" #include "snitch/snitch_test_data.hpp" -#define SNITCH_CONSTEXPR_REQUIRE_IMPL(CHECK, EXPECTED, MAYBE_ABORT, ...) \ - do { \ - auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ - SNITCH_WARNING_PUSH \ - SNITCH_WARNING_DISABLE_PARENTHESES \ - SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON \ - if constexpr (SNITCH_IS_DECOMPOSABLE(__VA_ARGS__)) { \ - { \ - constexpr SNITCH_EXPR(CHECK "[compile-time]", EXPECTED, __VA_ARGS__); \ - SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ - } \ - { \ - SNITCH_EXPR(CHECK "[run-time]", EXPECTED, __VA_ARGS__); \ - SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ +#if !(SNITCH_DISABLE) + +# define SNITCH_CONSTEXPR_REQUIRE_IMPL(CHECK, EXPECTED, MAYBE_ABORT, ...) \ + do { \ + auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ + SNITCH_WARNING_PUSH \ + SNITCH_WARNING_DISABLE_PARENTHESES \ + SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON \ + if constexpr (SNITCH_IS_DECOMPOSABLE(__VA_ARGS__)) { \ + { \ + constexpr SNITCH_EXPR(CHECK "[compile-time]", EXPECTED, __VA_ARGS__); \ + SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ + } \ + { \ + SNITCH_EXPR(CHECK "[run-time]", EXPECTED, __VA_ARGS__); \ + SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ + } \ + } else { \ + { \ + constexpr auto SNITCH_CURRENT_EXPRESSION = snitch::impl::expression{ \ + CHECK "[compile-time]", \ + #__VA_ARGS__, \ + {}, \ + static_cast(__VA_ARGS__) == EXPECTED}; \ + SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ + } \ + { \ + const auto SNITCH_CURRENT_EXPRESSION = snitch::impl::expression{ \ + CHECK "[run-time]", \ + #__VA_ARGS__, \ + {}, \ + static_cast(__VA_ARGS__) == EXPECTED}; \ + SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ + } \ } \ - } else { \ + SNITCH_WARNING_POP \ + } while (0) + +// clang-format off +# define SNITCH_CONSTEXPR_REQUIRE(...) SNITCH_CONSTEXPR_REQUIRE_IMPL("CONSTEXPR_REQUIRE", true, SNITCH_TESTING_ABORT, __VA_ARGS__) +# define SNITCH_CONSTEXPR_CHECK(...) SNITCH_CONSTEXPR_REQUIRE_IMPL("CONSTEXPR_CHECK", true, (void)0, __VA_ARGS__) +# define SNITCH_CONSTEXPR_REQUIRE_FALSE(...) SNITCH_CONSTEXPR_REQUIRE_IMPL("CONSTEXPR_REQUIRE_FALSE", false, SNITCH_TESTING_ABORT, __VA_ARGS__) +# define SNITCH_CONSTEXPR_CHECK_FALSE(...) SNITCH_CONSTEXPR_REQUIRE_IMPL("CONSTEXPR_CHECK_FALSE", false, (void)0, __VA_ARGS__) +// clang-format on + +# define SNITCH_CONSTEXPR_REQUIRE_THAT_IMPL(CHECK, MAYBE_ABORT, EXPR, ...) \ + do { \ + auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ { \ + constexpr auto SNITCH_TEMP_RESULT = snitch::impl::match(EXPR, __VA_ARGS__); \ constexpr auto SNITCH_CURRENT_EXPRESSION = snitch::impl::expression{ \ - CHECK "[compile-time]", \ - #__VA_ARGS__, \ - {}, \ - static_cast(__VA_ARGS__) == EXPECTED}; \ + CHECK "[compile-time]", #EXPR ", " #__VA_ARGS__, \ + snitch::resize_or_truncate( \ + SNITCH_TEMP_RESULT.second), \ + SNITCH_TEMP_RESULT.first}; \ SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ } \ { \ + const auto SNITCH_TEMP_RESULT = snitch::impl::match(EXPR, __VA_ARGS__); \ const auto SNITCH_CURRENT_EXPRESSION = snitch::impl::expression{ \ - CHECK "[run-time]", \ - #__VA_ARGS__, \ - {}, \ - static_cast(__VA_ARGS__) == EXPECTED}; \ + CHECK "[run-time]", #EXPR ", " #__VA_ARGS__, \ + snitch::resize_or_truncate( \ + SNITCH_TEMP_RESULT.second), \ + SNITCH_TEMP_RESULT.first}; \ SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ } \ - } \ - SNITCH_WARNING_POP \ - } while (0) + } while (0) // clang-format off -#define SNITCH_CONSTEXPR_REQUIRE(...) SNITCH_CONSTEXPR_REQUIRE_IMPL("CONSTEXPR_REQUIRE", true, SNITCH_TESTING_ABORT, __VA_ARGS__) -#define SNITCH_CONSTEXPR_CHECK(...) SNITCH_CONSTEXPR_REQUIRE_IMPL("CONSTEXPR_CHECK", true, (void)0, __VA_ARGS__) -#define SNITCH_CONSTEXPR_REQUIRE_FALSE(...) SNITCH_CONSTEXPR_REQUIRE_IMPL("CONSTEXPR_REQUIRE_FALSE", false, SNITCH_TESTING_ABORT, __VA_ARGS__) -#define SNITCH_CONSTEXPR_CHECK_FALSE(...) SNITCH_CONSTEXPR_REQUIRE_IMPL("CONSTEXPR_CHECK_FALSE", false, (void)0, __VA_ARGS__) +# define SNITCH_CONSTEXPR_REQUIRE_THAT(EXPR, ...) SNITCH_CONSTEXPR_REQUIRE_THAT_IMPL("CONSTEXPR_REQUIRE_THAT", SNITCH_TESTING_ABORT, EXPR, __VA_ARGS__) +# define SNITCH_CONSTEXPR_CHECK_THAT(EXPR, ...) SNITCH_CONSTEXPR_REQUIRE_THAT_IMPL("CONSTEXPR_CHECK_THAT", (void)0, EXPR, __VA_ARGS__) // clang-format on -#define SNITCH_CONSTEXPR_REQUIRE_THAT_IMPL(CHECK, MAYBE_ABORT, EXPR, ...) \ - do { \ - auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ - { \ - constexpr auto SNITCH_TEMP_RESULT = snitch::impl::match(EXPR, __VA_ARGS__); \ - constexpr auto SNITCH_CURRENT_EXPRESSION = snitch::impl::expression{ \ - CHECK "[compile-time]", #EXPR ", " #__VA_ARGS__, \ - snitch::resize_or_truncate(SNITCH_TEMP_RESULT.second), \ - SNITCH_TEMP_RESULT.first}; \ - SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ - } \ - { \ - const auto SNITCH_TEMP_RESULT = snitch::impl::match(EXPR, __VA_ARGS__); \ - const auto SNITCH_CURRENT_EXPRESSION = snitch::impl::expression{ \ - CHECK "[run-time]", #EXPR ", " #__VA_ARGS__, \ - snitch::resize_or_truncate(SNITCH_TEMP_RESULT.second), \ - SNITCH_TEMP_RESULT.first}; \ - SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ - } \ - } while (0) +#else // SNITCH_DISABLE // clang-format off -#define SNITCH_CONSTEXPR_REQUIRE_THAT(EXPR, ...) SNITCH_CONSTEXPR_REQUIRE_THAT_IMPL("CONSTEXPR_REQUIRE_THAT", SNITCH_TESTING_ABORT, EXPR, __VA_ARGS__) -#define SNITCH_CONSTEXPR_CHECK_THAT(EXPR, ...) SNITCH_CONSTEXPR_REQUIRE_THAT_IMPL("CONSTEXPR_CHECK_THAT", (void)0, EXPR, __VA_ARGS__) +# define SNITCH_CONSTEXPR_REQUIRE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEXPR_CHECK(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEXPR_REQUIRE_FALSE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEXPR_CHECK_FALSE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEXPR_REQUIRE_THAT(EXPR, ...) SNITCH_DISCARD_ARGS(EXPR, __VA_ARGS__) +# define SNITCH_CONSTEXPR_CHECK_THAT(EXPR, ...) SNITCH_DISCARD_ARGS(EXPR, __VA_ARGS__) // clang-format on +#endif // SNITCH_DISABLE // clang-format off #if SNITCH_WITH_SHORTHAND_MACROS diff --git a/include/snitch/snitch_macros_exceptions.hpp b/include/snitch/snitch_macros_exceptions.hpp index 883e20e9..44d4ed19 100644 --- a/include/snitch/snitch_macros_exceptions.hpp +++ b/include/snitch/snitch_macros_exceptions.hpp @@ -3,125 +3,144 @@ #if SNITCH_WITH_EXCEPTIONS # include "snitch/snitch_config.hpp" +# include "snitch/snitch_macros_utility.hpp" # include "snitch/snitch_matcher.hpp" # include "snitch/snitch_registry.hpp" # include -# define SNITCH_REQUIRE_THROWS_AS_IMPL(MAYBE_ABORT, EXPRESSION, ...) \ - do { \ - auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ - bool SNITCH_NO_EXCEPTION_THROWN = false; \ - try { \ - static_cast(EXPRESSION); \ - SNITCH_NO_EXCEPTION_THROWN = true; \ - } catch (const __VA_ARGS__&) { \ - snitch::registry::report_assertion(true, #__VA_ARGS__ " was thrown as expected"); \ - snitch::notify_exception_handled(); \ - } catch (...) { \ +# if !(SNITCH_DISABLE) +# define SNITCH_REQUIRE_THROWS_AS_IMPL(MAYBE_ABORT, EXPRESSION, ...) \ + do { \ + auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ + bool SNITCH_NO_EXCEPTION_THROWN = false; \ try { \ - throw; \ - } catch (const std::exception& e) { \ + static_cast(EXPRESSION); \ + SNITCH_NO_EXCEPTION_THROWN = true; \ + } catch (const __VA_ARGS__&) { \ snitch::registry::report_assertion( \ - false, \ - #__VA_ARGS__ " expected but other std::exception thrown; message: ", \ - e.what()); \ + true, #__VA_ARGS__ " was thrown as expected"); \ + snitch::notify_exception_handled(); \ } catch (...) { \ + try { \ + throw; \ + } catch (const std::exception& e) { \ + snitch::registry::report_assertion( \ + false, \ + #__VA_ARGS__ " expected but other std::exception thrown; message: ", \ + e.what()); \ + } catch (...) { \ + snitch::registry::report_assertion( \ + false, #__VA_ARGS__ " expected but other unknown exception thrown"); \ + } \ + snitch::notify_exception_handled(); \ + MAYBE_ABORT; \ + } \ + if (SNITCH_NO_EXCEPTION_THROWN) { \ snitch::registry::report_assertion( \ - false, #__VA_ARGS__ " expected but other unknown exception thrown"); \ + false, #__VA_ARGS__ " expected but no exception thrown"); \ + MAYBE_ABORT; \ } \ - snitch::notify_exception_handled(); \ - MAYBE_ABORT; \ - } \ - if (SNITCH_NO_EXCEPTION_THROWN) { \ - snitch::registry::report_assertion( \ - false, #__VA_ARGS__ " expected but no exception thrown"); \ - MAYBE_ABORT; \ - } \ - } while (0) + } while (0) -# define SNITCH_REQUIRE_THROWS_AS(EXPRESSION, ...) \ - SNITCH_REQUIRE_THROWS_AS_IMPL(SNITCH_TESTING_ABORT, EXPRESSION, __VA_ARGS__) -# define SNITCH_CHECK_THROWS_AS(EXPRESSION, ...) \ - SNITCH_REQUIRE_THROWS_AS_IMPL((void)0, EXPRESSION, __VA_ARGS__) +# define SNITCH_REQUIRE_THROWS_AS(EXPRESSION, ...) \ + SNITCH_REQUIRE_THROWS_AS_IMPL(SNITCH_TESTING_ABORT, EXPRESSION, __VA_ARGS__) +# define SNITCH_CHECK_THROWS_AS(EXPRESSION, ...) \ + SNITCH_REQUIRE_THROWS_AS_IMPL((void)0, EXPRESSION, __VA_ARGS__) -# define SNITCH_REQUIRE_THROWS_MATCHES_IMPL(MAYBE_ABORT, EXPRESSION, EXCEPTION, ...) \ - do { \ - auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ - bool SNITCH_NO_EXCEPTION_THROWN = false; \ - try { \ - static_cast(EXPRESSION); \ - SNITCH_NO_EXCEPTION_THROWN = true; \ - } catch (const EXCEPTION& e) { \ - auto&& SNITCH_TEMP_MATCHER = __VA_ARGS__; \ - if (!SNITCH_TEMP_MATCHER.match(e)) { \ - snitch::registry::report_assertion( \ - false, "could not match caught " #EXCEPTION " with expected content: ", \ - SNITCH_TEMP_MATCHER.describe_match( \ - e, snitch::matchers::match_status::failed)); \ +# define SNITCH_REQUIRE_THROWS_MATCHES_IMPL(MAYBE_ABORT, EXPRESSION, EXCEPTION, ...) \ + do { \ + auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ + bool SNITCH_NO_EXCEPTION_THROWN = false; \ + try { \ + static_cast(EXPRESSION); \ + SNITCH_NO_EXCEPTION_THROWN = true; \ + } catch (const EXCEPTION& e) { \ + auto&& SNITCH_TEMP_MATCHER = __VA_ARGS__; \ + if (!SNITCH_TEMP_MATCHER.match(e)) { \ + snitch::registry::report_assertion( \ + false, \ + "could not match caught " #EXCEPTION " with expected content: ", \ + SNITCH_TEMP_MATCHER.describe_match( \ + e, snitch::matchers::match_status::failed)); \ + snitch::notify_exception_handled(); \ + MAYBE_ABORT; \ + } else { \ + snitch::registry::report_assertion( \ + true, "caught " #EXCEPTION " matched expected content: ", \ + SNITCH_TEMP_MATCHER.describe_match( \ + e, snitch::matchers::match_status::matched)); \ + snitch::notify_exception_handled(); \ + } \ + } catch (...) { \ + try { \ + throw; \ + } catch (const std::exception& e) { \ + snitch::registry::report_assertion( \ + false, \ + #EXCEPTION " expected but other std::exception thrown; message: ", \ + e.what()); \ + } catch (...) { \ + snitch::registry::report_assertion( \ + false, #EXCEPTION " expected but other unknown exception thrown"); \ + } \ snitch::notify_exception_handled(); \ MAYBE_ABORT; \ - } else { \ - snitch::registry::report_assertion( \ - true, "caught " #EXCEPTION " matched expected content: ", \ - SNITCH_TEMP_MATCHER.describe_match( \ - e, snitch::matchers::match_status::matched)); \ - snitch::notify_exception_handled(); \ } \ - } catch (...) { \ - try { \ - throw; \ - } catch (const std::exception& e) { \ + if (SNITCH_NO_EXCEPTION_THROWN) { \ snitch::registry::report_assertion( \ - false, #EXCEPTION " expected but other std::exception thrown; message: ", \ - e.what()); \ - } catch (...) { \ - snitch::registry::report_assertion( \ - false, #EXCEPTION " expected but other unknown exception thrown"); \ + false, #EXCEPTION " expected but no exception thrown"); \ + MAYBE_ABORT; \ } \ - snitch::notify_exception_handled(); \ - MAYBE_ABORT; \ - } \ - if (SNITCH_NO_EXCEPTION_THROWN) { \ - snitch::registry::report_assertion( \ - false, #EXCEPTION " expected but no exception thrown"); \ - MAYBE_ABORT; \ - } \ - } while (0) + } while (0) -# define SNITCH_REQUIRE_THROWS_MATCHES(EXPRESSION, EXCEPTION, ...) \ - SNITCH_REQUIRE_THROWS_MATCHES_IMPL(SNITCH_TESTING_ABORT, EXPRESSION, EXCEPTION, __VA_ARGS__) -# define SNITCH_CHECK_THROWS_MATCHES(EXPRESSION, EXCEPTION, ...) \ - SNITCH_REQUIRE_THROWS_MATCHES_IMPL((void)0, EXPRESSION, EXCEPTION, __VA_ARGS__) +# define SNITCH_REQUIRE_THROWS_MATCHES(EXPRESSION, EXCEPTION, ...) \ + SNITCH_REQUIRE_THROWS_MATCHES_IMPL( \ + SNITCH_TESTING_ABORT, EXPRESSION, EXCEPTION, __VA_ARGS__) +# define SNITCH_CHECK_THROWS_MATCHES(EXPRESSION, EXCEPTION, ...) \ + SNITCH_REQUIRE_THROWS_MATCHES_IMPL((void)0, EXPRESSION, EXCEPTION, __VA_ARGS__) -# define SNITCH_REQUIRE_NOTHROW_IMPL(MAYBE_ABORT, ...) \ - do { \ - auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ - try { \ - static_cast(__VA_ARGS__); \ - snitch::registry::report_assertion(true, #__VA_ARGS__ " did not throw"); \ - } catch (...) { \ +# define SNITCH_REQUIRE_NOTHROW_IMPL(MAYBE_ABORT, ...) \ + do { \ + auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ try { \ - throw; \ - } catch (const std::exception& e) { \ - snitch::registry::report_assertion( \ - false, \ - "expected " #__VA_ARGS__ \ - " not to throw but it threw a std::exception; message: ", \ - e.what()); \ + static_cast(__VA_ARGS__); \ + snitch::registry::report_assertion(true, #__VA_ARGS__ " did not throw"); \ } catch (...) { \ - snitch::registry::report_assertion( \ - false, "expected " #__VA_ARGS__ \ - " not to throw but it threw an unknown exception"); \ + try { \ + throw; \ + } catch (const std::exception& e) { \ + snitch::registry::report_assertion( \ + false, \ + "expected " #__VA_ARGS__ \ + " not to throw but it threw a std::exception; message: ", \ + e.what()); \ + } catch (...) { \ + snitch::registry::report_assertion( \ + false, "expected " #__VA_ARGS__ \ + " not to throw but it threw an unknown exception"); \ + } \ + snitch::notify_exception_handled(); \ + MAYBE_ABORT; \ } \ - snitch::notify_exception_handled(); \ - MAYBE_ABORT; \ - } \ - } while (0) + } while (0) + +# define SNITCH_REQUIRE_NOTHROW(...) \ + SNITCH_REQUIRE_NOTHROW_IMPL(SNITCH_TESTING_ABORT, __VA_ARGS__) +# define SNITCH_CHECK_NOTHROW(...) SNITCH_REQUIRE_NOTHROW_IMPL((void)0, __VA_ARGS__) + +# else // SNITCH_DISABLE + +// clang-format off +# define SNITCH_REQUIRE_THROWS_AS(EXPRESSION, ...) SNITCH_DISCARD_ARGS(EXPRESSION, sizeof(__VA_ARGS__)) +# define SNITCH_CHECK_THROWS_AS(EXPRESSION, ...) SNITCH_DISCARD_ARGS(EXPRESSION, sizeof(__VA_ARGS__)) +# define SNITCH_REQUIRE_THROWS_MATCHES(EXPRESSION, EXCEPTION, ...) SNITCH_DISCARD_ARGS(EXPRESSION, sizeof(EXCEPTION), __VA_ARGS__) +# define SNITCH_CHECK_THROWS_MATCHES(EXPRESSION, EXCEPTION, ...) SNITCH_DISCARD_ARGS(EXPRESSION, sizeof(EXCEPTION), __VA_ARGS__) +# define SNITCH_REQUIRE_NOTHROW(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CHECK_NOTHROW(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +// clang-format on -# define SNITCH_REQUIRE_NOTHROW(...) \ - SNITCH_REQUIRE_NOTHROW_IMPL(SNITCH_TESTING_ABORT, __VA_ARGS__) -# define SNITCH_CHECK_NOTHROW(...) SNITCH_REQUIRE_NOTHROW_IMPL((void)0, __VA_ARGS__) +# endif // clang-format off #if SNITCH_WITH_SHORTHAND_MACROS diff --git a/include/snitch/snitch_macros_misc.hpp b/include/snitch/snitch_macros_misc.hpp index 74a5fd4d..e67589dd 100644 --- a/include/snitch/snitch_macros_misc.hpp +++ b/include/snitch/snitch_macros_misc.hpp @@ -7,17 +7,23 @@ #include "snitch/snitch_section.hpp" #include "snitch/snitch_test_data.hpp" -#define SNITCH_SECTION(...) \ - if (snitch::impl::section_entry_checker SNITCH_MACRO_CONCAT(section_id_, __COUNTER__){ \ - {__VA_ARGS__}, SNITCH_CURRENT_LOCATION, snitch::impl::get_current_test()}) +#if !(SNITCH_DISABLE) +# define SNITCH_SECTION(...) \ + if (snitch::impl::section_entry_checker SNITCH_MACRO_CONCAT(section_id_, __COUNTER__){ \ + {__VA_ARGS__}, SNITCH_CURRENT_LOCATION, snitch::impl::get_current_test()}) -#define SNITCH_CAPTURE(...) \ - auto SNITCH_MACRO_CONCAT(capture_id_, __COUNTER__) = \ - snitch::impl::add_captures(snitch::impl::get_current_test(), #__VA_ARGS__, __VA_ARGS__) +# define SNITCH_CAPTURE(...) \ + auto SNITCH_MACRO_CONCAT(capture_id_, __COUNTER__) = snitch::impl::add_captures( \ + snitch::impl::get_current_test(), #__VA_ARGS__, __VA_ARGS__) -#define SNITCH_INFO(...) \ - auto SNITCH_MACRO_CONCAT(capture_id_, __COUNTER__) = \ - snitch::impl::add_info(snitch::impl::get_current_test(), __VA_ARGS__) +# define SNITCH_INFO(...) \ + auto SNITCH_MACRO_CONCAT(capture_id_, __COUNTER__) = \ + snitch::impl::add_info(snitch::impl::get_current_test(), __VA_ARGS__) +#else // SNITCH_DISABLE +# define SNITCH_SECTION(NAME, ...) if constexpr (false) +# define SNITCH_CAPTURE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_INFO(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +#endif // SNITCH_DISABLE // clang-format off #if SNITCH_WITH_SHORTHAND_MACROS diff --git a/include/snitch/snitch_macros_reporter.hpp b/include/snitch/snitch_macros_reporter.hpp index 91934758..8843e47f 100644 --- a/include/snitch/snitch_macros_reporter.hpp +++ b/include/snitch/snitch_macros_reporter.hpp @@ -5,13 +5,18 @@ #include "snitch/snitch_macros_utility.hpp" #include "snitch/snitch_registry.hpp" -#define SNITCH_REGISTER_REPORTER_CALLBACKS(NAME, ...) \ - static const std::string_view SNITCH_MACRO_CONCAT(reporter_id_, __COUNTER__) \ - [[maybe_unused]] = snitch::tests.add_reporter(NAME, __VA_ARGS__) +#if !(SNITCH_DISABLE) +# define SNITCH_REGISTER_REPORTER_CALLBACKS(NAME, ...) \ + static const std::string_view SNITCH_MACRO_CONCAT(reporter_id_, __COUNTER__) \ + [[maybe_unused]] = snitch::tests.add_reporter(NAME, __VA_ARGS__) -#define SNITCH_REGISTER_REPORTER(NAME, TYPE) \ - static const std::string_view SNITCH_MACRO_CONCAT(reporter_id_, __COUNTER__) \ - [[maybe_unused]] = snitch::tests.add_reporter(NAME) +# define SNITCH_REGISTER_REPORTER(NAME, TYPE) \ + static const std::string_view SNITCH_MACRO_CONCAT(reporter_id_, __COUNTER__) \ + [[maybe_unused]] = snitch::tests.add_reporter(NAME) +#else // SNITCH_DISABLE +# define SNITCH_REGISTER_REPORTER_CALLBACKS(NAME, ...) /* nothing */ +# define SNITCH_REGISTER_REPORTER(NAME, TYPE) static_assert(NAME) +#endif // SNITCH_DISABLE // clang-format off #if SNITCH_WITH_SHORTHAND_MACROS diff --git a/include/snitch/snitch_macros_test_case.hpp b/include/snitch/snitch_macros_test_case.hpp index 1fc42654..920d0210 100644 --- a/include/snitch/snitch_macros_test_case.hpp +++ b/include/snitch/snitch_macros_test_case.hpp @@ -11,8 +11,13 @@ snitch::tests.add({__VA_ARGS__}, SNITCH_CURRENT_LOCATION, &ID); \ void ID() -#define SNITCH_TEST_CASE(...) \ - SNITCH_TEST_CASE_IMPL(SNITCH_MACRO_CONCAT(test_fun_, __COUNTER__), __VA_ARGS__) +#if !(SNITCH_DISABLE) +# define SNITCH_TEST_CASE(...) \ + SNITCH_TEST_CASE_IMPL(SNITCH_MACRO_CONCAT(test_fun_, __COUNTER__), __VA_ARGS__) +#else // SNITCH_DISABLE +# define SNITCH_TEST_CASE(...) \ + [[maybe_unused]] static void SNITCH_MACRO_CONCAT(test_id_, __COUNTER__)() +#endif // SNITCH_DISABLE #define SNITCH_TEMPLATE_LIST_TEST_CASE_IMPL(ID, NAME, TAGS, TYPES) \ template \ @@ -23,9 +28,13 @@ template \ void ID() -#define SNITCH_TEMPLATE_LIST_TEST_CASE(NAME, TAGS, TYPES) \ - SNITCH_TEMPLATE_LIST_TEST_CASE_IMPL( \ - SNITCH_MACRO_CONCAT(test_fun_, __COUNTER__), NAME, TAGS, TYPES) +#if !(SNITCH_DISABLE) +# define SNITCH_TEMPLATE_LIST_TEST_CASE(NAME, TAGS, TYPES) \ + SNITCH_TEMPLATE_LIST_TEST_CASE_IMPL( \ + SNITCH_MACRO_CONCAT(test_fun_, __COUNTER__), NAME, TAGS, TYPES) +#else // SNITCH_DISABLE +# define SNITCH_TEMPLATE_LIST_TEST_CASE(NAME, TAGS, TYPES) SNITCH_VOID_STATEMENT +#endif // SNITCH_DISABLE #define SNITCH_TEMPLATE_TEST_CASE_IMPL(ID, NAME, TAGS, ...) \ template \ @@ -36,24 +45,43 @@ template \ void ID() -#define SNITCH_TEMPLATE_TEST_CASE(NAME, TAGS, ...) \ - SNITCH_TEMPLATE_TEST_CASE_IMPL( \ - SNITCH_MACRO_CONCAT(test_fun_, __COUNTER__), NAME, TAGS, __VA_ARGS__) - -#define SNITCH_TEST_CASE_METHOD_IMPL(ID, FIXTURE, ...) \ - namespace { \ - struct ID : FIXTURE { \ - void test_fun(); \ - }; \ - } \ - static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ - snitch::tests.add_fixture( \ - {#FIXTURE, __VA_ARGS__}, SNITCH_CURRENT_LOCATION, []() { ID{}.test_fun(); }); \ - void ID::test_fun() - -#define SNITCH_TEST_CASE_METHOD(FIXTURE, ...) \ - SNITCH_TEST_CASE_METHOD_IMPL( \ - SNITCH_MACRO_CONCAT(test_fixture_, __COUNTER__), FIXTURE, __VA_ARGS__) +#if !(SNITCH_DISABLE) +# define SNITCH_TEMPLATE_TEST_CASE(NAME, TAGS, ...) \ + SNITCH_TEMPLATE_TEST_CASE_IMPL( \ + SNITCH_MACRO_CONCAT(test_fun_, __COUNTER__), NAME, TAGS, __VA_ARGS__) +#else // SNITCH_DISABLE +# define SNITCH_TEMPLATE_TEST_CASE(NAME, TAGS, ...) \ + template \ + [[maybe_unused]] static void SNITCH_MACRO_CONCAT(test_id_, __COUNTER__)() +#endif // SNITCH_DISABLE + +#if !(SNITCH_DISABLE) +# define SNITCH_TEST_CASE_METHOD_IMPL(ID, FIXTURE, ...) \ + namespace { \ + struct ID : FIXTURE { \ + void test_fun(); \ + }; \ + } \ + static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ + snitch::tests.add_fixture( \ + {#FIXTURE, __VA_ARGS__}, SNITCH_CURRENT_LOCATION, []() { ID{}.test_fun(); }); \ + void ID::test_fun() + +# define SNITCH_TEST_CASE_METHOD(FIXTURE, ...) \ + SNITCH_TEST_CASE_METHOD_IMPL( \ + SNITCH_MACRO_CONCAT(test_fixture_, __COUNTER__), FIXTURE, __VA_ARGS__) +#else // SNITCH_DISABLE +# define SNITCH_TEST_CASE_METHOD_IMPL(ID, FIXTURE, ...) \ + namespace { \ + struct ID : FIXTURE { \ + void test_fun(); \ + }; \ + } \ + inline void ID::test_fun() + +# define SNITCH_TEST_CASE_METHOD(FIXTURE, ...) \ + SNITCH_TEST_CASE_METHOD_IMPL(SNITCH_MACRO_CONCAT(test_id_, __COUNTER__), FIXTURE) +#endif // SNITCH_DISABLE #define SNITCH_TEMPLATE_LIST_TEST_CASE_METHOD_IMPL(ID, FIXTURE, NAME, TAGS, TYPES) \ namespace { \ @@ -69,9 +97,13 @@ template \ void ID::test_fun() -#define SNITCH_TEMPLATE_LIST_TEST_CASE_METHOD(FIXTURE, NAME, TAGS, TYPES) \ - SNITCH_TEMPLATE_LIST_TEST_CASE_METHOD_IMPL( \ - SNITCH_MACRO_CONCAT(test_fixture_, __COUNTER__), FIXTURE, NAME, TAGS, TYPES) +#if !(SNITCH_DISABLE) +# define SNITCH_TEMPLATE_LIST_TEST_CASE_METHOD(FIXTURE, NAME, TAGS, TYPES) \ + SNITCH_TEMPLATE_LIST_TEST_CASE_METHOD_IMPL( \ + SNITCH_MACRO_CONCAT(test_fixture_, __COUNTER__), FIXTURE, NAME, TAGS, TYPES) +#else // SNITCH_DISABLE +# define SNITCH_TEMPLATE_LIST_TEST_CASE_METHOD(FIXTURE, NAME, TAGS, TYPES) SNITCH_VOID_STATEMENT +#endif // SNITCH_DISABLE #define SNITCH_TEMPLATE_TEST_CASE_METHOD_IMPL(ID, FIXTURE, NAME, TAGS, ...) \ namespace { \ @@ -87,9 +119,13 @@ template \ void ID::test_fun() -#define SNITCH_TEMPLATE_TEST_CASE_METHOD(FIXTURE, NAME, TAGS, ...) \ - SNITCH_TEMPLATE_TEST_CASE_METHOD_IMPL( \ - SNITCH_MACRO_CONCAT(test_fixture_, __COUNTER__), FIXTURE, NAME, TAGS, __VA_ARGS__) +#if !(SNITCH_DISABLE) +# define SNITCH_TEMPLATE_TEST_CASE_METHOD(FIXTURE, NAME, TAGS, ...) \ + SNITCH_TEMPLATE_TEST_CASE_METHOD_IMPL( \ + SNITCH_MACRO_CONCAT(test_fixture_, __COUNTER__), FIXTURE, NAME, TAGS, __VA_ARGS__) +#else // SNITCH_DISABLE +# define SNITCH_TEMPLATE_TEST_CASE_METHOD(FIXTURE, NAME, TAGS, ...) SNITCH_VOID_STATEMENT +#endif // SNITCH_DISABLE // clang-format off #if SNITCH_WITH_SHORTHAND_MACROS diff --git a/include/snitch/snitch_macros_utility.hpp b/include/snitch/snitch_macros_utility.hpp index 038fd854..869a1652 100644 --- a/include/snitch/snitch_macros_utility.hpp +++ b/include/snitch/snitch_macros_utility.hpp @@ -2,11 +2,25 @@ #define SNITCH_MACROS_UTILITY_HPP #include "snitch/snitch_config.hpp" +#include "snitch/snitch_macros_warnings.hpp" #define SNITCH_CONCAT_IMPL(x, y) x##y #define SNITCH_MACRO_CONCAT(x, y) SNITCH_CONCAT_IMPL(x, y) #define SNITCH_CURRENT_LOCATION \ - snitch::source_location { std::string_view{__FILE__}, static_cast(__LINE__) } + snitch::source_location { \ + std::string_view{__FILE__}, static_cast(__LINE__) \ + } + +#define SNITCH_DISCARD_ARGS(...) \ + do { \ + SNITCH_WARNING_PUSH \ + SNITCH_WARNING_DISABLE_PARENTHESES \ + SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON \ + static_cast(sizeof(__VA_ARGS__, 0)); \ + SNITCH_WARNING_POP \ + } while (0) + +#define SNITCH_VOID_STATEMENT static_cast(0) #endif diff --git a/include/snitch/snitch_registry.hpp b/include/snitch/snitch_registry.hpp index 051f9da0..0f173684 100644 --- a/include/snitch/snitch_registry.hpp +++ b/include/snitch/snitch_registry.hpp @@ -37,6 +37,8 @@ constexpr std::size_t max_unique_tags = SNITCH_MAX_UNIQUE_TAGS; constexpr std::size_t max_registered_reporters = SNITCH_MAX_REGISTERED_REPORTERS; // Maximum size of a reporter instance, in bytes. constexpr std::size_t max_reporter_size_bytes = SNITCH_MAX_REPORTER_SIZE_BYTES; +// Is Snitch disabled? +constexpr bool is_disabled = SNITCH_DISABLE; } // namespace snitch namespace snitch::impl { @@ -106,12 +108,17 @@ struct registered_reporter { }; template -concept reporter_type = - requires(registry& reg) { T{reg}; } && - requires(T& rep, registry& reg, std::string_view k, std::string_view v) { - { rep.configure(reg, k, v) } -> convertible_to; - } && requires(T& rep, const registry& reg, const event::data& e) { rep.report(reg, e); }; +concept reporter_type = requires(registry& reg) { + T{reg}; +} +&&requires(T& rep, registry& reg, std::string_view k, std::string_view v) { + { rep.configure(reg, k, v) } -> convertible_to; +} +&&requires(T& rep, const registry& reg, const event::data& e) { + rep.report(reg, e); +}; +#if !(SNITCH_DISABLE) class registry { // Contains all registered test cases. small_vector test_list; @@ -330,6 +337,150 @@ class registry { SNITCH_EXPORT small_vector_span reporters() const noexcept; }; +#else // SNITCH_DISABLE + +class registry { + SNITCH_EXPORT void report_default(const registry&, const event::data&) noexcept {} + +public: + enum class verbosity { quiet, normal, high, full } verbose = verbosity::normal; + bool with_color = SNITCH_DEFAULT_WITH_COLOR == 1; + + using print_function = snitch::print_function; + using initialize_report_function = snitch::initialize_report_function; + using configure_report_function = snitch::configure_report_function; + using report_function = snitch::report_function; + using finish_report_function = snitch::finish_report_function; + + print_function print_callback = nullptr; + report_function report_callback = nullptr; + finish_report_function finish_callback = nullptr; + + // Internal API; do not use. + template + void append_or_print(small_string&, T&&) const noexcept {} + + template + void print(Args&&...) const noexcept {} + + template T> + void print(const T&) const noexcept {} + + // Requires: number of reporters + 1 <= max_registered_reporters. + SNITCH_EXPORT std::string_view add_reporter( + std::string_view name, + const std::optional& initialize, + const std::optional& configure, + const report_function& report, + const std::optional& finish); + + // Requires: number of reporters + 1 <= max_registered_reporters. + template + std::string_view add_reporter(std::string_view) { + return {}; + } + + // Internal API; do not use. + // Requires: number of tests + 1 <= max_test_cases, well-formed test ID. + SNITCH_EXPORT const char* + add_impl(const test_id& id, const source_location& location, impl::test_ptr func); + + // Internal API; do not use. + // Requires: number of tests + 1 <= max_test_cases, well-formed test ID. + SNITCH_EXPORT const char* + add(const impl::name_and_tags& id, const source_location& location, impl::test_ptr func); + + // Internal API; do not use. + // Requires: number of tests + added tests <= max_test_cases, well-formed test ID. + template + const char* add_with_types(const impl::name_and_tags&, const source_location&, const F&) { + static_assert(sizeof...(Args) > 0, "empty type list in TEMPLATE_TEST_CASE"); + return {}; + } + + // Internal API; do not use. + // Requires: number of tests + added tests <= max_test_cases, well-formed test ID. + template + const char* add_with_type_list(const impl::name_and_tags&, const source_location&, const F&) { + return {}; + } + + // Internal API; do not use. + // Requires: number of tests + 1 <= max_test_cases, well-formed test ID. + SNITCH_EXPORT const char* add_fixture( + const impl::fixture_name_and_tags& id, + const source_location& location, + impl::test_ptr func); + + // Internal API; do not use. + // Requires: number of tests + added tests <= max_test_cases, well-formed test ID. + template + const char* + add_fixture_with_types(const impl::fixture_name_and_tags&, const source_location&, const F&) { + return {}; + } + + // Internal API; do not use. + // Requires: number of tests + added tests <= max_test_cases, well-formed test ID. + template + const char* add_fixture_with_type_list( + const impl::fixture_name_and_tags&, const source_location&, const F&) { + return {}; + } + + // Internal API; do not use. + SNITCH_EXPORT static void report_assertion(bool, std::string_view) noexcept; + + // Internal API; do not use. + SNITCH_EXPORT static void report_assertion(bool, std::string_view, std::string_view) noexcept; + + // Internal API; do not use. + SNITCH_EXPORT static void report_assertion(bool, const impl::expression&) noexcept; + + // Internal API; do not use. + SNITCH_EXPORT static void report_skipped(std::string_view) noexcept; + + // Internal API; do not use. + SNITCH_EXPORT static void report_section_started(const section&) noexcept; + + // Internal API; do not use. + SNITCH_EXPORT static void report_section_ended(const section&) noexcept; + + // Internal API; do not use. + SNITCH_EXPORT impl::test_state run(impl::test_case& test) noexcept; + + // Internal API; do not use. + SNITCH_EXPORT bool run_tests(std::string_view) noexcept; + + // Internal API; do not use. + SNITCH_EXPORT bool run_selected_tests( + std::string_view, + const filter_info&, + const function_ref&) noexcept; + + /* ---- */ + + SNITCH_EXPORT bool run_tests(const cli::input&) noexcept; + + SNITCH_EXPORT void configure(const cli::input&); + + SNITCH_EXPORT void list_all_tests() const noexcept; + + SNITCH_EXPORT void list_all_tags() const; + + SNITCH_EXPORT void list_tests_with_tag(std::string_view) const noexcept; + + SNITCH_EXPORT void list_all_reporters() const noexcept; + + SNITCH_EXPORT small_vector_span test_cases() noexcept; + SNITCH_EXPORT small_vector_span test_cases() const noexcept; + + SNITCH_EXPORT small_vector_span reporters() noexcept; + SNITCH_EXPORT small_vector_span reporters() const noexcept; +}; + +#endif // SNITCH_DISABLE + SNITCH_EXPORT extern constinit registry tests; } // namespace snitch diff --git a/src/snitch_cli.cpp b/src/snitch_cli.cpp index 23cc6164..9fff49a4 100644 --- a/src/snitch_cli.cpp +++ b/src/snitch_cli.cpp @@ -401,19 +401,23 @@ void print_help(std::string_view program_name, const print_help_settings& settin } std::optional parse_arguments(int argc, const char* const argv[]) noexcept { - // First, parse just looking for color options so we can display console messages correctly. - const bool with_color = impl::parse_color_options(argc, argv); - - // Now parse everything for real. - std::optional ret_args = - impl::parse_arguments(argc, argv, impl::expected_args, {.with_color = with_color}); + if constexpr (SNITCH_DISABLE) { + return {}; + } else { + // First, parse just looking for color options so we can display console messages correctly. + const bool with_color = impl::parse_color_options(argc, argv); + + // Now parse everything for real. + std::optional ret_args = + impl::parse_arguments(argc, argv, impl::expected_args, {.with_color = with_color}); + + if (!ret_args) { + print("\n"); + print_help(argv[0], {.with_color = with_color}); + } - if (!ret_args) { - print("\n"); - print_help(argv[0], {.with_color = with_color}); + return ret_args; } - - return ret_args; } std::optional get_option(const cli::input& args, std::string_view name) noexcept { diff --git a/src/snitch_registry.cpp b/src/snitch_registry.cpp index 36a74562..583a8b5b 100644 --- a/src/snitch_registry.cpp +++ b/src/snitch_registry.cpp @@ -1,9 +1,11 @@ #include "snitch/snitch_registry.hpp" -#include "snitch/snitch_time.hpp" +#if !(SNITCH_DISABLE) -#include // for std::sort -#include // for std::optional +# include "snitch/snitch_time.hpp" + +# include // for std::sort +# include // for std::optional // Testing framework implementation. // --------------------------------- @@ -399,14 +401,14 @@ void register_assertion(bool success, impl::test_state& state) { ++section.allowed_assertion_failure_count; } -#if SNITCH_WITH_EXCEPTIONS +# if SNITCH_WITH_EXCEPTIONS if (state.held_info.has_value()) { for (auto& section : state.held_info.value().sections.current_section) { ++section.assertion_count; ++section.allowed_assertion_failure_count; } } -#endif +# endif impl::set_state(state.test, impl::test_case_state::allowed_fail); } else { @@ -418,14 +420,14 @@ void register_assertion(bool success, impl::test_state& state) { ++section.assertion_failure_count; } -#if SNITCH_WITH_EXCEPTIONS +# if SNITCH_WITH_EXCEPTIONS if (state.held_info.has_value()) { for (auto& section : state.held_info.value().sections.current_section) { ++section.assertion_count; ++section.assertion_failure_count; } } -#endif +# endif impl::set_state(state.test, impl::test_case_state::failed); } @@ -436,13 +438,13 @@ void register_assertion(bool success, impl::test_state& state) { ++section.assertion_count; } -#if SNITCH_WITH_EXCEPTIONS +# if SNITCH_WITH_EXCEPTIONS if (state.held_info.has_value()) { for (auto& section : state.held_info.value().sections.current_section) { ++section.assertion_count; } } -#endif +# endif } } @@ -455,7 +457,7 @@ void report_assertion_impl( register_assertion(success, state); -#if SNITCH_WITH_EXCEPTIONS +# if SNITCH_WITH_EXCEPTIONS const bool use_held_info = (state.unhandled_exception || std::uncaught_exceptions() > 0) && state.held_info.has_value(); @@ -472,13 +474,13 @@ void report_assertion_impl( state.in_check ? assertion_location{last_location.file, last_location.line, location_type::exact} : last_location; -#else +# else const auto captures_buffer = impl::make_capture_buffer(state.info.captures); const auto& current_section = state.info.sections.current_section; const auto& last_location = state.info.locations.back(); const auto location = assertion_location{last_location.file, last_location.line, location_type::exact}; -#endif +# endif if (success) { if (r.verbose >= registry::verbosity::full) { @@ -558,7 +560,7 @@ void registry::report_section_ended(const section& sec) noexcept { const bool skipped = state.test.state == impl::test_case_state::skipped; -#if SNITCH_WITH_TIMINGS +# if SNITCH_WITH_TIMINGS const auto duration = get_duration_in_seconds(sec.start_time, get_current_time()); state.reg.report_callback( state.reg, event::section_ended{ @@ -569,7 +571,7 @@ void registry::report_section_ended(const section& sec) noexcept { .assertion_failure_count = sec.assertion_failure_count, .allowed_assertion_failure_count = sec.allowed_assertion_failure_count, .duration = duration}); -#else +# else state.reg.report_callback( state.reg, event::section_ended{ .id = sec.id, @@ -578,7 +580,7 @@ void registry::report_section_ended(const section& sec) noexcept { .assertion_count = sec.assertion_count, .assertion_failure_count = sec.assertion_failure_count, .allowed_assertion_failure_count = sec.allowed_assertion_failure_count}); -#endif +# endif } impl::test_state registry::run(impl::test_case& test) noexcept { @@ -610,13 +612,13 @@ impl::test_state registry::run(impl::test_case& test) noexcept { impl::test_state* previous_run = impl::try_get_current_test(); impl::set_current_test(&state); -#if SNITCH_WITH_TIMINGS +# if SNITCH_WITH_TIMINGS const auto time_start = get_current_time(); -#endif +# endif -#if SNITCH_WITH_EXCEPTIONS +# if SNITCH_WITH_EXCEPTIONS try { -#endif +# endif do { // Reset section state. @@ -640,7 +642,7 @@ impl::test_state registry::run(impl::test_case& test) noexcept { } while (!state.info.sections.levels.empty() && state.test.state != impl::test_case_state::skipped); -#if SNITCH_WITH_EXCEPTIONS +# if SNITCH_WITH_EXCEPTIONS state.in_check = true; report_assertion(true, "no exception caught"); state.in_check = false; @@ -660,7 +662,7 @@ impl::test_state registry::run(impl::test_case& test) noexcept { } state.unhandled_exception = false; -#endif +# endif if (state.should_fail) { state.should_fail = false; @@ -671,12 +673,12 @@ impl::test_state registry::run(impl::test_case& test) noexcept { state.should_fail = true; } -#if SNITCH_WITH_TIMINGS +# if SNITCH_WITH_TIMINGS state.duration = get_duration_in_seconds(time_start, get_current_time()); -#endif +# endif if (verbose >= registry::verbosity::high) { -#if SNITCH_WITH_TIMINGS +# if SNITCH_WITH_TIMINGS report_callback( *this, event::test_case_ended{ .id = test.id, @@ -686,7 +688,7 @@ impl::test_state registry::run(impl::test_case& test) noexcept { .allowed_assertion_failure_count = state.allowed_failures, .state = impl::convert_to_public_state(state.test.state), .duration = state.duration}); -#else +# else report_callback( *this, event::test_case_ended{ .id = test.id, @@ -695,7 +697,7 @@ impl::test_state registry::run(impl::test_case& test) noexcept { .assertion_failure_count = state.failures, .allowed_assertion_failure_count = state.allowed_failures, .state = impl::convert_to_public_state(state.test.state)}); -#endif +# endif } impl::set_current_test(previous_run); @@ -722,9 +724,9 @@ bool registry::run_selected_tests( std::size_t assertion_failure_count = 0; std::size_t allowed_assertion_failure_count = 0; -#if SNITCH_WITH_TIMINGS +# if SNITCH_WITH_TIMINGS const auto time_start = get_current_time(); -#endif +# endif for (impl::test_case& t : this->test_cases()) { if (!predicate(t.id)) { @@ -763,12 +765,12 @@ bool registry::run_selected_tests( } } -#if SNITCH_WITH_TIMINGS +# if SNITCH_WITH_TIMINGS const float duration = get_duration_in_seconds(time_start, get_current_time()); -#endif +# endif if (verbose >= registry::verbosity::normal) { -#if SNITCH_WITH_TIMINGS +# if SNITCH_WITH_TIMINGS report_callback( *this, event::test_run_ended{ .name = run_name, @@ -783,7 +785,7 @@ bool registry::run_selected_tests( .duration = duration, .success = success, }); -#else +# else report_callback( *this, event::test_run_ended{ .name = run_name, @@ -796,7 +798,7 @@ bool registry::run_selected_tests( .assertion_failure_count = assertion_failure_count, .allowed_assertion_failure_count = allowed_assertion_failure_count, .success = success}); -#endif +# endif } return success; @@ -1134,3 +1136,138 @@ small_vector_span registry::reporters() const noexcep constinit registry tests; } // namespace snitch + +#else // SNITCH_DISABLE + +namespace snitch { +filter_result filter_result_and(filter_result first, filter_result second) noexcept { + return {}; +} + +filter_result filter_result_or(filter_result first, filter_result second) noexcept { + return {}; +} + +filter_result is_filter_match_name(std::string_view name, std::string_view filter) noexcept { + return {}; +} + +filter_result is_filter_match_tags_single(std::string_view tags, std::string_view filter) noexcept { + return {}; +} + +filter_result is_filter_match_tags(std::string_view tags, std::string_view filter) noexcept { + return {}; +} + +filter_result is_filter_match_id_single( + std::string_view name, std::string_view tags, std::string_view filter) noexcept { + return {}; +} + +filter_result +is_filter_match_id(std::string_view name, std::string_view tags, std::string_view filter) noexcept { + return {}; +} +} // namespace snitch + +namespace snitch::impl { +std::string_view +make_full_name(small_string& buffer, const test_id& id) noexcept { + return {}; +} + +bool parse_colour_mode_option(registry& reg, std::string_view color_option) noexcept { + return {}; +} +bool parse_color_option(registry& reg, std::string_view color_option) noexcept { + return {}; +} +} // namespace snitch::impl + +namespace snitch { + +const char* +registry::add_impl(const test_id& id, const source_location& location, impl::test_ptr func) { + return {}; +} + +const char* +registry::add(const impl::name_and_tags& id, const source_location& location, impl::test_ptr func) { + return {}; +} + +const char* registry::add_fixture( + const impl::fixture_name_and_tags& id, const source_location& location, impl::test_ptr func) { + return {}; +} + +std::string_view registry::add_reporter( + std::string_view, + const std::optional&, + const std::optional&, + const report_function&, + const std::optional&) { + return {}; +} + +void registry::report_assertion(bool, std::string_view) noexcept {} + +void registry::report_assertion(bool, std::string_view, std::string_view) noexcept {} + +void registry::report_assertion(bool, const impl::expression&) noexcept {} + +void registry::report_skipped(std::string_view) noexcept {} + +void registry::report_section_started(const section&) noexcept {} + +void registry::report_section_ended(const section&) noexcept {} + +impl::test_state registry::run(impl::test_case& test) noexcept { + return impl::test_state{*this, test}; +} + +bool registry::run_tests(std::string_view) noexcept { + return true; +} + +bool registry::run_selected_tests( + std::string_view, + const filter_info&, + const function_ref&) noexcept { + return true; +} + +/* ---- */ + +bool registry::run_tests(const cli::input&) noexcept { + return true; +} + +void registry::configure(const cli::input&) {} + +void registry::list_all_tests() const noexcept {} + +void registry::list_all_tags() const {} + +void registry::list_tests_with_tag(std::string_view) const noexcept {} + +void registry::list_all_reporters() const noexcept {} + +small_vector_span registry::test_cases() noexcept { + return small_vector_span{nullptr, 0, nullptr}; +} +small_vector_span registry::test_cases() const noexcept { + return {}; +} + +small_vector_span registry::reporters() noexcept { + return small_vector_span{nullptr, 0, nullptr}; +} +small_vector_span registry::reporters() const noexcept { + return {}; +} + +constinit registry tests; +} // namespace snitch +#endif // SNITCH_DISABLE diff --git a/tests/runtime_tests/check.cpp b/tests/runtime_tests/check.cpp index aeb00612..04f86890 100644 --- a/tests/runtime_tests/check.cpp +++ b/tests/runtime_tests/check.cpp @@ -32,6 +32,9 @@ struct non_relocatable { } }; +#if SNITCH_DISABLE +[[maybe_unused]] +#endif bool append(snitch::small_string_span ss, const non_relocatable& o) noexcept { return append(ss, "non_relocatable{", o.value, "}"); } @@ -67,6 +70,9 @@ struct unary_long_string { } }; +#if SNITCH_DISABLE +[[maybe_unused]] +#endif bool append(snitch::small_string_span ss, const unary_long_string& u) noexcept { return append(ss, u.value); } From f0d790c77a9eb31175062442e0fd53b7cbcedf9b Mon Sep 17 00:00:00 2001 From: NicoMuleo <49640252+NicoMuleo@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:33:46 +0100 Subject: [PATCH 02/21] Update CMakeLists.txt make snitch lower case Co-authored-by: Corentin Schreiber --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 017b315b..ea91d52e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ set(SNITCH_MAX_PATH_LENGTH 1024 CACHE STRING "Maximum length of a file set(SNITCH_MAX_REPORTER_SIZE_BYTES 128 CACHE STRING "Maximum size (in bytes) of a reporter object.") # Feature toggles. -set(SNITCH_DISABLE OFF CACHE BOOL "Disable Snitch at build time") +set(SNITCH_DISABLE OFF CACHE BOOL "Disable snitch at build time") set(SNITCH_DEFINE_MAIN ON CACHE BOOL "Define main() in snitch -- disable to provide your own main() function.") set(SNITCH_WITH_EXCEPTIONS ON CACHE BOOL "Use exceptions in snitch implementation -- will be forced OFF if exceptions are not available.") set(SNITCH_WITH_MULTITHREADING ON CACHE BOOL "Make the testing framework thread-safe -- disable if multithreading is not needed.") From d94cb7b935eb887e431eb76874f093c8658e0eb4 Mon Sep 17 00:00:00 2001 From: NicoMuleo <49640252+NicoMuleo@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:34:14 +0100 Subject: [PATCH 03/21] Update README.md Co-authored-by: Corentin Schreiber --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f18b0dcb..d37fcdc5 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ The goal of _snitch_ is to be a simple, cheap, non-invasive, and user-friendly t - Additional API not in _Catch2_, or different from _Catch2_: - Matchers use a different API (see [Matchers](#matchers) below). - Additional macros for testing [`constexpr`](#run-time-and-compile-time) and [`consteval`](#compile-time) expressions. -- Can be disabled at build time. As a side effect, this will reduce the size of the executable, as most, if not all, the Snitch symbols will be removed by the compiler and/or linker (especially when LTO is enabled). +- Can be disabled at build time, to allow mixing code and tests in the same file with minimal overheads. If you need features that are not in the list above, please use _Catch2_ or _doctest_. From 28ef1a9069022a789a1c96a6872fbc410cb85596 Mon Sep 17 00:00:00 2001 From: NicoMuleo <49640252+NicoMuleo@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:37:39 +0100 Subject: [PATCH 04/21] Update include/snitch/snitch_macros_consteval.hpp Fix indentation Co-authored-by: Corentin Schreiber --- include/snitch/snitch_macros_consteval.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/snitch/snitch_macros_consteval.hpp b/include/snitch/snitch_macros_consteval.hpp index 8dac0cd5..b20d71c4 100644 --- a/include/snitch/snitch_macros_consteval.hpp +++ b/include/snitch/snitch_macros_consteval.hpp @@ -55,10 +55,10 @@ #else // SNITCH_DISABLE // clang-format off -# define SNITCH_CONSTEVAL_REQUIRE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) -# define SNITCH_CONSTEVAL_CHECK(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) -# define SNITCH_CONSTEVAL_REQUIRE_FALSE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) -# define SNITCH_CONSTEVAL_CHECK_FALSE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEVAL_REQUIRE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEVAL_CHECK(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEVAL_REQUIRE_FALSE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEVAL_CHECK_FALSE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) # define SNITCH_CONSTEVAL_REQUIRE_THAT(EXPR, ...) SNITCH_DISCARD_ARGS(EXPR, __VA_ARGS__) # define SNITCH_CONSTEVAL_CHECK_THAT(EXPR, ...) SNITCH_DISCARD_ARGS(EXPR, __VA_ARGS__) // clang-format on From 3b7073c61415813352720f12291ff9ffc96a9ba6 Mon Sep 17 00:00:00 2001 From: NicoMuleo <49640252+NicoMuleo@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:38:03 +0100 Subject: [PATCH 05/21] Update include/snitch/snitch_macros_constexpr.hpp Fix indentation Co-authored-by: Corentin Schreiber --- include/snitch/snitch_macros_constexpr.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/snitch/snitch_macros_constexpr.hpp b/include/snitch/snitch_macros_constexpr.hpp index b1479734..12f1050f 100644 --- a/include/snitch/snitch_macros_constexpr.hpp +++ b/include/snitch/snitch_macros_constexpr.hpp @@ -86,10 +86,10 @@ #else // SNITCH_DISABLE // clang-format off -# define SNITCH_CONSTEXPR_REQUIRE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) -# define SNITCH_CONSTEXPR_CHECK(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) -# define SNITCH_CONSTEXPR_REQUIRE_FALSE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) -# define SNITCH_CONSTEXPR_CHECK_FALSE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEXPR_REQUIRE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEXPR_CHECK(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEXPR_REQUIRE_FALSE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CONSTEXPR_CHECK_FALSE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) # define SNITCH_CONSTEXPR_REQUIRE_THAT(EXPR, ...) SNITCH_DISCARD_ARGS(EXPR, __VA_ARGS__) # define SNITCH_CONSTEXPR_CHECK_THAT(EXPR, ...) SNITCH_DISCARD_ARGS(EXPR, __VA_ARGS__) // clang-format on From 35f5988651c89cf1b5a1def90d082421cb6ffdde Mon Sep 17 00:00:00 2001 From: NicoMuleo <49640252+NicoMuleo@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:38:27 +0100 Subject: [PATCH 06/21] Update include/snitch/snitch_macros_exceptions.hpp Fix indentation Co-authored-by: Corentin Schreiber --- include/snitch/snitch_macros_exceptions.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/snitch/snitch_macros_exceptions.hpp b/include/snitch/snitch_macros_exceptions.hpp index 44d4ed19..c5a4ab2b 100644 --- a/include/snitch/snitch_macros_exceptions.hpp +++ b/include/snitch/snitch_macros_exceptions.hpp @@ -132,12 +132,12 @@ # else // SNITCH_DISABLE // clang-format off -# define SNITCH_REQUIRE_THROWS_AS(EXPRESSION, ...) SNITCH_DISCARD_ARGS(EXPRESSION, sizeof(__VA_ARGS__)) -# define SNITCH_CHECK_THROWS_AS(EXPRESSION, ...) SNITCH_DISCARD_ARGS(EXPRESSION, sizeof(__VA_ARGS__)) +# define SNITCH_REQUIRE_THROWS_AS(EXPRESSION, ...) SNITCH_DISCARD_ARGS(EXPRESSION, sizeof(__VA_ARGS__)) +# define SNITCH_CHECK_THROWS_AS(EXPRESSION, ...) SNITCH_DISCARD_ARGS(EXPRESSION, sizeof(__VA_ARGS__)) # define SNITCH_REQUIRE_THROWS_MATCHES(EXPRESSION, EXCEPTION, ...) SNITCH_DISCARD_ARGS(EXPRESSION, sizeof(EXCEPTION), __VA_ARGS__) -# define SNITCH_CHECK_THROWS_MATCHES(EXPRESSION, EXCEPTION, ...) SNITCH_DISCARD_ARGS(EXPRESSION, sizeof(EXCEPTION), __VA_ARGS__) -# define SNITCH_REQUIRE_NOTHROW(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) -# define SNITCH_CHECK_NOTHROW(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CHECK_THROWS_MATCHES(EXPRESSION, EXCEPTION, ...) SNITCH_DISCARD_ARGS(EXPRESSION, sizeof(EXCEPTION), __VA_ARGS__) +# define SNITCH_REQUIRE_NOTHROW(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CHECK_NOTHROW(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) // clang-format on # endif From fa94a6af55f3b75f61544298df30e4a9307b9920 Mon Sep 17 00:00:00 2001 From: NicoMuleo <49640252+NicoMuleo@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:39:18 +0100 Subject: [PATCH 07/21] Update include/snitch/snitch_macros_misc.hpp Fix indentation Co-authored-by: Corentin Schreiber --- include/snitch/snitch_macros_misc.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/snitch/snitch_macros_misc.hpp b/include/snitch/snitch_macros_misc.hpp index e67589dd..d7e35844 100644 --- a/include/snitch/snitch_macros_misc.hpp +++ b/include/snitch/snitch_macros_misc.hpp @@ -20,9 +20,11 @@ auto SNITCH_MACRO_CONCAT(capture_id_, __COUNTER__) = \ snitch::impl::add_info(snitch::impl::get_current_test(), __VA_ARGS__) #else // SNITCH_DISABLE +// clang-format off # define SNITCH_SECTION(NAME, ...) if constexpr (false) -# define SNITCH_CAPTURE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) -# define SNITCH_INFO(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_CAPTURE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +# define SNITCH_INFO(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) +// clang-format on #endif // SNITCH_DISABLE // clang-format off From 94035404abc84fc63f9ff7df4695dc3d8a79708a Mon Sep 17 00:00:00 2001 From: NicoMuleo <49640252+NicoMuleo@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:40:38 +0100 Subject: [PATCH 08/21] Update include/snitch/snitch_macros_test_case.hpp remove inline Co-authored-by: Corentin Schreiber --- include/snitch/snitch_macros_test_case.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/snitch/snitch_macros_test_case.hpp b/include/snitch/snitch_macros_test_case.hpp index 920d0210..46a340fb 100644 --- a/include/snitch/snitch_macros_test_case.hpp +++ b/include/snitch/snitch_macros_test_case.hpp @@ -77,7 +77,7 @@ void test_fun(); \ }; \ } \ - inline void ID::test_fun() + void ID::test_fun() # define SNITCH_TEST_CASE_METHOD(FIXTURE, ...) \ SNITCH_TEST_CASE_METHOD_IMPL(SNITCH_MACRO_CONCAT(test_id_, __COUNTER__), FIXTURE) From b16d98201f49ddd19effafcf7d24169d1c52bd4f Mon Sep 17 00:00:00 2001 From: NicoMuleo <49640252+NicoMuleo@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:41:15 +0100 Subject: [PATCH 09/21] Update include/snitch/snitch_registry.hpp make snitch lower case Co-authored-by: Corentin Schreiber --- include/snitch/snitch_registry.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/snitch/snitch_registry.hpp b/include/snitch/snitch_registry.hpp index 0f173684..da0554ff 100644 --- a/include/snitch/snitch_registry.hpp +++ b/include/snitch/snitch_registry.hpp @@ -37,7 +37,7 @@ constexpr std::size_t max_unique_tags = SNITCH_MAX_UNIQUE_TAGS; constexpr std::size_t max_registered_reporters = SNITCH_MAX_REGISTERED_REPORTERS; // Maximum size of a reporter instance, in bytes. constexpr std::size_t max_reporter_size_bytes = SNITCH_MAX_REPORTER_SIZE_BYTES; -// Is Snitch disabled? +// Is snitch disabled? constexpr bool is_disabled = SNITCH_DISABLE; } // namespace snitch From 859461811b1b422967c1ae4820aaf8dcc2af5030 Mon Sep 17 00:00:00 2001 From: NMuleo Date: Tue, 5 Nov 2024 12:22:49 +0100 Subject: [PATCH 10/21] Invert SNITCH_DISABLE logic (introduce SNITCH_ENABLE) added necessary maybe_unused --- CMakeLists.txt | 2 +- include/snitch/snitch_config.hpp.config | 4 +- include/snitch/snitch_macros_check.hpp | 6 +- include/snitch/snitch_macros_consteval.hpp | 6 +- include/snitch/snitch_macros_constexpr.hpp | 6 +- include/snitch/snitch_macros_exceptions.hpp | 6 +- include/snitch/snitch_macros_misc.hpp | 6 +- include/snitch/snitch_macros_reporter.hpp | 6 +- include/snitch/snitch_macros_test_case.hpp | 162 ++++++++++---------- include/snitch/snitch_registry.hpp | 22 ++- src/snitch_cli.cpp | 6 +- src/snitch_registry.cpp | 6 +- tests/runtime_tests/check.cpp | 4 +- tests/testing_reporters.cpp | 3 + 14 files changed, 118 insertions(+), 127 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea91d52e..c8764f7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ set(SNITCH_MAX_PATH_LENGTH 1024 CACHE STRING "Maximum length of a file set(SNITCH_MAX_REPORTER_SIZE_BYTES 128 CACHE STRING "Maximum size (in bytes) of a reporter object.") # Feature toggles. -set(SNITCH_DISABLE OFF CACHE BOOL "Disable snitch at build time") +set(SNITCH_ENABLE ON CACHE BOOL "Enable snitch at build time") set(SNITCH_DEFINE_MAIN ON CACHE BOOL "Define main() in snitch -- disable to provide your own main() function.") set(SNITCH_WITH_EXCEPTIONS ON CACHE BOOL "Use exceptions in snitch implementation -- will be forced OFF if exceptions are not available.") set(SNITCH_WITH_MULTITHREADING ON CACHE BOOL "Make the testing framework thread-safe -- disable if multithreading is not needed.") diff --git a/include/snitch/snitch_config.hpp.config b/include/snitch/snitch_config.hpp.config index 30048ad1..fdbbcef4 100644 --- a/include/snitch/snitch_config.hpp.config +++ b/include/snitch/snitch_config.hpp.config @@ -89,8 +89,8 @@ #if !defined(SNITCH_SHARED_LIBRARY) #cmakedefine01 SNITCH_SHARED_LIBRARY #endif -#if !defined(SNITCH_DISABLE) -#cmakedefine01 SNITCH_DISABLE +#if !defined(SNITCH_ENABLE) +#cmakedefine01 SNITCH_ENABLE #endif // clang-format on diff --git a/include/snitch/snitch_macros_check.hpp b/include/snitch/snitch_macros_check.hpp index e7195bba..0c638b72 100644 --- a/include/snitch/snitch_macros_check.hpp +++ b/include/snitch/snitch_macros_check.hpp @@ -10,7 +10,7 @@ #include "snitch/snitch_registry.hpp" #include "snitch/snitch_test_data.hpp" -#if !(SNITCH_DISABLE) +#if SNITCH_ENABLE # define SNITCH_REQUIRE_IMPL(CHECK, EXPECTED, MAYBE_ABORT, ...) \ do { \ @@ -84,7 +84,7 @@ # define SNITCH_CHECK_THAT(EXPR, ...) SNITCH_REQUIRE_THAT_IMPL("CHECK_THAT", (void)0, EXPR, __VA_ARGS__) // clang-format on -#else // SNITCH_DISABLE +#else // SNITCH_ENABLE // clang-format off # define SNITCH_REQUIRE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) # define SNITCH_CHECK(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) @@ -101,7 +101,7 @@ # define SNITCH_CHECK_THAT(EXPR, ...) SNITCH_DISCARD_ARGS(EXPR, __VA_ARGS__) // clang-format on -#endif // SNITCH_DISABLE +#endif // SNITCH_ENABLE // clang-format on #if SNITCH_WITH_SHORTHAND_MACROS diff --git a/include/snitch/snitch_macros_consteval.hpp b/include/snitch/snitch_macros_consteval.hpp index b20d71c4..d0c09163 100644 --- a/include/snitch/snitch_macros_consteval.hpp +++ b/include/snitch/snitch_macros_consteval.hpp @@ -10,7 +10,7 @@ #include "snitch/snitch_registry.hpp" #include "snitch/snitch_test_data.hpp" -#if !(SNITCH_DISABLE) +#if SNITCH_ENABLE # define SNITCH_CONSTEVAL_REQUIRE_IMPL(CHECK, EXPECTED, MAYBE_ABORT, ...) \ do { \ @@ -52,7 +52,7 @@ # define SNITCH_CONSTEVAL_CHECK_THAT(EXPR, ...) SNITCH_CONSTEVAL_REQUIRE_THAT_IMPL("CONSTEVAL_CHECK_THAT", (void)0, EXPR, __VA_ARGS__) // clang-format on -#else // SNITCH_DISABLE +#else // SNITCH_ENABLE // clang-format off # define SNITCH_CONSTEVAL_REQUIRE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) @@ -63,7 +63,7 @@ # define SNITCH_CONSTEVAL_CHECK_THAT(EXPR, ...) SNITCH_DISCARD_ARGS(EXPR, __VA_ARGS__) // clang-format on -#endif // SNITCH_DISABLE +#endif // SNITCH_ENABLE // clang-format off #if SNITCH_WITH_SHORTHAND_MACROS diff --git a/include/snitch/snitch_macros_constexpr.hpp b/include/snitch/snitch_macros_constexpr.hpp index 12f1050f..94f53d7f 100644 --- a/include/snitch/snitch_macros_constexpr.hpp +++ b/include/snitch/snitch_macros_constexpr.hpp @@ -10,7 +10,7 @@ #include "snitch/snitch_registry.hpp" #include "snitch/snitch_test_data.hpp" -#if !(SNITCH_DISABLE) +#if SNITCH_ENABLE # define SNITCH_CONSTEXPR_REQUIRE_IMPL(CHECK, EXPECTED, MAYBE_ABORT, ...) \ do { \ @@ -83,7 +83,7 @@ # define SNITCH_CONSTEXPR_CHECK_THAT(EXPR, ...) SNITCH_CONSTEXPR_REQUIRE_THAT_IMPL("CONSTEXPR_CHECK_THAT", (void)0, EXPR, __VA_ARGS__) // clang-format on -#else // SNITCH_DISABLE +#else // SNITCH_ENABLE // clang-format off # define SNITCH_CONSTEXPR_REQUIRE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) @@ -93,7 +93,7 @@ # define SNITCH_CONSTEXPR_REQUIRE_THAT(EXPR, ...) SNITCH_DISCARD_ARGS(EXPR, __VA_ARGS__) # define SNITCH_CONSTEXPR_CHECK_THAT(EXPR, ...) SNITCH_DISCARD_ARGS(EXPR, __VA_ARGS__) // clang-format on -#endif // SNITCH_DISABLE +#endif // SNITCH_ENABLE // clang-format off #if SNITCH_WITH_SHORTHAND_MACROS diff --git a/include/snitch/snitch_macros_exceptions.hpp b/include/snitch/snitch_macros_exceptions.hpp index c5a4ab2b..339b8640 100644 --- a/include/snitch/snitch_macros_exceptions.hpp +++ b/include/snitch/snitch_macros_exceptions.hpp @@ -9,7 +9,7 @@ # include -# if !(SNITCH_DISABLE) +# if SNITCH_ENABLE # define SNITCH_REQUIRE_THROWS_AS_IMPL(MAYBE_ABORT, EXPRESSION, ...) \ do { \ auto SNITCH_CURRENT_CHECK = SNITCH_NEW_CHECK; \ @@ -129,7 +129,7 @@ SNITCH_REQUIRE_NOTHROW_IMPL(SNITCH_TESTING_ABORT, __VA_ARGS__) # define SNITCH_CHECK_NOTHROW(...) SNITCH_REQUIRE_NOTHROW_IMPL((void)0, __VA_ARGS__) -# else // SNITCH_DISABLE +# else // SNITCH_ENABLE // clang-format off # define SNITCH_REQUIRE_THROWS_AS(EXPRESSION, ...) SNITCH_DISCARD_ARGS(EXPRESSION, sizeof(__VA_ARGS__)) @@ -140,7 +140,7 @@ # define SNITCH_CHECK_NOTHROW(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) // clang-format on -# endif +# endif // SNITCH_ENABLE // clang-format off #if SNITCH_WITH_SHORTHAND_MACROS diff --git a/include/snitch/snitch_macros_misc.hpp b/include/snitch/snitch_macros_misc.hpp index d7e35844..878d1088 100644 --- a/include/snitch/snitch_macros_misc.hpp +++ b/include/snitch/snitch_macros_misc.hpp @@ -7,7 +7,7 @@ #include "snitch/snitch_section.hpp" #include "snitch/snitch_test_data.hpp" -#if !(SNITCH_DISABLE) +#if SNITCH_ENABLE # define SNITCH_SECTION(...) \ if (snitch::impl::section_entry_checker SNITCH_MACRO_CONCAT(section_id_, __COUNTER__){ \ {__VA_ARGS__}, SNITCH_CURRENT_LOCATION, snitch::impl::get_current_test()}) @@ -19,13 +19,13 @@ # define SNITCH_INFO(...) \ auto SNITCH_MACRO_CONCAT(capture_id_, __COUNTER__) = \ snitch::impl::add_info(snitch::impl::get_current_test(), __VA_ARGS__) -#else // SNITCH_DISABLE +#else // SNITCH_ENABLE // clang-format off # define SNITCH_SECTION(NAME, ...) if constexpr (false) # define SNITCH_CAPTURE(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) # define SNITCH_INFO(...) SNITCH_DISCARD_ARGS(__VA_ARGS__) // clang-format on -#endif // SNITCH_DISABLE +#endif // SNITCH_ENABLE // clang-format off #if SNITCH_WITH_SHORTHAND_MACROS diff --git a/include/snitch/snitch_macros_reporter.hpp b/include/snitch/snitch_macros_reporter.hpp index 8843e47f..22f73cf6 100644 --- a/include/snitch/snitch_macros_reporter.hpp +++ b/include/snitch/snitch_macros_reporter.hpp @@ -5,7 +5,7 @@ #include "snitch/snitch_macros_utility.hpp" #include "snitch/snitch_registry.hpp" -#if !(SNITCH_DISABLE) +#if SNITCH_ENABLE # define SNITCH_REGISTER_REPORTER_CALLBACKS(NAME, ...) \ static const std::string_view SNITCH_MACRO_CONCAT(reporter_id_, __COUNTER__) \ [[maybe_unused]] = snitch::tests.add_reporter(NAME, __VA_ARGS__) @@ -13,10 +13,10 @@ # define SNITCH_REGISTER_REPORTER(NAME, TYPE) \ static const std::string_view SNITCH_MACRO_CONCAT(reporter_id_, __COUNTER__) \ [[maybe_unused]] = snitch::tests.add_reporter(NAME) -#else // SNITCH_DISABLE +#else // SNITCH_ENABLE # define SNITCH_REGISTER_REPORTER_CALLBACKS(NAME, ...) /* nothing */ # define SNITCH_REGISTER_REPORTER(NAME, TYPE) static_assert(NAME) -#endif // SNITCH_DISABLE +#endif // SNITCH_ENABLE // clang-format off #if SNITCH_WITH_SHORTHAND_MACROS diff --git a/include/snitch/snitch_macros_test_case.hpp b/include/snitch/snitch_macros_test_case.hpp index 46a340fb..7f08fbe2 100644 --- a/include/snitch/snitch_macros_test_case.hpp +++ b/include/snitch/snitch_macros_test_case.hpp @@ -5,57 +5,42 @@ #include "snitch/snitch_macros_utility.hpp" #include "snitch/snitch_registry.hpp" -#define SNITCH_TEST_CASE_IMPL(ID, ...) \ - static void ID(); \ - static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ - snitch::tests.add({__VA_ARGS__}, SNITCH_CURRENT_LOCATION, &ID); \ - void ID() +#if SNITCH_ENABLE +# define SNITCH_TEST_CASE_IMPL(ID, ...) \ + static void ID(); \ + static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ + snitch::tests.add({__VA_ARGS__}, SNITCH_CURRENT_LOCATION, &ID); \ + void ID() -#if !(SNITCH_DISABLE) # define SNITCH_TEST_CASE(...) \ SNITCH_TEST_CASE_IMPL(SNITCH_MACRO_CONCAT(test_fun_, __COUNTER__), __VA_ARGS__) -#else // SNITCH_DISABLE -# define SNITCH_TEST_CASE(...) \ - [[maybe_unused]] static void SNITCH_MACRO_CONCAT(test_id_, __COUNTER__)() -#endif // SNITCH_DISABLE - -#define SNITCH_TEMPLATE_LIST_TEST_CASE_IMPL(ID, NAME, TAGS, TYPES) \ - template \ - static void ID(); \ - static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ - snitch::tests.add_with_type_list( \ - {NAME, TAGS}, SNITCH_CURRENT_LOCATION, []() { ID(); }); \ - template \ - void ID() - -#if !(SNITCH_DISABLE) + +# define SNITCH_TEMPLATE_LIST_TEST_CASE_IMPL(ID, NAME, TAGS, TYPES) \ + template \ + static void ID(); \ + static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ + snitch::tests.add_with_type_list( \ + {NAME, TAGS}, SNITCH_CURRENT_LOCATION, []() { ID(); });\ + template \ + void ID() + # define SNITCH_TEMPLATE_LIST_TEST_CASE(NAME, TAGS, TYPES) \ SNITCH_TEMPLATE_LIST_TEST_CASE_IMPL( \ SNITCH_MACRO_CONCAT(test_fun_, __COUNTER__), NAME, TAGS, TYPES) -#else // SNITCH_DISABLE -# define SNITCH_TEMPLATE_LIST_TEST_CASE(NAME, TAGS, TYPES) SNITCH_VOID_STATEMENT -#endif // SNITCH_DISABLE - -#define SNITCH_TEMPLATE_TEST_CASE_IMPL(ID, NAME, TAGS, ...) \ - template \ - static void ID(); \ - static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ - snitch::tests.add_with_types<__VA_ARGS__>( \ - {NAME, TAGS}, SNITCH_CURRENT_LOCATION, []() { ID(); }); \ - template \ - void ID() - -#if !(SNITCH_DISABLE) + +# define SNITCH_TEMPLATE_TEST_CASE_IMPL(ID, NAME, TAGS, ...) \ + template \ + static void ID(); \ + static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ + snitch::tests.add_with_types<__VA_ARGS__>( \ + {NAME, TAGS}, SNITCH_CURRENT_LOCATION, []() { ID(); });\ + template \ + void ID() + # define SNITCH_TEMPLATE_TEST_CASE(NAME, TAGS, ...) \ SNITCH_TEMPLATE_TEST_CASE_IMPL( \ SNITCH_MACRO_CONCAT(test_fun_, __COUNTER__), NAME, TAGS, __VA_ARGS__) -#else // SNITCH_DISABLE -# define SNITCH_TEMPLATE_TEST_CASE(NAME, TAGS, ...) \ - template \ - [[maybe_unused]] static void SNITCH_MACRO_CONCAT(test_id_, __COUNTER__)() -#endif // SNITCH_DISABLE -#if !(SNITCH_DISABLE) # define SNITCH_TEST_CASE_METHOD_IMPL(ID, FIXTURE, ...) \ namespace { \ struct ID : FIXTURE { \ @@ -70,62 +55,69 @@ # define SNITCH_TEST_CASE_METHOD(FIXTURE, ...) \ SNITCH_TEST_CASE_METHOD_IMPL( \ SNITCH_MACRO_CONCAT(test_fixture_, __COUNTER__), FIXTURE, __VA_ARGS__) -#else // SNITCH_DISABLE -# define SNITCH_TEST_CASE_METHOD_IMPL(ID, FIXTURE, ...) \ + +# define SNITCH_TEMPLATE_LIST_TEST_CASE_METHOD_IMPL(ID, FIXTURE, NAME, TAGS, TYPES) \ namespace { \ - struct ID : FIXTURE { \ + template \ + struct ID : FIXTURE { \ void test_fun(); \ }; \ } \ - void ID::test_fun() + static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ + snitch::tests.add_fixture_with_type_list( \ + {#FIXTURE, NAME, TAGS}, SNITCH_CURRENT_LOCATION, \ + []() < typename TestType > { ID{}.test_fun(); }); \ + template \ + void ID::test_fun() -# define SNITCH_TEST_CASE_METHOD(FIXTURE, ...) \ - SNITCH_TEST_CASE_METHOD_IMPL(SNITCH_MACRO_CONCAT(test_id_, __COUNTER__), FIXTURE) -#endif // SNITCH_DISABLE - -#define SNITCH_TEMPLATE_LIST_TEST_CASE_METHOD_IMPL(ID, FIXTURE, NAME, TAGS, TYPES) \ - namespace { \ - template \ - struct ID : FIXTURE { \ - void test_fun(); \ - }; \ - } \ - static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ - snitch::tests.add_fixture_with_type_list( \ - {#FIXTURE, NAME, TAGS}, SNITCH_CURRENT_LOCATION, \ - []() < typename TestType > { ID{}.test_fun(); }); \ - template \ - void ID::test_fun() - -#if !(SNITCH_DISABLE) # define SNITCH_TEMPLATE_LIST_TEST_CASE_METHOD(FIXTURE, NAME, TAGS, TYPES) \ SNITCH_TEMPLATE_LIST_TEST_CASE_METHOD_IMPL( \ SNITCH_MACRO_CONCAT(test_fixture_, __COUNTER__), FIXTURE, NAME, TAGS, TYPES) -#else // SNITCH_DISABLE -# define SNITCH_TEMPLATE_LIST_TEST_CASE_METHOD(FIXTURE, NAME, TAGS, TYPES) SNITCH_VOID_STATEMENT -#endif // SNITCH_DISABLE - -#define SNITCH_TEMPLATE_TEST_CASE_METHOD_IMPL(ID, FIXTURE, NAME, TAGS, ...) \ - namespace { \ - template \ - struct ID : FIXTURE { \ - void test_fun(); \ - }; \ - } \ - static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ - snitch::tests.add_fixture_with_types<__VA_ARGS__>( \ - {#FIXTURE, NAME, TAGS}, SNITCH_CURRENT_LOCATION, \ - []() < typename TestType > { ID{}.test_fun(); }); \ - template \ - void ID::test_fun() - -#if !(SNITCH_DISABLE) + +# define SNITCH_TEMPLATE_TEST_CASE_METHOD_IMPL(ID, FIXTURE, NAME, TAGS, ...) \ + namespace { \ + template \ + struct ID : FIXTURE { \ + void test_fun(); \ + }; \ + } \ + static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ + snitch::tests.add_fixture_with_types<__VA_ARGS__>( \ + {#FIXTURE, NAME, TAGS}, SNITCH_CURRENT_LOCATION, \ + []() < typename TestType > { ID{}.test_fun(); }); \ + template \ + void ID::test_fun() + # define SNITCH_TEMPLATE_TEST_CASE_METHOD(FIXTURE, NAME, TAGS, ...) \ SNITCH_TEMPLATE_TEST_CASE_METHOD_IMPL( \ SNITCH_MACRO_CONCAT(test_fixture_, __COUNTER__), FIXTURE, NAME, TAGS, __VA_ARGS__) -#else // SNITCH_DISABLE + +#else // SNITCH_ENABLE + +# define SNITCH_TEST_CASE(...) \ + [[maybe_unused]] static void SNITCH_MACRO_CONCAT(test_id_, __COUNTER__)() + +# define SNITCH_TEMPLATE_LIST_TEST_CASE(NAME, TAGS, TYPES) SNITCH_VOID_STATEMENT + +# define SNITCH_TEMPLATE_TEST_CASE(NAME, TAGS, ...) \ + template \ + [[maybe_unused]] static void SNITCH_MACRO_CONCAT(test_id_, __COUNTER__)() + +# define SNITCH_TEST_CASE_METHOD_IMPL(ID, FIXTURE, ...) \ + namespace { \ + struct ID : FIXTURE { \ + void test_fun(); \ + }; \ + } \ + [[maybe_unused]] void ID::test_fun() + +# define SNITCH_TEST_CASE_METHOD(FIXTURE, ...) \ + SNITCH_TEST_CASE_METHOD_IMPL(SNITCH_MACRO_CONCAT(test_id_, __COUNTER__), FIXTURE) + +# define SNITCH_TEMPLATE_LIST_TEST_CASE_METHOD(FIXTURE, NAME, TAGS, TYPES) SNITCH_VOID_STATEMENT + # define SNITCH_TEMPLATE_TEST_CASE_METHOD(FIXTURE, NAME, TAGS, ...) SNITCH_VOID_STATEMENT -#endif // SNITCH_DISABLE +#endif // SNITCH_ENABLE // clang-format off #if SNITCH_WITH_SHORTHAND_MACROS diff --git a/include/snitch/snitch_registry.hpp b/include/snitch/snitch_registry.hpp index da0554ff..a952f31f 100644 --- a/include/snitch/snitch_registry.hpp +++ b/include/snitch/snitch_registry.hpp @@ -38,7 +38,7 @@ constexpr std::size_t max_registered_reporters = SNITCH_MAX_REGISTERED_REPORTERS // Maximum size of a reporter instance, in bytes. constexpr std::size_t max_reporter_size_bytes = SNITCH_MAX_REPORTER_SIZE_BYTES; // Is snitch disabled? -constexpr bool is_disabled = SNITCH_DISABLE; +constexpr bool is_disabled = !SNITCH_ENABLE; } // namespace snitch namespace snitch::impl { @@ -108,17 +108,13 @@ struct registered_reporter { }; template -concept reporter_type = requires(registry& reg) { - T{reg}; -} -&&requires(T& rep, registry& reg, std::string_view k, std::string_view v) { - { rep.configure(reg, k, v) } -> convertible_to; -} -&&requires(T& rep, const registry& reg, const event::data& e) { - rep.report(reg, e); -}; +concept reporter_type = + requires(registry& reg) { T{reg}; } && + requires(T& rep, registry& reg, std::string_view k, std::string_view v) { + { rep.configure(reg, k, v) } -> convertible_to; + } && requires(T& rep, const registry& reg, const event::data& e) { rep.report(reg, e); }; -#if !(SNITCH_DISABLE) +#if SNITCH_ENABLE class registry { // Contains all registered test cases. small_vector test_list; @@ -337,7 +333,7 @@ class registry { SNITCH_EXPORT small_vector_span reporters() const noexcept; }; -#else // SNITCH_DISABLE +#else // SNITCH_ENABLE class registry { SNITCH_EXPORT void report_default(const registry&, const event::data&) noexcept {} @@ -479,7 +475,7 @@ class registry { SNITCH_EXPORT small_vector_span reporters() const noexcept; }; -#endif // SNITCH_DISABLE +#endif // SNITCH_ENABLE SNITCH_EXPORT extern constinit registry tests; } // namespace snitch diff --git a/src/snitch_cli.cpp b/src/snitch_cli.cpp index 9fff49a4..d7b8bac8 100644 --- a/src/snitch_cli.cpp +++ b/src/snitch_cli.cpp @@ -401,9 +401,7 @@ void print_help(std::string_view program_name, const print_help_settings& settin } std::optional parse_arguments(int argc, const char* const argv[]) noexcept { - if constexpr (SNITCH_DISABLE) { - return {}; - } else { + if constexpr (SNITCH_ENABLE) { // First, parse just looking for color options so we can display console messages correctly. const bool with_color = impl::parse_color_options(argc, argv); @@ -417,6 +415,8 @@ std::optional parse_arguments(int argc, const char* const argv[]) no } return ret_args; + } else { + return {}; } } diff --git a/src/snitch_registry.cpp b/src/snitch_registry.cpp index 583a8b5b..bca95ee1 100644 --- a/src/snitch_registry.cpp +++ b/src/snitch_registry.cpp @@ -1,6 +1,6 @@ #include "snitch/snitch_registry.hpp" -#if !(SNITCH_DISABLE) +#if SNITCH_ENABLE # include "snitch/snitch_time.hpp" @@ -1137,7 +1137,7 @@ small_vector_span registry::reporters() const noexcep constinit registry tests; } // namespace snitch -#else // SNITCH_DISABLE +#else // SNITCH_ENABLE namespace snitch { filter_result filter_result_and(filter_result first, filter_result second) noexcept { @@ -1270,4 +1270,4 @@ small_vector_span registry::reporters() const noexcep constinit registry tests; } // namespace snitch -#endif // SNITCH_DISABLE +#endif // SNITCH_ENABLE diff --git a/tests/runtime_tests/check.cpp b/tests/runtime_tests/check.cpp index 04f86890..b74d36f8 100644 --- a/tests/runtime_tests/check.cpp +++ b/tests/runtime_tests/check.cpp @@ -32,7 +32,7 @@ struct non_relocatable { } }; -#if SNITCH_DISABLE +#if !SNITCH_ENABLE [[maybe_unused]] #endif bool append(snitch::small_string_span ss, const non_relocatable& o) noexcept { @@ -70,7 +70,7 @@ struct unary_long_string { } }; -#if SNITCH_DISABLE +#if !SNITCH_ENABLE [[maybe_unused]] #endif bool append(snitch::small_string_span ss, const unary_long_string& u) noexcept { diff --git a/tests/testing_reporters.cpp b/tests/testing_reporters.cpp index afce1e78..927a6137 100644 --- a/tests/testing_reporters.cpp +++ b/tests/testing_reporters.cpp @@ -5,6 +5,9 @@ namespace { #if SNITCH_WITH_EXCEPTIONS +#if !SNITCH_ENABLE +[[maybe_unused]] +#endif void throw_something(bool do_throw) { if (do_throw) { throw std::runtime_error("I threw"); From 83165fac1bd0654d3e5d61748fac4aecd66fe8fa Mon Sep 17 00:00:00 2001 From: NMuleo Date: Tue, 5 Nov 2024 17:14:17 +0100 Subject: [PATCH 11/21] added CI platforms Fix clang buil skipped doctest stage for disabled --- .github/workflows/cmake.yml | 11 +++++++++-- tests/runtime_tests/check.cpp | 7 ++++++- tests/runtime_tests/function_ref.cpp | 3 +++ tests/runtime_tests/registry.cpp | 12 ++++++++++++ tests/runtime_tests/string_utility.cpp | 6 ++++++ 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 6a027c3c..610cfe28 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -90,6 +90,7 @@ jobs: matrix: platform: - { name: Ubuntu GCC, os: ubuntu-latest, publish: true, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS='--coverage' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} + - { name: Ubuntu GCC disabled, os: ubuntu-latest, publish: true, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS='--coverage' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"} - { name: Ubuntu GCC noexcept, os: ubuntu-latest, publish: false, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static-noexcept", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS='-fno-exceptions' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: Ubuntu GCC notime, os: ubuntu-latest, publish: false, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static-notime", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DSNITCH_WITH_TIMINGS=0 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: Ubuntu GCC nounity, os: ubuntu-latest, publish: false, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static-nounity", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DSNITCH_UNITY_BUILD=0 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} @@ -97,14 +98,19 @@ jobs: - { name: Ubuntu GCC shared, os: ubuntu-latest, publish: false, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-shared", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DBUILD_SHARED_LIBS=1 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: Ubuntu Clang, os: ubuntu-latest, publish: true, compiler: clang++, arch: "64", build: "ubuntu64-libc++-static", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS='-stdlib=libc++' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: Ubuntu Clang noexcept, os: ubuntu-latest, publish: false, compiler: clang++, arch: "64", build: "ubuntu64-libc++-static-noexcept", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS='-stdlib=libc++ -fno-exceptions' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} + - { name: Ubuntu Clang disabled, os: ubuntu-latest, publish: true, compiler: clang++, arch: "64", build: "ubuntu64-libc++-static", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS='-stdlib=libc++' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"} - { name: Windows 32, os: windows-latest, publish: true, compiler: vs2019, arch: "32", build: "win32-vs2019-static", cmakepp: "", flags: "-A Win32 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} + - { name: Windows 32 disable, os: windows-latest, publish: true, compiler: vs2019, arch: "32", build: "win32-vs2019-static", cmakepp: "", flags: "-A Win32 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"} - { name: Windows 64, os: windows-latest, publish: true, compiler: vs2019, arch: "64", build: "win64-vs2019-static", cmakepp: "", flags: "-A x64 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: Windows 64 noexcept, os: windows-latest, publish: false, compiler: vs2019, arch: "64", build: "win64-vs2019-static-noexcept", cmakepp: "", flags: "-A x64 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: Windows 64 shared, os: windows-latest, publish: false, compiler: vs2019, arch: "64", build: "win64-vs2019-shared", cmakepp: "", flags: "-A x64 -DBUILD_SHARED_LIBS=1 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} + - { name: Windows 64 disable, os: windows-latest, publish: true, compiler: vs2019, arch: "64", build: "win64-vs2019-static", cmakepp: "", flags: "-A x64 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"} - { name: MacOS, os: macos-latest, publish: true, compiler: clang++, arch: "64", build: "osx-libc++-static", cmakepp: "", flags: "--warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: MacOS noexcept, os: macos-latest, publish: false, compiler: clang++, arch: "64", build: "osx-libc++-static-noexcept", cmakepp: "", flags: "-DCMAKE_CXX_FLAGS='-fno-exceptions' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} + - { name: MacOS disable, os: macos-latest, publish: true, compiler: clang++, arch: "64", build: "osx-libc++-static", cmakepp: "", flags: "--warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"} - { name: WebAssembly, os: ubuntu-latest, publish: true, compiler: em++, arch: "32", build: "wasm32", cmakepp: "emcmake", flags: "-DCMAKE_CXX_FLAGS='-s DISABLE_EXCEPTION_CATCHING=0' -DCMAKE_CROSSCOMPILING_EMULATOR=node"} - { name: WebAssembly noexcept, os: ubuntu-latest, publish: false, compiler: em++, arch: "32", build: "wasm32-noexcept", cmakepp: "emcmake", flags: "-DCMAKE_CXX_FLAGS='-fno-exceptions' -DCMAKE_CROSSCOMPILING_EMULATOR=node"} + - { name: WebAssembly disable, os: ubuntu-latest, publish: true, compiler: em++, arch: "32", build: "wasm32", cmakepp: "emcmake", flags: "-DCMAKE_CXX_FLAGS='-s DISABLE_EXCEPTION_CATCHING=0' -DCMAKE_CROSSCOMPILING_EMULATOR=node -DSNITCH_ENABLE=OFF"} build-type: - Release - Debug @@ -161,19 +167,20 @@ jobs: - name: Test (with doctest) # A bug in Node.js/V8 prevents these tests from running in Debug config for WebAssembly. # https://bugs.chromium.org/p/v8/issues/detail?id=13961 - if: ${{!(matrix.platform.compiler == 'em++' && matrix.build-type == 'Debug')}} + if: ${{!(matrix.platform.compiler == 'em++' && matrix.build-type == 'Debug') && !contains(matrix.platform.flags, '-DSNITCH_ENABLE=OFF')}} shell: bash working-directory: ${{github.workspace}}/build run: cmake --build . --config ${{matrix.build-type}} --target snitch_runtime_tests_run - name: Test (with snitch) + if: ${{!contains(matrix.platform.flags, '-DSNITCH_ENABLE=OFF')}} shell: bash working-directory: ${{github.workspace}}/build run: cmake --build . --config ${{matrix.build-type}} --target snitch_runtime_tests_self_run - name: Approval tests (with doctest) # Approval tests only run on "default" library configuration, which happens to be the published one - if: matrix.platform.publish + if: ${{matrix.platform.publish && !contains(matrix.platform.flags, '-DSNITCH_ENABLE=OFF')}} shell: bash working-directory: ${{github.workspace}}/build run: cmake --build . --config ${{matrix.build-type}} --target snitch_approval_tests_run diff --git a/tests/runtime_tests/check.cpp b/tests/runtime_tests/check.cpp index b74d36f8..62123e1a 100644 --- a/tests/runtime_tests/check.cpp +++ b/tests/runtime_tests/check.cpp @@ -1688,7 +1688,12 @@ TEST_CASE("require throws matches", "[test macros]") { } namespace { -[[nodiscard]] int nodiscard_function() { +#if SNITCH_ENABLE +[[nodiscard]] +#else +[[maybe_unused]] +#endif +int nodiscard_function() { return 1; } } // namespace diff --git a/tests/runtime_tests/function_ref.cpp b/tests/runtime_tests/function_ref.cpp index 6baaf96c..3c0b075f 100644 --- a/tests/runtime_tests/function_ref.cpp +++ b/tests/runtime_tests/function_ref.cpp @@ -5,6 +5,9 @@ namespace { std::size_t test_object_instances = 0u; bool function_called = false; +#if !SNITCH_ENABLE +[[maybe_unused]] +#endif int return_value = 0u; struct test_object { diff --git a/tests/runtime_tests/registry.cpp b/tests/runtime_tests/registry.cpp index f5177763..79fa891e 100644 --- a/tests/runtime_tests/registry.cpp +++ b/tests/runtime_tests/registry.cpp @@ -156,16 +156,28 @@ bool configure_called = false; bool report_called = false; bool finish_called = false; +#if !SNITCH_ENABLE +[[maybe_unused]] +#endif void init(snitch::registry&) noexcept { init_called = true; } +#if !SNITCH_ENABLE +[[maybe_unused]] +#endif bool configure(snitch::registry&, std::string_view, std::string_view) noexcept { configure_called = true; return configure_result; } +#if !SNITCH_ENABLE +[[maybe_unused]] +#endif void report(const snitch::registry&, const snitch::event::data&) noexcept { report_called = true; } +#if !SNITCH_ENABLE +[[maybe_unused]] +#endif void finish(snitch::registry&) noexcept { finish_called = true; } diff --git a/tests/runtime_tests/string_utility.cpp b/tests/runtime_tests/string_utility.cpp index 824df7be..8b5b97d0 100644 --- a/tests/runtime_tests/string_utility.cpp +++ b/tests/runtime_tests/string_utility.cpp @@ -16,6 +16,9 @@ struct frob { void knob() {} }; +#if !SNITCH_ENABLE +[[maybe_unused]] +#endif void foo() {} using function_ptr_type = void (*)(); @@ -1043,6 +1046,9 @@ constexpr filter_result EE = {.included = false, .implicit = false}; constexpr filter_result II = {.included = true, .implicit = true}; constexpr filter_result IE = {.included = false, .implicit = true}; +#if !SNITCH_ENABLE +[[maybe_unused]] +#endif bool operator==(const filter_result& first, const filter_result& second) noexcept { return first.included == second.included && first.implicit == second.implicit; } From d7599ecf29b05e1d116c803ba56791ee4ffd021f Mon Sep 17 00:00:00 2001 From: Aleksandar Glisic Date: Mon, 11 Nov 2024 13:16:40 +0100 Subject: [PATCH 12/21] Removed CI platforms --- .github/workflows/cmake.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 610cfe28..aff1f631 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -90,7 +90,7 @@ jobs: matrix: platform: - { name: Ubuntu GCC, os: ubuntu-latest, publish: true, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS='--coverage' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - - { name: Ubuntu GCC disabled, os: ubuntu-latest, publish: true, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS='--coverage' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"} + - { name: Ubuntu GCC disabled, os: ubuntu-latest, publish: false, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static-disabled", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"} - { name: Ubuntu GCC noexcept, os: ubuntu-latest, publish: false, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static-noexcept", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS='-fno-exceptions' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: Ubuntu GCC notime, os: ubuntu-latest, publish: false, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static-notime", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DSNITCH_WITH_TIMINGS=0 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: Ubuntu GCC nounity, os: ubuntu-latest, publish: false, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static-nounity", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DSNITCH_UNITY_BUILD=0 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} @@ -98,16 +98,12 @@ jobs: - { name: Ubuntu GCC shared, os: ubuntu-latest, publish: false, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-shared", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DBUILD_SHARED_LIBS=1 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: Ubuntu Clang, os: ubuntu-latest, publish: true, compiler: clang++, arch: "64", build: "ubuntu64-libc++-static", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS='-stdlib=libc++' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: Ubuntu Clang noexcept, os: ubuntu-latest, publish: false, compiler: clang++, arch: "64", build: "ubuntu64-libc++-static-noexcept", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS='-stdlib=libc++ -fno-exceptions' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - - { name: Ubuntu Clang disabled, os: ubuntu-latest, publish: true, compiler: clang++, arch: "64", build: "ubuntu64-libc++-static", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS='-stdlib=libc++' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"} - { name: Windows 32, os: windows-latest, publish: true, compiler: vs2019, arch: "32", build: "win32-vs2019-static", cmakepp: "", flags: "-A Win32 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - - { name: Windows 32 disable, os: windows-latest, publish: true, compiler: vs2019, arch: "32", build: "win32-vs2019-static", cmakepp: "", flags: "-A Win32 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"} - { name: Windows 64, os: windows-latest, publish: true, compiler: vs2019, arch: "64", build: "win64-vs2019-static", cmakepp: "", flags: "-A x64 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: Windows 64 noexcept, os: windows-latest, publish: false, compiler: vs2019, arch: "64", build: "win64-vs2019-static-noexcept", cmakepp: "", flags: "-A x64 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: Windows 64 shared, os: windows-latest, publish: false, compiler: vs2019, arch: "64", build: "win64-vs2019-shared", cmakepp: "", flags: "-A x64 -DBUILD_SHARED_LIBS=1 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - - { name: Windows 64 disable, os: windows-latest, publish: true, compiler: vs2019, arch: "64", build: "win64-vs2019-static", cmakepp: "", flags: "-A x64 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"} - { name: MacOS, os: macos-latest, publish: true, compiler: clang++, arch: "64", build: "osx-libc++-static", cmakepp: "", flags: "--warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: MacOS noexcept, os: macos-latest, publish: false, compiler: clang++, arch: "64", build: "osx-libc++-static-noexcept", cmakepp: "", flags: "-DCMAKE_CXX_FLAGS='-fno-exceptions' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - - { name: MacOS disable, os: macos-latest, publish: true, compiler: clang++, arch: "64", build: "osx-libc++-static", cmakepp: "", flags: "--warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"} - { name: WebAssembly, os: ubuntu-latest, publish: true, compiler: em++, arch: "32", build: "wasm32", cmakepp: "emcmake", flags: "-DCMAKE_CXX_FLAGS='-s DISABLE_EXCEPTION_CATCHING=0' -DCMAKE_CROSSCOMPILING_EMULATOR=node"} - { name: WebAssembly noexcept, os: ubuntu-latest, publish: false, compiler: em++, arch: "32", build: "wasm32-noexcept", cmakepp: "emcmake", flags: "-DCMAKE_CXX_FLAGS='-fno-exceptions' -DCMAKE_CROSSCOMPILING_EMULATOR=node"} - { name: WebAssembly disable, os: ubuntu-latest, publish: true, compiler: em++, arch: "32", build: "wasm32", cmakepp: "emcmake", flags: "-DCMAKE_CXX_FLAGS='-s DISABLE_EXCEPTION_CATCHING=0' -DCMAKE_CROSSCOMPILING_EMULATOR=node -DSNITCH_ENABLE=OFF"} From d5d49372839476ca682272fed29baee12c4238d1 Mon Sep 17 00:00:00 2001 From: Aleksandar Glisic Date: Mon, 11 Nov 2024 13:17:14 +0100 Subject: [PATCH 13/21] Invert logic --- include/snitch/snitch_registry.hpp | 147 +---------------------------- 1 file changed, 2 insertions(+), 145 deletions(-) diff --git a/include/snitch/snitch_registry.hpp b/include/snitch/snitch_registry.hpp index a952f31f..08316c08 100644 --- a/include/snitch/snitch_registry.hpp +++ b/include/snitch/snitch_registry.hpp @@ -38,7 +38,7 @@ constexpr std::size_t max_registered_reporters = SNITCH_MAX_REGISTERED_REPORTERS // Maximum size of a reporter instance, in bytes. constexpr std::size_t max_reporter_size_bytes = SNITCH_MAX_REPORTER_SIZE_BYTES; // Is snitch disabled? -constexpr bool is_disabled = !SNITCH_ENABLE; +constexpr bool is_enabled = SNITCH_ENABLE; } // namespace snitch namespace snitch::impl { @@ -333,151 +333,8 @@ class registry { SNITCH_EXPORT small_vector_span reporters() const noexcept; }; -#else // SNITCH_ENABLE - -class registry { - SNITCH_EXPORT void report_default(const registry&, const event::data&) noexcept {} - -public: - enum class verbosity { quiet, normal, high, full } verbose = verbosity::normal; - bool with_color = SNITCH_DEFAULT_WITH_COLOR == 1; - - using print_function = snitch::print_function; - using initialize_report_function = snitch::initialize_report_function; - using configure_report_function = snitch::configure_report_function; - using report_function = snitch::report_function; - using finish_report_function = snitch::finish_report_function; - - print_function print_callback = nullptr; - report_function report_callback = nullptr; - finish_report_function finish_callback = nullptr; - - // Internal API; do not use. - template - void append_or_print(small_string&, T&&) const noexcept {} - - template - void print(Args&&...) const noexcept {} - - template T> - void print(const T&) const noexcept {} - - // Requires: number of reporters + 1 <= max_registered_reporters. - SNITCH_EXPORT std::string_view add_reporter( - std::string_view name, - const std::optional& initialize, - const std::optional& configure, - const report_function& report, - const std::optional& finish); - - // Requires: number of reporters + 1 <= max_registered_reporters. - template - std::string_view add_reporter(std::string_view) { - return {}; - } - - // Internal API; do not use. - // Requires: number of tests + 1 <= max_test_cases, well-formed test ID. - SNITCH_EXPORT const char* - add_impl(const test_id& id, const source_location& location, impl::test_ptr func); - - // Internal API; do not use. - // Requires: number of tests + 1 <= max_test_cases, well-formed test ID. - SNITCH_EXPORT const char* - add(const impl::name_and_tags& id, const source_location& location, impl::test_ptr func); - - // Internal API; do not use. - // Requires: number of tests + added tests <= max_test_cases, well-formed test ID. - template - const char* add_with_types(const impl::name_and_tags&, const source_location&, const F&) { - static_assert(sizeof...(Args) > 0, "empty type list in TEMPLATE_TEST_CASE"); - return {}; - } - - // Internal API; do not use. - // Requires: number of tests + added tests <= max_test_cases, well-formed test ID. - template - const char* add_with_type_list(const impl::name_and_tags&, const source_location&, const F&) { - return {}; - } - - // Internal API; do not use. - // Requires: number of tests + 1 <= max_test_cases, well-formed test ID. - SNITCH_EXPORT const char* add_fixture( - const impl::fixture_name_and_tags& id, - const source_location& location, - impl::test_ptr func); - - // Internal API; do not use. - // Requires: number of tests + added tests <= max_test_cases, well-formed test ID. - template - const char* - add_fixture_with_types(const impl::fixture_name_and_tags&, const source_location&, const F&) { - return {}; - } - - // Internal API; do not use. - // Requires: number of tests + added tests <= max_test_cases, well-formed test ID. - template - const char* add_fixture_with_type_list( - const impl::fixture_name_and_tags&, const source_location&, const F&) { - return {}; - } - - // Internal API; do not use. - SNITCH_EXPORT static void report_assertion(bool, std::string_view) noexcept; - - // Internal API; do not use. - SNITCH_EXPORT static void report_assertion(bool, std::string_view, std::string_view) noexcept; - - // Internal API; do not use. - SNITCH_EXPORT static void report_assertion(bool, const impl::expression&) noexcept; - - // Internal API; do not use. - SNITCH_EXPORT static void report_skipped(std::string_view) noexcept; - - // Internal API; do not use. - SNITCH_EXPORT static void report_section_started(const section&) noexcept; - - // Internal API; do not use. - SNITCH_EXPORT static void report_section_ended(const section&) noexcept; - - // Internal API; do not use. - SNITCH_EXPORT impl::test_state run(impl::test_case& test) noexcept; - - // Internal API; do not use. - SNITCH_EXPORT bool run_tests(std::string_view) noexcept; - - // Internal API; do not use. - SNITCH_EXPORT bool run_selected_tests( - std::string_view, - const filter_info&, - const function_ref&) noexcept; - - /* ---- */ - - SNITCH_EXPORT bool run_tests(const cli::input&) noexcept; - - SNITCH_EXPORT void configure(const cli::input&); - - SNITCH_EXPORT void list_all_tests() const noexcept; - - SNITCH_EXPORT void list_all_tags() const; - - SNITCH_EXPORT void list_tests_with_tag(std::string_view) const noexcept; - - SNITCH_EXPORT void list_all_reporters() const noexcept; - - SNITCH_EXPORT small_vector_span test_cases() noexcept; - SNITCH_EXPORT small_vector_span test_cases() const noexcept; - - SNITCH_EXPORT small_vector_span reporters() noexcept; - SNITCH_EXPORT small_vector_span reporters() const noexcept; -}; - -#endif // SNITCH_ENABLE - SNITCH_EXPORT extern constinit registry tests; +#endif // SNITCH_ENABLE } // namespace snitch #endif From e4e7624f917820de400cb6d2c63622d1f45d779e Mon Sep 17 00:00:00 2001 From: Aleksandar Glisic Date: Mon, 11 Nov 2024 13:17:45 +0100 Subject: [PATCH 14/21] Revert to pre-existing code --- src/snitch_cli.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/snitch_cli.cpp b/src/snitch_cli.cpp index d7b8bac8..23cc6164 100644 --- a/src/snitch_cli.cpp +++ b/src/snitch_cli.cpp @@ -401,23 +401,19 @@ void print_help(std::string_view program_name, const print_help_settings& settin } std::optional parse_arguments(int argc, const char* const argv[]) noexcept { - if constexpr (SNITCH_ENABLE) { - // First, parse just looking for color options so we can display console messages correctly. - const bool with_color = impl::parse_color_options(argc, argv); + // First, parse just looking for color options so we can display console messages correctly. + const bool with_color = impl::parse_color_options(argc, argv); - // Now parse everything for real. - std::optional ret_args = - impl::parse_arguments(argc, argv, impl::expected_args, {.with_color = with_color}); + // Now parse everything for real. + std::optional ret_args = + impl::parse_arguments(argc, argv, impl::expected_args, {.with_color = with_color}); - if (!ret_args) { - print("\n"); - print_help(argv[0], {.with_color = with_color}); - } - - return ret_args; - } else { - return {}; + if (!ret_args) { + print("\n"); + print_help(argv[0], {.with_color = with_color}); } + + return ret_args; } std::optional get_option(const cli::input& args, std::string_view name) noexcept { From dd0533e2b0cf551359dfa157d6a8d51152509cd3 Mon Sep 17 00:00:00 2001 From: Aleksandar Glisic Date: Mon, 11 Nov 2024 13:17:55 +0100 Subject: [PATCH 15/21] New main --- CMakeLists.txt | 12 ++- include/snitch/snitch_registry.hpp | 2 - src/snitch_main.cpp | 22 +++-- src/snitch_registry.cpp | 139 +---------------------------- 4 files changed, 25 insertions(+), 150 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8764f7d..65252591 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,10 +116,14 @@ set(SNITCH_SOURCES_INDIVIDUAL ${PROJECT_SOURCE_DIR}/src/snitch_test_data.cpp ${PROJECT_SOURCE_DIR}/src/snitch_time.cpp) -if (SNITCH_UNITY_BUILD) - set(SNITCH_SOURCES ${PROJECT_SOURCE_DIR}/src/snitch.cpp) +if (SNITCH_ENABLE) + if (SNITCH_UNITY_BUILD) + set(SNITCH_SOURCES ${PROJECT_SOURCE_DIR}/src/snitch.cpp) + else() + set(SNITCH_SOURCES ${SNITCH_SOURCES_INDIVIDUAL}) + endif() else() - set(SNITCH_SOURCES ${SNITCH_SOURCES_INDIVIDUAL}) + set(SNITCH_SOURCES ${PROJECT_SOURCE_DIR}/src/snitch_main.cpp) endif() function(configure_snitch_exports TARGET) @@ -212,7 +216,7 @@ install(FILES DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/snitch COMPONENT Development) # Setup tests -if (SNITCH_DO_TEST) +if (SNITCH_DO_TEST AND SNITCH_ENABLE) enable_testing() # We need to use a different snitch configuration for tests, so we can't reuse diff --git a/include/snitch/snitch_registry.hpp b/include/snitch/snitch_registry.hpp index 08316c08..f7ee719c 100644 --- a/include/snitch/snitch_registry.hpp +++ b/include/snitch/snitch_registry.hpp @@ -114,7 +114,6 @@ concept reporter_type = { rep.configure(reg, k, v) } -> convertible_to; } && requires(T& rep, const registry& reg, const event::data& e) { rep.report(reg, e); }; -#if SNITCH_ENABLE class registry { // Contains all registered test cases. small_vector test_list; @@ -334,7 +333,6 @@ class registry { }; SNITCH_EXPORT extern constinit registry tests; -#endif // SNITCH_ENABLE } // namespace snitch #endif diff --git a/src/snitch_main.cpp b/src/snitch_main.cpp index 8b066c36..b707aa7f 100644 --- a/src/snitch_main.cpp +++ b/src/snitch_main.cpp @@ -2,14 +2,22 @@ #include "snitch/snitch_registry.hpp" #if SNITCH_DEFINE_MAIN -SNITCH_EXPORT int main(int argc, char* argv[]) { - std::optional args = snitch::cli::parse_arguments(argc, argv); - if (!args) { - return 1; +namespace snitch { +int main(int argc, char* argv[]) { + if constexpr(snitch::is_enabled) { + std::optional args = snitch::cli::parse_arguments(argc, argv); + if (!args) { + return 1; + } + snitch::tests.configure(*args); + return snitch::tests.run_tests(*args) ? 0 : 1; + } else { + return 0; } +} +} - snitch::tests.configure(*args); - - return snitch::tests.run_tests(*args) ? 0 : 1; +SNITCH_EXPORT int main(int argc, char* argv[]) { + return snitch::main(argc, argv); } #endif diff --git a/src/snitch_registry.cpp b/src/snitch_registry.cpp index bca95ee1..dc864837 100644 --- a/src/snitch_registry.cpp +++ b/src/snitch_registry.cpp @@ -1,7 +1,5 @@ #include "snitch/snitch_registry.hpp" -#if SNITCH_ENABLE - # include "snitch/snitch_time.hpp" # include // for std::sort @@ -1134,140 +1132,7 @@ small_vector_span registry::reporters() const noexcep return registered_reporters; } +#if SNITCH_ENABLE constinit registry tests; -} // namespace snitch - -#else // SNITCH_ENABLE - -namespace snitch { -filter_result filter_result_and(filter_result first, filter_result second) noexcept { - return {}; -} - -filter_result filter_result_or(filter_result first, filter_result second) noexcept { - return {}; -} - -filter_result is_filter_match_name(std::string_view name, std::string_view filter) noexcept { - return {}; -} - -filter_result is_filter_match_tags_single(std::string_view tags, std::string_view filter) noexcept { - return {}; -} - -filter_result is_filter_match_tags(std::string_view tags, std::string_view filter) noexcept { - return {}; -} - -filter_result is_filter_match_id_single( - std::string_view name, std::string_view tags, std::string_view filter) noexcept { - return {}; -} - -filter_result -is_filter_match_id(std::string_view name, std::string_view tags, std::string_view filter) noexcept { - return {}; -} -} // namespace snitch - -namespace snitch::impl { -std::string_view -make_full_name(small_string& buffer, const test_id& id) noexcept { - return {}; -} - -bool parse_colour_mode_option(registry& reg, std::string_view color_option) noexcept { - return {}; -} -bool parse_color_option(registry& reg, std::string_view color_option) noexcept { - return {}; -} -} // namespace snitch::impl - -namespace snitch { - -const char* -registry::add_impl(const test_id& id, const source_location& location, impl::test_ptr func) { - return {}; -} - -const char* -registry::add(const impl::name_and_tags& id, const source_location& location, impl::test_ptr func) { - return {}; -} - -const char* registry::add_fixture( - const impl::fixture_name_and_tags& id, const source_location& location, impl::test_ptr func) { - return {}; -} - -std::string_view registry::add_reporter( - std::string_view, - const std::optional&, - const std::optional&, - const report_function&, - const std::optional&) { - return {}; -} - -void registry::report_assertion(bool, std::string_view) noexcept {} - -void registry::report_assertion(bool, std::string_view, std::string_view) noexcept {} - -void registry::report_assertion(bool, const impl::expression&) noexcept {} - -void registry::report_skipped(std::string_view) noexcept {} - -void registry::report_section_started(const section&) noexcept {} - -void registry::report_section_ended(const section&) noexcept {} - -impl::test_state registry::run(impl::test_case& test) noexcept { - return impl::test_state{*this, test}; -} - -bool registry::run_tests(std::string_view) noexcept { - return true; -} - -bool registry::run_selected_tests( - std::string_view, - const filter_info&, - const function_ref&) noexcept { - return true; -} - -/* ---- */ - -bool registry::run_tests(const cli::input&) noexcept { - return true; -} - -void registry::configure(const cli::input&) {} - -void registry::list_all_tests() const noexcept {} - -void registry::list_all_tags() const {} - -void registry::list_tests_with_tag(std::string_view) const noexcept {} - -void registry::list_all_reporters() const noexcept {} - -small_vector_span registry::test_cases() noexcept { - return small_vector_span{nullptr, 0, nullptr}; -} -small_vector_span registry::test_cases() const noexcept { - return {}; -} - -small_vector_span registry::reporters() noexcept { - return small_vector_span{nullptr, 0, nullptr}; -} -small_vector_span registry::reporters() const noexcept { - return {}; -} - -constinit registry tests; -} // namespace snitch #endif // SNITCH_ENABLE +} // namespace snitch From 692382f1f30d744fa61e60c20f1d84a12c39e589 Mon Sep 17 00:00:00 2001 From: NMuleo Date: Mon, 18 Nov 2024 12:52:34 +0100 Subject: [PATCH 16/21] indentation clang-format-18 --- include/snitch/snitch_expression.hpp | 2 +- include/snitch/snitch_macros_test_case.hpp | 30 +++++----- include/snitch/snitch_matcher.hpp | 12 ++-- include/snitch/snitch_registry.hpp | 10 ++-- src/snitch_main.cpp | 6 +- src/snitch_registry.cpp | 66 +++++++++++----------- src/snitch_reporter_catch2_xml.cpp | 2 +- tests/runtime_tests/check.cpp | 6 +- tests/runtime_tests/function_ref.cpp | 2 +- tests/runtime_tests/string_utility.cpp | 3 +- tests/testing.hpp | 10 ++-- tests/testing_reporters.cpp | 4 +- 12 files changed, 77 insertions(+), 76 deletions(-) diff --git a/include/snitch/snitch_expression.hpp b/include/snitch/snitch_expression.hpp index 85bf9eb5..42928380 100644 --- a/include/snitch/snitch_expression.hpp +++ b/include/snitch/snitch_expression.hpp @@ -204,7 +204,7 @@ struct extracted_unary_expression { // Operators we want to decompose. #define EXPR_OPERATOR(OP, OP_TYPE) \ template \ - constexpr extracted_binary_expression operator OP(const U& rhs) \ + constexpr extracted_binary_expression operator OP(const U & rhs) \ const noexcept { \ return {type, expected, lhs, rhs}; \ } diff --git a/include/snitch/snitch_macros_test_case.hpp b/include/snitch/snitch_macros_test_case.hpp index 7f08fbe2..a0fbaec1 100644 --- a/include/snitch/snitch_macros_test_case.hpp +++ b/include/snitch/snitch_macros_test_case.hpp @@ -15,26 +15,28 @@ # define SNITCH_TEST_CASE(...) \ SNITCH_TEST_CASE_IMPL(SNITCH_MACRO_CONCAT(test_fun_, __COUNTER__), __VA_ARGS__) -# define SNITCH_TEMPLATE_LIST_TEST_CASE_IMPL(ID, NAME, TAGS, TYPES) \ - template \ - static void ID(); \ - static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ - snitch::tests.add_with_type_list( \ - {NAME, TAGS}, SNITCH_CURRENT_LOCATION, []() { ID(); });\ - template \ +# define SNITCH_TEMPLATE_LIST_TEST_CASE_IMPL(ID, NAME, TAGS, TYPES) \ + template \ + static void ID(); \ + static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ + snitch::tests.add_with_type_list( \ + {NAME, TAGS}, SNITCH_CURRENT_LOCATION, \ + []() { ID(); }); \ + template \ void ID() # define SNITCH_TEMPLATE_LIST_TEST_CASE(NAME, TAGS, TYPES) \ SNITCH_TEMPLATE_LIST_TEST_CASE_IMPL( \ SNITCH_MACRO_CONCAT(test_fun_, __COUNTER__), NAME, TAGS, TYPES) -# define SNITCH_TEMPLATE_TEST_CASE_IMPL(ID, NAME, TAGS, ...) \ - template \ - static void ID(); \ - static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ - snitch::tests.add_with_types<__VA_ARGS__>( \ - {NAME, TAGS}, SNITCH_CURRENT_LOCATION, []() { ID(); });\ - template \ +# define SNITCH_TEMPLATE_TEST_CASE_IMPL(ID, NAME, TAGS, ...) \ + template \ + static void ID(); \ + static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \ + snitch::tests.add_with_types<__VA_ARGS__>( \ + {NAME, TAGS}, SNITCH_CURRENT_LOCATION, \ + []() { ID(); }); \ + template \ void ID() # define SNITCH_TEMPLATE_TEST_CASE(NAME, TAGS, ...) \ diff --git a/include/snitch/snitch_matcher.hpp b/include/snitch/snitch_matcher.hpp index 34631514..afeb3337 100644 --- a/include/snitch/snitch_matcher.hpp +++ b/include/snitch/snitch_matcher.hpp @@ -16,18 +16,16 @@ enum class match_status { failed, matched }; namespace snitch { template concept matcher_for = requires(const T& m, const U& value) { - { m.match(value) } -> convertible_to; - { - m.describe_match(value, matchers::match_status{}) - } -> convertible_to; - }; + { m.match(value) } -> convertible_to; + { m.describe_match(value, matchers::match_status{}) } -> convertible_to; +}; } // namespace snitch namespace snitch::impl { template concept exception_with_what = requires(const T& e) { - { e.what() } -> convertible_to; - }; + { e.what() } -> convertible_to; +}; template [[nodiscard]] constexpr auto match(T&& value, M&& matcher) noexcept { diff --git a/include/snitch/snitch_registry.hpp b/include/snitch/snitch_registry.hpp index f7ee719c..81b8c49a 100644 --- a/include/snitch/snitch_registry.hpp +++ b/include/snitch/snitch_registry.hpp @@ -108,11 +108,11 @@ struct registered_reporter { }; template -concept reporter_type = - requires(registry& reg) { T{reg}; } && - requires(T& rep, registry& reg, std::string_view k, std::string_view v) { - { rep.configure(reg, k, v) } -> convertible_to; - } && requires(T& rep, const registry& reg, const event::data& e) { rep.report(reg, e); }; +concept reporter_type = requires(registry& reg) { + T{reg}; +} && requires(T& rep, registry& reg, std::string_view k, std::string_view v) { + { rep.configure(reg, k, v) } -> convertible_to; +} && requires(T& rep, const registry& reg, const event::data& e) { rep.report(reg, e); }; class registry { // Contains all registered test cases. diff --git a/src/snitch_main.cpp b/src/snitch_main.cpp index b707aa7f..95869907 100644 --- a/src/snitch_main.cpp +++ b/src/snitch_main.cpp @@ -3,8 +3,8 @@ #if SNITCH_DEFINE_MAIN namespace snitch { -int main(int argc, char* argv[]) { - if constexpr(snitch::is_enabled) { +int main(int argc, char* argv[]) { + if constexpr (snitch::is_enabled) { std::optional args = snitch::cli::parse_arguments(argc, argv); if (!args) { return 1; @@ -15,7 +15,7 @@ int main(int argc, char* argv[]) { return 0; } } -} +} // namespace snitch SNITCH_EXPORT int main(int argc, char* argv[]) { return snitch::main(argc, argv); diff --git a/src/snitch_registry.cpp b/src/snitch_registry.cpp index dc864837..b16f33fb 100644 --- a/src/snitch_registry.cpp +++ b/src/snitch_registry.cpp @@ -1,9 +1,9 @@ #include "snitch/snitch_registry.hpp" -# include "snitch/snitch_time.hpp" +#include "snitch/snitch_time.hpp" -# include // for std::sort -# include // for std::optional +#include // for std::sort +#include // for std::optional // Testing framework implementation. // --------------------------------- @@ -399,14 +399,14 @@ void register_assertion(bool success, impl::test_state& state) { ++section.allowed_assertion_failure_count; } -# if SNITCH_WITH_EXCEPTIONS +#if SNITCH_WITH_EXCEPTIONS if (state.held_info.has_value()) { for (auto& section : state.held_info.value().sections.current_section) { ++section.assertion_count; ++section.allowed_assertion_failure_count; } } -# endif +#endif impl::set_state(state.test, impl::test_case_state::allowed_fail); } else { @@ -418,14 +418,14 @@ void register_assertion(bool success, impl::test_state& state) { ++section.assertion_failure_count; } -# if SNITCH_WITH_EXCEPTIONS +#if SNITCH_WITH_EXCEPTIONS if (state.held_info.has_value()) { for (auto& section : state.held_info.value().sections.current_section) { ++section.assertion_count; ++section.assertion_failure_count; } } -# endif +#endif impl::set_state(state.test, impl::test_case_state::failed); } @@ -436,13 +436,13 @@ void register_assertion(bool success, impl::test_state& state) { ++section.assertion_count; } -# if SNITCH_WITH_EXCEPTIONS +#if SNITCH_WITH_EXCEPTIONS if (state.held_info.has_value()) { for (auto& section : state.held_info.value().sections.current_section) { ++section.assertion_count; } } -# endif +#endif } } @@ -455,7 +455,7 @@ void report_assertion_impl( register_assertion(success, state); -# if SNITCH_WITH_EXCEPTIONS +#if SNITCH_WITH_EXCEPTIONS const bool use_held_info = (state.unhandled_exception || std::uncaught_exceptions() > 0) && state.held_info.has_value(); @@ -472,13 +472,13 @@ void report_assertion_impl( state.in_check ? assertion_location{last_location.file, last_location.line, location_type::exact} : last_location; -# else +#else const auto captures_buffer = impl::make_capture_buffer(state.info.captures); const auto& current_section = state.info.sections.current_section; const auto& last_location = state.info.locations.back(); const auto location = assertion_location{last_location.file, last_location.line, location_type::exact}; -# endif +#endif if (success) { if (r.verbose >= registry::verbosity::full) { @@ -558,7 +558,7 @@ void registry::report_section_ended(const section& sec) noexcept { const bool skipped = state.test.state == impl::test_case_state::skipped; -# if SNITCH_WITH_TIMINGS +#if SNITCH_WITH_TIMINGS const auto duration = get_duration_in_seconds(sec.start_time, get_current_time()); state.reg.report_callback( state.reg, event::section_ended{ @@ -569,7 +569,7 @@ void registry::report_section_ended(const section& sec) noexcept { .assertion_failure_count = sec.assertion_failure_count, .allowed_assertion_failure_count = sec.allowed_assertion_failure_count, .duration = duration}); -# else +#else state.reg.report_callback( state.reg, event::section_ended{ .id = sec.id, @@ -578,7 +578,7 @@ void registry::report_section_ended(const section& sec) noexcept { .assertion_count = sec.assertion_count, .assertion_failure_count = sec.assertion_failure_count, .allowed_assertion_failure_count = sec.allowed_assertion_failure_count}); -# endif +#endif } impl::test_state registry::run(impl::test_case& test) noexcept { @@ -610,13 +610,13 @@ impl::test_state registry::run(impl::test_case& test) noexcept { impl::test_state* previous_run = impl::try_get_current_test(); impl::set_current_test(&state); -# if SNITCH_WITH_TIMINGS +#if SNITCH_WITH_TIMINGS const auto time_start = get_current_time(); -# endif +#endif -# if SNITCH_WITH_EXCEPTIONS +#if SNITCH_WITH_EXCEPTIONS try { -# endif +#endif do { // Reset section state. @@ -640,7 +640,7 @@ impl::test_state registry::run(impl::test_case& test) noexcept { } while (!state.info.sections.levels.empty() && state.test.state != impl::test_case_state::skipped); -# if SNITCH_WITH_EXCEPTIONS +#if SNITCH_WITH_EXCEPTIONS state.in_check = true; report_assertion(true, "no exception caught"); state.in_check = false; @@ -660,7 +660,7 @@ impl::test_state registry::run(impl::test_case& test) noexcept { } state.unhandled_exception = false; -# endif +#endif if (state.should_fail) { state.should_fail = false; @@ -671,12 +671,12 @@ impl::test_state registry::run(impl::test_case& test) noexcept { state.should_fail = true; } -# if SNITCH_WITH_TIMINGS +#if SNITCH_WITH_TIMINGS state.duration = get_duration_in_seconds(time_start, get_current_time()); -# endif +#endif if (verbose >= registry::verbosity::high) { -# if SNITCH_WITH_TIMINGS +#if SNITCH_WITH_TIMINGS report_callback( *this, event::test_case_ended{ .id = test.id, @@ -686,7 +686,7 @@ impl::test_state registry::run(impl::test_case& test) noexcept { .allowed_assertion_failure_count = state.allowed_failures, .state = impl::convert_to_public_state(state.test.state), .duration = state.duration}); -# else +#else report_callback( *this, event::test_case_ended{ .id = test.id, @@ -695,7 +695,7 @@ impl::test_state registry::run(impl::test_case& test) noexcept { .assertion_failure_count = state.failures, .allowed_assertion_failure_count = state.allowed_failures, .state = impl::convert_to_public_state(state.test.state)}); -# endif +#endif } impl::set_current_test(previous_run); @@ -722,9 +722,9 @@ bool registry::run_selected_tests( std::size_t assertion_failure_count = 0; std::size_t allowed_assertion_failure_count = 0; -# if SNITCH_WITH_TIMINGS +#if SNITCH_WITH_TIMINGS const auto time_start = get_current_time(); -# endif +#endif for (impl::test_case& t : this->test_cases()) { if (!predicate(t.id)) { @@ -763,12 +763,12 @@ bool registry::run_selected_tests( } } -# if SNITCH_WITH_TIMINGS +#if SNITCH_WITH_TIMINGS const float duration = get_duration_in_seconds(time_start, get_current_time()); -# endif +#endif if (verbose >= registry::verbosity::normal) { -# if SNITCH_WITH_TIMINGS +#if SNITCH_WITH_TIMINGS report_callback( *this, event::test_run_ended{ .name = run_name, @@ -783,7 +783,7 @@ bool registry::run_selected_tests( .duration = duration, .success = success, }); -# else +#else report_callback( *this, event::test_run_ended{ .name = run_name, @@ -796,7 +796,7 @@ bool registry::run_selected_tests( .assertion_failure_count = assertion_failure_count, .allowed_assertion_failure_count = allowed_assertion_failure_count, .success = success}); -# endif +#endif } return success; diff --git a/src/snitch_reporter_catch2_xml.cpp b/src/snitch_reporter_catch2_xml.cpp index bcca9727..4b64fa46 100644 --- a/src/snitch_reporter_catch2_xml.cpp +++ b/src/snitch_reporter_catch2_xml.cpp @@ -243,7 +243,7 @@ void reporter::report(const registry& r, const snitch::event::data& event) noexc e.allowed_assertion_failure_count)}, {"failures", make_string(e.assertion_failure_count)}, {"expectedFailures", make_string(e.allowed_assertion_failure_count)}, - {"skipped", e.skipped?"true":"false"} + {"skipped", e.skipped ? "true" : "false"} # if SNITCH_WITH_TIMINGS , {"durationInSeconds", make_string(e.duration)} diff --git a/tests/runtime_tests/check.cpp b/tests/runtime_tests/check.cpp index 62123e1a..2aaa7e55 100644 --- a/tests/runtime_tests/check.cpp +++ b/tests/runtime_tests/check.cpp @@ -1688,11 +1688,11 @@ TEST_CASE("require throws matches", "[test macros]") { } namespace { -#if SNITCH_ENABLE +# if SNITCH_ENABLE [[nodiscard]] -#else +# else [[maybe_unused]] -#endif +# endif int nodiscard_function() { return 1; } diff --git a/tests/runtime_tests/function_ref.cpp b/tests/runtime_tests/function_ref.cpp index 3c0b075f..3186d4d6 100644 --- a/tests/runtime_tests/function_ref.cpp +++ b/tests/runtime_tests/function_ref.cpp @@ -8,7 +8,7 @@ bool function_called = false; #if !SNITCH_ENABLE [[maybe_unused]] #endif -int return_value = 0u; +int return_value = 0u; struct test_object { test_object() noexcept { diff --git a/tests/runtime_tests/string_utility.cpp b/tests/runtime_tests/string_utility.cpp index 8b5b97d0..ca664bd7 100644 --- a/tests/runtime_tests/string_utility.cpp +++ b/tests/runtime_tests/string_utility.cpp @@ -19,7 +19,8 @@ struct frob { #if !SNITCH_ENABLE [[maybe_unused]] #endif -void foo() {} +void foo() { +} using function_ptr_type = void (*)(); using member_function_ptr_type = void (frob::*)(); diff --git a/tests/testing.hpp b/tests/testing.hpp index dcb2f1fa..a5fb55dc 100644 --- a/tests/testing.hpp +++ b/tests/testing.hpp @@ -52,11 +52,11 @@ struct any_arg { template concept matcher = requires(const T& m) { - { m.match(any_arg{}) } -> snitch::convertible_to; - { - m.describe_match(any_arg{}, snitch::matchers::match_status{}) - } -> snitch::convertible_to; - }; + { m.match(any_arg{}) } -> snitch::convertible_to; + { + m.describe_match(any_arg{}, snitch::matchers::match_status{}) + } -> snitch::convertible_to; +}; template concept function = std::is_function_v; diff --git a/tests/testing_reporters.cpp b/tests/testing_reporters.cpp index 927a6137..415dabf8 100644 --- a/tests/testing_reporters.cpp +++ b/tests/testing_reporters.cpp @@ -5,9 +5,9 @@ namespace { #if SNITCH_WITH_EXCEPTIONS -#if !SNITCH_ENABLE +# if !SNITCH_ENABLE [[maybe_unused]] -#endif +# endif void throw_something(bool do_throw) { if (do_throw) { throw std::runtime_error("I threw"); From 70d1b55739267f0c35d9efe4bbe064cdc93298b4 Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Fri, 22 Nov 2024 16:57:03 +0000 Subject: [PATCH 17/21] Remove WASM disabled build --- .github/workflows/cmake.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index aff1f631..04dfa84f 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -106,7 +106,6 @@ jobs: - { name: MacOS noexcept, os: macos-latest, publish: false, compiler: clang++, arch: "64", build: "osx-libc++-static-noexcept", cmakepp: "", flags: "-DCMAKE_CXX_FLAGS='-fno-exceptions' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"} - { name: WebAssembly, os: ubuntu-latest, publish: true, compiler: em++, arch: "32", build: "wasm32", cmakepp: "emcmake", flags: "-DCMAKE_CXX_FLAGS='-s DISABLE_EXCEPTION_CATCHING=0' -DCMAKE_CROSSCOMPILING_EMULATOR=node"} - { name: WebAssembly noexcept, os: ubuntu-latest, publish: false, compiler: em++, arch: "32", build: "wasm32-noexcept", cmakepp: "emcmake", flags: "-DCMAKE_CXX_FLAGS='-fno-exceptions' -DCMAKE_CROSSCOMPILING_EMULATOR=node"} - - { name: WebAssembly disable, os: ubuntu-latest, publish: true, compiler: em++, arch: "32", build: "wasm32", cmakepp: "emcmake", flags: "-DCMAKE_CXX_FLAGS='-s DISABLE_EXCEPTION_CATCHING=0' -DCMAKE_CROSSCOMPILING_EMULATOR=node -DSNITCH_ENABLE=OFF"} build-type: - Release - Debug From 4d6c8e974bd42eb91f1031b394469387f865f6a4 Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Fri, 22 Nov 2024 17:05:27 +0000 Subject: [PATCH 18/21] Expose snitch::main() in a header --- include/snitch/snitch.hpp | 1 + include/snitch/snitch_main.hpp | 10 ++++++++++ src/snitch_main.cpp | 6 ++++-- tests/testing.cpp | 6 +++--- 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 include/snitch/snitch_main.hpp diff --git a/include/snitch/snitch.hpp b/include/snitch/snitch.hpp index 3fdbf709..b6cd6cd6 100644 --- a/include/snitch/snitch.hpp +++ b/include/snitch/snitch.hpp @@ -23,6 +23,7 @@ #include "snitch/snitch_macros_test_case.hpp" #include "snitch/snitch_macros_utility.hpp" #include "snitch/snitch_macros_warnings.hpp" +#include "snitch/snitch_main.hpp" #include "snitch/snitch_matcher.hpp" #include "snitch/snitch_registry.hpp" #include "snitch/snitch_reporter_catch2_xml.hpp" diff --git a/include/snitch/snitch_main.hpp b/include/snitch/snitch_main.hpp new file mode 100644 index 00000000..4225ffe7 --- /dev/null +++ b/include/snitch/snitch_main.hpp @@ -0,0 +1,10 @@ +#ifndef SNITCH_MAIN_HPP +#define SNITCH_MAIN_HPP + +#include "snitch/snitch_config.hpp" + +namespace snitch { +SNITCH_EXPORT int main(int argc, char* argv[]); +} // namespace snitch + +#endif diff --git a/src/snitch_main.cpp b/src/snitch_main.cpp index 95869907..295bcde4 100644 --- a/src/snitch_main.cpp +++ b/src/snitch_main.cpp @@ -1,9 +1,10 @@ +#include "snitch/snitch_main.hpp" + #include "snitch/snitch_cli.hpp" #include "snitch/snitch_registry.hpp" -#if SNITCH_DEFINE_MAIN namespace snitch { -int main(int argc, char* argv[]) { +SNITCH_EXPORT int main(int argc, char* argv[]) { if constexpr (snitch::is_enabled) { std::optional args = snitch::cli::parse_arguments(argc, argv); if (!args) { @@ -17,6 +18,7 @@ int main(int argc, char* argv[]) { } } // namespace snitch +#if SNITCH_DEFINE_MAIN SNITCH_EXPORT int main(int argc, char* argv[]) { return snitch::main(argc, argv); } diff --git a/tests/testing.cpp b/tests/testing.cpp index b430bbb8..ca43c54f 100644 --- a/tests/testing.cpp +++ b/tests/testing.cpp @@ -8,9 +8,9 @@ #include "testing.hpp" #if defined(SNITCH_TEST_WITH_SNITCH) && !defined(SNITCH_TEST_HEADER_ONLY) -# undef SNITCH_EXPORT -# define SNITCH_EXPORT -# include "snitch_main.cpp" +int main(int argc, char* argv[]) { + return snitch::main(argc, argv); +} #endif bool contains_color_codes(std::string_view msg) noexcept { From 760bdecdd424331ec336c7ead9a59ffec9eff844 Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Fri, 22 Nov 2024 17:10:35 +0000 Subject: [PATCH 19/21] Clean up --- include/snitch/snitch_expression.hpp | 2 +- tests/runtime_tests/check.cpp | 13 +------------ tests/runtime_tests/function_ref.cpp | 5 +---- tests/runtime_tests/registry.cpp | 12 ------------ tests/testing_reporters.cpp | 3 --- 5 files changed, 3 insertions(+), 32 deletions(-) diff --git a/include/snitch/snitch_expression.hpp b/include/snitch/snitch_expression.hpp index 42928380..85bf9eb5 100644 --- a/include/snitch/snitch_expression.hpp +++ b/include/snitch/snitch_expression.hpp @@ -204,7 +204,7 @@ struct extracted_unary_expression { // Operators we want to decompose. #define EXPR_OPERATOR(OP, OP_TYPE) \ template \ - constexpr extracted_binary_expression operator OP(const U & rhs) \ + constexpr extracted_binary_expression operator OP(const U& rhs) \ const noexcept { \ return {type, expected, lhs, rhs}; \ } diff --git a/tests/runtime_tests/check.cpp b/tests/runtime_tests/check.cpp index 2aaa7e55..aeb00612 100644 --- a/tests/runtime_tests/check.cpp +++ b/tests/runtime_tests/check.cpp @@ -32,9 +32,6 @@ struct non_relocatable { } }; -#if !SNITCH_ENABLE -[[maybe_unused]] -#endif bool append(snitch::small_string_span ss, const non_relocatable& o) noexcept { return append(ss, "non_relocatable{", o.value, "}"); } @@ -70,9 +67,6 @@ struct unary_long_string { } }; -#if !SNITCH_ENABLE -[[maybe_unused]] -#endif bool append(snitch::small_string_span ss, const unary_long_string& u) noexcept { return append(ss, u.value); } @@ -1688,12 +1682,7 @@ TEST_CASE("require throws matches", "[test macros]") { } namespace { -# if SNITCH_ENABLE -[[nodiscard]] -# else -[[maybe_unused]] -# endif -int nodiscard_function() { +[[nodiscard]] int nodiscard_function() { return 1; } } // namespace diff --git a/tests/runtime_tests/function_ref.cpp b/tests/runtime_tests/function_ref.cpp index 3186d4d6..6baaf96c 100644 --- a/tests/runtime_tests/function_ref.cpp +++ b/tests/runtime_tests/function_ref.cpp @@ -5,10 +5,7 @@ namespace { std::size_t test_object_instances = 0u; bool function_called = false; -#if !SNITCH_ENABLE -[[maybe_unused]] -#endif -int return_value = 0u; +int return_value = 0u; struct test_object { test_object() noexcept { diff --git a/tests/runtime_tests/registry.cpp b/tests/runtime_tests/registry.cpp index 79fa891e..f5177763 100644 --- a/tests/runtime_tests/registry.cpp +++ b/tests/runtime_tests/registry.cpp @@ -156,28 +156,16 @@ bool configure_called = false; bool report_called = false; bool finish_called = false; -#if !SNITCH_ENABLE -[[maybe_unused]] -#endif void init(snitch::registry&) noexcept { init_called = true; } -#if !SNITCH_ENABLE -[[maybe_unused]] -#endif bool configure(snitch::registry&, std::string_view, std::string_view) noexcept { configure_called = true; return configure_result; } -#if !SNITCH_ENABLE -[[maybe_unused]] -#endif void report(const snitch::registry&, const snitch::event::data&) noexcept { report_called = true; } -#if !SNITCH_ENABLE -[[maybe_unused]] -#endif void finish(snitch::registry&) noexcept { finish_called = true; } diff --git a/tests/testing_reporters.cpp b/tests/testing_reporters.cpp index 415dabf8..afce1e78 100644 --- a/tests/testing_reporters.cpp +++ b/tests/testing_reporters.cpp @@ -5,9 +5,6 @@ namespace { #if SNITCH_WITH_EXCEPTIONS -# if !SNITCH_ENABLE -[[maybe_unused]] -# endif void throw_something(bool do_throw) { if (do_throw) { throw std::runtime_error("I threw"); From ee389f875d3e039d4b28ee7f76a472d13873f71c Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Fri, 22 Nov 2024 17:11:42 +0000 Subject: [PATCH 20/21] Clean up --- tests/runtime_tests/string_utility.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/runtime_tests/string_utility.cpp b/tests/runtime_tests/string_utility.cpp index ca664bd7..824df7be 100644 --- a/tests/runtime_tests/string_utility.cpp +++ b/tests/runtime_tests/string_utility.cpp @@ -16,11 +16,7 @@ struct frob { void knob() {} }; -#if !SNITCH_ENABLE -[[maybe_unused]] -#endif -void foo() { -} +void foo() {} using function_ptr_type = void (*)(); using member_function_ptr_type = void (frob::*)(); @@ -1047,9 +1043,6 @@ constexpr filter_result EE = {.included = false, .implicit = false}; constexpr filter_result II = {.included = true, .implicit = true}; constexpr filter_result IE = {.included = false, .implicit = true}; -#if !SNITCH_ENABLE -[[maybe_unused]] -#endif bool operator==(const filter_result& first, const filter_result& second) noexcept { return first.included == second.included && first.implicit == second.implicit; } From ddf1002069afbcdeb83c30af98d459397b6bc8ea Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Sat, 30 Nov 2024 10:05:24 +0000 Subject: [PATCH 21/21] Port SNITCH_ENABLE to Meson scripts --- CMakeLists.txt | 2 +- meson.build | 32 ++++++++++++-------------- meson_options.txt | 57 +++++++++++++++++++++++----------------------- snitch/meson.build | 1 + 4 files changed, 46 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65252591..ecde2825 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ set(SNITCH_MAX_PATH_LENGTH 1024 CACHE STRING "Maximum length of a file set(SNITCH_MAX_REPORTER_SIZE_BYTES 128 CACHE STRING "Maximum size (in bytes) of a reporter object.") # Feature toggles. -set(SNITCH_ENABLE ON CACHE BOOL "Enable snitch at build time") +set(SNITCH_ENABLE ON CACHE BOOL "Enable/disable snitch at build time.") set(SNITCH_DEFINE_MAIN ON CACHE BOOL "Define main() in snitch -- disable to provide your own main() function.") set(SNITCH_WITH_EXCEPTIONS ON CACHE BOOL "Use exceptions in snitch implementation -- will be forced OFF if exceptions are not available.") set(SNITCH_WITH_MULTITHREADING ON CACHE BOOL "Make the testing framework thread-safe -- disable if multithreading is not needed.") diff --git a/meson.build b/meson.build index 4188a5e7..e3ff3fa3 100644 --- a/meson.build +++ b/meson.build @@ -78,14 +78,14 @@ sources = files('src/snitch_append.cpp', 'src/snitch_string_utility.cpp', 'src/snitch_test_data.cpp') -if get_option('unity_build') - - main = files('src/snitch.cpp') - +if get_option('enable') + if get_option('unity_build') + main = files('src/snitch.cpp') + else + main = sources + endif else - - main = sources - + main = files('src/snitch_main.cpp') endif make_snitch_all = files('make_snitch_all.py') @@ -95,7 +95,6 @@ subdir('snitch') install_headers(headers, subdir: 'snitch') if get_option('create_library') - snitch = library('snitch', conf_file, main, headers, include_directories: include_dirs, @@ -113,21 +112,20 @@ if get_option('create_library') description: 'Lightweight C++20 testing framework.', url: 'https://github.com/cschreib/snitch', ) - else - snitch_dep = declare_dependency(include_directories: include_dirs) - endif if meson.version().version_compare('>=0.54.0') meson.override_dependency('snitch', snitch_dep) endif -test('snitch_all_test', - executable('snitch_all_test', - [snitch_all, 'tests/testing.cpp'], - cpp_args: ['-DSNITCH_TEST_WITH_SNITCH', '-DSNITCH_TEST_HEADER_ONLY'], - dependencies: [snitch_dep] +if get_option('enable') + test('snitch_all_test', + executable('snitch_all_test', + [snitch_all, 'tests/testing.cpp'], + cpp_args: ['-DSNITCH_TEST_WITH_SNITCH', '-DSNITCH_TEST_HEADER_ONLY'], + dependencies: [snitch_dep] + ) ) -) +endif diff --git a/meson_options.txt b/meson_options.txt index 18aad8d0..28c91230 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,33 +1,34 @@ # Maximum lengths. -option('max_test_cases' ,type: 'integer' ,value: 5000, description: 'Maximum number of test cases in a test application.') -option('max_nested_sections' ,type: 'integer' ,value: 8 , description: 'Maximum depth of nested sections in a test case.') -option('max_expr_length' ,type: 'integer' ,value: 1024, description: 'Maximum length of a printed expression when reporting failure.') -option('max_message_length' ,type: 'integer' ,value: 1024, description: 'Maximum length of error or status messages.') -option('max_test_name_length' ,type: 'integer' ,value: 1024, description: 'Maximum length of a test case name.') -option('max_tag_length' ,type: 'integer' ,value: 256 , description: 'Maximum length of a test tag.') -option('max_captures' ,type: 'integer' ,value: 8 , description: 'Maximum number of captured expressions in a test case.') -option('max_capture_length' ,type: 'integer' ,value: 256 , description: 'Maximum length of a captured expression.') -option('max_unique_tags' ,type: 'integer' ,value: 1024, description: 'Maximum number of unique tags in a test application.') -option('max_command_line_args' ,type: 'integer' ,value: 1024, description: 'Maximum number of command line arguments to a test application.') -option('max_registered_reporters' ,type: 'integer' ,value: 8 , description: 'Maximum number of registered reporter that can be selected from the command line.') -option('max_path_length' ,type: 'integer' ,value: 1024, description: 'Maximum length of a file path when writing output to file.') -option('max_reporter_size_bytes' ,type: 'integer' ,value: 128, description: 'Maximum size (in bytes) of a reporter object.') +option('max_test_cases' , type: 'integer', value: 5000, description: 'Maximum number of test cases in a test application.') +option('max_nested_sections' , type: 'integer', value: 8 , description: 'Maximum depth of nested sections in a test case.') +option('max_expr_length' , type: 'integer', value: 1024, description: 'Maximum length of a printed expression when reporting failure.') +option('max_message_length' , type: 'integer', value: 1024, description: 'Maximum length of error or status messages.') +option('max_test_name_length' , type: 'integer', value: 1024, description: 'Maximum length of a test case name.') +option('max_tag_length' , type: 'integer', value: 256 , description: 'Maximum length of a test tag.') +option('max_captures' , type: 'integer', value: 8 , description: 'Maximum number of captured expressions in a test case.') +option('max_capture_length' , type: 'integer', value: 256 , description: 'Maximum length of a captured expression.') +option('max_unique_tags' , type: 'integer', value: 1024, description: 'Maximum number of unique tags in a test application.') +option('max_command_line_args' , type: 'integer', value: 1024, description: 'Maximum number of command line arguments to a test application.') +option('max_registered_reporters', type: 'integer', value: 8 , description: 'Maximum number of registered reporter that can be selected from the command line.') +option('max_path_length' , type: 'integer', value: 1024, description: 'Maximum length of a file path when writing output to file.') +option('max_reporter_size_bytes' , type: 'integer', value: 128, description: 'Maximum size (in bytes) of a reporter object.') # Feature toggles. -option('define_main' ,type: 'boolean' ,value: true, description: 'Define main() in snitch -- disable to provide your own main() function.') -option('with_exceptions' ,type: 'boolean' ,value: true, description: 'Use exceptions in snitch implementation -- will be forced OFF if exceptions are not available.') -option('with_multithreading' ,type: 'boolean', value: true, description: 'Make the testing framework thread-safe -- disable if multithreading is not needed.') -option('with_timings' ,type: 'boolean' ,value: true, description: 'Measure the time taken by each test case -- disable to speed up tests.') -option('with_shorthand_macros' ,type: 'boolean' ,value: true, description: 'Use short names for test macros -- disable if this causes conflicts.') -option('constexpr_float_use_bitcast' ,type: 'boolean' ,value: true, description: 'Use std::bit_cast if available to implement exact constexpr float-to-string conversion.') -option('snitch_append_to_chars' ,type: 'boolean' ,value: true, description: 'Use std::to_chars for string conversions -- disable for greater compatability with a slight performance cost.') -option('default_with_color' ,type: 'boolean' ,value: true, description: 'Enable terminal colors by default -- can also be controlled by command line interface.') -option('decompose_successful_assertions' ,type: 'boolean' ,value: true, description: 'Enable expression decomposition even for successful assertions -- more expensive.') -option('with_all_reporters' ,type: 'boolean' ,value: true, description: 'Allow all built-in reporters to be selected from the command line -- disable for faster compilation.') -option('with_teamcity_reporter' ,type: 'boolean' ,value: true, description: 'Allow the TeamCity reporter to be selected from the command line -- enable if needed.') -option('with_catch2_xml_reporter' ,type: 'boolean' ,value: true, description: 'Allow the Catch2 XML reporter to be selected from the command line -- enable if needed.') +option('enable' , type: 'boolean', value: true, description: 'Enable/disable snitch at build time.') +option('define_main' , type: 'boolean', value: true, description: 'Define main() in snitch -- disable to provide your own main() function.') +option('with_exceptions' , type: 'boolean', value: true, description: 'Use exceptions in snitch implementation -- will be forced OFF if exceptions are not available.') +option('with_multithreading' , type: 'boolean', value: true, description: 'Make the testing framework thread-safe -- disable if multithreading is not needed.') +option('with_timings' , type: 'boolean', value: true, description: 'Measure the time taken by each test case -- disable to speed up tests.') +option('with_shorthand_macros' , type: 'boolean', value: true, description: 'Use short names for test macros -- disable if this causes conflicts.') +option('constexpr_float_use_bitcast' , type: 'boolean', value: true, description: 'Use std::bit_cast if available to implement exact constexpr float-to-string conversion.') +option('snitch_append_to_chars' , type: 'boolean', value: true, description: 'Use std::to_chars for string conversions -- disable for greater compatability with a slight performance cost.') +option('default_with_color' , type: 'boolean', value: true, description: 'Enable terminal colors by default -- can also be controlled by command line interface.') +option('decompose_successful_assertions', type: 'boolean', value: true, description: 'Enable expression decomposition even for successful assertions -- more expensive.') +option('with_all_reporters' , type: 'boolean', value: true, description: 'Allow all built-in reporters to be selected from the command line -- disable for faster compilation.') +option('with_teamcity_reporter' , type: 'boolean', value: true, description: 'Allow the TeamCity reporter to be selected from the command line -- enable if needed.') +option('with_catch2_xml_reporter' , type: 'boolean', value: true, description: 'Allow the Catch2 XML reporter to be selected from the command line -- enable if needed.') # Building and packaging options; not part of the library API. -option('create_header_only' ,type: 'boolean' ,value: true, description: 'Create a single-header header-only version of snitch.') -option('create_library' ,type: 'boolean' ,value: true, description: 'Build a compiled library version of snitch.') -option('unity_build' ,type: 'boolean' ,value: true, description: 'Build sources as single file instead of separate files (faster full build).') +option('create_header_only' , type: 'boolean', value: true, description: 'Create a single-header header-only version of snitch.') +option('create_library' , type: 'boolean', value: true, description: 'Build a compiled library version of snitch.') +option('unity_build' , type: 'boolean', value: true, description: 'Build sources as single file instead of separate files (faster full build).') diff --git a/snitch/meson.build b/snitch/meson.build index 078b40bc..54a3848e 100644 --- a/snitch/meson.build +++ b/snitch/meson.build @@ -33,6 +33,7 @@ conf_data = configuration_data({ 'SNITCH_MAX_PATH_LENGTH' : get_option('max_path_length'), 'SNITCH_MAX_REPORTER_SIZE_BYTES' : get_option('max_reporter_size_bytes'), + 'SNITCH_ENABLE' : get_option('enable').to_int(), 'SNITCH_DEFINE_MAIN' : get_option('define_main').to_int(), 'SNITCH_WITH_EXCEPTIONS' : get_option('with_exceptions').to_int(), 'SNITCH_WITH_MULTITHREADING' : get_option('with_multithreading').to_int(),