Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

// UNSUPPORTED: c++03

// XFAIL: LIBCXX-WINDOWS-FIXME

// <filesystem>

// bool is_symlink(file_status s) noexcept
Expand Down Expand Up @@ -94,15 +92,24 @@ TEST_CASE(test_exist_not_found)
TEST_CASE(test_is_symlink_fails)
{
scoped_test_env env;
#ifdef _WIN32
// Windows doesn't support setting perms::none to trigger failures
// reading directories; test using a special inaccessible directory
// instead.
const path p = GetWindowsInaccessibleDir();
if (p.empty())
TEST_UNSUPPORTED();
#else
const path dir = env.create_dir("dir");
const path file = env.create_file("dir/file", 42);
const path p = env.create_file("dir/file", 42);
permissions(dir, perms::none);
#endif

std::error_code ec;
TEST_CHECK(is_symlink(file, ec) == false);
TEST_CHECK(is_symlink(p, ec) == false);
TEST_CHECK(ec);

TEST_CHECK_THROW(filesystem_error, is_symlink(file));
TEST_CHECK_THROW(filesystem_error, is_symlink(p));
}

TEST_SUITE_END()
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,31 @@ TEST_CASE(basic_rename_test)
}
}

TEST_CASE(basic_rename_dir_test)
{
static_test_env env;
const std::error_code set_ec = std::make_error_code(std::errc::address_in_use);
const path new_dir = env.makePath("new_dir");
{ // dir -> dir (with contents)
std::error_code ec = set_ec;
rename(env.Dir, new_dir, ec);
TEST_CHECK(!ec);
TEST_CHECK(!exists(env.Dir));
TEST_CHECK(is_directory(new_dir));
TEST_CHECK(exists(new_dir / "file1"));
}
#ifdef _WIN32
// On Windows, renaming a directory over a file isn't an error (this
// case is skipped in test_error_reporting above).
{ // dir -> file
std::error_code ec = set_ec;
rename(new_dir, env.NonEmptyFile, ec);
TEST_CHECK(!ec);
TEST_CHECK(!exists(new_dir));
TEST_CHECK(is_directory(env.NonEmptyFile));
TEST_CHECK(exists(env.NonEmptyFile / "file1"));
}
#endif
}

TEST_SUITE_END()
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

// UNSUPPORTED: c++03

// XFAIL: LIBCXX-WINDOWS-FIXME

// <filesystem>

// path temp_directory_path();
Expand Down Expand Up @@ -49,9 +47,16 @@ TEST_CASE(basic_tests)
scoped_test_env env;
const path dne = env.make_env_path("dne");
const path file = env.create_file("file", 42);
#ifdef _WIN32
// Windows doesn't support setting perms::none to trigger failures
// reading directories; test using a special inaccessible directory
// instead.
const path inaccessible_dir = GetWindowsInaccessibleDir();
#else
const path dir_perms = env.create_dir("bad_perms_dir");
const path nested_dir = env.create_dir("bad_perms_dir/nested");
const path inaccessible_dir = env.create_dir("bad_perms_dir/nested");
permissions(dir_perms, perms::none);
#endif
LIBCPP_ONLY(const std::errc expect_errc = std::errc::not_a_directory);
struct TestCase {
std::string name;
Expand Down Expand Up @@ -105,12 +110,14 @@ TEST_CASE(basic_tests)
TEST_CHECK(ec);
TEST_CHECK(ret == "");

// Set the env variable to point to a dir we can't access
PutEnv(TC.name, nested_dir);
ec = GetTestEC();
ret = temp_directory_path(ec);
TEST_CHECK(ErrorIs(ec, std::errc::permission_denied));
TEST_CHECK(ret == "");
if (!inaccessible_dir.empty()) {
// Set the env variable to point to a dir we can't access
PutEnv(TC.name, inaccessible_dir);
ec = GetTestEC();
ret = temp_directory_path(ec);
TEST_CHECK(ErrorIs(ec, std::errc::permission_denied));
TEST_CHECK(ret == "");
}

// Set the env variable to point to a non-existent dir
PutEnv(TC.name, TC.p / "does_not_exist");
Expand Down