r184429 - Enhancements for the DynTypedMatcher system.
Reid Kleckner
rnk at google.com
Fri Jun 21 05:59:34 PDT 2013
Should be fixed by r184544.
On Fri, Jun 21, 2013 at 8:42 AM, Reid Kleckner <rnk at google.com> wrote:
> On Thu, Jun 20, 2013 at 10:28 AM, Samuel Benzaquen <sbenza at google.com>wrote:
>
>> Author: sbenza
>> Date: Thu Jun 20 09:28:32 2013
>> New Revision: 184429
>>
>> Modified: cfe/trunk/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp?rev=184429&r1=184428&r2=184429&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp
>> (original)
>> +++ cfe/trunk/unittests/ASTMatchers/Dynamic/VariantValueTest.cpp Thu Jun
>> 20 09:28:32 2013
>> @@ -28,8 +28,8 @@ TEST(VariantValueTest, Unsigned) {
>>
>> EXPECT_FALSE(Value.isString());
>> EXPECT_FALSE(Value.isMatcher());
>> - EXPECT_FALSE(Value.isTypedMatcher<clang::Decl>());
>> - EXPECT_FALSE(Value.isTypedMatcher<clang::UnaryOperator>());
>> + EXPECT_FALSE(Value.hasTypedMatcher<clang::Decl>());
>> + EXPECT_FALSE(Value.hasTypedMatcher<clang::UnaryOperator>());
>> }
>>
>> TEST(VariantValueTest, String) {
>> @@ -38,11 +38,12 @@ TEST(VariantValueTest, String) {
>>
>> EXPECT_TRUE(Value.isString());
>> EXPECT_EQ(kString, Value.getString());
>> + EXPECT_EQ("String", Value.getTypeAsString());
>>
>> EXPECT_FALSE(Value.isUnsigned());
>> EXPECT_FALSE(Value.isMatcher());
>> - EXPECT_FALSE(Value.isTypedMatcher<clang::Decl>());
>> - EXPECT_FALSE(Value.isTypedMatcher<clang::UnaryOperator>());
>> + EXPECT_FALSE(Value.hasTypedMatcher<clang::Decl>());
>> + EXPECT_FALSE(Value.hasTypedMatcher<clang::UnaryOperator>());
>> }
>>
>> TEST(VariantValueTest, DynTypedMatcher) {
>> @@ -52,22 +53,25 @@ TEST(VariantValueTest, DynTypedMatcher)
>> EXPECT_FALSE(Value.isString());
>>
>> EXPECT_TRUE(Value.isMatcher());
>> - EXPECT_TRUE(Value.isTypedMatcher<clang::Decl>());
>> - EXPECT_TRUE(Value.isTypedMatcher<clang::UnaryOperator>());
>> + EXPECT_FALSE(Value.hasTypedMatcher<clang::Decl>());
>> + EXPECT_TRUE(Value.hasTypedMatcher<clang::UnaryOperator>());
>> + EXPECT_EQ("Matcher<Stmt>", Value.getTypeAsString());
>>
>> - // Conversion to any type of matcher works.
>> - // If they are not compatible it would just return a matcher that
>> matches
>> - // nothing. We test this below.
>> + // Can only convert to compatible matchers.
>> Value = recordDecl();
>> EXPECT_TRUE(Value.isMatcher());
>> - EXPECT_TRUE(Value.isTypedMatcher<clang::Decl>());
>> - EXPECT_TRUE(Value.isTypedMatcher<clang::UnaryOperator>());
>> + EXPECT_TRUE(Value.hasTypedMatcher<clang::Decl>());
>> + EXPECT_FALSE(Value.hasTypedMatcher<clang::UnaryOperator>());
>> + EXPECT_EQ("Matcher<Decl>", Value.getTypeAsString());
>>
>> - Value = unaryOperator();
>> + Value = ignoringImpCasts(expr());
>> EXPECT_TRUE(Value.isMatcher());
>> - EXPECT_TRUE(Value.isTypedMatcher<clang::Decl>());
>> - EXPECT_TRUE(Value.isTypedMatcher<clang::Stmt>());
>> - EXPECT_TRUE(Value.isTypedMatcher<clang::UnaryOperator>());
>> + EXPECT_FALSE(Value.hasTypedMatcher<clang::Decl>());
>> + EXPECT_FALSE(Value.hasTypedMatcher<clang::Stmt>());
>> + EXPECT_TRUE(Value.hasTypedMatcher<clang::Expr>());
>> + EXPECT_TRUE(Value.hasTypedMatcher<clang::IntegerLiteral>());
>> + EXPECT_FALSE(Value.hasTypedMatcher<clang::GotoStmt>());
>> + EXPECT_EQ("Matcher<Expr>", Value.getTypeAsString());
>> }
>>
>> TEST(VariantValueTest, Assignment) {
>> @@ -76,13 +80,15 @@ TEST(VariantValueTest, Assignment) {
>> EXPECT_EQ("A", Value.getString());
>> EXPECT_FALSE(Value.isUnsigned());
>> EXPECT_FALSE(Value.isMatcher());
>> + EXPECT_EQ("String", Value.getTypeAsString());
>>
>> Value = recordDecl();
>> EXPECT_FALSE(Value.isUnsigned());
>> EXPECT_FALSE(Value.isString());
>> EXPECT_TRUE(Value.isMatcher());
>> - EXPECT_TRUE(Value.isTypedMatcher<clang::Decl>());
>> - EXPECT_TRUE(Value.isTypedMatcher<clang::UnaryOperator>());
>> + EXPECT_TRUE(Value.hasTypedMatcher<clang::Decl>());
>> + EXPECT_FALSE(Value.hasTypedMatcher<clang::UnaryOperator>());
>> + EXPECT_EQ("Matcher<Decl>", Value.getTypeAsString());
>>
>> Value = 17;
>> EXPECT_TRUE(Value.isUnsigned());
>> @@ -94,25 +100,28 @@ TEST(VariantValueTest, Assignment) {
>> EXPECT_FALSE(Value.isUnsigned());
>> EXPECT_FALSE(Value.isString());
>> EXPECT_FALSE(Value.isMatcher());
>> + EXPECT_EQ("Nothing", Value.getTypeAsString());
>> }
>>
>> TEST(GeneicValueTest, Matcher) {
>>
>
> s/Geneic/Generic/
>
>
>> - EXPECT_TRUE(matchesDynamic(
>> - "class X {};",
>> VariantValue(recordDecl(hasName("X"))).getMatcher()));
>> - EXPECT_TRUE(matchesDynamic(
>> - "int x;", VariantValue(varDecl()).getTypedMatcher<clang::Decl>()));
>> - EXPECT_TRUE(matchesDynamic("int foo() { return 1 + 1; }",
>> - VariantValue(functionDecl()).getMatcher()));
>> - // Going through the wrong Matcher<T> will fail to match, even if the
>> - // underlying matcher is correct.
>> - EXPECT_FALSE(matchesDynamic(
>> - "int x;", VariantValue(varDecl()).getTypedMatcher<clang::Stmt>()));
>> + EXPECT_TRUE(matches("class X {};",
>> VariantValue(recordDecl(hasName("X")))
>> + .getTypedMatcher<Decl>()));
>> + EXPECT_TRUE(
>> + matches("int x;",
>> VariantValue(varDecl()).getTypedMatcher<Decl>()));
>> + EXPECT_TRUE(matches("int foo() { return 1 + 1; }",
>> +
>> VariantValue(functionDecl()).getTypedMatcher<Decl>()));
>> + // Can't get the wrong matcher.
>> + EXPECT_FALSE(VariantValue(varDecl()).hasTypedMatcher<Stmt>());
>> +#if GTEST_HAS_DEATH_TEST and DEBUG
>> + // Trying to get the wrong matcher fails an assertion in Matcher<T>.
>> + EXPECT_DEATH(VariantValue(varDecl()).getTypedMatcher<Stmt>(),
>> + "canConstructFrom");
>>
>
> On Windows, assertion failures are printed as wide characters, so I get
> this hilarious failure:
>
> [----------] 1 test from GeneicValueTest
> [ RUN ] GeneicValueTest.Matcher
> ..\tools\clang\unittests\ASTMatchers\Dynamic\VariantValueTest.cpp(118):
> error: Death test: VariantValue(varDecl()).getTypedMatcher<Stmt>()
> Result: died but not with expected error.
> Expected: canConstructFrom
> Actual msg:
> [ 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
> [ DEATH ] \0
> [ FAILED ] GeneicValueTest.Matcher (420 ms)
>
> Strip out the null chars and I get back the expected:
> Assertion failed: canConstructFrom(Other), file
> ..\tools\clang\include\clang/ASTMatchers/ASTMatchersInternal.h, line 287
> 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
>
> It's also failing here because presumably assertions are disabled:
> http://bb.pgr.jp/builders/ninja-clang-i686-msc17-R/builds/2266
> Assertions are enabled by !defined(NDEBUG), not DEBUG.
>
> +#endif
>>
>> EXPECT_FALSE(
>> - matchesDynamic("int x;",
>> VariantValue(functionDecl()).getMatcher()));
>> - EXPECT_FALSE(matchesDynamic(
>> - "int foo() { return 1 + 1; }",
>> -
>> VariantValue(declRefExpr()).getTypedMatcher<clang::DeclRefExpr>()));
>> + matches("int x;",
>> VariantValue(functionDecl()).getTypedMatcher<Decl>()));
>> + EXPECT_FALSE(matches("int foo() { return 1 + 1; }",
>> +
>> VariantValue(declRefExpr()).getTypedMatcher<Stmt>()));
>> }
>>
>> } // end anonymous namespace
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130621/4958ef76/attachment.html>
More information about the cfe-commits
mailing list