diff options
author | George L. Albany <Megacake1234@gmail.com> | 2024-06-22 21:58:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-22 21:58:35 +0200 |
commit | deed8ec0ae23651529a58125012c1b4aab015d02 (patch) | |
tree | 51ca6d5948e92be37b9ee6674cb96801d2cd03f8 /tests/src/Helper.hpp | |
parent | 8b623bf4087aa360842ad31145d4ab6946cee9aa (diff) | |
parent | 1a694a8b26a441b12547057d6e0be61a111cced3 (diff) |
Merge pull request #49 from OpenVicProject/add/unit-testing
Add unit testing
Diffstat (limited to 'tests/src/Helper.hpp')
-rw-r--r-- | tests/src/Helper.hpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/src/Helper.hpp b/tests/src/Helper.hpp new file mode 100644 index 0000000..f12c11d --- /dev/null +++ b/tests/src/Helper.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include <snitch/snitch_macros_utility.hpp> + +#define _EXPR(TYPE, EXPECTED, ASSIGN_VALUE, ...) \ + auto SNITCH_CURRENT_EXPRESSION = \ + (snitch::impl::expression_extractor<EXPECTED> { TYPE, #__VA_ARGS__ } <= __VA_ARGS__) \ + .to_expression(); \ + ASSIGN_VALUE = SNITCH_CURRENT_EXPRESSION.success; + +#define _REQUIRE_IMPL(CHECK, EXPECTED, MAYBE_ABORT, ASSIGN_VALUE, ...) \ + 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__)) { \ + _EXPR(CHECK, EXPECTED, ASSIGN_VALUE, __VA_ARGS__); \ + ASSIGN_VALUE = EXPECTED; \ + SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ + } else { \ + ASSIGN_VALUE = static_cast<bool>(__VA_ARGS__); \ + const auto SNITCH_CURRENT_EXPRESSION = snitch::impl::expression { \ + CHECK, #__VA_ARGS__, {}, ASSIGN_VALUE == EXPECTED \ + }; \ + SNITCH_REPORT_EXPRESSION(MAYBE_ABORT); \ + } \ + SNITCH_WARNING_POP \ + } while (0) + +// clang-format off +#define _OVDL_REQUIRE(NAME, ASSIGN_VALUE, ...) _REQUIRE_IMPL("REQUIRE" NAME, true, SNITCH_TESTING_ABORT, ASSIGN_VALUE, __VA_ARGS__) +#define _OVDL_CHECK(NAME, ASSIGN_VALUE, ...) _REQUIRE_IMPL("CHECK" NAME, true, (void)0, ASSIGN_VALUE, __VA_ARGS__) +#define _OVDL_REQUIRE_FALSE(NAME, ASSIGN_VALUE, ...) _REQUIRE_IMPL("REQUIRE_FALSE" NAME, false, SNITCH_TESTING_ABORT, ASSIGN_VALUE, __VA_ARGS__) +#define _OVDL_CHECK_FALSE(NAME, ASSIGN_VALUE, ...) _REQUIRE_IMPL("CHECK_FALSE" NAME, false, (void)0, ASSIGN_VALUE, __VA_ARGS__) +// clang-format on + +#define _OVDL_CHECK_IF(NAME, ...) \ + if (bool SNITCH_MACRO_CONCAT(result_, __LINE__) = false; [&] { _OVDL_CHECK(NAME, (SNITCH_MACRO_CONCAT(result_, __LINE__)), __VA_ARGS__); }(), (SNITCH_MACRO_CONCAT(result_, __LINE__))) + +#define _OVDL_CHECK_FALSE_IF(NAME, ...) \ + if (bool SNITCH_MACRO_CONCAT(result_, __LINE__) = false; [&] { _OVDL_CHECK_FALSE(NAME, (SNITCH_MACRO_CONCAT(result_, __LINE__)), __VA_ARGS__); }(), (!SNITCH_MACRO_CONCAT(result_, __LINE__))) + +#define CHECK_IF(...) _OVDL_CHECK_IF("_IF", __VA_ARGS__) + +#define CHECK_FALSE_IF(...) _OVDL_CHECK_FALSE_IF("_IF", __VA_ARGS__) + +#define CHECK_OR_RETURN(...) \ + _OVDL_CHECK_IF("_OR_RETURN", __VA_ARGS__); \ + else return +#define CHECK_FALSE_OR_RETURN(...) \ + _OVDL_CHECK_FALSE_IF("_OR_RETURN", __VA_ARGS__); \ + else return + +#define CHECK_OR_CONTINUE(...) \ + _OVDL_CHECK_IF("_OR_CONTINUE", __VA_ARGS__); \ + else continue +#define CHECK_FALSE_OR_CONTINUE(...) \ + _OVDL_CHECK_FALSE_IF("_OR_CONTINUE", __VA_ARGS__); \ + else continue |