Skip to content

Commit 59c72a7

Browse files
committed
[libc++] [P1164] Add tests for create_directories. NFC.
That's a follow-up patch after D92769. Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D93026
1 parent c9213e1 commit 59c72a7

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
// UNSUPPORTED: c++03
1010

11+
// This test requires the dylib support introduced in D92769.
12+
// XFAIL: with_system_cxx_lib=macosx10.15
13+
1114
// <filesystem>
1215

1316
// bool create_directories(const path& p);
@@ -75,12 +78,12 @@ TEST_CASE(create_directory_symlinks) {
7578
std::error_code ec = GetTestEC();
7679
TEST_CHECK(create_directories(target, ec) == false);
7780
TEST_CHECK(ec);
81+
TEST_CHECK(ErrorIs(ec, std::errc::file_exists));
7882
TEST_CHECK(!exists(sym_dest_dead));
7983
TEST_CHECK(!exists(dead_sym));
8084
}
8185
}
8286

83-
8487
TEST_CASE(create_directory_through_symlinks) {
8588
scoped_test_env env;
8689
const path root = env.create_dir("dir");
@@ -97,4 +100,42 @@ TEST_CASE(create_directory_through_symlinks) {
97100
}
98101
}
99102

103+
TEST_CASE(dest_is_file)
104+
{
105+
scoped_test_env env;
106+
const path file = env.create_file("file", 42);
107+
std::error_code ec = GetTestEC();
108+
TEST_CHECK(fs::create_directories(file, ec) == false);
109+
TEST_CHECK(ec);
110+
TEST_CHECK(ErrorIs(ec, std::errc::file_exists));
111+
TEST_CHECK(is_regular_file(file));
112+
}
113+
114+
TEST_CASE(dest_part_is_file)
115+
{
116+
scoped_test_env env;
117+
const path file = env.create_file("file");
118+
const path dir = env.make_env_path("file/dir1");
119+
std::error_code ec = GetTestEC();
120+
TEST_CHECK(fs::create_directories(dir, ec) == false);
121+
TEST_CHECK(ec);
122+
TEST_CHECK(ErrorIs(ec, std::errc::not_a_directory));
123+
TEST_CHECK(is_regular_file(file));
124+
TEST_CHECK(!exists(dir));
125+
}
126+
127+
TEST_CASE(dest_final_part_is_file)
128+
{
129+
scoped_test_env env;
130+
env.create_dir("dir");
131+
const path file = env.create_file("dir/file");
132+
const path dir = env.make_env_path("dir/file/dir1");
133+
std::error_code ec = GetTestEC();
134+
TEST_CHECK(fs::create_directories(dir, ec) == false);
135+
TEST_CHECK(ec);
136+
TEST_CHECK(ErrorIs(ec, std::errc::not_a_directory));
137+
TEST_CHECK(is_regular_file(file));
138+
TEST_CHECK(!exists(dir));
139+
}
140+
100141
TEST_SUITE_END()

0 commit comments

Comments
 (0)