aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/LockFileManagerTest.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2025-03-11 13:49:44 -0700
committerGitHub <noreply@github.com>2025-03-11 13:49:44 -0700
commitdafb566710cd03b7fbb4b187a91f32be9452fd8c (patch)
treef9172bdc54446b2880444d5b0d0dbd69d2533e61 /llvm/unittests/Support/LockFileManagerTest.cpp
parent7573ee17813b266fdca4dc3041d07bbe616df458 (diff)
downloadllvm-dafb566710cd03b7fbb4b187a91f32be9452fd8c.zip
llvm-dafb566710cd03b7fbb4b187a91f32be9452fd8c.tar.gz
llvm-dafb566710cd03b7fbb4b187a91f32be9452fd8c.tar.bz2
[Support] Return `LockFileManager` errors right away (#130627)
This patch removes some internal state out of `LockFileManager` by moving the locking code from the constructor into new member function `tryLock()` which returns the errors right away. This simplifies and modernizes the interface.
Diffstat (limited to 'llvm/unittests/Support/LockFileManagerTest.cpp')
-rw-r--r--llvm/unittests/Support/LockFileManagerTest.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/llvm/unittests/Support/LockFileManagerTest.cpp b/llvm/unittests/Support/LockFileManagerTest.cpp
index 552053d..627b2da 100644
--- a/llvm/unittests/Support/LockFileManagerTest.cpp
+++ b/llvm/unittests/Support/LockFileManagerTest.cpp
@@ -9,6 +9,7 @@
#include "llvm/Support/LockFileManager.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
+#include "llvm/Testing/Support/Error.h"
#include "llvm/Testing/Support/SupportHelpers.h"
#include "gtest/gtest.h"
#include <memory>
@@ -27,12 +28,12 @@ TEST(LockFileManagerTest, Basic) {
{
// The lock file should not exist, so we should successfully acquire it.
LockFileManager Locked1(LockedFile);
- EXPECT_EQ(LockFileManager::LFS_Owned, Locked1.getState());
+ EXPECT_THAT_EXPECTED(Locked1.tryLock(), HasValue(true));
// Attempting to reacquire the lock should fail. Waiting on it would cause
// deadlock, so don't try that.
LockFileManager Locked2(LockedFile);
- EXPECT_NE(LockFileManager::LFS_Owned, Locked2.getState());
+ EXPECT_THAT_EXPECTED(Locked2.tryLock(), HasValue(false));
}
// Now that the lock is out of scope, the file should be gone.
@@ -68,7 +69,7 @@ TEST(LockFileManagerTest, LinkLockExists) {
// The lock file doesn't point to a real file, so we should successfully
// acquire it.
LockFileManager Locked(LockedFile);
- EXPECT_EQ(LockFileManager::LFS_Owned, Locked.getState());
+ EXPECT_THAT_EXPECTED(Locked.tryLock(), HasValue(true));
}
// Now that the lock is out of scope, the file should be gone.
@@ -93,7 +94,7 @@ TEST(LockFileManagerTest, RelativePath) {
{
// The lock file should not exist, so we should successfully acquire it.
LockFileManager Locked(LockedFile);
- EXPECT_EQ(LockFileManager::LFS_Owned, Locked.getState());
+ EXPECT_THAT_EXPECTED(Locked.tryLock(), HasValue(true));
EXPECT_TRUE(sys::fs::exists(FileLock.str()));
}