<div dir="ltr">On Fri, Jun 21, 2013 at 8:59 AM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank" class="cremed">rnk@google.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"><div dir="ltr">Should be fixed by r184544.</div></blockquote><div><br></div><div style>Thanks for the fix.</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><div class="gmail_extra">On Fri, Jun 21, 2013 at 8:42 AM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank" class="cremed">rnk@google.com</a>></span> wrote:<br>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>On Thu, Jun 20, 2013 at 10:28 AM, Samuel Benzaquen <span dir="ltr"><<a href="mailto:sbenza@google.com" target="_blank" class="cremed">sbenza@google.com</a>></span> wrote:<br>
</div><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>Author: sbenza<br>
Date: Thu Jun 20 09:28:32 2013<br>
New Revision: 184429<br><br></div><div><div>
Modified: cfe/trunk/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp?rev=184429&r1=184428&r2=184429&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp?rev=184429&r1=184428&r2=184429&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp (original)<br>
+++ cfe/trunk/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp Thu Jun 20 09:28:32 2013<br>
@@ -28,8 +28,8 @@ TEST(VariantValueTest, Unsigned) {<br>
<br>
EXPECT_FALSE(Value.isString());<br>
EXPECT_FALSE(Value.isMatcher());<br>
- EXPECT_FALSE(Value.isTypedMatcher<clang::Decl>());<br>
- EXPECT_FALSE(Value.isTypedMatcher<clang::UnaryOperator>());<br>
+ EXPECT_FALSE(Value.hasTypedMatcher<clang::Decl>());<br>
+ EXPECT_FALSE(Value.hasTypedMatcher<clang::UnaryOperator>());<br>
}<br>
<br>
TEST(VariantValueTest, String) {<br>
@@ -38,11 +38,12 @@ TEST(VariantValueTest, String) {<br>
<br>
EXPECT_TRUE(Value.isString());<br>
EXPECT_EQ(kString, Value.getString());<br>
+ EXPECT_EQ("String", Value.getTypeAsString());<br>
<br>
EXPECT_FALSE(Value.isUnsigned());<br>
EXPECT_FALSE(Value.isMatcher());<br>
- EXPECT_FALSE(Value.isTypedMatcher<clang::Decl>());<br>
- EXPECT_FALSE(Value.isTypedMatcher<clang::UnaryOperator>());<br>
+ EXPECT_FALSE(Value.hasTypedMatcher<clang::Decl>());<br>
+ EXPECT_FALSE(Value.hasTypedMatcher<clang::UnaryOperator>());<br>
}<br>
<br>
TEST(VariantValueTest, DynTypedMatcher) {<br>
@@ -52,22 +53,25 @@ TEST(VariantValueTest, DynTypedMatcher)<br>
EXPECT_FALSE(Value.isString());<br>
<br>
EXPECT_TRUE(Value.isMatcher());<br>
- EXPECT_TRUE(Value.isTypedMatcher<clang::Decl>());<br>
- EXPECT_TRUE(Value.isTypedMatcher<clang::UnaryOperator>());<br>
+ EXPECT_FALSE(Value.hasTypedMatcher<clang::Decl>());<br>
+ EXPECT_TRUE(Value.hasTypedMatcher<clang::UnaryOperator>());<br>
+ EXPECT_EQ("Matcher<Stmt>", Value.getTypeAsString());<br>
<br>
- // Conversion to any type of matcher works.<br>
- // If they are not compatible it would just return a matcher that matches<br>
- // nothing. We test this below.<br>
+ // Can only convert to compatible matchers.<br>
Value = recordDecl();<br>
EXPECT_TRUE(Value.isMatcher());<br>
- EXPECT_TRUE(Value.isTypedMatcher<clang::Decl>());<br>
- EXPECT_TRUE(Value.isTypedMatcher<clang::UnaryOperator>());<br>
+ EXPECT_TRUE(Value.hasTypedMatcher<clang::Decl>());<br>
+ EXPECT_FALSE(Value.hasTypedMatcher<clang::UnaryOperator>());<br>
+ EXPECT_EQ("Matcher<Decl>", Value.getTypeAsString());<br>
<br>
- Value = unaryOperator();<br>
+ Value = ignoringImpCasts(expr());<br>
EXPECT_TRUE(Value.isMatcher());<br>
- EXPECT_TRUE(Value.isTypedMatcher<clang::Decl>());<br>
- EXPECT_TRUE(Value.isTypedMatcher<clang::Stmt>());<br>
- EXPECT_TRUE(Value.isTypedMatcher<clang::UnaryOperator>());<br>
+ EXPECT_FALSE(Value.hasTypedMatcher<clang::Decl>());<br>
+ EXPECT_FALSE(Value.hasTypedMatcher<clang::Stmt>());<br>
+ EXPECT_TRUE(Value.hasTypedMatcher<clang::Expr>());<br>
+ EXPECT_TRUE(Value.hasTypedMatcher<clang::IntegerLiteral>());<br>
+ EXPECT_FALSE(Value.hasTypedMatcher<clang::GotoStmt>());<br>
+ EXPECT_EQ("Matcher<Expr>", Value.getTypeAsString());<br>
}<br>
<br>
TEST(VariantValueTest, Assignment) {<br>
@@ -76,13 +80,15 @@ TEST(VariantValueTest, Assignment) {<br>
EXPECT_EQ("A", Value.getString());<br>
EXPECT_FALSE(Value.isUnsigned());<br>
EXPECT_FALSE(Value.isMatcher());<br>
+ EXPECT_EQ("String", Value.getTypeAsString());<br>
<br>
Value = recordDecl();<br>
EXPECT_FALSE(Value.isUnsigned());<br>
EXPECT_FALSE(Value.isString());<br>
EXPECT_TRUE(Value.isMatcher());<br>
- EXPECT_TRUE(Value.isTypedMatcher<clang::Decl>());<br>
- EXPECT_TRUE(Value.isTypedMatcher<clang::UnaryOperator>());<br>
+ EXPECT_TRUE(Value.hasTypedMatcher<clang::Decl>());<br>
+ EXPECT_FALSE(Value.hasTypedMatcher<clang::UnaryOperator>());<br>
+ EXPECT_EQ("Matcher<Decl>", Value.getTypeAsString());<br>
<br>
Value = 17;<br>
EXPECT_TRUE(Value.isUnsigned());<br>
@@ -94,25 +100,28 @@ TEST(VariantValueTest, Assignment) {<br>
EXPECT_FALSE(Value.isUnsigned());<br>
EXPECT_FALSE(Value.isString());<br>
EXPECT_FALSE(Value.isMatcher());<br>
+ EXPECT_EQ("Nothing", Value.getTypeAsString());<br>
}<br>
<br>
TEST(GeneicValueTest, Matcher) {<br></div></div></blockquote><div><br></div><div>s/Geneic/Generic/</div><div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
- EXPECT_TRUE(matchesDynamic(<br>
- "class X {};", VariantValue(recordDecl(hasName("X"))).getMatcher()));<br>
- EXPECT_TRUE(matchesDynamic(<br>
- "int x;", VariantValue(varDecl()).getTypedMatcher<clang::Decl>()));<br>
- EXPECT_TRUE(matchesDynamic("int foo() { return 1 + 1; }",<br>
- VariantValue(functionDecl()).getMatcher()));<br>
- // Going through the wrong Matcher<T> will fail to match, even if the<br>
- // underlying matcher is correct.<br>
- EXPECT_FALSE(matchesDynamic(<br>
- "int x;", VariantValue(varDecl()).getTypedMatcher<clang::Stmt>()));<br>
+ EXPECT_TRUE(matches("class X {};", VariantValue(recordDecl(hasName("X")))<br>
+ .getTypedMatcher<Decl>()));<br>
+ EXPECT_TRUE(<br>
+ matches("int x;", VariantValue(varDecl()).getTypedMatcher<Decl>()));<br>
+ EXPECT_TRUE(matches("int foo() { return 1 + 1; }",<br>
+ VariantValue(functionDecl()).getTypedMatcher<Decl>()));<br>
+ // Can't get the wrong matcher.<br>
+ EXPECT_FALSE(VariantValue(varDecl()).hasTypedMatcher<Stmt>());<br>
+#if GTEST_HAS_DEATH_TEST and DEBUG<br>
+ // Trying to get the wrong matcher fails an assertion in Matcher<T>.<br>
+ EXPECT_DEATH(VariantValue(varDecl()).getTypedMatcher<Stmt>(),<br>
+ "canConstructFrom");<br></blockquote><div><br></div></div><div>On Windows, assertion failures are printed as wide characters, so I get this hilarious failure:</div><div><div><br></div><div>
[----------] 1 test from GeneicValueTest</div><div>[ RUN ] GeneicValueTest.Matcher</div><div>..\tools\clang\unittests\ASTMatchers\Dynamic\VariantValueTest.cpp(118): error: Death test: VariantValue(varDecl()).getTypedMatcher<Stmt>()</div>
<div> Result: died but not with expected error.</div><div> Expected: canConstructFrom</div><div>Actual msg:</div><div>[ DEATH ] A\0s\0s\0e\0r\0t\0i\0o\0n\0 \0f\0a\0i\0l\0e\0d\0:\0 \0c\0a\0n\0C\0o\0n\0s\0t\0r\0u\0c\0t\0F\0r\0o\0m\0(\0O\0t\0h\0e\0r\0)\0,\0 \0f\0i\0l\0e\0 \0.\0.\0\\0t\0o\0o\0l\0s\0\\0c\0l\0a\0n\0g\0\\0i\0n\0c\0l\0u\0d\0e\0\\0c\0l\0a\0n\0g\0/\0A\0S\0T\0M\0a\0t\0c\0h\0e\0r\0s\0/\0A\0S\0T\0M\0a\0t\0c\0h\0e\0r\0s\0I\0n\0t\0e\0r\0n\0a\0l\0.\0h\0,\0 \0l\0i\0n\0e\0 \02\08\07\0</div>
<div>[ DEATH ] \0</div><div>[ FAILED ] GeneicValueTest.Matcher (420 ms)</div><div><br></div><div>Strip out the null chars and I get back the expected:</div><div><div>Assertion failed: canConstructFrom(Other), file ..\tools\clang\include\clang/ASTMatchers/ASTMatchersInternal.h, line 287</div>
<div>So far as I can tell, there's no way to force printing as ASCII or UTF-8. The docs proudly proclaim that assert prints wide chars so that Unicode works. =P</div></div></div><div><br></div><div>It's also failing here because presumably assertions are disabled:</div>
<div><a href="http://bb.pgr.jp/builders/ninja-clang-i686-msc17-R/builds/2266" target="_blank" class="cremed">http://bb.pgr.jp/builders/ninja-clang-i686-msc17-R/builds/2266</a></div><div>Assertions are enabled by !defined(NDEBUG), not DEBUG.</div>
<div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+#endif<br>
<br>
EXPECT_FALSE(<br>
- matchesDynamic("int x;", VariantValue(functionDecl()).getMatcher()));<br>
- EXPECT_FALSE(matchesDynamic(<br>
- "int foo() { return 1 + 1; }",<br>
- VariantValue(declRefExpr()).getTypedMatcher<clang::DeclRefExpr>()));<br>
+ matches("int x;", VariantValue(functionDecl()).getTypedMatcher<Decl>()));<br>
+ EXPECT_FALSE(matches("int foo() { return 1 + 1; }",<br>
+ VariantValue(declRefExpr()).getTypedMatcher<Stmt>()));<br>
}<br>
<br>
} // end anonymous namespace<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank" class="cremed">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank" class="cremed">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div><br></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>