From 6340e047b50aed66ef1fa6c868098f484805c8c6 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Fri, 1 Nov 2024 14:24:58 +0100 Subject: [PATCH] Add tests for SourceLocation --- tests/CMakeLists.txt | 1 + tests/test_SourceLocation.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/test_SourceLocation.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5de31be85..5b7ff6b06 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -144,6 +144,7 @@ add_executable (unit_tests test_SmallVector.cpp test_Socket.cpp test_SocketModule.cpp + test_SourceLocation.cpp test_SquareGaussQuadrature.cpp test_SquareTransformation.cpp test_SymbolTable.cpp diff --git a/tests/test_SourceLocation.cpp b/tests/test_SourceLocation.cpp new file mode 100644 index 000000000..f27a14b95 --- /dev/null +++ b/tests/test_SourceLocation.cpp @@ -0,0 +1,30 @@ +#include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers_all.hpp> + +#include <utils/SourceLocation.hpp> + +// clazy:excludeall=non-pod-global-static + +TEST_CASE("SourceLocation", "[utils]") +{ + SECTION("provided") + { + SourceLocation source_location("filename", 3, 2, "function_name"); + + REQUIRE(source_location.filename() == "filename"); + REQUIRE(source_location.line() == 3); + REQUIRE(source_location.column() == 2); + REQUIRE(source_location.function() == "function_name"); + } + + SECTION("from std::source_location") + { + auto std_source_location = std::experimental::source_location::current(); + SourceLocation source_location(std_source_location); + + REQUIRE(source_location.filename() == std_source_location.file_name()); + REQUIRE(source_location.line() == std_source_location.line()); + REQUIRE(source_location.column() == std_source_location.column()); + REQUIRE(source_location.function() == std_source_location.function_name()); + } +} -- GitLab