summaryrefslogtreecommitdiff
path: root/unittests
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
commitfb307be5afa79bc65b75885ee6c3ced3b450b037 (patch)
treeb367b36f17e67056dd8119ed0fc26e2e9a4055e3 /unittests
parentc53b3dbc20739e63c058b4a35f8f0caec18618c5 (diff)
downloadllvm-fb307be5afa79bc65b75885ee6c3ced3b450b037.tar.gz
llvm-fb307be5afa79bc65b75885ee6c3ced3b450b037.tar.bz2
llvm-fb307be5afa79bc65b75885ee6c3ced3b450b037.tar.xz
[Support] Make sure LockFileManager works correctly with relative paths.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204426 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Support/LockFileManagerTest.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/unittests/Support/LockFileManagerTest.cpp b/unittests/Support/LockFileManagerTest.cpp
index 6392739778..91339ff38d 100644
--- a/unittests/Support/LockFileManagerTest.cpp
+++ b/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