summaryrefslogtreecommitdiff
path: root/unittests/Support
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2010-12-04 03:18:42 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2010-12-04 03:18:42 +0000
commit9ad8221bcb26643ae5837d7f27b41610eeec98a7 (patch)
tree4a56357a64a958cf93af387362c492c3d71402f7 /unittests/Support
parent470ae13be812132097cf4c17a189c47def5c19a1 (diff)
downloadllvm-9ad8221bcb26643ae5837d7f27b41610eeec98a7.tar.gz
llvm-9ad8221bcb26643ae5837d7f27b41610eeec98a7.tar.bz2
llvm-9ad8221bcb26643ae5837d7f27b41610eeec98a7.tar.xz
Unittests/Support/PathV2: Add FileSystem tests.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120888 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Support')
-rw-r--r--unittests/Support/Path.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp
index 40e62811d0..7d94bc3195 100644
--- a/unittests/Support/Path.cpp
+++ b/unittests/Support/Path.cpp
@@ -119,18 +119,53 @@ TEST(Support, Path) {
outs().flush();
}
+ // Create a temp file.
int FileDescriptor;
SmallString<64> TempPath;
ASSERT_FALSE(fs::unique_file("%%-%%-%%-%%.temp", FileDescriptor, TempPath));
+ // Make sure it exists.
bool TempFileExists;
ASSERT_FALSE(sys::fs::exists(Twine(TempPath), TempFileExists));
EXPECT_TRUE(TempFileExists);
+ // Create another temp tile.
+ int FD2;
+ SmallString<64> TempPath2;
+ ASSERT_FALSE(fs::unique_file("%%-%%-%%-%%.temp", FD2, TempPath2));
+ ASSERT_NE(TempPath.str(), TempPath2.str());
+
+ // Try to copy the first to the second.
+ EXPECT_EQ(fs::copy_file(Twine(TempPath), Twine(TempPath2)), errc::file_exists);
+
+ ::close(FD2);
+ // Try again with the proper options.
+ ASSERT_FALSE(fs::copy_file(Twine(TempPath), Twine(TempPath2),
+ fs::copy_option::overwrite_if_exists));
+ // Remove Temp2.
+ ASSERT_FALSE(fs::remove(Twine(TempPath2), TempFileExists));
+ EXPECT_TRUE(TempFileExists);
+
+ // Make sure Temp2 doesn't exist.
+ ASSERT_FALSE(fs::exists(Twine(TempPath2), TempFileExists));
+ EXPECT_FALSE(TempFileExists);
+
+ // Create a hard link to Temp1.
+ ASSERT_FALSE(fs::create_hard_link(Twine(TempPath), Twine(TempPath2)));
+ bool equal;
+ ASSERT_FALSE(fs::equivalent(Twine(TempPath), Twine(TempPath2), equal));
+ EXPECT_TRUE(equal);
+
+ // Remove Temp1.
::close(FileDescriptor);
ASSERT_FALSE(fs::remove(Twine(TempPath), TempFileExists));
EXPECT_TRUE(TempFileExists);
+ // Remove the hard link.
+ ASSERT_FALSE(fs::remove(Twine(TempPath2), TempFileExists));
+ EXPECT_TRUE(TempFileExists);
+
+ // Make sure Temp1 doesn't exist.
ASSERT_FALSE(fs::exists(Twine(TempPath), TempFileExists));
EXPECT_FALSE(TempFileExists);
}