[cfe-dev] gtest and AST matchers

Jesper Eskilson jesper.eskilson at iar.com
Mon Nov 18 02:14:22 PST 2013


Hi,

I'm trying to use gtest to write tests for stuff that goes on inside an 
AST matcher, but it seems like any gtest assertions made inside a AST 
matcher callback are silently ignored.

For example, in the following program, the "FAIL" in the callback is 
silently ignored, but the TEST in the test-method succeeds.

--
#include "gtest/gtest.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Tooling/Tooling.h"

using namespace clang::ast_matchers;
using namespace clang::tooling;

class Callback : public MatchFinder::MatchCallback {
   virtual void run(const MatchFinder::MatchResult &result) { FAIL(); }
};

TEST(suite, test) {
   MatchFinder f;
   f.addMatcher(expr(), new Callback);
   runToolOnCode(newFrontendActionFactory(&f)->create(), "int x;");
   FAIL() << "We should have failed in the callback!";
}

int main(int argc, char **argv) {
   testing::InitGoogleTest(&argc, argv);
   return RUN_ALL_TESTS();
}
--

Is there a way around this? (Or should I be asking on the gtest-mailing 
list instead?)

/Jesper
-- 
*Jesper Eskilson* /Development Engineer/
IAR Systems AB
Box 23051, Strandbodgatan 1
SE-750 23 Uppsala, SWEDEN
E-mail: jesper.eskilson at iar.com <mailto:jesper.eskilson at iar.com>
Website: www.iar.com
<http://www.iar.com> Twitter: www.twitter.com/iarsystems
<http://www.twitter.com/iarsystems>



More information about the cfe-dev mailing list