aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/spdlog/tests/test_time_point.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-10-24 10:19:24 +0200
committerGitHub Enterprise <[email protected]>2025-10-24 10:19:24 +0200
commit0e21e0d57a5da36f2a4fbbd315254b22cd2fbf00 (patch)
treebe7c96101bf9c91615f04412c7bafe156a3d6ac8 /thirdparty/spdlog/tests/test_time_point.cpp
parentchangelog (diff)
downloadzen-0e21e0d57a5da36f2a4fbbd315254b22cd2fbf00.tar.xz
zen-0e21e0d57a5da36f2a4fbbd315254b22cd2fbf00.zip
in-tree spdlog (#602)
move spdlog into the tree to remove dependency on vcpkg::spdlog, to allow diverging from the official version and evolve it to fit better with OTLP logging requirements
Diffstat (limited to 'thirdparty/spdlog/tests/test_time_point.cpp')
-rw-r--r--thirdparty/spdlog/tests/test_time_point.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/thirdparty/spdlog/tests/test_time_point.cpp b/thirdparty/spdlog/tests/test_time_point.cpp
new file mode 100644
index 000000000..b7b1b2323
--- /dev/null
+++ b/thirdparty/spdlog/tests/test_time_point.cpp
@@ -0,0 +1,35 @@
+#include "includes.h"
+#include "test_sink.h"
+#include "spdlog/async.h"
+
+TEST_CASE("time_point1", "[time_point log_msg]") {
+ std::shared_ptr<spdlog::sinks::test_sink_st> test_sink(new spdlog::sinks::test_sink_st);
+ spdlog::logger logger("test-time_point", test_sink);
+
+ spdlog::source_loc source{};
+ std::chrono::system_clock::time_point tp{std::chrono::system_clock::now()};
+ test_sink->set_pattern("%T.%F"); // interested in the time_point
+
+ // all the following should have the same time
+ test_sink->set_delay(std::chrono::milliseconds(10));
+ for (int i = 0; i < 5; i++) {
+ spdlog::details::log_msg msg{tp, source, "test_logger", spdlog::level::info, "message"};
+ test_sink->log(msg);
+ }
+
+ logger.log(tp, source, spdlog::level::info, "formatted message");
+ logger.log(tp, source, spdlog::level::info, "formatted message");
+ logger.log(tp, source, spdlog::level::info, "formatted message");
+ logger.log(tp, source, spdlog::level::info, "formatted message");
+ logger.log(source, spdlog::level::info,
+ "formatted message"); // last line has different time_point
+
+ // now the real test... that the times are the same.
+ std::vector<std::string> lines = test_sink->lines();
+ REQUIRE(lines[0] == lines[1]);
+ REQUIRE(lines[2] == lines[3]);
+ REQUIRE(lines[4] == lines[5]);
+ REQUIRE(lines[6] == lines[7]);
+ REQUIRE(lines[8] != lines[9]);
+ spdlog::drop_all();
+}