From a79c1c5b8718347047ffbed4979c696d7a10484a Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 11 May 2022 16:49:27 +0200 Subject: Ensure consistent path normalisation In particular, ensure that the empty path and "." have the same normal form. --- test/utils/cpp/TARGETS | 13 +++++++++++++ test/utils/cpp/path.test.cpp | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/utils/cpp/TARGETS create mode 100644 test/utils/cpp/path.test.cpp (limited to 'test/utils/cpp') diff --git a/test/utils/cpp/TARGETS b/test/utils/cpp/TARGETS new file mode 100644 index 00000000..5e11d258 --- /dev/null +++ b/test/utils/cpp/TARGETS @@ -0,0 +1,13 @@ +{ "path": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["path"] + , "srcs": ["path.test.cpp"] + , "deps": + [ ["@", "catch2", "", "catch2"] + , ["test", "catch-main"] + , ["src/utils/cpp", "path"] + ] + , "stage": ["test", "utils", "cpp"] + } +, "TESTS": {"type": "install", "tainted": ["test"], "deps": ["path"]} +} diff --git a/test/utils/cpp/path.test.cpp b/test/utils/cpp/path.test.cpp new file mode 100644 index 00000000..b0e7eff8 --- /dev/null +++ b/test/utils/cpp/path.test.cpp @@ -0,0 +1,20 @@ +#include + +#include "catch2/catch.hpp" +#include "src/utils/cpp/path.hpp" + +TEST_CASE("normalization", "[path]") { + CHECK(ToNormalPath(std::filesystem::path{""}) == + ToNormalPath(std::filesystem::path{"."})); + CHECK(ToNormalPath(std::filesystem::path{""}).string() == "."); + CHECK(ToNormalPath(std::filesystem::path{"."}).string() == "."); + + CHECK(ToNormalPath(std::filesystem::path{"foo/bar/.."}).string() == "foo"); + CHECK(ToNormalPath(std::filesystem::path{"foo/bar/../"}).string() == "foo"); + CHECK(ToNormalPath(std::filesystem::path{"foo/bar/../baz"}).string() == + "foo/baz"); + CHECK(ToNormalPath(std::filesystem::path{"./foo/bar"}).string() == + "foo/bar"); + CHECK(ToNormalPath(std::filesystem::path{"foo/.."}).string() == "."); + CHECK(ToNormalPath(std::filesystem::path{"./foo/.."}).string() == "."); +} -- cgit v1.2.3