aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src
diff options
context:
space:
mode:
authorNicole Mazzuca <mazzucan@outlook.com>2019-07-19 23:20:28 -0700
committerNicole Mazzuca <mazzucan@outlook.com>2019-07-19 23:20:28 -0700
commit0d8bba52e4c0a861b25f9d32006bfde9b749e09f (patch)
tree5e0a29aeb6b3aa79925ca1191ea41129484f48e2 /toolsrc/src
parentc55ea0a0d5229b9dd79aa8ea888f6c0408f9e5dd (diff)
downloadvcpkg-0d8bba52e4c0a861b25f9d32006bfde9b749e09f.tar.gz
vcpkg-0d8bba52e4c0a861b25f9d32006bfde9b749e09f.zip
allow tests to run on older standard libraries
Diffstat (limited to 'toolsrc/src')
-rw-r--r--toolsrc/src/vcpkg-test/arguments.cpp (renamed from toolsrc/src/vcpkg-tests/arguments.cpp)2
-rw-r--r--toolsrc/src/vcpkg-test/catch.cpp (renamed from toolsrc/src/vcpkg-tests/catch.cpp)2
-rw-r--r--toolsrc/src/vcpkg-test/chrono.cpp (renamed from toolsrc/src/vcpkg-tests/chrono.cpp)2
-rw-r--r--toolsrc/src/vcpkg-test/dependencies.cpp (renamed from toolsrc/src/vcpkg-tests/dependencies.cpp)2
-rw-r--r--toolsrc/src/vcpkg-test/files.cpp (renamed from toolsrc/src/vcpkg-tests/files.cpp)17
-rw-r--r--toolsrc/src/vcpkg-test/paragraph.cpp (renamed from toolsrc/src/vcpkg-tests/paragraph.cpp)4
-rw-r--r--toolsrc/src/vcpkg-test/plan.cpp (renamed from toolsrc/src/vcpkg-tests/plan.cpp)4
-rw-r--r--toolsrc/src/vcpkg-test/specifier.cpp (renamed from toolsrc/src/vcpkg-tests/specifier.cpp)2
-rw-r--r--toolsrc/src/vcpkg-test/statusparagraphs.cpp (renamed from toolsrc/src/vcpkg-tests/statusparagraphs.cpp)4
-rw-r--r--toolsrc/src/vcpkg-test/strings.cpp (renamed from toolsrc/src/vcpkg-tests/strings.cpp)2
-rw-r--r--toolsrc/src/vcpkg-test/supports.cpp (renamed from toolsrc/src/vcpkg-tests/supports.cpp)2
-rw-r--r--toolsrc/src/vcpkg-test/update.cpp (renamed from toolsrc/src/vcpkg-tests/update.cpp)4
-rw-r--r--toolsrc/src/vcpkg-test/util.cpp (renamed from toolsrc/src/vcpkg-tests/util.cpp)81
13 files changed, 91 insertions, 37 deletions
diff --git a/toolsrc/src/vcpkg-tests/arguments.cpp b/toolsrc/src/vcpkg-test/arguments.cpp
index 8c625be0f..3fe5fa420 100644
--- a/toolsrc/src/vcpkg-tests/arguments.cpp
+++ b/toolsrc/src/vcpkg-test/arguments.cpp
@@ -1,4 +1,4 @@
-#include <vcpkg-tests/catch.h>
+#include <vcpkg-test/catch.h>
#include <vcpkg/vcpkgcmdarguments.h>
diff --git a/toolsrc/src/vcpkg-tests/catch.cpp b/toolsrc/src/vcpkg-test/catch.cpp
index 701dcb39a..8b5d1aa15 100644
--- a/toolsrc/src/vcpkg-tests/catch.cpp
+++ b/toolsrc/src/vcpkg-test/catch.cpp
@@ -1,5 +1,5 @@
#define CATCH_CONFIG_RUNNER
-#include <vcpkg-tests/catch.h>
+#include <vcpkg-test/catch.h>
#include <vcpkg/base/system.debug.h>
diff --git a/toolsrc/src/vcpkg-tests/chrono.cpp b/toolsrc/src/vcpkg-test/chrono.cpp
index c164753f9..306217ad0 100644
--- a/toolsrc/src/vcpkg-tests/chrono.cpp
+++ b/toolsrc/src/vcpkg-test/chrono.cpp
@@ -1,4 +1,4 @@
-#include <vcpkg-tests/catch.h>
+#include <vcpkg-test/catch.h>
#include <vcpkg/base/chrono.h>
diff --git a/toolsrc/src/vcpkg-tests/dependencies.cpp b/toolsrc/src/vcpkg-test/dependencies.cpp
index 0dee6f296..5ed05cc07 100644
--- a/toolsrc/src/vcpkg-tests/dependencies.cpp
+++ b/toolsrc/src/vcpkg-test/dependencies.cpp
@@ -1,4 +1,4 @@
-#include <vcpkg-tests/catch.h>
+#include <vcpkg-test/catch.h>
#include <vcpkg/sourceparagraph.h>
diff --git a/toolsrc/src/vcpkg-tests/files.cpp b/toolsrc/src/vcpkg-test/files.cpp
index d2edffcff..9e14cec0c 100644
--- a/toolsrc/src/vcpkg-tests/files.cpp
+++ b/toolsrc/src/vcpkg-test/files.cpp
@@ -1,10 +1,9 @@
-#include <vcpkg-tests/catch.h>
-#include <vcpkg-tests/util.h>
+#include <vcpkg-test/catch.h>
+#include <vcpkg-test/util.h>
#include <vcpkg/base/files.h>
#include <vcpkg/base/strings.h>
-#include <filesystem> // required for filesystem::create_{directory_}symlink
#include <iostream>
#include <random>
@@ -20,7 +19,7 @@ namespace
std::mt19937_64 get_urbg(std::uint64_t index)
{
// smallest prime > 2**63 - 1
- return std::mt19937_64{index + 9223372036854775837};
+ return std::mt19937_64{index + 9223372036854775837ULL};
}
std::string get_random_filename(std::mt19937_64& urbg) { return vcpkg::Strings::b32_encode(uid{}(urbg)); }
@@ -83,16 +82,14 @@ namespace
// regular symlink
fs.write_contents(base, "", ec);
REQUIRE_FALSE(ec);
- const std::filesystem::path basep = base.native();
- auto basep_link = basep;
- basep_link.replace_filename(basep.filename().native() + L"-link");
- std::filesystem::create_symlink(basep, basep_link, ec);
+ auto base_link = base;
+ base_link.replace_filename(base.filename().u8string() + "-link");
+ vcpkg::Test::create_symlink(base, base_link, ec);
}
else // type == directory_symlink_tag
{
// directory symlink
- std::filesystem::path basep = base.native();
- std::filesystem::create_directory_symlink(basep / "..", basep, ec);
+ vcpkg::Test::create_directory_symlink(base / "..", base, ec);
}
REQUIRE_FALSE(ec);
diff --git a/toolsrc/src/vcpkg-tests/paragraph.cpp b/toolsrc/src/vcpkg-test/paragraph.cpp
index 0fb85ec69..a95879cfa 100644
--- a/toolsrc/src/vcpkg-tests/paragraph.cpp
+++ b/toolsrc/src/vcpkg-test/paragraph.cpp
@@ -1,5 +1,5 @@
-#include <vcpkg-tests/catch.h>
-#include <vcpkg-tests/util.h>
+#include <vcpkg-test/catch.h>
+#include <vcpkg-test/util.h>
#include <vcpkg/base/strings.h>
diff --git a/toolsrc/src/vcpkg-tests/plan.cpp b/toolsrc/src/vcpkg-test/plan.cpp
index 7ecab460b..049ef2066 100644
--- a/toolsrc/src/vcpkg-tests/plan.cpp
+++ b/toolsrc/src/vcpkg-test/plan.cpp
@@ -1,5 +1,5 @@
-#include <vcpkg-tests/catch.h>
-#include <vcpkg-tests/util.h>
+#include <vcpkg-test/catch.h>
+#include <vcpkg-test/util.h>
#include <vcpkg/dependencies.h>
#include <vcpkg/sourceparagraph.h>
diff --git a/toolsrc/src/vcpkg-tests/specifier.cpp b/toolsrc/src/vcpkg-test/specifier.cpp
index 52ef044e7..330a96d78 100644
--- a/toolsrc/src/vcpkg-tests/specifier.cpp
+++ b/toolsrc/src/vcpkg-test/specifier.cpp
@@ -1,4 +1,4 @@
-#include <vcpkg-tests/catch.h>
+#include <vcpkg-test/catch.h>
#include <vcpkg/base/util.h>
#include <vcpkg/packagespec.h>
diff --git a/toolsrc/src/vcpkg-tests/statusparagraphs.cpp b/toolsrc/src/vcpkg-test/statusparagraphs.cpp
index df52ccb87..c0833e8ba 100644
--- a/toolsrc/src/vcpkg-tests/statusparagraphs.cpp
+++ b/toolsrc/src/vcpkg-test/statusparagraphs.cpp
@@ -1,5 +1,5 @@
-#include <vcpkg-tests/catch.h>
-#include <vcpkg-tests/util.h>
+#include <vcpkg-test/catch.h>
+#include <vcpkg-test/util.h>
#include <vcpkg/base/util.h>
#include <vcpkg/paragraphs.h>
diff --git a/toolsrc/src/vcpkg-tests/strings.cpp b/toolsrc/src/vcpkg-test/strings.cpp
index 3168a7c95..6b744eee6 100644
--- a/toolsrc/src/vcpkg-tests/strings.cpp
+++ b/toolsrc/src/vcpkg-test/strings.cpp
@@ -1,4 +1,4 @@
-#include <vcpkg-tests/catch.h>
+#include <vcpkg-test/catch.h>
#include <vcpkg/base/strings.h>
diff --git a/toolsrc/src/vcpkg-tests/supports.cpp b/toolsrc/src/vcpkg-test/supports.cpp
index c6c88bdbc..8bd386da0 100644
--- a/toolsrc/src/vcpkg-tests/supports.cpp
+++ b/toolsrc/src/vcpkg-test/supports.cpp
@@ -1,4 +1,4 @@
-#include <vcpkg-tests/catch.h>
+#include <vcpkg-test/catch.h>
#include <vcpkg/sourceparagraph.h>
diff --git a/toolsrc/src/vcpkg-tests/update.cpp b/toolsrc/src/vcpkg-test/update.cpp
index 93a8f74a9..70b2f04c1 100644
--- a/toolsrc/src/vcpkg-tests/update.cpp
+++ b/toolsrc/src/vcpkg-test/update.cpp
@@ -1,5 +1,5 @@
-#include <vcpkg-tests/catch.h>
-#include <vcpkg-tests/util.h>
+#include <vcpkg-test/catch.h>
+#include <vcpkg-test/util.h>
#include <vcpkg/base/sortedvector.h>
diff --git a/toolsrc/src/vcpkg-tests/util.cpp b/toolsrc/src/vcpkg-test/util.cpp
index f14628379..19f8f355e 100644
--- a/toolsrc/src/vcpkg-tests/util.cpp
+++ b/toolsrc/src/vcpkg-test/util.cpp
@@ -1,6 +1,7 @@
-#include <vcpkg-tests/catch.h>
-#include <vcpkg-tests/util.h>
+#include <vcpkg-test/catch.h>
+#include <vcpkg-test/util.h>
+#include <vcpkg/base/checks.h>
#include <vcpkg/base/files.h>
#include <vcpkg/statusparagraph.h>
@@ -11,6 +12,18 @@
#include <windows.h>
#endif
+#if defined(_MSC_VER) && _MSC_VER >= 1914
+
+#define USE_STD_FILESYSTEM
+
+#include <filesystem> // required for filesystem::create_{directory_}symlink
+
+#elif !defined(_MSC_VER)
+
+#include <unistd.h>
+
+#endif
+
namespace vcpkg::Test
{
std::unique_ptr<vcpkg::StatusParagraph> make_status_pgh(const char* name,
@@ -51,9 +64,14 @@ namespace vcpkg::Test
}
- #if defined(_WIN32)
+
+ // I am so sorry for this awful mix of macros
static bool system_allows_symlinks() {
+#if defined(_WIN32)
+ #if !defined(USE_STD_FILESYSTEM)
+ return false;
+ #else
HKEY key;
bool allow_symlinks = true;
@@ -69,9 +87,14 @@ namespace vcpkg::Test
if (status == ERROR_SUCCESS) RegCloseKey(key);
return allow_symlinks;
+ #endif
+#else
+ return true;
+#endif
}
static fs::path internal_temporary_directory() {
+#if defined(_WIN32)
wchar_t* tmp = static_cast<wchar_t*>(std::calloc(32'767, 2));
if (!GetEnvironmentVariableW(L"TEMP", tmp, 32'767)) {
@@ -83,19 +106,53 @@ namespace vcpkg::Test
std::free(tmp);
return result / L"vcpkg-test";
+#else
+ return "/tmp/vcpkg-test";
+#endif
}
- #else
+ const bool SYMLINKS_ALLOWED = system_allows_symlinks();
+ const fs::path TEMPORARY_DIRECTORY = internal_temporary_directory();
- constexpr static bool system_allows_symlinks() {
- return true;
- }
- static fs::path internal_temporary_directory() {
- return "/tmp/vcpkg-test";
- }
+ void create_symlink(const fs::path& target, const fs::path& file, std::error_code& ec) {
+#if defined(_MSC_VER)
+ #if defined(USE_STD_FILESYSTEM)
+ if (SYMLINKS_ALLOWED)
+ {
+ std::filesystem::path targetp = target.native();
+ std::filesystem::path filep = file.native();
+ std::filesystem::create_symlink(targetp, filep);
+ }
+ else
#endif
+ {
+ vcpkg::Checks::exit_with_message(VCPKG_LINE_INFO, "Symlinks are not allowed on this system");
+ }
+#else
+ if(symlink(target.c_str(), file.c_str()) != 0) {
+ ec.assign(errno, std::system_category());
+ }
+#endif
+ }
- const bool SYMLINKS_ALLOWED = system_allows_symlinks();
- const fs::path TEMPORARY_DIRECTORY = internal_temporary_directory();
+ void create_directory_symlink(const fs::path& target, const fs::path& file, std::error_code& ec) {
+#if defined(_MSC_VER)
+ #if defined(USE_STD_FILESYSTEM)
+ if (SYMLINKS_ALLOWED)
+ {
+ std::filesystem::path targetp = target.native();
+ std::filesystem::path filep = file.native();
+
+ std::filesystem::create_symlink(targetp, filep);
+ }
+ else
+ #endif
+ {
+ vcpkg::Checks::exit_with_message(VCPKG_LINE_INFO, "Symlinks are not allowed on this system");
+ }
+#else
+ ::vcpkg::Test::create_symlink(target, file, ec);
+#endif
+ }
}