mirror of
https://github.com/cemu-project/vcpkg.git
synced 2024-11-27 21:20:21 +00:00
switch to new test framework
This commit is contained in:
parent
b3caf67749
commit
c55ea0a0d5
@ -52,7 +52,11 @@ add_executable(vcpkg-test EXCLUDE_FROM_ALL ${VCPKGTEST_SOURCES} ${VCPKGLIB_SOURC
|
||||
target_compile_definitions(vcpkg-test PRIVATE -DDISABLE_METRICS=${DISABLE_METRICS_VALUE})
|
||||
target_include_directories(vcpkg-test PRIVATE include)
|
||||
|
||||
foreach(TEST_NAME arguments chrono dependencies paragraph plan specifier supports)
|
||||
foreach(TEST_NAME
|
||||
arguments chrono dependencies files
|
||||
paragraph plan specifier statusparagraphs
|
||||
strings supports update
|
||||
)
|
||||
add_test(${TEST_NAME} vcpkg-test [${TEST_NAME}])
|
||||
endforeach()
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <vcpkg/base/files.h>
|
||||
#include <vcpkg/statusparagraph.h>
|
||||
|
||||
#include <memory>
|
||||
@ -30,4 +31,8 @@ T&& unwrap(vcpkg::Optional<T>&& opt)
|
||||
return std::move(*opt.get());
|
||||
}
|
||||
|
||||
extern const bool SYMLINKS_ALLOWED;
|
||||
|
||||
extern const fs::path TEMPORARY_DIRECTORY;
|
||||
|
||||
}
|
||||
|
@ -1,158 +0,0 @@
|
||||
#include "tests.pch.h"
|
||||
|
||||
#include <vcpkg/base/files.h>
|
||||
#include <vcpkg/base/strings.h>
|
||||
|
||||
#include <filesystem> // required for filesystem::create_{directory_}symlink
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace UnitTest1
|
||||
{
|
||||
class FilesTest : public TestClass<FilesTest>
|
||||
{
|
||||
using uid = std::uniform_int_distribution<std::uint64_t>;
|
||||
|
||||
public:
|
||||
FilesTest()
|
||||
{
|
||||
HKEY key;
|
||||
const auto status = RegOpenKeyExW(
|
||||
HKEY_LOCAL_MACHINE, LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock)", 0, 0, &key);
|
||||
|
||||
if (status == ERROR_FILE_NOT_FOUND)
|
||||
{
|
||||
ALLOW_SYMLINKS = false;
|
||||
std::clog << "Symlinks are not allowed on this system\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
// if we get a permissions error, we still know that we're in developer mode
|
||||
ALLOW_SYMLINKS = true;
|
||||
}
|
||||
|
||||
if (status == ERROR_SUCCESS) RegCloseKey(key);
|
||||
}
|
||||
|
||||
private:
|
||||
TEST_METHOD(remove_all)
|
||||
{
|
||||
auto urbg = get_urbg(0);
|
||||
|
||||
fs::path temp_dir;
|
||||
|
||||
{
|
||||
wchar_t* tmp = static_cast<wchar_t*>(calloc(32'767, 2));
|
||||
|
||||
if (!GetEnvironmentVariableW(L"TEMP", tmp, 32'767))
|
||||
{
|
||||
Assert::Fail(L"GetEnvironmentVariable(\"TEMP\") failed");
|
||||
}
|
||||
|
||||
temp_dir = tmp;
|
||||
|
||||
std::string dir_name = "vcpkg-tmp-dir-";
|
||||
dir_name += get_random_filename(urbg);
|
||||
|
||||
temp_dir /= dir_name;
|
||||
}
|
||||
|
||||
auto& fs = vcpkg::Files::get_real_filesystem();
|
||||
|
||||
std::clog << "temp dir is: " << temp_dir << '\n';
|
||||
|
||||
create_directory_tree(urbg, fs, 0, temp_dir);
|
||||
|
||||
std::error_code ec;
|
||||
fs::path fp;
|
||||
fs.remove_all(temp_dir, ec, fp);
|
||||
Assert::IsFalse(bool(ec));
|
||||
|
||||
Assert::IsFalse(fs.exists(temp_dir));
|
||||
}
|
||||
|
||||
bool ALLOW_SYMLINKS;
|
||||
|
||||
std::mt19937_64 get_urbg(std::uint64_t index)
|
||||
{
|
||||
// smallest prime > 2**63 - 1
|
||||
return std::mt19937_64{index + 9223372036854775837};
|
||||
}
|
||||
|
||||
std::string get_random_filename(std::mt19937_64& urbg) { return vcpkg::Strings::b32_encode(uid{}(urbg)); }
|
||||
|
||||
void create_directory_tree(std::mt19937_64& urbg,
|
||||
vcpkg::Files::Filesystem& fs,
|
||||
std::uint64_t depth,
|
||||
const fs::path& base)
|
||||
{
|
||||
std::random_device rd;
|
||||
constexpr std::uint64_t max_depth = 5;
|
||||
constexpr std::uint64_t width = 5;
|
||||
|
||||
// we want ~70% of our "files" to be directories, and then a third
|
||||
// each of the remaining ~30% to be regular files, directory symlinks,
|
||||
// and regular symlinks
|
||||
constexpr std::uint64_t directory_min_tag = 0;
|
||||
constexpr std::uint64_t directory_max_tag = 6;
|
||||
constexpr std::uint64_t regular_file_tag = 7;
|
||||
constexpr std::uint64_t regular_symlink_tag = 8;
|
||||
constexpr std::uint64_t directory_symlink_tag = 9;
|
||||
|
||||
// if we're at the max depth, we only want to build non-directories
|
||||
std::uint64_t file_type;
|
||||
if (depth < max_depth)
|
||||
{
|
||||
file_type = uid{directory_min_tag, regular_symlink_tag}(urbg);
|
||||
}
|
||||
else
|
||||
{
|
||||
file_type = uid{regular_file_tag, regular_symlink_tag}(urbg);
|
||||
}
|
||||
|
||||
if (!ALLOW_SYMLINKS && file_type > regular_file_tag)
|
||||
{
|
||||
file_type = regular_file_tag;
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
if (type <= directory_max_tag)
|
||||
{
|
||||
fs.create_directory(base, ec);
|
||||
Assert::IsFalse(bool(ec));
|
||||
|
||||
for (int i = 0; i < width; ++i)
|
||||
{
|
||||
create_directory_tree(urbg, fs, depth + 1, base / get_random_filename(urbg));
|
||||
}
|
||||
}
|
||||
else if (type == regular_file_tag)
|
||||
{
|
||||
// regular file
|
||||
fs.write_contents(base, "", ec);
|
||||
}
|
||||
else if (type == regular_symlink_tag)
|
||||
{
|
||||
// regular symlink
|
||||
fs.write_contents(base, "", ec);
|
||||
Assert::IsFalse(bool(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);
|
||||
}
|
||||
else // type == directory_symlink_tag
|
||||
{
|
||||
// directory symlink
|
||||
std::filesystem::path basep = base.native();
|
||||
std::filesystem::create_directory_symlink(basep / "..", basep, ec);
|
||||
}
|
||||
|
||||
Assert::IsFalse(bool(ec));
|
||||
}
|
||||
};
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
#include "tests.pch.h"
|
||||
|
||||
#include <vcpkg/base/strings.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace UnitTest1
|
||||
{
|
||||
class StringsTest : public TestClass<StringsTest>
|
||||
{
|
||||
TEST_METHOD(b64url_encode)
|
||||
{
|
||||
using u64 = std::uint64_t;
|
||||
|
||||
std::vector<std::pair<std::uint64_t, std::string>> map;
|
||||
|
||||
map.emplace_back(0, "AAAAAAAAAAAAA");
|
||||
map.emplace_back(1, "BAAAAAAAAAAAA");
|
||||
|
||||
map.emplace_back(u64(1) << 32, "AAAAAAEAAAAAA");
|
||||
map.emplace_back((u64(1) << 32) + 1, "BAAAAAEAAAAAA");
|
||||
|
||||
map.emplace_back(0xE4D0'1065'D11E'0229, "JRA4RIXMQAUJO");
|
||||
map.emplace_back(0xA626'FE45'B135'07FF, "77BKTYWI6XJMK");
|
||||
map.emplace_back(0xEE36'D228'0C31'D405, "FAVDDGAFSWN4O");
|
||||
map.emplace_back(0x1405'64E7'FE7E'A88C, "MEK5H774ELBIB");
|
||||
map.emplace_back(0xFFFF'FFFF'FFFF'FFFF, "777777777777P");
|
||||
|
||||
std::string result;
|
||||
for (const auto& pr : map)
|
||||
{
|
||||
result = vcpkg::Strings::b32_encode(pr.first);
|
||||
Assert::AreEqual(result, pr.second);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
124
toolsrc/src/vcpkg-tests/files.cpp
Normal file
124
toolsrc/src/vcpkg-tests/files.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-tests/util.h>
|
||||
|
||||
#include <vcpkg/base/files.h>
|
||||
#include <vcpkg/base/strings.h>
|
||||
|
||||
#include <filesystem> // required for filesystem::create_{directory_}symlink
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
|
||||
#include <vector>
|
||||
|
||||
using vcpkg::Test::SYMLINKS_ALLOWED;
|
||||
using vcpkg::Test::TEMPORARY_DIRECTORY;
|
||||
|
||||
namespace
|
||||
{
|
||||
using uid = std::uniform_int_distribution<std::uint64_t>;
|
||||
|
||||
std::mt19937_64 get_urbg(std::uint64_t index)
|
||||
{
|
||||
// smallest prime > 2**63 - 1
|
||||
return std::mt19937_64{index + 9223372036854775837};
|
||||
}
|
||||
|
||||
std::string get_random_filename(std::mt19937_64& urbg) { return vcpkg::Strings::b32_encode(uid{}(urbg)); }
|
||||
|
||||
void create_directory_tree(std::mt19937_64& urbg,
|
||||
vcpkg::Files::Filesystem& fs,
|
||||
std::uint64_t depth,
|
||||
const fs::path& base)
|
||||
{
|
||||
std::random_device rd;
|
||||
constexpr std::uint64_t max_depth = 5;
|
||||
constexpr std::uint64_t width = 5;
|
||||
|
||||
// we want ~70% of our "files" to be directories, and then a third
|
||||
// each of the remaining ~30% to be regular files, directory symlinks,
|
||||
// and regular symlinks
|
||||
constexpr std::uint64_t directory_min_tag = 0;
|
||||
constexpr std::uint64_t directory_max_tag = 6;
|
||||
constexpr std::uint64_t regular_file_tag = 7;
|
||||
constexpr std::uint64_t regular_symlink_tag = 8;
|
||||
constexpr std::uint64_t directory_symlink_tag = 9;
|
||||
|
||||
// if we're at the max depth, we only want to build non-directories
|
||||
std::uint64_t file_type;
|
||||
if (depth < max_depth)
|
||||
{
|
||||
file_type = uid{directory_min_tag, regular_symlink_tag}(urbg);
|
||||
}
|
||||
else
|
||||
{
|
||||
file_type = uid{regular_file_tag, regular_symlink_tag}(urbg);
|
||||
}
|
||||
|
||||
if (!SYMLINKS_ALLOWED && file_type > regular_file_tag)
|
||||
{
|
||||
file_type = regular_file_tag;
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
if (file_type <= directory_max_tag)
|
||||
{
|
||||
fs.create_directory(base, ec);
|
||||
if (ec) {
|
||||
INFO("File that failed: " << base);
|
||||
REQUIRE_FALSE(ec);
|
||||
}
|
||||
|
||||
for (int i = 0; i < width; ++i)
|
||||
{
|
||||
create_directory_tree(urbg, fs, depth + 1, base / get_random_filename(urbg));
|
||||
}
|
||||
}
|
||||
else if (file_type == regular_file_tag)
|
||||
{
|
||||
// regular file
|
||||
fs.write_contents(base, "", ec);
|
||||
}
|
||||
else if (file_type == regular_symlink_tag)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
else // type == directory_symlink_tag
|
||||
{
|
||||
// directory symlink
|
||||
std::filesystem::path basep = base.native();
|
||||
std::filesystem::create_directory_symlink(basep / "..", basep, ec);
|
||||
}
|
||||
|
||||
REQUIRE_FALSE(ec);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE ("remove all", "[files]")
|
||||
{
|
||||
auto urbg = get_urbg(0);
|
||||
|
||||
fs::path temp_dir = TEMPORARY_DIRECTORY / get_random_filename(urbg);
|
||||
|
||||
auto& fs = vcpkg::Files::get_real_filesystem();
|
||||
|
||||
std::error_code ec;
|
||||
fs.create_directory(TEMPORARY_DIRECTORY, ec);
|
||||
|
||||
REQUIRE_FALSE(ec);
|
||||
|
||||
INFO("temp dir is: " << temp_dir);
|
||||
|
||||
create_directory_tree(urbg, fs, 0, temp_dir);
|
||||
|
||||
fs::path fp;
|
||||
fs.remove_all(temp_dir, ec, fp);
|
||||
REQUIRE_FALSE(ec);
|
||||
|
||||
REQUIRE_FALSE(fs.exists(temp_dir));
|
||||
}
|
33
toolsrc/src/vcpkg-tests/strings.cpp
Normal file
33
toolsrc/src/vcpkg-tests/strings.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
|
||||
#include <vcpkg/base/strings.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
TEST_CASE ("b32 encoding", "[strings]")
|
||||
{
|
||||
using u64 = std::uint64_t;
|
||||
|
||||
std::vector<std::pair<std::uint64_t, std::string>> map;
|
||||
|
||||
map.emplace_back(0, "AAAAAAAAAAAAA");
|
||||
map.emplace_back(1, "BAAAAAAAAAAAA");
|
||||
|
||||
map.emplace_back(u64(1) << 32, "AAAAAAEAAAAAA");
|
||||
map.emplace_back((u64(1) << 32) + 1, "BAAAAAEAAAAAA");
|
||||
|
||||
map.emplace_back(0xE4D0'1065'D11E'0229, "JRA4RIXMQAUJO");
|
||||
map.emplace_back(0xA626'FE45'B135'07FF, "77BKTYWI6XJMK");
|
||||
map.emplace_back(0xEE36'D228'0C31'D405, "FAVDDGAFSWN4O");
|
||||
map.emplace_back(0x1405'64E7'FE7E'A88C, "MEK5H774ELBIB");
|
||||
map.emplace_back(0xFFFF'FFFF'FFFF'FFFF, "777777777777P");
|
||||
|
||||
std::string result;
|
||||
for (const auto& pr : map)
|
||||
{
|
||||
result = vcpkg::Strings::b32_encode(pr.first);
|
||||
REQUIRE(vcpkg::Strings::b32_encode(pr.first) == pr.second);
|
||||
}
|
||||
}
|
@ -1,10 +1,16 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-tests/util.h>
|
||||
|
||||
#include <vcpkg/base/files.h>
|
||||
#include <vcpkg/statusparagraph.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace vcpkg::Test
|
||||
{
|
||||
std::unique_ptr<vcpkg::StatusParagraph> make_status_pgh(const char* name,
|
||||
@ -44,4 +50,52 @@ namespace vcpkg::Test
|
||||
return m_ret.value_or_exit(VCPKG_LINE_INFO);
|
||||
}
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
static bool system_allows_symlinks() {
|
||||
HKEY key;
|
||||
bool allow_symlinks = true;
|
||||
|
||||
const auto status = RegOpenKeyExW(
|
||||
HKEY_LOCAL_MACHINE, LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock)", 0, 0, &key);
|
||||
|
||||
if (status == ERROR_FILE_NOT_FOUND)
|
||||
{
|
||||
allow_symlinks = false;
|
||||
std::clog << "Symlinks are not allowed on this system\n";
|
||||
}
|
||||
|
||||
if (status == ERROR_SUCCESS) RegCloseKey(key);
|
||||
|
||||
return allow_symlinks;
|
||||
}
|
||||
|
||||
static fs::path internal_temporary_directory() {
|
||||
wchar_t* tmp = static_cast<wchar_t*>(std::calloc(32'767, 2));
|
||||
|
||||
if (!GetEnvironmentVariableW(L"TEMP", tmp, 32'767)) {
|
||||
std::cerr << "No temporary directory found.\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
fs::path result = tmp;
|
||||
std::free(tmp);
|
||||
|
||||
return result / L"vcpkg-test";
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
constexpr static bool system_allows_symlinks() {
|
||||
return true;
|
||||
}
|
||||
static fs::path internal_temporary_directory() {
|
||||
return "/tmp/vcpkg-test";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
const bool SYMLINKS_ALLOWED = system_allows_symlinks();
|
||||
const fs::path TEMPORARY_DIRECTORY = internal_temporary_directory();
|
||||
}
|
||||
|
@ -1097,56 +1097,8 @@ namespace vcpkg::Build
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
pre_build_info.triplet_abi_tag = [&]() {
|
||||
const auto& fs = paths.get_filesystem();
|
||||
static std::map<fs::path, std::string> s_hash_cache;
|
||||
|
||||
auto it_hash = s_hash_cache.find(triplet_file_path);
|
||||
if (it_hash != s_hash_cache.end())
|
||||
{
|
||||
return it_hash->second;
|
||||
}
|
||||
auto hash = Hash::get_file_hash(fs, triplet_file_path, "SHA1");
|
||||
|
||||
if (auto p = pre_build_info.external_toolchain_file.get())
|
||||
{
|
||||
hash += "-";
|
||||
hash += Hash::get_file_hash(fs, *p, "SHA1");
|
||||
}
|
||||
else if (pre_build_info.cmake_system_name.empty() || pre_build_info.cmake_system_name == "WindowsStore")
|
||||
{
|
||||
hash += "-";
|
||||
hash += Hash::get_file_hash(fs, paths.scripts / "toolchains" / "windows.cmake", "SHA1");
|
||||
}
|
||||
else if (pre_build_info.cmake_system_name == "Linux")
|
||||
{
|
||||
hash += "-";
|
||||
hash += Hash::get_file_hash(fs, paths.scripts / "toolchains" / "linux.cmake", "SHA1");
|
||||
}
|
||||
else if (pre_build_info.cmake_system_name == "Darwin")
|
||||
{
|
||||
hash += "-";
|
||||
hash += Hash::get_file_hash(fs, paths.scripts / "toolchains" / "osx.cmake", "SHA1");
|
||||
}
|
||||
else if (pre_build_info.cmake_system_name == "FreeBSD")
|
||||
{
|
||||
hash += "-";
|
||||
hash += Hash::get_file_hash(fs, paths.scripts / "toolchains" / "freebsd.cmake", "SHA1");
|
||||
}
|
||||
else if (pre_build_info.cmake_system_name == "Android")
|
||||
{
|
||||
hash += "-";
|
||||
hash += Hash::get_file_hash(fs, paths.scripts / "toolchains" / "android.cmake", "SHA1");
|
||||
}
|
||||
|
||||
s_hash_cache.emplace(triplet_file_path, hash);
|
||||
return hash;
|
||||
}();
|
||||
=======
|
||||
pre_build_info.triplet_abi_tag =
|
||||
get_triplet_abi(paths, pre_build_info, triplet);
|
||||
>>>>>>> trunk
|
||||
|
||||
return pre_build_info;
|
||||
}
|
||||
|
@ -23,10 +23,12 @@
|
||||
<ClCompile Include="..\src\vcpkg-tests\catch.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg-tests\chrono.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg-tests\dependencies.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg-tests\files.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg-tests\paragraph.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg-tests\plan.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg-tests\specifier.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg-tests\statusparagraphs.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg-tests\strings.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg-tests\supports.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg-tests\update.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg-tests\util.cpp" />
|
||||
|
Loading…
Reference in New Issue
Block a user