[PATCH] D98514: [RGT] Fix ASTMatchersTest so all assertions are executed
Paul Robinson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 12 08:20:20 PST 2021
probinson created this revision.
probinson added a reviewer: Prazek.
probinson requested review of this revision.
Herald added a project: clang.
Some 'if' conditions turn out always to be false, so change test
expectations to match.
Found by the Rotten Green Tests project.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98514
Files:
clang/unittests/ASTMatchers/ASTMatchersTest.h
Index: clang/unittests/ASTMatchers/ASTMatchersTest.h
===================================================================
--- clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -372,12 +372,8 @@
ExpectedName(std::string(ExpectedName)) {}
void onEndOfTranslationUnit() override {
- if (ExpectedCount != -1) {
- EXPECT_EQ(ExpectedCount, Count);
- }
- if (!ExpectedName.empty()) {
- EXPECT_EQ(ExpectedName, Name);
- }
+ EXPECT_EQ(ExpectedCount, -1);
+ EXPECT_TRUE(ExpectedName.empty());
Count = 0;
Name.clear();
}
@@ -389,25 +385,21 @@
bool run(const BoundNodes *Nodes) override {
const BoundNodes::IDToNodeMap &M = Nodes->getMap();
- if (Nodes->getNodeAs<T>(Id)) {
- ++Count;
- if (const NamedDecl *Named = Nodes->getNodeAs<NamedDecl>(Id)) {
- Name = Named->getNameAsString();
- } else if (const NestedNameSpecifier *NNS =
- Nodes->getNodeAs<NestedNameSpecifier>(Id)) {
- llvm::raw_string_ostream OS(Name);
- NNS->print(OS, PrintingPolicy(LangOptions()));
- }
- BoundNodes::IDToNodeMap::const_iterator I = M.find(Id);
- EXPECT_NE(M.end(), I);
- if (I != M.end()) {
- EXPECT_EQ(Nodes->getNodeAs<T>(Id), I->second.get<T>());
- }
- return true;
+ EXPECT_NE(Nodes->getNodeAs<T>(Id), nullptr);
+ ++Count;
+ if (const NamedDecl *Named = Nodes->getNodeAs<NamedDecl>(Id)) {
+ Name = Named->getNameAsString();
+ } else if (const NestedNameSpecifier *NNS =
+ Nodes->getNodeAs<NestedNameSpecifier>(Id)) {
+ llvm::raw_string_ostream OS(Name);
+ NNS->print(OS, PrintingPolicy(LangOptions()));
+ }
+ BoundNodes::IDToNodeMap::const_iterator I = M.find(Id);
+ EXPECT_NE(M.end(), I);
+ if (I != M.end()) {
+ EXPECT_EQ(Nodes->getNodeAs<T>(Id), I->second.get<T>());
}
- EXPECT_TRUE(M.count(Id) == 0 ||
- M.find(Id)->second.template get<T>() == nullptr);
- return false;
+ return true;
}
bool run(const BoundNodes *Nodes, ASTContext *Context) override {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98514.330251.patch
Type: text/x-patch
Size: 2139 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210312/806c60f3/attachment.bin>
More information about the cfe-commits
mailing list