<div dir="ltr">On Mon, Nov 18, 2013 at 11:14 AM, Jesper Eskilson <span dir="ltr"><<a href="mailto:jesper.eskilson@iar.com" target="_blank">jesper.eskilson@iar.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hi,<br>
<br>
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.<br>
<br>
For example, in the following program, the "FAIL" in the callback is silently ignored, but the TEST in the test-method succeeds.<br></blockquote><div><br></div><div>Yep, this generally doesn't work - just set a variable from the callback, and check that from the test...</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
--<br>
#include "gtest/gtest.h"<br>
#include "clang/ASTMatchers/<u></u>ASTMatchFinder.h"<br>
#include "clang/Frontend/<u></u>FrontendActions.h"<br>
#include "clang/Tooling/Tooling.h"<br>
<br>
using namespace clang::ast_matchers;<br>
using namespace clang::tooling;<br>
<br>
class Callback : public MatchFinder::MatchCallback {<br>
virtual void run(const MatchFinder::MatchResult &result) { FAIL(); }<br>
};<br>
<br>
TEST(suite, test) {<br>
MatchFinder f;<br>
f.addMatcher(expr(), new Callback);<br>
runToolOnCode(<u></u>newFrontendActionFactory(&f)-><u></u>create(), "int x;");<br>
FAIL() << "We should have failed in the callback!";<br>
}<br>
<br>
int main(int argc, char **argv) {<br>
testing::InitGoogleTest(&argc, argv);<br>
return RUN_ALL_TESTS();<br>
}<br>
--<br>
<br>
Is there a way around this? (Or should I be asking on the gtest-mailing list instead?)<br>
<br>
/Jesper<br>
-- <br>
*Jesper Eskilson* /Development Engineer/<br>
IAR Systems AB<br>
Box 23051, Strandbodgatan 1<br>
SE-750 23 Uppsala, SWEDEN<br>
E-mail: <a href="mailto:jesper.eskilson@iar.com" target="_blank">jesper.eskilson@iar.com</a> <mailto:<a href="mailto:jesper.eskilson@iar.com" target="_blank">jesper.eskilson@iar.<u></u>com</a>><br>
Website: <a href="http://www.iar.com" target="_blank">www.iar.com</a><br>
<<a href="http://www.iar.com" target="_blank">http://www.iar.com</a>> Twitter: <a href="http://www.twitter.com/iarsystems" target="_blank">www.twitter.com/iarsystems</a><br>
<<a href="http://www.twitter.com/iarsystems" target="_blank">http://www.twitter.com/<u></u>iarsystems</a>><br>
______________________________<u></u>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></div>