aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/Tooling/Syntax/BuildTreeTest.cpp')
-rw-r--r--clang/unittests/Tooling/Syntax/BuildTreeTest.cpp38
1 files changed, 28 insertions, 10 deletions
diff --git a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
index a76557d..299a2c3 100644
--- a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -23,11 +23,9 @@ protected:
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 ErrorOK = errorOK(Code);
+ if (!ErrorOK)
+ return ErrorOK;
auto Actual = StringRef(Root->dump(Arena->getSourceManager())).trim().str();
// EXPECT_EQ shows the diff between the two strings if they are different.
EXPECT_EQ(Tree.trim().str(), Actual);
@@ -45,11 +43,9 @@ protected:
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 ErrorOK = errorOK(AnnotatedCode.code());
+ if (!ErrorOK)
+ return ErrorOK;
auto AnnotatedRanges = AnnotatedCode.ranges();
if (AnnotatedRanges.size() != TreeDumps.size()) {
@@ -77,6 +73,19 @@ protected:
return Failed ? ::testing::AssertionFailure()
: ::testing::AssertionSuccess();
}
+
+private:
+ ::testing::AssertionResult errorOK(StringRef RawCode) {
+ if (!RawCode.contains("error-ok")) {
+ if (Diags->getClient()->getNumErrors() != 0) {
+ return ::testing::AssertionFailure()
+ << "Source file has syntax errors (suppress with /*error-ok*/), "
+ "they were printed to the "
+ "test log";
+ }
+ }
+ return ::testing::AssertionSuccess();
+ }
};
INSTANTIATE_TEST_CASE_P(SyntaxTreeTests, BuildSyntaxTreeTest,
@@ -4773,6 +4782,7 @@ TEST_P(BuildSyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_Named) {
int func1([[int a]]);
int func2([[int *ap]]);
int func3([[int a, float b]]);
+ int func4([[undef a]]); // error-ok: no crash on invalid type
)cpp",
{R"txt(
ParameterDeclarationList Parameters
@@ -4804,6 +4814,14 @@ ParameterDeclarationList Parameters
`-DeclaratorList Declarators
`-SimpleDeclarator ListElement
`-'b'
+)txt",
+ R"txt(
+ParameterDeclarationList Parameters
+`-SimpleDeclaration ListElement
+ |-'undef'
+ `-DeclaratorList Declarators
+ `-SimpleDeclarator ListElement
+ `-'a'
)txt"}));
}