Skip to content

Commit

Permalink
[libc++] [test] Generate static_test_env on the fly
Browse files Browse the repository at this point in the history
Summary:
Instead of storing `static_test_env` (with all the symlinks) in the repo, we create it on the fly to be cross-toolchain-friendly. The primary use case for this are Windows-hosted cross-toolchains. Windows doesn't really have a concept of symlinks. So, when the monorepo is cloned, those symlinks turn to ordinary text files. Previously, if we cross-compiled libc++ for some symlink-friendly system (e. g. Linux) and ran tests on the target system, some tests would fail. This patch makes them pass.

Reviewers: ldionne, #libc

Reviewed By: ldionne, #libc

Subscribers: EricWF, dexonsmith, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D78200
  • Loading branch information
broadwaylamb committed May 5, 2020
1 parent 718a292 commit 52cc8ba
Show file tree
Hide file tree
Showing 60 changed files with 519 additions and 426 deletions.

This file was deleted.

Empty file.
Empty file.
Empty file.

This file was deleted.

Empty file.

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

// FILE_DEPENDENCIES: ../../Inputs/static_test_env
// UNSUPPORTED: c++98, c++03

// <filesystem>
Expand Down Expand Up @@ -46,6 +45,7 @@ TEST_CASE(path_ctor) {
}

TEST_CASE(path_ec_ctor) {
static_test_env static_env;
using namespace fs;
{
static_assert(
Expand All @@ -61,8 +61,8 @@ TEST_CASE(path_ec_ctor) {
}
{
std::error_code ec = GetTestEC();
const directory_entry e(StaticEnv::File, ec);
TEST_CHECK(e.path() == StaticEnv::File);
const directory_entry e(static_env.File, ec);
TEST_CHECK(e.path() == static_env.File);
TEST_CHECK(!ec);
}
{
Expand Down Expand Up @@ -121,26 +121,28 @@ TEST_CASE(path_ctor_calls_refresh) {
TEST_CASE(path_ctor_dne) {
using namespace fs;

static_test_env static_env;

{
std::error_code ec = GetTestEC();
directory_entry ent(StaticEnv::DNE, ec);
directory_entry ent(static_env.DNE, ec);
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));
TEST_CHECK(ent.path() == StaticEnv::DNE);
TEST_CHECK(ent.path() == static_env.DNE);
}
// don't report dead symlinks as an error.
{
std::error_code ec = GetTestEC();
directory_entry ent(StaticEnv::BadSymlink, ec);
directory_entry ent(static_env.BadSymlink, ec);
TEST_CHECK(!ec);
TEST_CHECK(ent.path() == StaticEnv::BadSymlink);
TEST_CHECK(ent.path() == static_env.BadSymlink);
}
// DNE does not cause the constructor to throw
{
directory_entry ent(StaticEnv::DNE);
TEST_CHECK(ent.path() == StaticEnv::DNE);
directory_entry ent(static_env.DNE);
TEST_CHECK(ent.path() == static_env.DNE);

directory_entry ent_two(StaticEnv::BadSymlink);
TEST_CHECK(ent_two.path() == StaticEnv::BadSymlink);
directory_entry ent_two(static_env.BadSymlink);
TEST_CHECK(ent_two.path() == static_env.BadSymlink);
}
}

Expand Down
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

// FILE_DEPENDENCIES: ../../Inputs/static_test_env
// UNSUPPORTED: c++98, c++03

// <filesystem>
Expand Down Expand Up @@ -54,6 +53,7 @@ TEST_CASE(test_replace_filename_method) {
TEST_CASE(test_replace_filename_ec_method) {
using namespace fs;

static_test_env static_env;
{
directory_entry e;
path replace;
Expand All @@ -76,9 +76,9 @@ TEST_CASE(test_replace_filename_ec_method) {
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));
}
{
const path p = StaticEnv::EmptyFile;
const path expect = StaticEnv::NonEmptyFile;
const path replace = StaticEnv::NonEmptyFile.filename();
const path p = static_env.EmptyFile;
const path expect = static_env.NonEmptyFile;
const path replace = static_env.NonEmptyFile.filename();
TEST_REQUIRE(expect.parent_path() == p.parent_path());
directory_entry e(p);
TEST_CHECK(e.path() == p);
Expand Down
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

// FILE_DEPENDENCIES: ../../Inputs/static_test_env
// UNSUPPORTED: c++98, c++03

// <filesystem>
Expand Down Expand Up @@ -112,6 +111,7 @@ TEST_CASE(not_regular_file) {
TEST_CASE(error_reporting) {
using namespace fs;

static_test_env static_env;
scoped_test_env env;

const path dir = env.create_dir("dir");
Expand All @@ -127,15 +127,15 @@ TEST_CASE(error_reporting) {
directory_entry ent;

std::error_code ec = GetTestEC();
ent.assign(StaticEnv::DNE, ec);
TEST_REQUIRE(ent.path() == StaticEnv::DNE);
ent.assign(static_env.DNE, ec);
TEST_REQUIRE(ent.path() == static_env.DNE);
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));

ec = GetTestEC();
TEST_CHECK(ent.file_size(ec) == uintmax_t(-1));
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));

ExceptionChecker Checker(StaticEnv::DNE,
ExceptionChecker Checker(static_env.DNE,
std::errc::no_such_file_or_directory,
"directory_entry::file_size");
TEST_CHECK_THROW_RESULT(filesystem_error, Checker, ent.file_size());
Expand All @@ -145,20 +145,20 @@ TEST_CASE(error_reporting) {
directory_entry ent;

std::error_code ec = GetTestEC();
uintmax_t expect_bad = file_size(StaticEnv::BadSymlink, ec);
uintmax_t expect_bad = file_size(static_env.BadSymlink, ec);
TEST_CHECK(expect_bad == uintmax_t(-1));
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));

ec = GetTestEC();
ent.assign(StaticEnv::BadSymlink, ec);
TEST_REQUIRE(ent.path() == StaticEnv::BadSymlink);
ent.assign(static_env.BadSymlink, ec);
TEST_REQUIRE(ent.path() == static_env.BadSymlink);
TEST_CHECK(!ec);

ec = GetTestEC();
TEST_CHECK(ent.file_size(ec) == expect_bad);
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));

ExceptionChecker Checker(StaticEnv::BadSymlink,
ExceptionChecker Checker(static_env.BadSymlink,
std::errc::no_such_file_or_directory,
"directory_entry::file_size");
TEST_CHECK_THROW_RESULT(filesystem_error, Checker, ent.file_size());
Expand Down
Expand Up @@ -149,8 +149,8 @@ TEST_CASE(test_with_ec_dne) {
using fs::directory_entry;
using fs::file_status;
using fs::path;

for (auto p : {StaticEnv::DNE, StaticEnv::BadSymlink}) {
static_test_env static_env;
for (auto p : {static_env.DNE, static_env.BadSymlink}) {

directory_entry e(p);
std::error_code status_ec = GetTestEC();
Expand Down
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

// FILE_DEPENDENCIES: ../../Inputs/static_test_env
// UNSUPPORTED: c++98, c++03

// <filesystem>
Expand Down Expand Up @@ -110,6 +109,7 @@ TEST_CASE(not_regular_file) {
TEST_CASE(error_reporting) {
using namespace fs;

static_test_env static_env;
scoped_test_env env;

const path dir = env.create_dir("dir");
Expand All @@ -125,16 +125,16 @@ TEST_CASE(error_reporting) {
directory_entry ent;

std::error_code ec = GetTestEC();
ent.assign(StaticEnv::DNE, ec);
ent.assign(static_env.DNE, ec);
TEST_CHECK(ec);
TEST_REQUIRE(ent.path() == StaticEnv::DNE);
TEST_REQUIRE(ent.path() == static_env.DNE);
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));

ec = GetTestEC();
TEST_CHECK(ent.hard_link_count(ec) == uintmax_t(-1));
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));

ExceptionChecker Checker(StaticEnv::DNE,
ExceptionChecker Checker(static_env.DNE,
std::errc::no_such_file_or_directory,
"directory_entry::hard_link_count");
TEST_CHECK_THROW_RESULT(filesystem_error, Checker, ent.hard_link_count());
Expand All @@ -144,20 +144,20 @@ TEST_CASE(error_reporting) {
directory_entry ent;

std::error_code ec = GetTestEC();
uintmax_t expect_bad = hard_link_count(StaticEnv::BadSymlink, ec);
uintmax_t expect_bad = hard_link_count(static_env.BadSymlink, ec);
TEST_CHECK(expect_bad == uintmax_t(-1));
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));

ec = GetTestEC();
ent.assign(StaticEnv::BadSymlink, ec);
TEST_REQUIRE(ent.path() == StaticEnv::BadSymlink);
ent.assign(static_env.BadSymlink, ec);
TEST_REQUIRE(ent.path() == static_env.BadSymlink);
TEST_CHECK(!ec);

ec = GetTestEC();
TEST_CHECK(ent.hard_link_count(ec) == expect_bad);
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));

ExceptionChecker Checker(StaticEnv::BadSymlink,
ExceptionChecker Checker(static_env.BadSymlink,
std::errc::no_such_file_or_directory,
"directory_entry::hard_link_count");
TEST_CHECK_THROW_RESULT(filesystem_error, Checker, ent.hard_link_count());
Expand Down
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

// FILE_DEPENDENCIES: ../../Inputs/static_test_env
// UNSUPPORTED: c++98, c++03

// <filesystem>
Expand Down Expand Up @@ -84,6 +83,7 @@ TEST_CASE(basic) {
TEST_CASE(error_reporting) {
using namespace fs;

static_test_env static_env;
scoped_test_env env;

const path dir = env.create_dir("dir");
Expand All @@ -99,15 +99,15 @@ TEST_CASE(error_reporting) {
directory_entry ent;

std::error_code ec = GetTestEC();
ent.assign(StaticEnv::DNE, ec);
TEST_REQUIRE(ent.path() == StaticEnv::DNE);
ent.assign(static_env.DNE, ec);
TEST_REQUIRE(ent.path() == static_env.DNE);
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));

ec = GetTestEC();
TEST_CHECK(ent.last_write_time(ec) == file_time_type::min());
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));

ExceptionChecker Checker(StaticEnv::DNE,
ExceptionChecker Checker(static_env.DNE,
std::errc::no_such_file_or_directory,
"directory_entry::last_write_time");
TEST_CHECK_THROW_RESULT(filesystem_error, Checker, ent.last_write_time());
Expand All @@ -117,20 +117,20 @@ TEST_CASE(error_reporting) {
directory_entry ent;

std::error_code ec = GetTestEC();
file_time_type expect_bad = last_write_time(StaticEnv::BadSymlink, ec);
file_time_type expect_bad = last_write_time(static_env.BadSymlink, ec);
TEST_CHECK(expect_bad == file_time_type::min());
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));

ec = GetTestEC();
ent.assign(StaticEnv::BadSymlink, ec);
TEST_REQUIRE(ent.path() == StaticEnv::BadSymlink);
ent.assign(static_env.BadSymlink, ec);
TEST_REQUIRE(ent.path() == static_env.BadSymlink);
TEST_CHECK(!ec);

ec = GetTestEC();
TEST_CHECK(ent.last_write_time(ec) == expect_bad);
TEST_CHECK(ErrorIs(ec, std::errc::no_such_file_or_directory));

ExceptionChecker Checker(StaticEnv::BadSymlink,
ExceptionChecker Checker(static_env.BadSymlink,
std::errc::no_such_file_or_directory,
"directory_entry::last_write_time");
TEST_CHECK_THROW_RESULT(filesystem_error, Checker, ent.last_write_time());
Expand Down
Expand Up @@ -28,6 +28,7 @@ TEST_SUITE(directory_entry_status_testsuite)

TEST_CASE(test_basic) {
using namespace fs;
static_test_env static_env;
{
const fs::directory_entry e("foo");
std::error_code ec;
Expand All @@ -36,8 +37,8 @@ TEST_CASE(test_basic) {
static_assert(noexcept(e.status()) == false, "");
static_assert(noexcept(e.status(ec)) == true, "");
}
path TestCases[] = {StaticEnv::File, StaticEnv::Dir, StaticEnv::SymlinkToFile,
StaticEnv::DNE};
path TestCases[] = {static_env.File, static_env.Dir, static_env.SymlinkToFile,
static_env.DNE};
for (const auto& p : TestCases) {
const directory_entry e(p);
std::error_code pec = GetTestEC(), eec = GetTestEC(1);
Expand Down
Expand Up @@ -28,6 +28,7 @@ TEST_SUITE(directory_entry_obs_suite)

TEST_CASE(test_signature) {
using namespace fs;
static_test_env static_env;
{
const directory_entry e("foo");
std::error_code ec;
Expand All @@ -36,8 +37,8 @@ TEST_CASE(test_signature) {
static_assert(noexcept(e.symlink_status()) == false, "");
static_assert(noexcept(e.symlink_status(ec)) == true, "");
}
path TestCases[] = {StaticEnv::File, StaticEnv::Dir, StaticEnv::SymlinkToFile,
StaticEnv::DNE};
path TestCases[] = {static_env.File, static_env.Dir, static_env.SymlinkToFile,
static_env.DNE};
for (const auto& p : TestCases) {
const directory_entry e(p);
std::error_code pec = GetTestEC(), eec = GetTestEC(1);
Expand Down
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

// FILE_DEPENDENCIES: ../../Inputs/static_test_env
// UNSUPPORTED: c++98, c++03

// <filesystem>
Expand Down Expand Up @@ -43,7 +42,8 @@ TEST_CASE(test_copy_end_iterator)

TEST_CASE(test_copy_valid_iterator)
{
const path testDir = StaticEnv::Dir;
static_test_env static_env;
const path testDir = static_env.Dir;
const directory_iterator endIt{};

const directory_iterator it(testDir);
Expand Down
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

// FILE_DEPENDENCIES: ../../Inputs/static_test_env
// UNSUPPORTED: c++98, c++03

// <filesystem>
Expand Down Expand Up @@ -36,7 +35,8 @@ TEST_CASE(test_assignment_signature)

TEST_CASE(test_copy_to_end_iterator)
{
const path testDir = StaticEnv::Dir;
static_test_env static_env;
const path testDir = static_env.Dir;

const directory_iterator from(testDir);
TEST_REQUIRE(from != directory_iterator{});
Expand All @@ -52,7 +52,8 @@ TEST_CASE(test_copy_to_end_iterator)

TEST_CASE(test_copy_from_end_iterator)
{
const path testDir = StaticEnv::Dir;
static_test_env static_env;
const path testDir = static_env.Dir;

const directory_iterator from{};

Expand All @@ -66,7 +67,8 @@ TEST_CASE(test_copy_from_end_iterator)

TEST_CASE(test_copy_valid_iterator)
{
const path testDir = StaticEnv::Dir;
static_test_env static_env;
const path testDir = static_env.Dir;
const directory_iterator endIt{};

directory_iterator it_obj(testDir);
Expand Down

0 comments on commit 52cc8ba

Please sign in to comment.