OSDN Git Service

[FileCheck] Add CHECK-EMPTY directive for checking for blank lines
authorJames Henderson <jh7370@my.bristol.ac.uk>
Tue, 26 Jun 2018 15:15:45 +0000 (15:15 +0000)
committerJames Henderson <jh7370@my.bristol.ac.uk>
Tue, 26 Jun 2018 15:15:45 +0000 (15:15 +0000)
commit583ccd4384c8f830a8a3b6b97613c20761b69240
treef36e69304f5a91eb50632568f3636f191aa9f8ed
parente873939bd3e97389fd4cdd3fd47c7852b6c12683
[FileCheck] Add CHECK-EMPTY directive for checking for blank lines

Prior to this change, there was no clean way of getting FileCheck to
check that a line is completely empty. The expected way of using
"CHECK: {{^$}}" does not work because the '^' matches the end of the
previous match (this behaviour may be desirable in certain instances).
For the same reason, "CHECK-NEXT: {{^$}}" will fail when the previous
match was at the end of the line, as the pattern will match there.
Using the recommended [[:space:]] to match an explicit new line could
also match a space, and thus is not always desired. Literal '\n'
matches also do not work. A workaround was suggested in the review, but
it is a little clunky.

This change adds a new directive that behaves the same as CHECK-NEXT,
except that it only matches against empty lines (nothing, not even
whitespace, is allowed). As with CHECK-NEXT, it will fail if more than
one newline occurs before the next blank line. Example usage:
; test.txt
foo

bar
; CHECK: foo
; CHECK-EMPTY:
; CHECK-NEXT: bar

Differential Revision: https://reviews.llvm.org/D28896

Reviewed by: probinson

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335613 91177308-0d34-0410-b5e6-96231b3b80d8
docs/CommandGuide/FileCheck.rst
test/FileCheck/check-empty-tag.txt [new file with mode: 0644]
utils/FileCheck/FileCheck.cpp