[PATCH] D29122: [FileCheck] Add ability to match newline characters

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 10 05:56:07 PST 2017


jhenderson added a comment.

In https://reviews.llvm.org/D29122#673328, @dsanders wrote:

> > Currently there is no way using FileCheck to match an explicit newline character. Using,
> >  for example, the pattern "{{\n}}" matches an 'n' character, not '\n' (nor for that matter the
> >  string "\n"). The current suggested method of using [[:space:]] matches all forms of
> >  whitespace, so may not be always suitable.
>
> Does this kind of pattern work on Windows? That OS uses CRLF (\r\n) for line endings and will probably fail to match patterns that explicitly check for \n.


Yes, FileCheck normalises line endings to '\n'. In fact, all my development on this was done on Windows, so I'm more confident about that side than the Linux side!

> Does something like this achieve the effect you need?:
> 
>   // CHECK: foo{{$}}
>   // CHECK-NEXT: {{^}}bar

Unfortunately, this isn't sufficient for our use case. FileCheck doesn't provide a method for the matching explicit blank lines, due to the way the checks work. If the previous check matches to the end of a line, e.g. foo\n\nbar becomes \n\nbar in the buffer after matching foo{{$}}. A "CHECK-NEXT: {{^$}}" will then match immediately, but be treated as on the same line, causing an error. @probinson suggested an alternative method in https://reviews.llvm.org/D28896 which would work, but is not particularly clear, whereas I think a "CHECK: abc{{\n\n}}def" would be quite clear. It also reduces the need of using {{$}} and {{^}} repeatedly, if exact matches are desired.


https://reviews.llvm.org/D29122





More information about the llvm-commits mailing list