[clang-tools-extra] r347472 - [clangd] Cleanup error consumption code. NFC

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 22 08:20:12 PST 2018


Author: ibiryukov
Date: Thu Nov 22 08:20:12 2018
New Revision: 347472

URL: http://llvm.org/viewvc/llvm-project?rev=347472&view=rev
Log:
[clangd] Cleanup error consumption code. NFC

- Remove reimplementations of llvm::consumeError.
- Simplify test code by using EXPECT_ERROR where it fits.

Modified:
    clang-tools-extra/trunk/clangd/ClangdServer.cpp
    clang-tools-extra/trunk/unittests/clangd/Matchers.h
    clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
    clang-tools-extra/trunk/unittests/clangd/URITests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=347472&r1=347471&r2=347472&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Thu Nov 22 08:20:12 2018
@@ -39,10 +39,6 @@ namespace clang {
 namespace clangd {
 namespace {
 
-void ignoreError(Error Err) {
-  handleAllErrors(std::move(Err), [](const ErrorInfoBase &) {});
-}
-
 std::string getStandardResourceDir() {
   static int Dummy; // Just an address in this process.
   return CompilerInvocation::GetResourcesPath("clangd", (void *)&Dummy);
@@ -312,7 +308,7 @@ void ClangdServer::dumpAST(PathRef File,
                            unique_function<void(std::string)> Callback) {
   auto Action = [](decltype(Callback) Callback, Expected<InputsAndAST> InpAST) {
     if (!InpAST) {
-      ignoreError(InpAST.takeError());
+      llvm::consumeError(InpAST.takeError());
       return Callback("<no-ast>");
     }
     std::string Result;

Modified: clang-tools-extra/trunk/unittests/clangd/Matchers.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/Matchers.h?rev=347472&r1=347471&r2=347472&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/Matchers.h (original)
+++ clang-tools-extra/trunk/unittests/clangd/Matchers.h Thu Nov 22 08:20:12 2018
@@ -125,9 +125,7 @@ PolySubsequenceMatcher<Args...> HasSubse
                     << ::testing::PrintToString(*ComputedValue);               \
       break;                                                                   \
     }                                                                          \
-    handleAllErrors(ComputedValue.takeError(),                                 \
-                    [](const llvm::ErrorInfoBase &) {});                       \
-                                                                               \
+    llvm::consumeError(ComputedValue.takeError());                             \
   } while (false)
 
 } // namespace clangd

Modified: clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp?rev=347472&r1=347471&r2=347472&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp Thu Nov 22 08:20:12 2018
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Context.h"
+#include "Matchers.h"
 #include "TUScheduler.h"
 #include "TestFS.h"
 #include "gmock/gmock.h"
@@ -29,9 +30,6 @@ using ::testing::Pointee;
 using ::testing::UnorderedElementsAre;
 
 void ignoreUpdate(Optional<std::vector<Diag>>) {}
-void ignoreError(Error Err) {
-  handleAllErrors(std::move(Err), [](const ErrorInfoBase &) {});
-}
 
 class TUSchedulerTests : public ::testing::Test {
 protected:
@@ -61,15 +59,11 @@ TEST_F(TUSchedulerTests, MissingFiles) {
 
   // Assert each operation for missing file is an error (even if it's available
   // in VFS).
-  S.runWithAST("", Missing, [&](Expected<InputsAndAST> AST) {
-    ASSERT_FALSE(bool(AST));
-    ignoreError(AST.takeError());
-  });
-  S.runWithPreamble("", Missing, TUScheduler::Stale,
-                    [&](Expected<InputsAndPreamble> Preamble) {
-                      ASSERT_FALSE(bool(Preamble));
-                      ignoreError(Preamble.takeError());
-                    });
+  S.runWithAST("", Missing,
+               [&](Expected<InputsAndAST> AST) { EXPECT_ERROR(AST); });
+  S.runWithPreamble(
+      "", Missing, TUScheduler::Stale,
+      [&](Expected<InputsAndPreamble> Preamble) { EXPECT_ERROR(Preamble); });
   // remove() shouldn't crash on missing files.
   S.remove(Missing);
 
@@ -83,14 +77,12 @@ TEST_F(TUSchedulerTests, MissingFiles) {
   S.remove(Added);
 
   // Assert that all operations fail after removing the file.
-  S.runWithAST("", Added, [&](Expected<InputsAndAST> AST) {
-    ASSERT_FALSE(bool(AST));
-    ignoreError(AST.takeError());
-  });
+  S.runWithAST("", Added,
+               [&](Expected<InputsAndAST> AST) { EXPECT_ERROR(AST); });
   S.runWithPreamble("", Added, TUScheduler::Stale,
                     [&](Expected<InputsAndPreamble> Preamble) {
                       ASSERT_FALSE(bool(Preamble));
-                      ignoreError(Preamble.takeError());
+                      llvm::consumeError(Preamble.takeError());
                     });
   // remove() shouldn't crash on missing files.
   S.remove(Added);

Modified: clang-tools-extra/trunk/unittests/clangd/URITests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/URITests.cpp?rev=347472&r1=347471&r2=347472&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/URITests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/URITests.cpp Thu Nov 22 08:20:12 2018
@@ -7,6 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "Matchers.h"
 #include "TestFS.h"
 #include "URI.h"
 #include "gmock/gmock.h"
@@ -77,16 +78,9 @@ TEST(URITest, Create) {
 }
 
 TEST(URITest, FailedCreate) {
-  auto Fail = [](Expected<URI> U) {
-    if (!U) {
-      consumeError(U.takeError());
-      return true;
-    }
-    return false;
-  };
-  EXPECT_TRUE(Fail(URI::create("/x/y/z", "no")));
+  EXPECT_ERROR(URI::create("/x/y/z", "no"));
   // Path has to be absolute.
-  EXPECT_TRUE(Fail(URI::create("x/y/z", "file")));
+  EXPECT_ERROR(URI::create("x/y/z", "file"));
 }
 
 TEST(URITest, Parse) {
@@ -120,21 +114,12 @@ TEST(URITest, Parse) {
 }
 
 TEST(URITest, ParseFailed) {
-  auto FailedParse = [](StringRef U) {
-    auto URI = URI::parse(U);
-    if (!URI) {
-      consumeError(URI.takeError());
-      return true;
-    }
-    return false;
-  };
-
   // Expect ':' in URI.
-  EXPECT_TRUE(FailedParse("file//x/y/z"));
+  EXPECT_ERROR(URI::parse("file//x/y/z"));
   // Empty.
-  EXPECT_TRUE(FailedParse(""));
-  EXPECT_TRUE(FailedParse(":/a/b/c"));
-  EXPECT_TRUE(FailedParse("\"/a/b/c\" IWYU pragma: abc"));
+  EXPECT_ERROR(URI::parse(""));
+  EXPECT_ERROR(URI::parse(":/a/b/c"));
+  EXPECT_ERROR(URI::parse("\"/a/b/c\" IWYU pragma: abc"));
 }
 
 TEST(URITest, Resolve) {




More information about the cfe-commits mailing list