[llvm-commits] [llvm] r120888 - /llvm/trunk/unittests/Support/Path.cpp

Michael J. Spencer bigcheesegs at gmail.com
Fri Dec 3 19:18:42 PST 2010


Author: mspencer
Date: Fri Dec  3 21:18:42 2010
New Revision: 120888

URL: http://llvm.org/viewvc/llvm-project?rev=120888&view=rev
Log:
Unittests/Support/PathV2: Add FileSystem tests.

Modified:
    llvm/trunk/unittests/Support/Path.cpp

Modified: llvm/trunk/unittests/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=120888&r1=120887&r2=120888&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Fri Dec  3 21:18:42 2010
@@ -119,18 +119,53 @@
     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);
 }





More information about the llvm-commits mailing list