Author: nico Date: Sun Oct 13 06:15:27 2019 New Revision: 374718 URL: http://llvm.org/viewvc/llvm-project?rev=374718&view=rev Log: 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. Modified: clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp clang-tools-extra/trunk/clangd/unittests/ParsedASTTests.cpp clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp clang-tools-extra/trunk/clangd/unittests/TweakTesting.cpp clang-tools-extra/trunk/clangd/unittests/TweakTesting.h clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp Modified: clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp?rev=374718&r1=374717&r2=374718&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp (original) +++ clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp Sun Oct 13 06:15:27 2019 @@ -226,18 +226,26 @@ TEST_F(TargetDeclTest, Types) { 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, Lambda) { } 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 @@ protected: 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"); Modified: clang-tools-extra/trunk/clangd/unittests/ParsedASTTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/ParsedASTTests.cpp?rev=374718&r1=374717&r2=374718&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/unittests/ParsedASTTests.cpp (original) +++ clang-tools-extra/trunk/clangd/unittests/ParsedASTTests.cpp Sun Oct 13 06:15:27 2019 @@ -144,6 +144,9 @@ TEST(ParsedASTTest, 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( Modified: clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp?rev=374718&r1=374717&r2=374718&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp (original) +++ clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp Sun Oct 13 06:15:27 2019 @@ -289,7 +289,15 @@ TEST(SelectionTest, CommonAncestor) { }; 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; Modified: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp?rev=374718&r1=374717&r2=374718&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp (original) +++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp Sun Oct 13 06:15:27 2019 @@ -99,7 +99,13 @@ void checkHighlightings(llvm::StringRef /*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 @@ TEST(SemanticHighlighting, DiffBeyondThe } // namespace } // namespace clangd -} // namespace clang \ No newline at end of file +} // namespace clang Modified: clang-tools-extra/trunk/clangd/unittests/TweakTesting.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/TweakTesting.cpp?rev=374718&r1=374717&r2=374718&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/unittests/TweakTesting.cpp (original) +++ clang-tools-extra/trunk/clangd/unittests/TweakTesting.cpp Sun Oct 13 06:15:27 2019 @@ -82,9 +82,11 @@ std::string TweakTest::apply(llvm::Strin 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); Modified: clang-tools-extra/trunk/clangd/unittests/TweakTesting.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/TweakTesting.h?rev=374718&r1=374717&r2=374718&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/unittests/TweakTesting.h (original) +++ clang-tools-extra/trunk/clangd/unittests/TweakTesting.h Sun Oct 13 06:15:27 2019 @@ -55,6 +55,9 @@ protected: // 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; Modified: clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp?rev=374718&r1=374717&r2=374718&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp (original) +++ clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp Sun Oct 13 06:15:27 2019 @@ -481,6 +481,7 @@ TEST_F(ExpandMacroTest, Test) { TWEAK_TEST(ExpandAutoType); TEST_F(ExpandAutoTypeTest, Test) { + Header = R"cpp( namespace ns { struct Class { @@ -507,9 +508,6 @@ TEST_F(ExpandAutoTypeTest, Test) { // 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 @@ TEST_F(ExpandAutoTypeTest, Test) { 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); Modified: clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp?rev=374718&r1=374717&r2=374718&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp (original) +++ clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp Sun Oct 13 06:15:27 2019 @@ -462,7 +462,14 @@ TEST(LocateSymbol, All) { 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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits