aboutsummaryrefslogtreecommitdiff
path: root/tests/src/Helper.hpp
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2024-06-15 15:40:31 +0200
committer Spartan322 <Megacake1234@gmail.com>2024-06-22 13:57:49 +0200
commit1a694a8b26a441b12547057d6e0be61a111cced3 (patch)
tree51ca6d5948e92be37b9ee6674cb96801d2cd03f8 /tests/src/Helper.hpp
parent8b623bf4087aa360842ad31145d4ab6946cee9aa (diff)
Add unit testsadd/unit-testing
Make github action tests run explicit Fix dropping annotation list for Errors Fix potential empty get_errors crashes Fix incorrect csv error behavior Add use_sep for `LineObject` and `std::vector<LineObject>` Remove constexpr of load_from_buffer and load_from_string for parsers Add snitch-org/snitch@d6632123cc8d13bdbc5cd60fd6741b9e0f635e82 Make versioned submodules ignore dirty Add tests/bin/* to gitignore
Diffstat (limited to 'tests/src/Helper.hpp')
-rw-r--r--tests/src/Helper.hpp60
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