Skip to content

Commit

Permalink
Allow multiple check prefixes in FileCheck.
Browse files Browse the repository at this point in the history
This is useful if you want to run multiple variations
of a single test, and the majority of check lines
should be the same.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194343 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
arsenm committed Nov 10, 2013
1 parent 432bdf6 commit ee4f5ea
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 87 deletions.
12 changes: 7 additions & 5 deletions docs/CommandGuide/FileCheck.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ OPTIONS

.. option:: --check-prefix prefix

FileCheck searches the contents of ``match-filename`` for patterns to match.
By default, these patterns are prefixed with "``CHECK:``". If you'd like to
use a different prefix (e.g. because the same input file is checking multiple
different tool or options), the :option:`--check-prefix` argument allows you
to specify a specific prefix to match.
FileCheck searches the contents of ``match-filename`` for patterns to
match. By default, these patterns are prefixed with "``CHECK:``".
If you'd like to use a different prefix (e.g. because the same input
file is checking multiple different tool or options), the
:option:`--check-prefix` argument allows you to specify one or more
prefixes to match. Multiple prefixes are useful for tests which might
change for different run options, but most lines remain the same.

.. option:: --input-file filename

Expand Down
5 changes: 5 additions & 0 deletions test/FileCheck/check-a-b-has-b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
; RUN: FileCheck -check-prefix=A -check-prefix=B -input-file %s %s

this is the string to be matched

; B-DAG: this is the string to be {{matched}}
5 changes: 5 additions & 0 deletions test/FileCheck/check-b-a-has-b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
; RUN: FileCheck -check-prefix=B -check-prefix=A -input-file %s %s

this is the string to be matched

; B-DAG: this is the string to be {{matched}}
7 changes: 7 additions & 0 deletions test/FileCheck/check-dag-multi-prefix-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; RUN: FileCheck -check-prefix=A -input-file %s %s

this should be matched

; B-DAG: foo

; A-DAG: {{this}} should be matched
27 changes: 27 additions & 0 deletions test/FileCheck/check-dag-multi-prefix.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; RUN: FileCheck -check-prefix=A -check-prefix=B -input-file %s %s

add r10, r1, r2
add r11, r3, r4
mul r5, r10, r11

mul r11, r3, r4
mul r10, r1, r2
add r5, r10, r11

add r11, r3, r4
add r10, r1, r2
mul r5, r10, r11

; B-DAG: add [[REG1:r[0-9]+]], r1, r2
; B-DAG: add [[REG2:r[0-9]+]], r3, r4
; B: mul r5, [[REG1]], [[REG2]]

; A-DAG: mul [[REG1:r[0-9]+]], r1, r2
; A-DAG: mul [[REG2:r[0-9]+]], r3, r4
; A: add r5, [[REG1]], [[REG2]]

; B-DAG: add [[REG1:r[0-9]+]], r1, r2
; B-DAG: add [[REG2:r[0-9]+]], r3, r4
; B-NOT: xor
; B-DAG: mul r5, [[REG1]], [[REG2]]

7 changes: 7 additions & 0 deletions test/FileCheck/check-dag-substring-prefix.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; RUN: not FileCheck -check-prefix=A -check-prefix=AA -input-file %s %s

this is the string to be matched
this should also be matched

; BAA-DAG: this is the string to be {{matched}}
; BAA-DAG: this should also be {{matched}}
6 changes: 6 additions & 0 deletions test/FileCheck/check-multi-prefix-label.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: FileCheck -check-prefix=ONE -check-prefix=TWO -input-file %s %s

foo
bar
; ONE-LABEL: {{f}}oo
; TWO-NEXT: {{b}}ar
10 changes: 10 additions & 0 deletions test/FileCheck/check-multiple-prefixes-mixed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: FileCheck -check-prefix=B -check-prefix=BOTH -input-file %s %s
// RUN: FileCheck -check-prefix=A -check-prefix=BOTH -input-file %s %s

; A: {{a}}aaaaa
; B: {{b}}bbbb
; BOTH: {{q}}qqqqq
aaaaaa
bbbbb
qqqqqq
ccccc
11 changes: 11 additions & 0 deletions test/FileCheck/check-substring-multi-prefix-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; RUN: FileCheck -check-prefix=FOO -check-prefix=FOOBAR -check-prefix=BARFOO -input-file %s %s
; RUN: FileCheck -check-prefix=FOOBAR -check-prefix=FOO -check-prefix=BARFOO -input-file %s %s
; RUN: FileCheck -check-prefix=FOOBAR -check-prefix=BARFOO -check-prefix=FOO -input-file %s %s

this is the match
this is another

FOO
FOOBAR
FOOBAR: this is the {{match}}
BARFOO: this is {{another}}
9 changes: 9 additions & 0 deletions test/FileCheck/check-substring-multi-prefix.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: FileCheck -check-prefix=AAAOVERLAP -check-prefix=OVERLAP -input-file %s %s

foo
bar
buzz

OVERLAP: foo
AAAOVERLAP: bar
OVERLAP: buzz
2 changes: 2 additions & 0 deletions test/FileCheck/first-character-match.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RUN: FileCheck -check-prefix=RUN -input-file %s %s
// Prefix is at the first character in the file. The run line then matches itself.
9 changes: 9 additions & 0 deletions test/FileCheck/multiple-missing-prefixes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: FileCheck -check-prefix=ANOTHER-PREFIX -input-file %s %s
// RUN: not FileCheck -check-prefix=PREFIX1 -check-prefix=PREFIX2 -input-file %s %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK-NONEXISTENT-PREFIX -check-prefix=ALSO-NONEXISTENT %s

foobar
; ANOTHER-PREFIX: foobar

; We use regex to match the colon so that FileCheck won't think it is a check
; prefix.
; CHECK-NONEXISTENT-PREFIX: error: no check strings found with prefixes 'PREFIX1{{:}}', 'PREFIX2{{:}}'
7 changes: 7 additions & 0 deletions test/FileCheck/separate-multi-prefix.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: not FileCheck -check-prefix=SOMEPREFIX -input-file %s %s
// RUN: FileCheck -check-prefix=ANOTHER -input-file %s %s

asdf
; SOMEPREFIX: {{t}}his_is_not_asdf
; ANOTHER: {{a}}sdf

6 changes: 4 additions & 2 deletions test/FileCheck/validate-check-prefix.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// RUN: not FileCheck -check-prefix=A! -input-file %s %s 2>&1 | FileCheck -check-prefix=BAD_PREFIX %s
// RUN: FileCheck -check-prefix=A1a-B_c -input-file %s %s

// RUN: not FileCheck -check-prefix=REPEAT -check-prefix=REPEAT -input-file %s %s 2>&1 | FileCheck -check-prefix=BAD_PREFIX %s
// RUN: not FileCheck -check-prefix=VALID -check-prefix=A! -input-file %s %s 2>&1 | FileCheck -check-prefix=BAD_PREFIX %s
foobar
; A1a-B_c: foobar

; BAD_PREFIX: Supplied check-prefix is invalid! Prefixes must start with a letter and contain only alphanumeric characters, hyphens and underscores
; BAD_PREFIX: Supplied check-prefix is invalid! Prefixes must be
unique and start with a letter and contain only alphanumeric characters, hyphens and underscores
Loading

0 comments on commit ee4f5ea

Please sign in to comment.