aboutsummaryrefslogtreecommitdiff
path: root/zencore/include
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-04-24 15:53:30 +0200
committerStefan Boberg <[email protected]>2023-04-24 15:53:30 +0200
commit9ee1a686c29b7ab18207c2963497337532f441cb (patch)
tree17d2681767e92603b7199d88235a775e5ca354ab /zencore/include
parentadded changelog comment (diff)
parentfixed dashboard file serving bug (#255) (diff)
downloadzen-9ee1a686c29b7ab18207c2963497337532f441cb.tar.xz
zen-9ee1a686c29b7ab18207c2963497337532f441cb.zip
Merge branch 'main' of https://github.com/EpicGames/zen
Diffstat (limited to 'zencore/include')
-rw-r--r--zencore/include/zencore/testing.h54
1 files changed, 47 insertions, 7 deletions
diff --git a/zencore/include/zencore/testing.h b/zencore/include/zencore/testing.h
index bd55524aa..a00ee3166 100644
--- a/zencore/include/zencore/testing.h
+++ b/zencore/include/zencore/testing.h
@@ -4,24 +4,64 @@
#include <zencore/zencore.h>
-#ifdef ZEN_TEST_WITH_RUNNER
-# define CATCH_CONFIG_RUNNER
+#include <memory>
+
+#ifndef ZEN_TEST_WITH_RUNNER
+# define ZEN_TEST_WITH_RUNNER 0
+#endif
+
+#if ZEN_TEST_WITH_RUNNER
# define DOCTEST_CONFIG_IMPLEMENT
#endif
#if ZEN_WITH_TESTS
# include <doctest/doctest.h>
-# define ZEN_RUN_TESTS(argC, argV) doctest::Context(argc, argv).run()
inline auto
Approx(auto Value)
{
return doctest::Approx(Value);
}
-#else
-# define ZEN_RUN_TESTS(argC, argV)
#endif
-#ifdef ZEN_TEST_WITH_RUNNER
-# undef CATCH_CONFIG_RUNNER
+/**
+ * Test runner helper
+ *
+ * This acts as a thin layer between the test app and the test
+ * framework, which is used to customize configuration logic
+ * and to set up logging.
+ *
+ * If you don't want to implement custom setup then the
+ * ZEN_RUN_TESTS macro can be used instead.
+ */
+
+#if ZEN_WITH_TESTS
+namespace zen::testing {
+
+class TestRunner
+{
+public:
+ TestRunner();
+ ~TestRunner();
+
+ int ApplyCommandLine(int argc, char const* const* argv);
+ int Run();
+
+private:
+ struct Impl;
+
+ std::unique_ptr<Impl> m_Impl;
+};
+
+# define ZEN_RUN_TESTS(argC, argV) \
+ [&] { \
+ zen::testing::TestRunner Runner; \
+ Runner.ApplyCommandLine(argC, argV); \
+ return Runner.Run(); \
+ }()
+
+} // namespace zen::testing
+#endif
+
+#if ZEN_TEST_WITH_RUNNER
# undef DOCTEST_CONFIG_IMPLEMENT
#endif