aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg-test/files.cpp
diff options
context:
space:
mode:
authornicole mazzuca <mazzucan@outlook.com>2020-11-09 11:15:31 -0800
committerGitHub <noreply@github.com>2020-11-09 11:15:31 -0800
commita94f261320398b859e5afb2b4d4c5a574f5d205a (patch)
treed8ae8ad5f740275f2c75e4981c5bd27a9b15a9ed /toolsrc/src/vcpkg-test/files.cpp
parent179bdd1697e03663869c2c3341343396c3ac6dfb (diff)
downloadvcpkg-a94f261320398b859e5afb2b4d4c5a574f5d205a.tar.gz
vcpkg-a94f261320398b859e5afb2b4d4c5a574f5d205a.zip
[vcpkg] Initial Registries: Part 2 MVP (#14153)
* [vcpkg wip] start implementation of registries pt. 2 * Remove the `ports` field of `VcpkgPaths` This is an implementation detail, and so we want to make sure that it's obvious that this is an internal detail; thus, we add a new function `builtin_ports_directory()`, which returns the directory where the builtin ports backing store is. * continue WIP * wip * It works! * format * fix some issues * switch from function static to DelayedInit * fix lexically_normal for experimental::filesystem * format * fix missing include * add STL notice * whee error handling * moar error handling! * ignore extra files in registries * formatting * Billy CRs * Update toolsrc/include/vcpkg/versiont.h * fix add_filename test * fix tests * remove unused function add_filename
Diffstat (limited to 'toolsrc/src/vcpkg-test/files.cpp')
-rw-r--r--toolsrc/src/vcpkg-test/files.cpp105
1 files changed, 90 insertions, 15 deletions
diff --git a/toolsrc/src/vcpkg-test/files.cpp b/toolsrc/src/vcpkg-test/files.cpp
index 94cf7e1dd..ffa72d0fb 100644
--- a/toolsrc/src/vcpkg-test/files.cpp
+++ b/toolsrc/src/vcpkg-test/files.cpp
@@ -194,6 +194,96 @@ TEST_CASE ("remove all", "[files]")
CHECK_EC_ON_FILE(temp_dir, ec);
}
+TEST_CASE ("lexically_normal", "[files]")
+{
+ const auto lexically_normal = [](const char* s) { return fs::lexically_normal(fs::u8path(s)); };
+ const auto native = [](const char* s) { return std::move(fs::u8path(s).make_preferred()); };
+ CHECK(fs::lexically_normal(fs::path()).native() == fs::path().native());
+
+ // these test cases are taken from the MS STL tests
+ CHECK(lexically_normal("cat/./dog/..").native() == native("cat/").native());
+ CHECK(lexically_normal("cat/.///dog/../").native() == native("cat/").native());
+
+ CHECK(lexically_normal("cat/./dog/..").native() == native("cat/").native());
+ CHECK(lexically_normal("cat/.///dog/../").native() == native("cat/").native());
+
+ CHECK(lexically_normal(".").native() == native(".").native());
+ CHECK(lexically_normal("./").native() == native(".").native());
+ CHECK(lexically_normal("./.").native() == native(".").native());
+ CHECK(lexically_normal("././").native() == native(".").native());
+
+ CHECK(lexically_normal("../../..").native() == native("../../..").native());
+ CHECK(lexically_normal("../../../").native() == native("../../..").native());
+
+ CHECK(lexically_normal("../../../a/b/c").native() == native("../../../a/b/c").native());
+
+ CHECK(lexically_normal("/../../..").native() == native("/").native());
+ CHECK(lexically_normal("/../../../").native() == native("/").native());
+
+ CHECK(lexically_normal("/../../../a/b/c").native() == native("/a/b/c").native());
+
+ CHECK(lexically_normal("a/..").native() == native(".").native());
+ CHECK(lexically_normal("a/../").native() == native(".").native());
+
+#if defined(_WIN32)
+ CHECK(lexically_normal(R"(X:)").native() == LR"(X:)");
+
+ CHECK(lexically_normal(R"(X:DriveRelative)").native() == LR"(X:DriveRelative)");
+
+ CHECK(lexically_normal(R"(X:\)").native() == LR"(X:\)");
+ CHECK(lexically_normal(R"(X:/)").native() == LR"(X:\)");
+ CHECK(lexically_normal(R"(X:\\\)").native() == LR"(X:\)");
+ CHECK(lexically_normal(R"(X:///)").native() == LR"(X:\)");
+
+ CHECK(lexically_normal(R"(X:\DosAbsolute)").native() == LR"(X:\DosAbsolute)");
+ CHECK(lexically_normal(R"(X:/DosAbsolute)").native() == LR"(X:\DosAbsolute)");
+ CHECK(lexically_normal(R"(X:\\\DosAbsolute)").native() == LR"(X:\DosAbsolute)");
+ CHECK(lexically_normal(R"(X:///DosAbsolute)").native() == LR"(X:\DosAbsolute)");
+
+ CHECK(lexically_normal(R"(\RootRelative)").native() == LR"(\RootRelative)");
+ CHECK(lexically_normal(R"(/RootRelative)").native() == LR"(\RootRelative)");
+ CHECK(lexically_normal(R"(\\\RootRelative)").native() == LR"(\RootRelative)");
+ CHECK(lexically_normal(R"(///RootRelative)").native() == LR"(\RootRelative)");
+
+ CHECK(lexically_normal(R"(\\server\share)").native() == LR"(\\server\share)");
+ CHECK(lexically_normal(R"(//server/share)").native() == LR"(\\server\share)");
+ CHECK(lexically_normal(R"(\\server\\\share)").native() == LR"(\\server\share)");
+ CHECK(lexically_normal(R"(//server///share)").native() == LR"(\\server\share)");
+
+ CHECK(lexically_normal(R"(\\?\device)").native() == LR"(\\?\device)");
+ CHECK(lexically_normal(R"(//?/device)").native() == LR"(\\?\device)");
+
+ CHECK(lexically_normal(R"(\??\device)").native() == LR"(\??\device)");
+ CHECK(lexically_normal(R"(/??/device)").native() == LR"(\??\device)");
+
+ CHECK(lexically_normal(R"(\\.\device)").native() == LR"(\\.\device)");
+ CHECK(lexically_normal(R"(//./device)").native() == LR"(\\.\device)");
+
+ CHECK(lexically_normal(R"(\\?\UNC\server\share)").native() == LR"(\\?\UNC\server\share)");
+ CHECK(lexically_normal(R"(//?/UNC/server/share)").native() == LR"(\\?\UNC\server\share)");
+
+ CHECK(lexically_normal(R"(C:\a/b\\c\/d/\e//f)").native() == LR"(C:\a\b\c\d\e\f)");
+
+ CHECK(lexically_normal(R"(C:\meow\)").native() == LR"(C:\meow\)");
+ CHECK(lexically_normal(R"(C:\meow/)").native() == LR"(C:\meow\)");
+ CHECK(lexically_normal(R"(C:\meow\\)").native() == LR"(C:\meow\)");
+ CHECK(lexically_normal(R"(C:\meow\/)").native() == LR"(C:\meow\)");
+ CHECK(lexically_normal(R"(C:\meow/\)").native() == LR"(C:\meow\)");
+ CHECK(lexically_normal(R"(C:\meow//)").native() == LR"(C:\meow\)");
+
+ CHECK(lexically_normal(R"(C:\a\.\b\.\.\c\.\.\.)").native() == LR"(C:\a\b\c\)");
+ CHECK(lexically_normal(R"(C:\a\.\b\.\.\c\.\.\.\)").native() == LR"(C:\a\b\c\)");
+
+ CHECK(lexically_normal(R"(C:\a\b\c\d\e\..\f\..\..\..\g\h)").native() == LR"(C:\a\b\g\h)");
+
+ CHECK(lexically_normal(R"(C:\a\b\c\d\e\..\f\..\..\..\g\h\..)").native() == LR"(C:\a\b\g\)");
+ CHECK(lexically_normal(R"(C:\a\b\c\d\e\..\f\..\..\..\g\h\..\)").native() == LR"(C:\a\b\g\)");
+ CHECK(lexically_normal(
+ R"(/\server/\share/\a/\b/\c/\./\./\d/\../\../\../\../\../\../\../\other/x/y/z/.././..\meow.txt)")
+ .native() == LR"(\\server\other\x\meow.txt)");
+#endif
+}
+
#if defined(_WIN32)
TEST_CASE ("win32_fix_path_case", "[files]")
{
@@ -250,21 +340,6 @@ TEST_CASE ("win32_fix_path_case", "[files]")
}
#endif // _WIN32
-TEST_CASE ("add_filename", "[files]")
-{
- using vcpkg::Files::add_filename;
- using vcpkg::Files::preferred_separator;
-
- CHECK(add_filename("a/b", "c") == std::string("a/b") + preferred_separator + "c");
- CHECK(add_filename("a/b/", "c") == "a/b/c");
- CHECK(add_filename("a/b\\", "c") == "a/b\\c");
- CHECK(add_filename("", "c") == "c");
-
- // note that we don't special case slashes in the second argument; the caller shouldn't do that
- CHECK(add_filename("a/b/", "\\c") == "a/b/\\c");
- CHECK(add_filename("a/b\\", "/c") == "a/b\\/c");
-}
-
#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
TEST_CASE ("remove all -- benchmarks", "[files][!benchmark]")
{