aboutsummaryrefslogtreecommitdiff
path: root/zencore
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-04-24 15:48:55 +0200
committerGitHub <[email protected]>2023-04-24 15:48:55 +0200
commit1a345a720f728438d0884c3ade4aa37d5c994701 (patch)
tree8c06d8142b9774913c5de8a661080c25e1e74b6c /zencore
parent0.2.5-pre4 (diff)
downloadzen-1a345a720f728438d0884c3ade4aa37d5c994701.tar.xz
zen-1a345a720f728438d0884c3ade4aa37d5c994701.zip
fixed dashboard file serving bug (#255)
a recent change which introduced support for specifying accept: implicitly via the file extension in the URI caused fallout in the dashboard which would fail to serve any content because the extension was stripped from the RelativeUri accessor. This change fixes that by retaining a copy of the Uri string view which includes the suffix additionally, in order to test this change with both asio/http.sys paths I made the path used for all tests configurable in zenserver-test which involved pulling in a change from sb/proto which makes testing configuration a bit more flexible
Diffstat (limited to 'zencore')
-rw-r--r--zencore/include/zencore/testing.h54
-rw-r--r--zencore/testing.cpp52
2 files changed, 99 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
diff --git a/zencore/testing.cpp b/zencore/testing.cpp
new file mode 100644
index 000000000..15be4b716
--- /dev/null
+++ b/zencore/testing.cpp
@@ -0,0 +1,52 @@
+#include "zencore/testing.h"
+#include "zencore/logging.h"
+
+#if ZEN_WITH_TESTS
+
+namespace zen::testing {
+
+using namespace std::literals;
+
+struct TestRunner::Impl
+{
+ doctest::Context Session;
+};
+
+TestRunner::TestRunner()
+{
+ m_Impl = std::make_unique<Impl>();
+}
+
+TestRunner::~TestRunner()
+{
+}
+
+int
+TestRunner::ApplyCommandLine(int argc, char const* const* argv)
+{
+ m_Impl->Session.applyCommandLine(argc, argv);
+
+ for (int i = 1; i < argc; ++i)
+ {
+ if (argv[i] == "--debug"sv)
+ {
+ spdlog::set_level(spdlog::level::debug);
+ }
+ }
+
+ return 0;
+}
+
+int
+TestRunner::Run()
+{
+ int Rv = 0;
+
+ m_Impl->Session.run();
+
+ return Rv;
+}
+
+} // namespace zen::testing
+
+#endif