malaperle updated this revision to Diff 139598.
malaperle added a comment.

Use a header for common inclusions for tests


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44764

Files:
  unittests/clangd/ClangdTesting.h
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/ClangdUnitTests.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/CodeCompletionStringsTests.cpp
  unittests/clangd/ContextTests.cpp
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/FuzzyMatchTests.cpp
  unittests/clangd/HeadersTests.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/JSONExprTests.cpp
  unittests/clangd/Matchers.h
  unittests/clangd/Printers.h
  unittests/clangd/SourceCodeTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp
  unittests/clangd/TUSchedulerTests.cpp
  unittests/clangd/TestFS.cpp
  unittests/clangd/ThreadingTests.cpp
  unittests/clangd/TraceTests.cpp
  unittests/clangd/URITests.cpp
  unittests/clangd/XRefsTests.cpp

Index: unittests/clangd/XRefsTests.cpp
===================================================================
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -7,32 +7,21 @@
 //
 //===----------------------------------------------------------------------===//
 #include "Annotations.h"
+#include "ClangdTesting.h"
 #include "ClangdUnit.h"
 #include "Compiler.h"
-#include "Matchers.h"
 #include "SyncAPI.h"
 #include "TestFS.h"
 #include "XRefs.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/PCHContainerOperations.h"
 #include "clang/Frontend/Utils.h"
 #include "llvm/Support/Path.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
 using namespace llvm;
 
-void PrintTo(const DocumentHighlight &V, std::ostream *O) {
-  llvm::raw_os_ostream OS(*O);
-  OS << V.range;
-  if (V.kind == DocumentHighlightKind::Read)
-    OS << "(r)";
-  if (V.kind == DocumentHighlightKind::Write)
-    OS << "(w)";
-}
-
 namespace {
 using testing::ElementsAre;
 using testing::Field;
Index: unittests/clangd/URITests.cpp
===================================================================
--- unittests/clangd/URITests.cpp
+++ unittests/clangd/URITests.cpp
@@ -7,10 +7,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "ClangdTesting.h"
 #include "TestFS.h"
 #include "URI.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
Index: unittests/clangd/TraceTests.cpp
===================================================================
--- unittests/clangd/TraceTests.cpp
+++ unittests/clangd/TraceTests.cpp
@@ -7,15 +7,14 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "ClangdTesting.h"
 #include "Trace.h"
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/YAMLParser.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
Index: unittests/clangd/ThreadingTests.cpp
===================================================================
--- unittests/clangd/ThreadingTests.cpp
+++ unittests/clangd/ThreadingTests.cpp
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "ClangdTesting.h"
 #include "Threading.h"
-#include "gtest/gtest.h"
 #include <mutex>
 
 namespace clang {
Index: unittests/clangd/TestFS.cpp
===================================================================
--- unittests/clangd/TestFS.cpp
+++ unittests/clangd/TestFS.cpp
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 #include "TestFS.h"
+#include "ClangdTesting.h"
 #include "llvm/Support/Errc.h"
-#include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
Index: unittests/clangd/TUSchedulerTests.cpp
===================================================================
--- unittests/clangd/TUSchedulerTests.cpp
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -7,11 +7,10 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "ClangdTesting.h"
 #include "Context.h"
 #include "TUScheduler.h"
 #include "TestFS.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 #include <algorithm>
 #include <utility>
 
Index: unittests/clangd/SymbolCollectorTests.cpp
===================================================================
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Annotations.h"
+#include "ClangdTesting.h"
 #include "TestFS.h"
 #include "index/SymbolCollector.h"
 #include "index/SymbolYAML.h"
@@ -21,8 +22,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 
 #include <memory>
 #include <string>
Index: unittests/clangd/SourceCodeTests.cpp
===================================================================
--- unittests/clangd/SourceCodeTests.cpp
+++ unittests/clangd/SourceCodeTests.cpp
@@ -6,12 +6,11 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
+#include "ClangdTesting.h"
 #include "SourceCode.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/raw_os_ostream.h"
 #include "llvm/Testing/Support/Error.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 
 namespace clang{
 namespace clangd {
Index: unittests/clangd/Printers.h
===================================================================
--- /dev/null
+++ unittests/clangd/Printers.h
@@ -0,0 +1,77 @@
+//===-- Printers.h ----------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Custom GTest Printers. This should be included in any test that prints
+// objects on failure. Otherwise, it is possible that there will be two
+// different instantiations of the printer template for a given type and some
+// tests could end up calling the wrong (default) one.
+// See UniversalPrint::Print and UniversalPrinter::Print.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_PRINTERS_H
+#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_PRINTERS_H
+
+#include "ClangdUnit.h"
+#include "Protocol.h"
+#include "llvm/Support/raw_os_ostream.h"
+
+namespace clang {
+namespace clangd {
+
+namespace json {
+inline void PrintTo(const Expr &E, std::ostream *OS) {
+  llvm::raw_os_ostream(*OS) << llvm::formatv("{0:2}", E);
+}
+} // namespace json
+
+inline void PrintTo(const DocumentHighlight &V, std::ostream *O) {
+  llvm::raw_os_ostream OS(*O);
+  OS << V.range;
+  if (V.kind == DocumentHighlightKind::Read)
+    OS << "(r)";
+  if (V.kind == DocumentHighlightKind::Write)
+    OS << "(w)";
+}
+
+inline void PrintTo(const CompletionItem &I, std::ostream *O) {
+  llvm::raw_os_ostream OS(*O);
+  OS << I.label << " - " << toJSON(I);
+}
+
+inline void PrintTo(const std::vector<CompletionItem> &V, std::ostream *O) {
+  *O << "{\n";
+  for (const auto &I : V) {
+    *O << "\t";
+    PrintTo(I, O);
+    *O << "\n";
+  }
+  *O << "}";
+}
+
+inline void PrintTo(const SignatureInformation &I, std::ostream *O) {
+  llvm::raw_os_ostream OS(*O);
+  OS << I.label << " - " << toJSON(I);
+}
+
+inline void PrintTo(const std::vector<SignatureInformation> &V,
+                    std::ostream *O) {
+  *O << "{\n";
+  for (const auto &I : V) {
+    *O << "\t";
+    PrintTo(I, O);
+    *O << "\n";
+  }
+  *O << "}";
+}
+
+} // namespace clangd
+} // namespace clang
+
+#endif
Index: unittests/clangd/Matchers.h
===================================================================
--- unittests/clangd/Matchers.h
+++ unittests/clangd/Matchers.h
@@ -13,6 +13,7 @@
 
 #ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_MATCHERS_H
 #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_MATCHERS_H
+#include "Printers.h"
 #include "Protocol.h"
 #include "gmock/gmock.h"
 
Index: unittests/clangd/JSONExprTests.cpp
===================================================================
--- unittests/clangd/JSONExprTests.cpp
+++ unittests/clangd/JSONExprTests.cpp
@@ -7,17 +7,12 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "ClangdTesting.h"
 #include "JSONExpr.h"
 
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-
 namespace clang {
 namespace clangd {
 namespace json {
-void PrintTo(const Expr &E, std::ostream *OS) {
-  llvm::raw_os_ostream(*OS) << llvm::formatv("{0:2}", E);
-}
 namespace {
 
 std::string s(const Expr &E) { return llvm::formatv("{0}", E).str(); }
Index: unittests/clangd/IndexTests.cpp
===================================================================
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -7,11 +7,10 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "ClangdTesting.h"
 #include "index/Index.h"
 #include "index/MemIndex.h"
 #include "index/Merge.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 
 using testing::UnorderedElementsAre;
 using testing::Pointee;
Index: unittests/clangd/HeadersTests.cpp
===================================================================
--- unittests/clangd/HeadersTests.cpp
+++ unittests/clangd/HeadersTests.cpp
@@ -7,10 +7,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "ClangdTesting.h"
 #include "Headers.h"
 #include "TestFS.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
Index: unittests/clangd/FuzzyMatchTests.cpp
===================================================================
--- unittests/clangd/FuzzyMatchTests.cpp
+++ unittests/clangd/FuzzyMatchTests.cpp
@@ -7,11 +7,10 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "ClangdTesting.h"
 #include "FuzzyMatch.h"
 
 #include "llvm/ADT/StringExtras.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
Index: unittests/clangd/FileIndexTests.cpp
===================================================================
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -7,13 +7,12 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "ClangdTesting.h"
 #include "TestFS.h"
 #include "index/FileIndex.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/PCHContainerOperations.h"
 #include "clang/Frontend/Utils.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 
 using testing::UnorderedElementsAre;
 
Index: unittests/clangd/ContextTests.cpp
===================================================================
--- unittests/clangd/ContextTests.cpp
+++ unittests/clangd/ContextTests.cpp
@@ -7,10 +7,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "ClangdTesting.h"
 #include "Context.h"
 
-#include "gtest/gtest.h"
-
 namespace clang {
 namespace clangd {
 
Index: unittests/clangd/CodeCompletionStringsTests.cpp
===================================================================
--- unittests/clangd/CodeCompletionStringsTests.cpp
+++ unittests/clangd/CodeCompletionStringsTests.cpp
@@ -7,10 +7,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "ClangdTesting.h"
 #include "CodeCompletionStrings.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
Index: unittests/clangd/CodeCompleteTests.cpp
===================================================================
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -9,46 +9,17 @@
 
 #include "Annotations.h"
 #include "ClangdServer.h"
+#include "ClangdTesting.h"
 #include "CodeComplete.h"
 #include "Compiler.h"
-#include "Matchers.h"
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "SyncAPI.h"
 #include "TestFS.h"
 #include "index/MemIndex.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
-// Let GMock print completion items and signature help.
-void PrintTo(const CompletionItem &I, std::ostream *O) {
-  llvm::raw_os_ostream OS(*O);
-  OS << I.label << " - " << toJSON(I);
-}
-void PrintTo(const std::vector<CompletionItem> &V, std::ostream *O) {
-  *O << "{\n";
-  for (const auto &I : V) {
-    *O << "\t";
-    PrintTo(I, O);
-    *O << "\n";
-  }
-  *O << "}";
-}
-void PrintTo(const SignatureInformation &I, std::ostream *O) {
-  llvm::raw_os_ostream OS(*O);
-  OS << I.label << " - " << toJSON(I);
-}
-void PrintTo(const std::vector<SignatureInformation> &V, std::ostream *O) {
-  *O << "{\n";
-  for (const auto &I : V) {
-    *O << "\t";
-    PrintTo(I, O);
-    *O << "\n";
-  }
-  *O << "}";
-}
 
 namespace {
 using namespace llvm;
Index: unittests/clangd/ClangdUnitTests.cpp
===================================================================
--- unittests/clangd/ClangdUnitTests.cpp
+++ unittests/clangd/ClangdUnitTests.cpp
@@ -8,14 +8,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "Annotations.h"
+#include "ClangdTesting.h"
 #include "ClangdUnit.h"
 #include "TestFS.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/PCHContainerOperations.h"
 #include "clang/Frontend/Utils.h"
 #include "llvm/Support/ScopedPrinter.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
Index: unittests/clangd/ClangdTests.cpp
===================================================================
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -10,7 +10,7 @@
 #include "Annotations.h"
 #include "ClangdLSPServer.h"
 #include "ClangdServer.h"
-#include "Matchers.h"
+#include "ClangdTesting.h"
 #include "SyncAPI.h"
 #include "TestFS.h"
 #include "URI.h"
@@ -20,8 +20,6 @@
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Regex.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
 #include <algorithm>
 #include <chrono>
 #include <iostream>
Index: unittests/clangd/ClangdTesting.h
===================================================================
--- /dev/null
+++ unittests/clangd/ClangdTesting.h
@@ -0,0 +1,22 @@
+//===-- ClangdTesting.h -----------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Common header inclusions needed for Clangd testing.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_CLANGDTESTING_H
+#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_CLANGDTESTING_H
+
+#include "Matchers.h"
+#include "Printers.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#endif
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to