diff options
| author | Stefan Boberg <[email protected]> | 2022-05-20 18:45:35 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-05-20 18:45:35 +0200 |
| commit | f0d389a4430b62bfa8ea0852905fcf84065b08c2 (patch) | |
| tree | 450344815e7bb7c3dde0d94f6032f048f3430527 /zencore/include | |
| parent | fix mac compilation error (diff) | |
| download | zen-f0d389a4430b62bfa8ea0852905fcf84065b08c2.tar.xz zen-f0d389a4430b62bfa8ea0852905fcf84065b08c2.zip | |
Add catch2 support (#101)
Added option to use catch2 for unit tests
Currently both doctest and catch2 are supported via some compatibility macros. doctest is the default, and ZEN_USE_CATCH2 needs to be defined to switch to catch2.
Our goal is to evaluate how well catch2 works and switch to catch2 if everything pans out since UE5 now supports using catch2 for unit tests.
Diffstat (limited to 'zencore/include')
| -rw-r--r-- | zencore/include/zencore/testing.h | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/zencore/include/zencore/testing.h b/zencore/include/zencore/testing.h index 80aebc26e..faa4eef6c 100644 --- a/zencore/include/zencore/testing.h +++ b/zencore/include/zencore/testing.h @@ -4,6 +4,36 @@ #include <zencore/zencore.h> +#ifdef ZEN_TEST_WITH_RUNNER +# define CATCH_CONFIG_RUNNER +# define DOCTEST_CONFIG_IMPLEMENT +#endif + +#ifndef ZEN_USE_CATCH2 +# define ZEN_USE_CATCH2 0 +#endif + #if ZEN_WITH_TESTS -# include <doctest/doctest.h> +# if ZEN_USE_CATCH2 +# include <catch2/catch.hpp> +# define SUBCASE(x) SECTION(x) +# define CHECK_EQ(x, y) CHECK((x) == (y)) +# define CHECK_MESSAGE(x, y) CHECK(x) +# define ZEN_RUN_TESTS(argC, argV) Catch::Session().run(argC, argV) +# else +# include <doctest/doctest.h> +# define ZEN_RUN_TESTS(argC, argV) doctest::Context(argc, argv).run() +inline auto +Approx(auto Value) +{ + return doctest::Approx(Value); +} +# endif +#else +# define ZEN_RUN_TESTS(argC, argV) +#endif + +#ifdef ZEN_TEST_WITH_RUNNER +# undef CATCH_CONFIG_RUNNER +# undef DOCTEST_CONFIG_IMPLEMENT #endif |