Skip to content

Commit 4fb115d

Browse files
committed
Unittests/Support/PathV2: Add FileSystem tests.
llvm-svn: 120888
1 parent 0692a32 commit 4fb115d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

llvm/unittests/Support/Path.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,53 @@ TEST(Support, Path) {
119119
outs().flush();
120120
}
121121

122+
// Create a temp file.
122123
int FileDescriptor;
123124
SmallString<64> TempPath;
124125
ASSERT_FALSE(fs::unique_file("%%-%%-%%-%%.temp", FileDescriptor, TempPath));
125126

127+
// Make sure it exists.
126128
bool TempFileExists;
127129
ASSERT_FALSE(sys::fs::exists(Twine(TempPath), TempFileExists));
128130
EXPECT_TRUE(TempFileExists);
129131

132+
// Create another temp tile.
133+
int FD2;
134+
SmallString<64> TempPath2;
135+
ASSERT_FALSE(fs::unique_file("%%-%%-%%-%%.temp", FD2, TempPath2));
136+
ASSERT_NE(TempPath.str(), TempPath2.str());
137+
138+
// Try to copy the first to the second.
139+
EXPECT_EQ(fs::copy_file(Twine(TempPath), Twine(TempPath2)), errc::file_exists);
140+
141+
::close(FD2);
142+
// Try again with the proper options.
143+
ASSERT_FALSE(fs::copy_file(Twine(TempPath), Twine(TempPath2),
144+
fs::copy_option::overwrite_if_exists));
145+
// Remove Temp2.
146+
ASSERT_FALSE(fs::remove(Twine(TempPath2), TempFileExists));
147+
EXPECT_TRUE(TempFileExists);
148+
149+
// Make sure Temp2 doesn't exist.
150+
ASSERT_FALSE(fs::exists(Twine(TempPath2), TempFileExists));
151+
EXPECT_FALSE(TempFileExists);
152+
153+
// Create a hard link to Temp1.
154+
ASSERT_FALSE(fs::create_hard_link(Twine(TempPath), Twine(TempPath2)));
155+
bool equal;
156+
ASSERT_FALSE(fs::equivalent(Twine(TempPath), Twine(TempPath2), equal));
157+
EXPECT_TRUE(equal);
158+
159+
// Remove Temp1.
130160
::close(FileDescriptor);
131161
ASSERT_FALSE(fs::remove(Twine(TempPath), TempFileExists));
132162
EXPECT_TRUE(TempFileExists);
133163

164+
// Remove the hard link.
165+
ASSERT_FALSE(fs::remove(Twine(TempPath2), TempFileExists));
166+
EXPECT_TRUE(TempFileExists);
167+
168+
// Make sure Temp1 doesn't exist.
134169
ASSERT_FALSE(fs::exists(Twine(TempPath), TempFileExists));
135170
EXPECT_FALSE(TempFileExists);
136171
}

0 commit comments

Comments
 (0)