aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/LockFileManagerTest.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2014-03-21 02:31:56 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2014-03-21 02:31:56 +0000
commit531a5be4d07328b9a1b61a4ddf1b1750b1e22a68 (patch)
treedf9d8f2f65ba51d31fb8085b533824d25ba13a46 /llvm/unittests/Support/LockFileManagerTest.cpp
parent275ce912439f0dd3d51feb9f48466378e70bbe85 (diff)
downloadllvm-531a5be4d07328b9a1b61a4ddf1b1750b1e22a68.zip
llvm-531a5be4d07328b9a1b61a4ddf1b1750b1e22a68.tar.gz
llvm-531a5be4d07328b9a1b61a4ddf1b1750b1e22a68.tar.bz2
[Support] Make sure LockFileManager works correctly with relative paths.
llvm-svn: 204426
Diffstat (limited to 'llvm/unittests/Support/LockFileManagerTest.cpp')
-rw-r--r--llvm/unittests/Support/LockFileManagerTest.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/unittests/Support/LockFileManagerTest.cpp b/llvm/unittests/Support/LockFileManagerTest.cpp
index 6392739..91339ff 100644
--- a/llvm/unittests/Support/LockFileManagerTest.cpp
+++ b/llvm/unittests/Support/LockFileManagerTest.cpp
@@ -76,4 +76,41 @@ TEST(LockFileManagerTest, LinkLockExists) {
ASSERT_FALSE(EC);
}
+
+TEST(LockFileManagerTest, RelativePath) {
+ SmallString<64> TmpDir;
+ error_code EC;
+ EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir);
+ ASSERT_FALSE(EC);
+
+ char PathBuf[1024];
+ const char *OrigPath = getcwd(PathBuf, 1024);
+ chdir(TmpDir.c_str());
+
+ sys::fs::create_directory("inner");
+ SmallString<64> LockedFile("inner");
+ sys::path::append(LockedFile, "file");
+
+ SmallString<64> FileLock(LockedFile);
+ FileLock += ".lock";
+
+ {
+ // The lock file should not exist, so we should successfully acquire it.
+ LockFileManager Locked(LockedFile);
+ EXPECT_EQ(LockFileManager::LFS_Owned, Locked.getState());
+ EXPECT_TRUE(sys::fs::exists(FileLock.str()));
+ }
+
+ // Now that the lock is out of scope, the file should be gone.
+ EXPECT_FALSE(sys::fs::exists(LockedFile.str()));
+ EXPECT_FALSE(sys::fs::exists(FileLock.str()));
+
+ EC = sys::fs::remove("inner");
+ ASSERT_FALSE(EC);
+ EC = sys::fs::remove(StringRef(TmpDir));
+ ASSERT_FALSE(EC);
+
+ chdir(OrigPath);
+}
+
} // end anonymous namespace