aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/kstd/kstd/test_support/result.hpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/libs/kstd/kstd/test_support/result.hpp b/libs/kstd/kstd/test_support/result.hpp
new file mode 100644
index 00000000..7b6d765c
--- /dev/null
+++ b/libs/kstd/kstd/test_support/result.hpp
@@ -0,0 +1,33 @@
+#ifndef KSTD_TEST_SUPPORT_RESULT_HPP
+#define KSTD_TEST_SUPPORT_RESULT_HPP
+
+#include <kstd/result.hpp>
+#include <kstd/test_support/string_makers.hpp>
+
+#include <catch2/catch_test_macros.hpp>
+
+#include <source_location>
+#include <utility>
+
+namespace kstd::tests
+{
+
+ //! Require for a result to be successful.
+ //!
+ //! @param result The result to check.
+ //! @param where The source location to report in case of failure.
+ //! @return The successful value contained in the result.
+ template<typename ResultType>
+ auto require_ok(result<ResultType> result, std::source_location where = std::source_location::current()) -> ResultType
+ {
+ if (!result)
+ {
+ FAIL("expected success at " << where.file_name() << ':' << where.line() << ", got "
+ << error_to_string(result.error()));
+ }
+ return std::move(*result);
+ }
+
+} // namespace kstd::tests
+
+#endif