[libcxx-commits] [libcxx] [libc++] Refactor the std::unique_lock tests (PR #102151)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 15 08:28:06 PDT 2024


================
@@ -13,37 +13,23 @@
 // unique_lock& operator=(unique_lock&& u);
 
 #include <cassert>
+#include <memory>
 #include <mutex>
 
-#include "nasty_containers.h"
-#include "../types.h"
-#include "test_macros.h"
+#include "checking_mutex.h"
 
 int main(int, char**) {
-  {
-    typedef MyMutex M;
-    M m0;
-    M m1;
-    std::unique_lock<M> lk0(m0);
-    std::unique_lock<M> lk1(m1);
-    lk1 = std::move(lk0);
-    assert(lk1.mutex() == std::addressof(m0));
-    assert(lk1.owns_lock() == true);
-    assert(lk0.mutex() == nullptr);
-    assert(lk0.owns_lock() == false);
-  }
-  {
-    typedef nasty_mutex M;
-    M m0;
-    M m1;
-    std::unique_lock<M> lk0(m0);
-    std::unique_lock<M> lk1(m1);
-    lk1 = std::move(lk0);
-    assert(lk1.mutex() == std::addressof(m0));
-    assert(lk1.owns_lock() == true);
-    assert(lk0.mutex() == nullptr);
-    assert(lk0.owns_lock() == false);
-  }
+  checking_mutex m0;
+  checking_mutex m1;
+  std::unique_lock<checking_mutex> lk0(m0);
+  std::unique_lock<checking_mutex> lk1(m1);
+
+  lk1 = std::move(lk0);
----------------
ldionne wrote:

```suggestion
  auto& result = (lk1 = std::move(lk0));
  assert(&result == &lk1);
```

https://github.com/llvm/llvm-project/pull/102151


More information about the libcxx-commits mailing list