Make most clangd unittests pass on Windows

The Windows triple currently turns on delayed template parsing, which
confuses several unit tests that use templates.

For now, just explicitly disable delayed template parsing. This isn't
ideal, but:

- the Windows triple will soon no longer use delayed template parsing
  by default

- there's precedent for this in the clangd unit tests already

- let's get the clangd tests pass on Windows first before making
  behavioral changes

Part of PR43592.

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@374718 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/clangd/unittests/FindTargetTests.cpp b/clangd/unittests/FindTargetTests.cpp
index bf10063..9e1f1c1 100644
--- a/clangd/unittests/FindTargetTests.cpp
+++ b/clangd/unittests/FindTargetTests.cpp
@@ -226,18 +226,26 @@
   EXPECT_DECLS("TypedefTypeLoc", {"typedef S X", Rel::Alias},
                {"struct S", Rel::Underlying});
 
+  // FIXME: Auto-completion in a template requires disabling delayed template
+  // parsing.
+  Flags = {"-fno-delayed-template-parsing"};
   Code = R"cpp(
     template<class T>
     void foo() { [[T]] x; }
   )cpp";
   // FIXME: We don't do a good job printing TemplateTypeParmDecls, apparently!
   EXPECT_DECLS("TemplateTypeParmTypeLoc", "");
+  Flags.clear();
 
+  // FIXME: Auto-completion in a template requires disabling delayed template
+  // parsing.
+  Flags = {"-fno-delayed-template-parsing"};
   Code = R"cpp(
     template<template<typename> class T>
     void foo() { [[T<int>]] x; }
   )cpp";
   EXPECT_DECLS("TemplateSpecializationTypeLoc", "template <typename> class T");
+  Flags.clear();
 
   Code = R"cpp(
     struct S{};
@@ -394,6 +402,10 @@
 }
 
 TEST_F(TargetDeclTest, OverloadExpr) {
+  // FIXME: Auto-completion in a template requires disabling delayed template
+  // parsing.
+  Flags = {"-fno-delayed-template-parsing"};
+
   Code = R"cpp(
     void func(int*);
     void func(char*);
@@ -509,6 +521,10 @@
     TestTU TU;
     TU.Code = Code;
 
+    // FIXME: Auto-completion in a template requires disabling delayed template
+    // parsing.
+    TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
+
     auto AST = TU.build();
 
     auto *TestDecl = &findDecl(AST, "foo");
diff --git a/clangd/unittests/ParsedASTTests.cpp b/clangd/unittests/ParsedASTTests.cpp
index 53e2f4b..04a5767 100644
--- a/clangd/unittests/ParsedASTTests.cpp
+++ b/clangd/unittests/ParsedASTTests.cpp
@@ -144,6 +144,9 @@
     template <>
     int foo<bool> = 0;
   )cpp";
+  // FIXME: Auto-completion in a template requires disabling delayed template
+  // parsing.
+  TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
 
   auto AST = TU.build();
   EXPECT_THAT(
diff --git a/clangd/unittests/SelectionTests.cpp b/clangd/unittests/SelectionTests.cpp
index e2cbff3..309f4c0 100644
--- a/clangd/unittests/SelectionTests.cpp
+++ b/clangd/unittests/SelectionTests.cpp
@@ -289,7 +289,15 @@
   };
   for (const Case &C : Cases) {
     Annotations Test(C.Code);
-    auto AST = TestTU::withCode(Test.code()).build();
+
+    TestTU TU;
+    TU.Code = Test.code();
+
+    // FIXME: Auto-completion in a template requires disabling delayed template
+    // parsing.
+    TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
+
+    auto AST = TU.build();
     auto T = makeSelectionTree(C.Code, AST);
     EXPECT_EQ("TranslationUnitDecl", nodeKind(&T.root())) << C.Code;
 
diff --git a/clangd/unittests/SemanticHighlightingTests.cpp b/clangd/unittests/SemanticHighlightingTests.cpp
index 8003e35..1085b6f 100644
--- a/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clangd/unittests/SemanticHighlightingTests.cpp
@@ -99,7 +99,13 @@
                                               /*FileContent*/ llvm::StringRef>>
                             AdditionalFiles = {}) {
   Annotations Test(Code);
-  auto TU = TestTU::withCode(Test.code());
+  TestTU TU;
+  TU.Code = Test.code();
+
+  // FIXME: Auto-completion in a template requires disabling delayed template
+  // parsing.
+  TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
+
   for (auto File : AdditionalFiles)
     TU.AdditionalFiles.insert({File.first, File.second});
   auto AST = TU.build();
@@ -720,4 +726,4 @@
 
 } // namespace
 } // namespace clangd
-} // namespace clang
\ No newline at end of file
+} // namespace clang
diff --git a/clangd/unittests/TweakTesting.cpp b/clangd/unittests/TweakTesting.cpp
index 2e72cbd..63ecd7b 100644
--- a/clangd/unittests/TweakTesting.cpp
+++ b/clangd/unittests/TweakTesting.cpp
@@ -82,9 +82,11 @@
   std::string WrappedCode = wrap(Context, MarkedCode);
   Annotations Input(WrappedCode);
   auto Selection = rangeOrPoint(Input);
+
   TestTU TU;
   TU.HeaderCode = Header;
   TU.Code = Input.code();
+  TU.ExtraArgs = ExtraArgs;
   ParsedAST AST = TU.build();
   Tweak::Selection S(AST, Selection.first, Selection.second);
 
diff --git a/clangd/unittests/TweakTesting.h b/clangd/unittests/TweakTesting.h
index 6817e72..1e8cd58 100644
--- a/clangd/unittests/TweakTesting.h
+++ b/clangd/unittests/TweakTesting.h
@@ -55,6 +55,9 @@
   // testcases.
   std::string Header;
 
+  // Extra flags passed to the compilation in apply().
+  std::vector<const char *> ExtraArgs;
+
   // Context in which snippets of code should be placed to run tweaks.
   CodeContext Context = File;
 
diff --git a/clangd/unittests/TweakTests.cpp b/clangd/unittests/TweakTests.cpp
index 8cc29dd..36efbef 100644
--- a/clangd/unittests/TweakTests.cpp
+++ b/clangd/unittests/TweakTests.cpp
@@ -481,6 +481,7 @@
 
 TWEAK_TEST(ExpandAutoType);
 TEST_F(ExpandAutoTypeTest, Test) {
+
   Header = R"cpp(
     namespace ns {
       struct Class {
@@ -507,9 +508,6 @@
   // check that namespaces are shortened
   EXPECT_EQ(apply("namespace ns { void f() { ^auto C = Class(); } }"),
             "namespace ns { void f() { Class C = Class(); } }");
-  // unknown types in a template should not be replaced
-  EXPECT_THAT(apply("template <typename T> void x() { ^auto y = T::z(); }"),
-              StartsWith("fail: Could not deduce type for 'auto' type"));
   // undefined functions should not be replaced
   EXPECT_THAT(apply("au^to x = doesnt_exist();"),
               StartsWith("fail: Could not deduce type for 'auto' type"));
@@ -530,6 +528,13 @@
             R"cpp(const char * x = "test")cpp");
 
   EXPECT_UNAVAILABLE("dec^ltype(au^to) x = 10;");
+
+  // FIXME: Auto-completion in a template requires disabling delayed template
+  // parsing.
+  ExtraArgs.push_back("-fno-delayed-template-parsing");
+  // unknown types in a template should not be replaced
+  EXPECT_THAT(apply("template <typename T> void x() { ^auto y = T::z(); }"),
+              StartsWith("fail: Could not deduce type for 'auto' type"));
 }
 
 TWEAK_TEST(ExtractFunction);
diff --git a/clangd/unittests/XRefsTests.cpp b/clangd/unittests/XRefsTests.cpp
index 60cba82..aafcb47 100644
--- a/clangd/unittests/XRefsTests.cpp
+++ b/clangd/unittests/XRefsTests.cpp
@@ -462,7 +462,14 @@
     if (!T.ranges("def").empty())
       WantDef = T.range("def");
 
-    auto AST = TestTU::withCode(T.code()).build();
+    TestTU TU;
+    TU.Code = T.code();
+
+    // FIXME: Auto-completion in a template requires disabling delayed template
+    // parsing.
+    TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
+
+    auto AST = TU.build();
     auto Results = locateSymbolAt(AST, T.point());
 
     if (!WantDecl) {