diff --git a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp --- a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp +++ b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp @@ -17,7 +17,70 @@ namespace { -TEST_P(SyntaxTreeTest, Simple) { +class BuildSyntaxTreeTest : public SyntaxTreeTest { +protected: + ::testing::AssertionResult treeDumpEqual(StringRef Code, StringRef Tree) { + SCOPED_TRACE(llvm::join(GetParam().getCommandLineArgs(), " ")); + + auto *Root = buildTree(Code, GetParam()); + if (Diags->getClient()->getNumErrors() != 0) { + return ::testing::AssertionFailure() + << "Source file has syntax errors, they were printed to the test " + "log"; + } + auto Actual = StringRef(Root->dump(Arena->sourceManager())).trim().str(); + // EXPECT_EQ shows the diff between the two strings if they are different. + EXPECT_EQ(Tree.trim().str(), Actual); + if (Actual != Tree.trim().str()) { + return ::testing::AssertionFailure(); + } + return ::testing::AssertionSuccess(); + } + + ::testing::AssertionResult + treeDumpEqualOnAnnotations(StringRef CodeWithAnnotations, + ArrayRef TreeDumps) { + SCOPED_TRACE(llvm::join(GetParam().getCommandLineArgs(), " ")); + + auto AnnotatedCode = llvm::Annotations(CodeWithAnnotations); + auto *Root = buildTree(AnnotatedCode.code(), GetParam()); + + if (Diags->getClient()->getNumErrors() != 0) { + return ::testing::AssertionFailure() + << "Source file has syntax errors, they were printed to the test " + "log"; + } + + auto AnnotatedRanges = AnnotatedCode.ranges(); + if (AnnotatedRanges.size() != TreeDumps.size()) { + return ::testing::AssertionFailure() + << "The number of annotated ranges in the source code is " + "different " + "to the number of their corresponding tree dumps."; + } + bool Failed = false; + for (unsigned i = 0; i < AnnotatedRanges.size(); i++) { + auto *AnnotatedNode = nodeByRange(AnnotatedRanges[i], Root); + assert(AnnotatedNode); + auto AnnotatedNodeDump = + StringRef(AnnotatedNode->dump(Arena->sourceManager())).trim().str(); + // EXPECT_EQ shows the diff between the two strings if they are different. + EXPECT_EQ(TreeDumps[i].trim().str(), AnnotatedNodeDump) + << "Dumps diverged for the code:\n" + << AnnotatedCode.code().slice(AnnotatedRanges[i].Begin, + AnnotatedRanges[i].End); + if (AnnotatedNodeDump != TreeDumps[i].trim().str()) + Failed = true; + } + return Failed ? ::testing::AssertionFailure() + : ::testing::AssertionSuccess(); + } +}; + +INSTANTIATE_TEST_CASE_P(SyntaxTreeTests, BuildSyntaxTreeTest, + testing::ValuesIn(allTestClangConfigs()), ); + +TEST_P(BuildSyntaxTreeTest, Simple) { EXPECT_TRUE(treeDumpEqual( R"cpp( int main() {} @@ -48,7 +111,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, SimpleVariable) { +TEST_P(BuildSyntaxTreeTest, SimpleVariable) { EXPECT_TRUE(treeDumpEqual( R"cpp( int a; @@ -72,7 +135,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, SimpleFunction) { +TEST_P(BuildSyntaxTreeTest, SimpleFunction) { EXPECT_TRUE(treeDumpEqual( R"cpp( void foo(int a, int b) {} @@ -102,7 +165,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, If) { +TEST_P(BuildSyntaxTreeTest, If) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { @@ -144,7 +207,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, For) { +TEST_P(BuildSyntaxTreeTest, For) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { @@ -164,7 +227,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, RangeBasedFor) { +TEST_P(BuildSyntaxTreeTest, RangeBasedFor) { if (!GetParam().isCXX11OrLater()) { return; } @@ -194,7 +257,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, DeclarationStatement) { +TEST_P(BuildSyntaxTreeTest, DeclarationStatement) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { @@ -214,7 +277,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, Switch) { +TEST_P(BuildSyntaxTreeTest, Switch) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { @@ -247,7 +310,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, While) { +TEST_P(BuildSyntaxTreeTest, While) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { @@ -273,7 +336,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UnhandledStatement) { +TEST_P(BuildSyntaxTreeTest, UnhandledStatement) { // Unhandled statements should end up as 'unknown statement'. // This example uses a 'label statement', which does not yet have a syntax // counterpart. @@ -295,7 +358,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, Expressions) { +TEST_P(BuildSyntaxTreeTest, Expressions) { // expressions should be wrapped in 'ExpressionStatement' when they appear // in a statement position. EXPECT_TRUE(treeDumpEqual( @@ -351,7 +414,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, UnqualifiedId_Identifier) { +TEST_P(BuildSyntaxTreeTest, UnqualifiedId_Identifier) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test(int a) { @@ -365,7 +428,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UnqualifiedId_OperatorFunctionId) { +TEST_P(BuildSyntaxTreeTest, UnqualifiedId_OperatorFunctionId) { if (!GetParam().isCXX()) { return; } @@ -397,7 +460,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UnqualifiedId_ConversionFunctionId) { +TEST_P(BuildSyntaxTreeTest, UnqualifiedId_ConversionFunctionId) { if (!GetParam().isCXX()) { return; } @@ -426,7 +489,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UnqualifiedId_LiteralOperatorId) { +TEST_P(BuildSyntaxTreeTest, UnqualifiedId_LiteralOperatorId) { if (!GetParam().isCXX11OrLater()) { return; } @@ -452,7 +515,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UnqualifiedId_Destructor) { +TEST_P(BuildSyntaxTreeTest, UnqualifiedId_Destructor) { if (!GetParam().isCXX()) { return; } @@ -479,7 +542,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UnqualifiedId_DecltypeDestructor) { +TEST_P(BuildSyntaxTreeTest, UnqualifiedId_DecltypeDestructor) { if (!GetParam().isCXX11OrLater()) { return; } @@ -513,7 +576,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UnqualifiedId_TemplateId) { +TEST_P(BuildSyntaxTreeTest, UnqualifiedId_TemplateId) { if (!GetParam().isCXX()) { return; } @@ -538,7 +601,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, QualifiedId_NamespaceSpecifier) { +TEST_P(BuildSyntaxTreeTest, QualifiedId_NamespaceSpecifier) { if (!GetParam().isCXX()) { return; } @@ -575,7 +638,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, QualifiedId_TemplateSpecifier) { +TEST_P(BuildSyntaxTreeTest, QualifiedId_TemplateSpecifier) { if (!GetParam().isCXX()) { return; } @@ -621,7 +684,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, QualifiedId_DecltypeSpecifier) { +TEST_P(BuildSyntaxTreeTest, QualifiedId_DecltypeSpecifier) { if (!GetParam().isCXX11OrLater()) { return; } @@ -653,7 +716,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, QualifiedId_OptionalTemplateKw) { +TEST_P(BuildSyntaxTreeTest, QualifiedId_OptionalTemplateKw) { if (!GetParam().isCXX()) { return; } @@ -701,7 +764,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, QualifiedId_Complex) { +TEST_P(BuildSyntaxTreeTest, QualifiedId_Complex) { if (!GetParam().isCXX()) { return; } @@ -744,7 +807,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, QualifiedId_DependentType) { +TEST_P(BuildSyntaxTreeTest, QualifiedId_DependentType) { if (!GetParam().isCXX()) { return; } @@ -815,7 +878,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, This_Simple) { +TEST_P(BuildSyntaxTreeTest, This_Simple) { if (!GetParam().isCXX()) { return; } @@ -833,7 +896,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, This_ExplicitMemberAccess) { +TEST_P(BuildSyntaxTreeTest, This_ExplicitMemberAccess) { if (!GetParam().isCXX()) { return; } @@ -857,7 +920,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, This_ImplicitMemberAccess) { +TEST_P(BuildSyntaxTreeTest, This_ImplicitMemberAccess) { if (!GetParam().isCXX()) { return; } @@ -877,7 +940,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ParenExpr) { +TEST_P(BuildSyntaxTreeTest, ParenExpr) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { @@ -919,7 +982,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UserDefinedLiteral_Char) { +TEST_P(BuildSyntaxTreeTest, UserDefinedLiteral_Char) { if (!GetParam().isCXX11OrLater()) { return; } @@ -936,7 +999,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UserDefinedLiteral_String) { +TEST_P(BuildSyntaxTreeTest, UserDefinedLiteral_String) { if (!GetParam().isCXX11OrLater()) { return; } @@ -956,7 +1019,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UserDefinedLiteral_Integer) { +TEST_P(BuildSyntaxTreeTest, UserDefinedLiteral_Integer) { if (!GetParam().isCXX11OrLater()) { return; } @@ -987,7 +1050,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UserDefinedLiteral_Float) { +TEST_P(BuildSyntaxTreeTest, UserDefinedLiteral_Float) { if (!GetParam().isCXX11OrLater()) { return; } @@ -1018,7 +1081,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, IntegerLiteral_LongLong) { +TEST_P(BuildSyntaxTreeTest, IntegerLiteral_LongLong) { if (!GetParam().isCXX11OrLater()) { return; } @@ -1039,7 +1102,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, IntegerLiteral_Binary) { +TEST_P(BuildSyntaxTreeTest, IntegerLiteral_Binary) { if (!GetParam().isCXX14OrLater()) { return; } @@ -1055,7 +1118,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, IntegerLiteral_WithDigitSeparators) { +TEST_P(BuildSyntaxTreeTest, IntegerLiteral_WithDigitSeparators) { if (!GetParam().isCXX14OrLater()) { return; } @@ -1071,7 +1134,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CharacterLiteral) { +TEST_P(BuildSyntaxTreeTest, CharacterLiteral) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { @@ -1109,7 +1172,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CharacterLiteral_Utf) { +TEST_P(BuildSyntaxTreeTest, CharacterLiteral_Utf) { if (!GetParam().isCXX11OrLater()) { return; } @@ -1140,7 +1203,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CharacterLiteral_Utf8) { +TEST_P(BuildSyntaxTreeTest, CharacterLiteral_Utf8) { if (!GetParam().isCXX17OrLater()) { return; } @@ -1161,7 +1224,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, FloatingLiteral) { +TEST_P(BuildSyntaxTreeTest, FloatingLiteral) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { @@ -1189,7 +1252,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, FloatingLiteral_Hexadecimal) { +TEST_P(BuildSyntaxTreeTest, FloatingLiteral_Hexadecimal) { if (!GetParam().isCXX17OrLater()) { return; } @@ -1220,7 +1283,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, StringLiteral) { +TEST_P(BuildSyntaxTreeTest, StringLiteral) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { @@ -1238,7 +1301,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, StringLiteral_Utf) { +TEST_P(BuildSyntaxTreeTest, StringLiteral_Utf) { if (!GetParam().isCXX11OrLater()) { return; } @@ -1264,7 +1327,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, StringLiteral_Raw) { +TEST_P(BuildSyntaxTreeTest, StringLiteral_Raw) { if (!GetParam().isCXX11OrLater()) { return; } @@ -1297,7 +1360,7 @@ " `-'}' CloseParen\n")); } -TEST_P(SyntaxTreeTest, BoolLiteral) { +TEST_P(BuildSyntaxTreeTest, BoolLiteral) { if (GetParam().isC()) { return; } @@ -1318,7 +1381,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CxxNullPtrLiteral) { +TEST_P(BuildSyntaxTreeTest, CxxNullPtrLiteral) { if (!GetParam().isCXX11OrLater()) { return; } @@ -1334,7 +1397,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, PostfixUnaryOperator) { +TEST_P(BuildSyntaxTreeTest, PostfixUnaryOperator) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test(int a) { @@ -1358,7 +1421,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, PrefixUnaryOperator) { +TEST_P(BuildSyntaxTreeTest, PrefixUnaryOperator) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test(int a, int *ap) { @@ -1444,7 +1507,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, PrefixUnaryOperatorCxx) { +TEST_P(BuildSyntaxTreeTest, PrefixUnaryOperatorCxx) { if (!GetParam().isCXX()) { return; } @@ -1471,7 +1534,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, BinaryOperator) { +TEST_P(BuildSyntaxTreeTest, BinaryOperator) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test(int a) { @@ -1545,7 +1608,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, BinaryOperatorCxx) { +TEST_P(BuildSyntaxTreeTest, BinaryOperatorCxx) { if (!GetParam().isCXX()) { return; } @@ -1593,7 +1656,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, BinaryOperator_NestedWithParenthesis) { +TEST_P(BuildSyntaxTreeTest, BinaryOperator_NestedWithParenthesis) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { @@ -1624,7 +1687,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, BinaryOperator_Associativity) { +TEST_P(BuildSyntaxTreeTest, BinaryOperator_Associativity) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test(int a, int b) { @@ -1662,7 +1725,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, BinaryOperator_Precedence) { +TEST_P(BuildSyntaxTreeTest, BinaryOperator_Precedence) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { @@ -1704,7 +1767,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, OverloadedOperator_Assignment) { +TEST_P(BuildSyntaxTreeTest, OverloadedOperator_Assignment) { if (!GetParam().isCXX()) { return; } @@ -1729,7 +1792,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, OverloadedOperator_Plus) { +TEST_P(BuildSyntaxTreeTest, OverloadedOperator_Plus) { if (!GetParam().isCXX()) { return; } @@ -1754,7 +1817,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, OverloadedOperator_Less) { +TEST_P(BuildSyntaxTreeTest, OverloadedOperator_Less) { if (!GetParam().isCXX()) { return; } @@ -1779,7 +1842,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, OverloadedOperator_LeftShift) { +TEST_P(BuildSyntaxTreeTest, OverloadedOperator_LeftShift) { if (!GetParam().isCXX()) { return; } @@ -1804,7 +1867,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, OverloadedOperator_Comma) { +TEST_P(BuildSyntaxTreeTest, OverloadedOperator_Comma) { if (!GetParam().isCXX()) { return; } @@ -1829,7 +1892,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, OverloadedOperator_PointerToMember) { +TEST_P(BuildSyntaxTreeTest, OverloadedOperator_PointerToMember) { if (!GetParam().isCXX()) { return; } @@ -1854,7 +1917,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, OverloadedOperator_Negation) { +TEST_P(BuildSyntaxTreeTest, OverloadedOperator_Negation) { if (!GetParam().isCXX()) { return; } @@ -1876,7 +1939,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, OverloadedOperator_AddressOf) { +TEST_P(BuildSyntaxTreeTest, OverloadedOperator_AddressOf) { if (!GetParam().isCXX()) { return; } @@ -1898,7 +1961,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, OverloadedOperator_PrefixIncrement) { +TEST_P(BuildSyntaxTreeTest, OverloadedOperator_PrefixIncrement) { if (!GetParam().isCXX()) { return; } @@ -1920,7 +1983,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, OverloadedOperator_PostfixIncrement) { +TEST_P(BuildSyntaxTreeTest, OverloadedOperator_PostfixIncrement) { if (!GetParam().isCXX()) { return; } @@ -1942,7 +2005,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, MemberExpression_SimpleWithDot) { +TEST_P(BuildSyntaxTreeTest, MemberExpression_SimpleWithDot) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( struct S { @@ -1964,7 +2027,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, MemberExpression_StaticDataMember) { +TEST_P(BuildSyntaxTreeTest, MemberExpression_StaticDataMember) { if (!GetParam().isCXX()) { return; } @@ -1989,7 +2052,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, MemberExpression_SimpleWithArrow) { +TEST_P(BuildSyntaxTreeTest, MemberExpression_SimpleWithArrow) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( struct S { @@ -2011,7 +2074,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, MemberExpression_Chaining) { +TEST_P(BuildSyntaxTreeTest, MemberExpression_Chaining) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( struct S { @@ -2038,7 +2101,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, MemberExpression_OperatorFunction) { +TEST_P(BuildSyntaxTreeTest, MemberExpression_OperatorFunction) { if (!GetParam().isCXX()) { return; } @@ -2067,7 +2130,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, MemberExpression_VariableTemplate) { +TEST_P(BuildSyntaxTreeTest, MemberExpression_VariableTemplate) { if (!GetParam().isCXX14OrLater()) { return; } @@ -2103,7 +2166,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, MemberExpression_FunctionTemplate) { +TEST_P(BuildSyntaxTreeTest, MemberExpression_FunctionTemplate) { if (!GetParam().isCXX()) { return; } @@ -2135,7 +2198,8 @@ )txt"})); } -TEST_P(SyntaxTreeTest, MemberExpression_FunctionTemplateWithTemplateKeyword) { +TEST_P(BuildSyntaxTreeTest, + MemberExpression_FunctionTemplateWithTemplateKeyword) { if (!GetParam().isCXX()) { return; } @@ -2168,7 +2232,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, MemberExpression_WithQualifier) { +TEST_P(BuildSyntaxTreeTest, MemberExpression_WithQualifier) { if (!GetParam().isCXX()) { return; } @@ -2221,7 +2285,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, MemberExpression_Complex) { +TEST_P(BuildSyntaxTreeTest, MemberExpression_Complex) { if (!GetParam().isCXX()) { return; } @@ -2279,7 +2343,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_Callee_Member) { +TEST_P(BuildSyntaxTreeTest, CallExpression_Callee_Member) { if (!GetParam().isCXX()) { return; } @@ -2307,7 +2371,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_Callee_OperatorParens) { +TEST_P(BuildSyntaxTreeTest, CallExpression_Callee_OperatorParens) { if (!GetParam().isCXX()) { return; } @@ -2330,7 +2394,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_Callee_OperatorParensChaining) { +TEST_P(BuildSyntaxTreeTest, CallExpression_Callee_OperatorParensChaining) { if (!GetParam().isCXX()) { return; } @@ -2356,7 +2420,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_Callee_MemberWithThis) { +TEST_P(BuildSyntaxTreeTest, CallExpression_Callee_MemberWithThis) { if (!GetParam().isCXX()) { return; } @@ -2412,7 +2476,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_Callee_FunctionPointer) { +TEST_P(BuildSyntaxTreeTest, CallExpression_Callee_FunctionPointer) { if (!GetParam().isCXX()) { return; } @@ -2447,7 +2511,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_Callee_MemberFunctionPointer) { +TEST_P(BuildSyntaxTreeTest, CallExpression_Callee_MemberFunctionPointer) { if (!GetParam().isCXX()) { return; } @@ -2480,7 +2544,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_Arguments_Zero) { +TEST_P(BuildSyntaxTreeTest, CallExpression_Arguments_Zero) { if (!GetParam().isCXX()) { return; } @@ -2503,7 +2567,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_Arguments_One) { +TEST_P(BuildSyntaxTreeTest, CallExpression_Arguments_One) { if (!GetParam().isCXX()) { return; } @@ -2529,7 +2593,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_Arguments_Multiple) { +TEST_P(BuildSyntaxTreeTest, CallExpression_Arguments_Multiple) { if (!GetParam().isCXX()) { return; } @@ -2561,7 +2625,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_Arguments_Assignment) { +TEST_P(BuildSyntaxTreeTest, CallExpression_Arguments_Assignment) { if (!GetParam().isCXX()) { return; } @@ -2592,7 +2656,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_Arguments_BracedInitList_Empty) { +TEST_P(BuildSyntaxTreeTest, CallExpression_Arguments_BracedInitList_Empty) { if (!GetParam().isCXX11OrLater()) { return; } @@ -2620,7 +2684,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_Arguments_BracedInitList_Simple) { +TEST_P(BuildSyntaxTreeTest, CallExpression_Arguments_BracedInitList_Simple) { if (!GetParam().isCXX11OrLater()) { return; } @@ -2660,7 +2724,8 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_Arguments_BracedInitList_Designated) { +TEST_P(BuildSyntaxTreeTest, + CallExpression_Arguments_BracedInitList_Designated) { if (!GetParam().isCXX11OrLater()) { return; } @@ -2707,7 +2772,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_Arguments_ParameterPack) { +TEST_P(BuildSyntaxTreeTest, CallExpression_Arguments_ParameterPack) { if (!GetParam().isCXX11OrLater() || GetParam().hasDelayedTemplateParsing()) { return; } @@ -2733,7 +2798,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, CallExpression_DefaultArguments) { +TEST_P(BuildSyntaxTreeTest, CallExpression_DefaultArguments) { if (!GetParam().isCXX11OrLater()) { return; } @@ -2781,7 +2846,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, MultipleDeclaratorsGrouping) { +TEST_P(BuildSyntaxTreeTest, MultipleDeclaratorsGrouping) { EXPECT_TRUE(treeDumpEqual( R"cpp( int *a, b; @@ -2810,7 +2875,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, MultipleDeclaratorsGroupingTypedef) { +TEST_P(BuildSyntaxTreeTest, MultipleDeclaratorsGroupingTypedef) { EXPECT_TRUE(treeDumpEqual( R"cpp( typedef int *a, b; @@ -2830,7 +2895,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, MultipleDeclaratorsInsideStatement) { +TEST_P(BuildSyntaxTreeTest, MultipleDeclaratorsInsideStatement) { EXPECT_TRUE(treeDumpEqual( R"cpp( void foo() { @@ -2874,7 +2939,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, SizeTTypedef) { +TEST_P(BuildSyntaxTreeTest, SizeTTypedef) { if (!GetParam().isCXX11OrLater()) { return; } @@ -2901,7 +2966,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, Namespace_Nested) { +TEST_P(BuildSyntaxTreeTest, Namespace_Nested) { if (!GetParam().isCXX()) { return; } @@ -2924,7 +2989,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, Namespace_NestedDefinition) { +TEST_P(BuildSyntaxTreeTest, Namespace_NestedDefinition) { if (!GetParam().isCXX17OrLater()) { return; } @@ -2944,7 +3009,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, Namespace_Unnamed) { +TEST_P(BuildSyntaxTreeTest, Namespace_Unnamed) { if (!GetParam().isCXX()) { return; } @@ -2961,7 +3026,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, Namespace_Alias) { +TEST_P(BuildSyntaxTreeTest, Namespace_Alias) { if (!GetParam().isCXX()) { return; } @@ -2980,7 +3045,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UsingDirective) { +TEST_P(BuildSyntaxTreeTest, UsingDirective) { if (!GetParam().isCXX()) { return; } @@ -3000,7 +3065,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UsingDeclaration_Namespace) { +TEST_P(BuildSyntaxTreeTest, UsingDeclaration_Namespace) { if (!GetParam().isCXX()) { return; } @@ -3021,7 +3086,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UsingDeclaration_ClassMember) { +TEST_P(BuildSyntaxTreeTest, UsingDeclaration_ClassMember) { if (!GetParam().isCXX()) { return; } @@ -3055,7 +3120,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, UsingTypeAlias) { +TEST_P(BuildSyntaxTreeTest, UsingTypeAlias) { if (!GetParam().isCXX11OrLater()) { return; } @@ -3074,7 +3139,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, FreeStandingClass_ForwardDeclaration) { +TEST_P(BuildSyntaxTreeTest, FreeStandingClass_ForwardDeclaration) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( [[struct X;]] @@ -3097,7 +3162,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, FreeStandingClasses_Definition) { +TEST_P(BuildSyntaxTreeTest, FreeStandingClasses_Definition) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( [[struct X {};]] @@ -3135,7 +3200,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, StaticMemberFunction) { +TEST_P(BuildSyntaxTreeTest, StaticMemberFunction) { if (!GetParam().isCXX11OrLater()) { return; } @@ -3160,7 +3225,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, OutOfLineMemberFunctionDefinition) { +TEST_P(BuildSyntaxTreeTest, OutOfLineMemberFunctionDefinition) { if (!GetParam().isCXX11OrLater()) { return; } @@ -3189,7 +3254,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ConversionMemberFunction) { +TEST_P(BuildSyntaxTreeTest, ConversionMemberFunction) { if (!GetParam().isCXX()) { return; } @@ -3211,7 +3276,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, LiteralOperatorDeclaration) { +TEST_P(BuildSyntaxTreeTest, LiteralOperatorDeclaration) { if (!GetParam().isCXX11OrLater()) { return; } @@ -3237,7 +3302,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, NumericLiteralOperatorTemplateDeclaration) { +TEST_P(BuildSyntaxTreeTest, NumericLiteralOperatorTemplateDeclaration) { if (!GetParam().isCXX11OrLater()) { return; } @@ -3268,7 +3333,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, OverloadedOperatorDeclaration) { +TEST_P(BuildSyntaxTreeTest, OverloadedOperatorDeclaration) { if (!GetParam().isCXX()) { return; } @@ -3298,7 +3363,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, OverloadedOperatorFriendDeclaration) { +TEST_P(BuildSyntaxTreeTest, OverloadedOperatorFriendDeclaration) { if (!GetParam().isCXX()) { return; } @@ -3332,7 +3397,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ClassTemplateDeclaration) { +TEST_P(BuildSyntaxTreeTest, ClassTemplateDeclaration) { if (!GetParam().isCXX()) { return; } @@ -3359,7 +3424,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, FunctionTemplateDeclaration) { +TEST_P(BuildSyntaxTreeTest, FunctionTemplateDeclaration) { if (!GetParam().isCXX()) { return; } @@ -3388,7 +3453,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, VariableTemplateDeclaration) { +TEST_P(BuildSyntaxTreeTest, VariableTemplateDeclaration) { if (!GetParam().isCXX14OrLater()) { return; } @@ -3416,7 +3481,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, StaticMemberFunctionTemplate) { +TEST_P(BuildSyntaxTreeTest, StaticMemberFunctionTemplate) { if (!GetParam().isCXX()) { return; } @@ -3447,7 +3512,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, NestedTemplates) { +TEST_P(BuildSyntaxTreeTest, NestedTemplates) { if (!GetParam().isCXX()) { return; } @@ -3492,7 +3557,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, NestedTemplatesInNamespace) { +TEST_P(BuildSyntaxTreeTest, NestedTemplatesInNamespace) { if (!GetParam().isCXX()) { return; } @@ -3545,7 +3610,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, ClassTemplate_MemberClassDefinition) { +TEST_P(BuildSyntaxTreeTest, ClassTemplate_MemberClassDefinition) { if (!GetParam().isCXX()) { return; } @@ -3578,7 +3643,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ExplicitClassTemplateInstantation_Definition) { +TEST_P(BuildSyntaxTreeTest, ExplicitClassTemplateInstantation_Definition) { if (!GetParam().isCXX()) { return; } @@ -3600,7 +3665,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ExplicitClassTemplateInstantation_Declaration) { +TEST_P(BuildSyntaxTreeTest, ExplicitClassTemplateInstantation_Declaration) { if (!GetParam().isCXX()) { return; } @@ -3623,7 +3688,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ClassTemplateSpecialization_Partial) { +TEST_P(BuildSyntaxTreeTest, ClassTemplateSpecialization_Partial) { if (!GetParam().isCXX()) { return; } @@ -3653,7 +3718,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ClassTemplateSpecialization_Full) { +TEST_P(BuildSyntaxTreeTest, ClassTemplateSpecialization_Full) { if (!GetParam().isCXX()) { return; } @@ -3679,7 +3744,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, EmptyDeclaration) { +TEST_P(BuildSyntaxTreeTest, EmptyDeclaration) { EXPECT_TRUE(treeDumpEqual( R"cpp( ; @@ -3691,7 +3756,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, StaticAssert) { +TEST_P(BuildSyntaxTreeTest, StaticAssert) { if (!GetParam().isCXX11OrLater()) { return; } @@ -3714,7 +3779,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, StaticAssert_WithoutMessage) { +TEST_P(BuildSyntaxTreeTest, StaticAssert_WithoutMessage) { if (!GetParam().isCXX17OrLater()) { return; } @@ -3734,7 +3799,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, ExternC) { +TEST_P(BuildSyntaxTreeTest, ExternC) { if (!GetParam().isCXX()) { return; } @@ -3771,7 +3836,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, NonModifiableNodes) { +TEST_P(BuildSyntaxTreeTest, NonModifiableNodes) { // Some nodes are non-modifiable, they are marked with 'I:'. EXPECT_TRUE(treeDumpEqual( R"cpp( @@ -3812,7 +3877,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, ModifiableNodes) { +TEST_P(BuildSyntaxTreeTest, ModifiableNodes) { // All nodes can be mutated. EXPECT_TRUE(treeDumpEqual( R"cpp( @@ -3858,7 +3923,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, InitDeclarator_Equal) { +TEST_P(BuildSyntaxTreeTest, InitDeclarator_Equal) { if (!GetParam().isCXX()) { return; } @@ -3880,7 +3945,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, InitDeclarator_Brace) { +TEST_P(BuildSyntaxTreeTest, InitDeclarator_Brace) { if (!GetParam().isCXX11OrLater()) { return; } @@ -3934,7 +3999,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, InitDeclarator_EqualBrace) { +TEST_P(BuildSyntaxTreeTest, InitDeclarator_EqualBrace) { if (!GetParam().isCXX11OrLater()) { return; } @@ -3991,7 +4056,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, InitDeclarator_Paren) { +TEST_P(BuildSyntaxTreeTest, InitDeclarator_Paren) { if (!GetParam().isCXX()) { return; } @@ -4034,7 +4099,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, InitDeclarator_Paren_DefaultArguments) { +TEST_P(BuildSyntaxTreeTest, InitDeclarator_Paren_DefaultArguments) { if (!GetParam().isCXX()) { return; } @@ -4084,7 +4149,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ImplicitConversion_Argument) { +TEST_P(BuildSyntaxTreeTest, ImplicitConversion_Argument) { if (!GetParam().isCXX()) { return; } @@ -4111,7 +4176,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ImplicitConversion_Return) { +TEST_P(BuildSyntaxTreeTest, ImplicitConversion_Return) { if (!GetParam().isCXX()) { return; } @@ -4133,7 +4198,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ConstructorCall_ZeroArguments) { +TEST_P(BuildSyntaxTreeTest, ConstructorCall_ZeroArguments) { if (!GetParam().isCXX()) { return; } @@ -4157,7 +4222,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ConstructorCall_OneArgument) { +TEST_P(BuildSyntaxTreeTest, ConstructorCall_OneArgument) { if (!GetParam().isCXX()) { return; } @@ -4183,7 +4248,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ConstructorCall_MultipleArguments) { +TEST_P(BuildSyntaxTreeTest, ConstructorCall_MultipleArguments) { if (!GetParam().isCXX()) { return; } @@ -4212,7 +4277,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ConstructorCall_DefaultArguments) { +TEST_P(BuildSyntaxTreeTest, ConstructorCall_DefaultArguments) { if (!GetParam().isCXX()) { return; } @@ -4254,7 +4319,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, TypeConversion_FunctionalNotation) { +TEST_P(BuildSyntaxTreeTest, TypeConversion_FunctionalNotation) { if (!GetParam().isCXX()) { return; } @@ -4277,7 +4342,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ArrayDeclarator_Simple) { +TEST_P(BuildSyntaxTreeTest, ArrayDeclarator_Simple) { EXPECT_TRUE(treeDumpEqual( R"cpp( int a[10]; @@ -4297,7 +4362,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, ArrayDeclarator_Multidimensional) { +TEST_P(BuildSyntaxTreeTest, ArrayDeclarator_Multidimensional) { EXPECT_TRUE(treeDumpEqual( R"cpp( int b[1][2][3]; @@ -4327,7 +4392,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, ArrayDeclarator_UnknownBound) { +TEST_P(BuildSyntaxTreeTest, ArrayDeclarator_UnknownBound) { EXPECT_TRUE(treeDumpEqual( R"cpp( int c[] = {1,2,3}; @@ -4358,7 +4423,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, ArrayDeclarator_Static) { +TEST_P(BuildSyntaxTreeTest, ArrayDeclarator_Static) { if (!GetParam().isC99OrLater()) { return; } @@ -4390,7 +4455,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_Empty) { +TEST_P(BuildSyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_Empty) { EXPECT_TRUE(treeDumpEqual( R"cpp( int func(); @@ -4408,7 +4473,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_Named) { +TEST_P(BuildSyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_Named) { EXPECT_TRUE(treeDumpEqual( R"cpp( int func1(int a); @@ -4465,7 +4530,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_Unnamed) { +TEST_P(BuildSyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_Unnamed) { EXPECT_TRUE(treeDumpEqual( R"cpp( int func1(int); @@ -4515,7 +4580,8 @@ )txt")); } -TEST_P(SyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_Default_One) { +TEST_P(BuildSyntaxTreeTest, + ParametersAndQualifiers_InFreeFunctions_Default_One) { if (!GetParam().isCXX()) { return; } @@ -4535,7 +4601,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, +TEST_P(BuildSyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_Default_Multiple) { if (!GetParam().isCXX()) { return; @@ -4570,7 +4636,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, +TEST_P(BuildSyntaxTreeTest, ParametersAndQualifiers_InVariadicFunctionTemplate_ParameterPack) { if (!GetParam().isCXX11OrLater() || GetParam().hasDelayedTemplateParsing()) { return; @@ -4599,7 +4665,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, +TEST_P(BuildSyntaxTreeTest, ParametersAndQualifiers_InVariadicFunctionTemplate_NamedParameterPack) { if (!GetParam().isCXX11OrLater() || GetParam().hasDelayedTemplateParsing()) { return; @@ -4632,7 +4698,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, +TEST_P(BuildSyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_VariadicArguments) { if (!GetParam().isCXX11OrLater()) { return; @@ -4661,7 +4727,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, +TEST_P(BuildSyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_Cxx_CvQualifiers) { if (!GetParam().isCXX()) { return; @@ -4702,7 +4768,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_Cxx_Ref) { +TEST_P(BuildSyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_Cxx_Ref) { if (!GetParam().isCXX()) { return; } @@ -4729,7 +4795,8 @@ )txt")); } -TEST_P(SyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_Cxx11_RefRef) { +TEST_P(BuildSyntaxTreeTest, + ParametersAndQualifiers_InFreeFunctions_Cxx11_RefRef) { if (!GetParam().isCXX11OrLater()) { return; } @@ -4756,7 +4823,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, ParametersAndQualifiers_InMemberFunctions_Simple) { +TEST_P(BuildSyntaxTreeTest, ParametersAndQualifiers_InMemberFunctions_Simple) { if (!GetParam().isCXX()) { return; } @@ -4785,7 +4852,8 @@ )txt")); } -TEST_P(SyntaxTreeTest, ParametersAndQualifiers_InMemberFunctions_CvQualifiers) { +TEST_P(BuildSyntaxTreeTest, + ParametersAndQualifiers_InMemberFunctions_CvQualifiers) { if (!GetParam().isCXX()) { return; } @@ -4833,7 +4901,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ParametersAndQualifiers_InMemberFunctions_Ref) { +TEST_P(BuildSyntaxTreeTest, ParametersAndQualifiers_InMemberFunctions_Ref) { if (!GetParam().isCXX11OrLater()) { return; } @@ -4856,7 +4924,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ParametersAndQualifiers_InMemberFunctions_RefRef) { +TEST_P(BuildSyntaxTreeTest, ParametersAndQualifiers_InMemberFunctions_RefRef) { if (!GetParam().isCXX11OrLater()) { return; } @@ -4879,7 +4947,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, TrailingReturn) { +TEST_P(BuildSyntaxTreeTest, TrailingReturn) { if (!GetParam().isCXX11OrLater()) { return; } @@ -4903,7 +4971,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, DynamicExceptionSpecification) { +TEST_P(BuildSyntaxTreeTest, DynamicExceptionSpecification) { if (!GetParam().supportsCXXDynamicExceptionSpecification()) { return; } @@ -4975,7 +5043,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, NoexceptExceptionSpecification) { +TEST_P(BuildSyntaxTreeTest, NoexceptExceptionSpecification) { if (!GetParam().isCXX11OrLater()) { return; } @@ -5011,7 +5079,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, DeclaratorsInParentheses) { +TEST_P(BuildSyntaxTreeTest, DeclaratorsInParentheses) { EXPECT_TRUE(treeDumpEqual( R"cpp( int (a); @@ -5071,7 +5139,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, Declaration_ConstVolatileQualifiers_SimpleConst) { +TEST_P(BuildSyntaxTreeTest, Declaration_ConstVolatileQualifiers_SimpleConst) { EXPECT_TRUE(treeDumpEqual( R"cpp( const int west = -1; @@ -5102,7 +5170,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, Declaration_ConstVolatileQualifiers_MultipleConst) { +TEST_P(BuildSyntaxTreeTest, Declaration_ConstVolatileQualifiers_MultipleConst) { EXPECT_TRUE(treeDumpEqual( R"cpp( const int const universal = 0; @@ -5122,7 +5190,8 @@ )txt")); } -TEST_P(SyntaxTreeTest, Declaration_ConstVolatileQualifiers_ConstAndVolatile) { +TEST_P(BuildSyntaxTreeTest, + Declaration_ConstVolatileQualifiers_ConstAndVolatile) { EXPECT_TRUE(treeDumpEqual( R"cpp( const int const *const *volatile b; @@ -5143,7 +5212,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, RangesOfDeclaratorsWithTrailingReturnTypes) { +TEST_P(BuildSyntaxTreeTest, RangesOfDeclaratorsWithTrailingReturnTypes) { if (!GetParam().isCXX11OrLater()) { return; } @@ -5183,7 +5252,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, MemberPointers) { +TEST_P(BuildSyntaxTreeTest, MemberPointers) { if (!GetParam().isCXX()) { return; } @@ -5218,7 +5287,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, MemberFunctionPointer) { +TEST_P(BuildSyntaxTreeTest, MemberFunctionPointer) { if (!GetParam().isCXX()) { return; } @@ -5304,7 +5373,7 @@ )txt"})); } -TEST_P(SyntaxTreeTest, ComplexDeclarator) { +TEST_P(BuildSyntaxTreeTest, ComplexDeclarator) { EXPECT_TRUE(treeDumpEqual( R"cpp( void x(char a, short (*b)(int)); @@ -5342,7 +5411,7 @@ )txt")); } -TEST_P(SyntaxTreeTest, ComplexDeclarator2) { +TEST_P(BuildSyntaxTreeTest, ComplexDeclarator2) { EXPECT_TRUE(treeDumpEqual( R"cpp( void x(char a, short (*b)(int), long (**c)(long long)); diff --git a/clang/unittests/Tooling/Syntax/MutationsTest.cpp b/clang/unittests/Tooling/Syntax/MutationsTest.cpp --- a/clang/unittests/Tooling/Syntax/MutationsTest.cpp +++ b/clang/unittests/Tooling/Syntax/MutationsTest.cpp @@ -19,15 +19,12 @@ namespace { -TEST_P(SyntaxTreeTest, Mutations) { - if (!GetParam().isCXX11OrLater()) { - return; - } - - using Transformation = std::function; - auto CheckTransformation = [this](std::string Input, std::string Expected, - Transformation Transform) -> void { +class MutationTest : public SyntaxTreeTest { +protected: + using Transformation = std::function; + void CheckTransformation(std::string Input, std::string Expected, + Transformation Transform) { llvm::Annotations Source(Input); auto *Root = buildTree(Source.code(), GetParam()); @@ -43,6 +40,15 @@ EXPECT_EQ(Expected, *Output) << "input is:\n" << Input; }; +}; + +INSTANTIATE_TEST_CASE_P(SyntaxTreeTests, MutationTest, + ::testing::ValuesIn(allTestClangConfigs()), ); + +TEST_P(MutationTest, Mutations) { + if (!GetParam().isCXX11OrLater()) { + return; + } // Removes the selected statement. Input should have exactly one selected // range and it should correspond to a single statement. @@ -66,6 +72,9 @@ CheckTransformation(C.first, C.second, RemoveStatement); } +INSTANTIATE_TEST_CASE_P(SyntaxTreeTests, SyntaxTreeTest, + ::testing::ValuesIn(allTestClangConfigs()), ); + TEST_P(SyntaxTreeTest, SynthesizedNodes) { buildTree("", GetParam()); diff --git a/clang/unittests/Tooling/Syntax/TreeTestBase.h b/clang/unittests/Tooling/Syntax/TreeTestBase.h --- a/clang/unittests/Tooling/Syntax/TreeTestBase.h +++ b/clang/unittests/Tooling/Syntax/TreeTestBase.h @@ -32,11 +32,6 @@ TranslationUnit *buildTree(StringRef Code, const TestClangConfig &ClangConfig); - ::testing::AssertionResult treeDumpEqual(StringRef Code, StringRef Tree); - - ::testing::AssertionResult - treeDumpEqualOnAnnotations(StringRef CodeWithAnnotations, - ArrayRef TreeDumps); /// Finds the deepest node in the tree that covers exactly \p R. /// FIXME: implement this efficiently and move to public syntax tree API. syntax::Node *nodeByRange(llvm::Annotations::Range R, syntax::Node *Root); @@ -56,6 +51,8 @@ std::unique_ptr TB; std::unique_ptr Arena; }; + +std::vector allTestClangConfigs(); } // namespace syntax } // namespace clang #endif // LLVM_CLANG_UNITTESTS_TOOLING_SYNTAX_TREETESTBASE_H diff --git a/clang/unittests/Tooling/Syntax/TreeTestBase.cpp b/clang/unittests/Tooling/Syntax/TreeTestBase.cpp --- a/clang/unittests/Tooling/Syntax/TreeTestBase.cpp +++ b/clang/unittests/Tooling/Syntax/TreeTestBase.cpp @@ -43,8 +43,9 @@ return llvm::makeArrayRef(T->firstLeaf()->token(), T->lastLeaf()->token() + 1); } +} // namespace -std::vector allTestClangConfigs() { +std::vector clang::syntax::allTestClangConfigs() { std::vector all_configs; for (TestLanguage lang : {Lang_C89, Lang_C99, Lang_CXX03, Lang_CXX11, Lang_CXX14, Lang_CXX17, Lang_CXX20}) { @@ -61,10 +62,6 @@ return all_configs; } -INSTANTIATE_TEST_CASE_P(SyntaxTreeTests, SyntaxTreeTest, - testing::ValuesIn(allTestClangConfigs()), ); -} // namespace - syntax::TranslationUnit * SyntaxTreeTest::buildTree(StringRef Code, const TestClangConfig &ClangConfig) { // FIXME: this code is almost the identical to the one in TokensTest. Share @@ -161,62 +158,6 @@ return Root; } -::testing::AssertionResult SyntaxTreeTest::treeDumpEqual(StringRef Code, - StringRef Tree) { - SCOPED_TRACE(llvm::join(GetParam().getCommandLineArgs(), " ")); - - auto *Root = buildTree(Code, GetParam()); - if (Diags->getClient()->getNumErrors() != 0) { - return ::testing::AssertionFailure() - << "Source file has syntax errors, they were printed to the test " - "log"; - } - auto Actual = StringRef(Root->dump(Arena->sourceManager())).trim().str(); - // EXPECT_EQ shows the diff between the two strings if they are different. - EXPECT_EQ(Tree.trim().str(), Actual); - if (Actual != Tree.trim().str()) { - return ::testing::AssertionFailure(); - } - return ::testing::AssertionSuccess(); -} - -::testing::AssertionResult -SyntaxTreeTest::treeDumpEqualOnAnnotations(StringRef CodeWithAnnotations, - ArrayRef TreeDumps) { - SCOPED_TRACE(llvm::join(GetParam().getCommandLineArgs(), " ")); - - auto AnnotatedCode = llvm::Annotations(CodeWithAnnotations); - auto *Root = buildTree(AnnotatedCode.code(), GetParam()); - - if (Diags->getClient()->getNumErrors() != 0) { - return ::testing::AssertionFailure() - << "Source file has syntax errors, they were printed to the test " - "log"; - } - - auto AnnotatedRanges = AnnotatedCode.ranges(); - if (AnnotatedRanges.size() != TreeDumps.size()) { - return ::testing::AssertionFailure() - << "The number of annotated ranges in the source code is different " - "to the number of their corresponding tree dumps."; - } - bool Failed = false; - for (unsigned i = 0; i < AnnotatedRanges.size(); i++) { - auto *AnnotatedNode = nodeByRange(AnnotatedRanges[i], Root); - assert(AnnotatedNode); - auto AnnotatedNodeDump = - StringRef(AnnotatedNode->dump(Arena->sourceManager())).trim().str(); - // EXPECT_EQ shows the diff between the two strings if they are different. - EXPECT_EQ(TreeDumps[i].trim().str(), AnnotatedNodeDump) - << "Dumps diverged for the code:\n" - << AnnotatedCode.code().slice(AnnotatedRanges[i].Begin, - AnnotatedRanges[i].End); - if (AnnotatedNodeDump != TreeDumps[i].trim().str()) - Failed = true; - } - return Failed ? ::testing::AssertionFailure() : ::testing::AssertionSuccess(); -} - syntax::Node *SyntaxTreeTest::nodeByRange(llvm::Annotations::Range R, syntax::Node *Root) { ArrayRef Toks = tokens(Root);