diff --git a/clang/unittests/DirectoryWatcher/CMakeLists.txt b/clang/unittests/DirectoryWatcher/CMakeLists.txt --- a/clang/unittests/DirectoryWatcher/CMakeLists.txt +++ b/clang/unittests/DirectoryWatcher/CMakeLists.txt @@ -10,8 +10,9 @@ target_link_libraries(DirectoryWatcherTests PRIVATE + LLVMTestingSupport clangDirectoryWatcher clangBasic ) -endif() \ No newline at end of file +endif() diff --git a/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp b/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp --- a/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp +++ b/clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp @@ -11,6 +11,7 @@ #include "llvm/Support/Mutex.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" #include #include @@ -285,12 +286,7 @@ TestConsumer.consume(Events, IsInitial); }, /*waitForInitialSync=*/true); - if (!DW) { - logAllUnhandledErrors( - DW.takeError(), llvm::errs(), - "DirectoryWatcherTest Failure on DirectoryWatcher::create(): "); - exit(EXIT_FAILURE); - } + ASSERT_THAT_ERROR(DW.takeError(), Succeeded()); checkEventualResultWithTimeout(TestConsumer); } @@ -323,12 +319,7 @@ TestConsumer.consume(Events, IsInitial); }, /*waitForInitialSync=*/false); - if (!DW) { - logAllUnhandledErrors( - DW.takeError(), llvm::errs(), - "DirectoryWatcherTest Failure on DirectoryWatcher::create(): "); - exit(EXIT_FAILURE); - } + ASSERT_THAT_ERROR(DW.takeError(), Succeeded()); checkEventualResultWithTimeout(TestConsumer); } @@ -350,12 +341,7 @@ TestConsumer.consume(Events, IsInitial); }, /*waitForInitialSync=*/true); - if (!DW) { - logAllUnhandledErrors( - DW.takeError(), llvm::errs(), - "DirectoryWatcherTest Failure on DirectoryWatcher::create(): "); - exit(EXIT_FAILURE); - } + ASSERT_THAT_ERROR(DW.takeError(), Succeeded()); fixture.addFile("a"); fixture.addFile("b"); @@ -382,12 +368,7 @@ TestConsumer.consume(Events, IsInitial); }, /*waitForInitialSync=*/true); - if (!DW) { - logAllUnhandledErrors( - DW.takeError(), llvm::errs(), - "DirectoryWatcherTest Failure on DirectoryWatcher::create(): "); - exit(EXIT_FAILURE); - } + ASSERT_THAT_ERROR(DW.takeError(), Succeeded()); // modify the file { @@ -419,12 +400,7 @@ TestConsumer.consume(Events, IsInitial); }, /*waitForInitialSync=*/true); - if (!DW) { - logAllUnhandledErrors( - DW.takeError(), llvm::errs(), - "DirectoryWatcherTest Failure on DirectoryWatcher::create(): "); - exit(EXIT_FAILURE); - } + ASSERT_THAT_ERROR(DW.takeError(), Succeeded()); fixture.deleteFile("a"); @@ -447,12 +423,7 @@ TestConsumer.consume(Events, IsInitial); }, /*waitForInitialSync=*/true); - if (!DW) { - logAllUnhandledErrors( - DW.takeError(), llvm::errs(), - "DirectoryWatcherTest Failure on DirectoryWatcher::create(): "); - exit(EXIT_FAILURE); - } + ASSERT_THAT_ERROR(DW.takeError(), Succeeded()); remove_directories(fixture.TestWatchedDir); @@ -474,12 +445,7 @@ TestConsumer.consume(Events, IsInitial); }, /*waitForInitialSync=*/true); - if (!DW) { - logAllUnhandledErrors( - DW.takeError(), llvm::errs(), - "DirectoryWatcherTest Failure on DirectoryWatcher::create(): "); - exit(EXIT_FAILURE); - } + ASSERT_THAT_ERROR(DW.takeError(), Succeeded()); } // DW is destructed here. checkEventualResultWithTimeout(TestConsumer);