[libcxx] [test] Ifdef out uses of create_fifo on windows

Restructure code in directory_entry.obs/file_type_obs.pass.cpp
and directory_entry.obs/hard_link_count.pass.cpp to reduce the
amount of ifdeffery needed.

In file_type_obs.pass.cpp, we can't inline the calls to
env.create_* into the lambda calls (e.g. "test_path(env.create_*())"),
because the lambda removes the referenced file, and the hardlink
must be created while the earlier test file exists.

In hard_link_count.pass.cpp, move restoration of the original
directory permissions to the end of the lambda, so that new
directory entries can be created after the lambda has run once.

Differential Revision: https://reviews.llvm.org/D89948
This commit is contained in:
Martin Storsjö 2020-10-19 10:57:36 +03:00
parent f15377084c
commit 3be7968c36
9 changed files with 44 additions and 11 deletions

View File

@ -83,7 +83,9 @@ TEST_CASE(not_regular_file) {
std::errc expected_err;
} TestCases[] = {
{env.create_dir("dir"), std::errc::is_a_directory},
#ifndef _WIN32
{env.create_fifo("fifo"), std::errc::not_supported},
#endif
{env.create_directory_symlink("dir", "sym"), std::errc::is_a_directory}};
for (auto const& TC : TestCases) {

View File

@ -65,9 +65,8 @@ TEST_CASE(test_without_ec) {
scoped_test_env env;
path f = env.create_file("foo", 42);
path d = env.create_dir("dir");
path fifo = env.create_fifo("fifo");
path hl = env.create_hardlink("foo", "hl");
for (auto p : {hl, f, d, fifo}) {
auto test_path = [=](const path &p) {
directory_entry e(p);
file_status st = status(p);
file_status sym_st = symlink_status(p);
@ -83,7 +82,14 @@ TEST_CASE(test_without_ec) {
TEST_CHECK(e.is_regular_file() == is_regular_file(st));
TEST_CHECK(e.is_socket() == is_socket(st));
TEST_CHECK(e.is_symlink() == is_symlink(sym_st));
}
};
test_path(f);
test_path(d);
test_path(hl);
#ifndef _WIN32
path fifo = env.create_fifo("fifo");
test_path(fifo);
#endif
}
TEST_CASE(test_with_ec) {
@ -95,9 +101,8 @@ TEST_CASE(test_with_ec) {
scoped_test_env env;
path f = env.create_file("foo", 42);
path d = env.create_dir("dir");
path fifo = env.create_fifo("fifo");
path hl = env.create_hardlink("foo", "hl");
for (auto p : {hl, f, d, fifo}) {
auto test_path = [=](const path &p) {
directory_entry e(p);
std::error_code status_ec = GetTestEC();
std::error_code sym_status_ec = GetTestEC(1);
@ -141,7 +146,14 @@ TEST_CASE(test_with_ec) {
TEST_CHECK(e.is_symlink(ec) == is_symlink(sym_st));
TEST_CHECK(CheckEC(sym_status_ec));
}
};
test_path(f);
test_path(d);
test_path(hl);
#ifndef _WIN32
path fifo = env.create_fifo("fifo");
test_path(fifo);
#endif
}
TEST_CASE(test_with_ec_dne) {

View File

@ -84,13 +84,10 @@ TEST_CASE(not_regular_file) {
scoped_test_env env;
const path dir = env.create_dir("dir");
const path dir2 = env.create_dir("dir/dir2");
const path fifo = env.create_fifo("dir/fifo");
const path sym_to_fifo = env.create_symlink("dir/fifo", "dir/sym");
const perms old_perms = status(dir).permissions();
for (auto p : {dir2, fifo, sym_to_fifo}) {
permissions(dir, old_perms);
auto test_path = [=](const path &p) {
std::error_code dummy_ec = GetTestEC();
directory_entry ent(p, dummy_ec);
TEST_CHECK(!dummy_ec);
@ -103,7 +100,15 @@ TEST_CASE(not_regular_file) {
TEST_CHECK(ent.hard_link_count(ec) == expect);
TEST_CHECK(!ec);
TEST_CHECK_NO_THROW(ent.hard_link_count());
}
permissions(dir, old_perms);
};
test_path(dir2);
#ifndef _WIN32
const path fifo = env.create_fifo("dir/fifo");
const path sym_to_fifo = env.create_symlink("dir/fifo", "dir/sym");
test_path(fifo);
test_path(sym_to_fifo);
#endif
}
TEST_CASE(error_reporting) {

View File

@ -67,8 +67,10 @@ TEST_CASE(test_error_reporting)
scoped_test_env env;
const path file = env.create_file("file1", 42);
const path dir = env.create_dir("dir");
#ifndef _WIN32
const path fifo = env.create_fifo("fifo");
TEST_REQUIRE(is_other(fifo));
#endif
const auto test_ec = GetTestEC();
@ -96,6 +98,7 @@ TEST_CASE(test_error_reporting)
TEST_REQUIRE(ec != test_ec);
TEST_CHECK(checkThrow(dir, file, ec));
}
#ifndef _WIN32
{ // is_other(from)
std::error_code ec = test_ec;
fs::copy(fifo, dir, ec);
@ -110,6 +113,7 @@ TEST_CASE(test_error_reporting)
TEST_REQUIRE(ec != test_ec);
TEST_CHECK(checkThrow(file, fifo, ec));
}
#endif
}
TEST_CASE(from_is_symlink)

View File

@ -73,6 +73,7 @@ TEST_CASE(test_error_reporting) {
}
}
#ifndef _WIN32
TEST_CASE(non_regular_file_test) {
scoped_test_env env;
const path fifo = env.create_fifo("fifo");
@ -94,6 +95,7 @@ TEST_CASE(non_regular_file_test) {
}
}
#endif
TEST_CASE(test_attributes_get_copied) {
scoped_test_env env;

View File

@ -97,6 +97,7 @@ TEST_CASE(equivalent_hardlink_succeeds) {
TEST_CHECK(equivalent(hl1, hl2));
}
#ifndef _WIN32
TEST_CASE(equivalent_is_other_succeeds) {
scoped_test_env env;
path const file = env.create_file("file", 42);
@ -109,5 +110,6 @@ TEST_CASE(equivalent_is_other_succeeds) {
TEST_CHECK(!equivalent(fifo1, fifo2));
TEST_CHECK(equivalent(fifo1, fifo1));
}
#endif
TEST_SUITE_END()

View File

@ -95,6 +95,7 @@ TEST_CASE(test_directory_access_denied)
}
#ifndef _WIN32
TEST_CASE(test_fifo_fails)
{
scoped_test_env env;
@ -107,5 +108,6 @@ TEST_CASE(test_fifo_fails)
TEST_CHECK_THROW(filesystem_error, is_empty(fifo));
}
#endif
TEST_SUITE_END()

View File

@ -114,7 +114,9 @@ TEST_CASE(status_file_types_test)
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(_WIN32) // No support for domain sockets
{env.create_socket("socket"), file_type::socket},
#endif
#ifndef _WIN32
{env.create_fifo("fifo"), file_type::fifo}
#endif
};
for (const auto& TC : cases) {
// test non-throwing case

View File

@ -123,7 +123,9 @@ TEST_CASE(symlink_status_file_types_test)
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(_WIN32) // No support for domain sockets
{env.create_socket("socket"), file_type::socket},
#endif
#ifndef _WIN32
{env.create_fifo("fifo"), file_type::fifo}
#endif
};
for (const auto& TC : cases) {
// test non-throwing case