On Tue, Oct 2, 2012 at 9:37 AM, Dmitri Gribenko <span dir="ltr"><<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.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 class="HOEnZb"><div class="h5">On Tue, Oct 2, 2012 at 7:22 PM, Alexander Kornienko <<a href="mailto:alexfh@google.com">alexfh@google.com</a>> wrote:<br>
> Let's put it this way: having a way to use "previous line" or "current line<br>
> + offset" variable in FileCheck, and having a better FileCheck performance<br>
> in debug mode, what would you prefer?<br>
><br>
> TEST(StmtDumper, TestDeclStmt) {<br>
>   ASSERT_TRUE(DumpedStmtCXX98Matches(<br>
>     "void A() {\n"<br>
>     "  int a = 1, b;\n"<br>
>     "}",<br>
>     "A",<br>
>     "(DeclStmt 0xXXXXXXXX <input.cc:2:3, col:15>\n"<br>
>     "  (VarDecl 0xXXXXXXXX <col:3, col:11> a 'int'\n"<br>
>     "    (IntegerLiteral 0xXXXXXXXX <col:11> 'int' 1))\n"<br>
>     "  (VarDecl 0xXXXXXXXX <col:3, col:14> b 'int'))\n"));<br>
> }<br>
><br>
> or<br>
><br>
> // RUN: clang_cc1 -ast-dump --std=c++98 -DTEST33 %s | FileCheck<br>
> --strict-whitespace --check-prefix CHECK33 %s<br>
> #ifdef TEST33<br>
> void A() {<br>
> // CHECK33: {{^}}(DeclStmt 0x{{........}} <input.cc:[[__LINE_MINUS_1__]]:3,<br>
> col:15><br>
>   int a = 1, b;<br>
> // CHECK33-NEXT: {{^  }}(VarDecl 0x{{........}} <col:3, col:11> a 'int'{{$}}<br>
> // CHECK33-NEXT: {{^    }}(IntegerLiteral 0x{{........}} <col:11> 'int'<br>
> 1)){{$}}<br>
> // CHECK33-NEXT: {{^  }}(VarDecl 0x{{........}} <col:3, col:14> b<br>
> 'int')){{$}}<br>
> }<br>
> #endif<br>
<br>
</div></div>I would prefer the first one and here's why:<br>
<br>
1. Obviously, it is smaller (less text), thus easier to parse.<br>
2. In FileCheck one has to do all this escaping and regex dances for<br>
every line.  In the first approach, it can be abstracted away.<br>
3. (a general FileCheck weakness) CHECKXX prefixes should be matched<br>
between RUN lines and CHECK lines.  It is not a big issue if the file<br>
has a few different CHECKXX prefixes, but it starts to matter if we<br>
introduce this kind of isolation into tests and will have lots of<br>
different prefixes.<br></blockquote><div><br></div><div>I prefer the FileCheck approach. I would expect it to be more familiar to most LLVM and Clang developers, and doesn't require learning another matching language (0xXXXXXXXX handling, etc). Also, it allows us to easily write tests which only match those bits of the output we care about, so we don't have to update a pile of tests when we change which details get dumped (for instance, I would suggest not matching source locations unless they're actually what you're testing for).</div>
<div><br></div><div>Also, lit-based tests are a whole lot easier to work with than the gtest tests. It's trivial to run lit on an individual test file, and to run clang on the code in the test to find out what output the AST dump is actually producing. And I don't need to rebuild when I'm hacking on the tests.</div>
</div>