[llvm] f471eb8 - [FileCheck] Make FILECHECK_OPTS useful for its test suite

Joel E. Denny via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 21 15:02:27 PST 2019


Author: Joel E. Denny
Date: 2019-11-21T18:01:12-05:00
New Revision: f471eb8e99b564265a4bea326922263ff06cda40

URL: https://github.com/llvm/llvm-project/commit/f471eb8e99b564265a4bea326922263ff06cda40
DIFF: https://github.com/llvm/llvm-project/commit/f471eb8e99b564265a4bea326922263ff06cda40.diff

LOG: [FileCheck] Make FILECHECK_OPTS useful for its test suite

Without this patch, `FILECHECK_OPTS` isn't propagated to FileCheck's
test suite so that `FILECHECK_OPTS` doesn't inadvertently affect test
results by affecting the output of FileCheck calls under test.  As a
result, `FILECHECK_OPTS` is useless for debugging FileCheck's test
suite.

In `llvm/test/FileCheck/lit.local.cfg`, this patch provides a new
subsitution, `%ProtectFileCheckOutput`, to address this problem for
both `FILECHECK_OPTS` and the deprecated
`FILECHECK_DUMP_INPUT_ON_FAILURE`.  The rest of the patch uses
`%ProtectFileCheckOutput` throughout the test suite

Fixes PR40284.

Reviewed By: probinson, thopre

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

Added: 
    

Modified: 
    llvm/docs/TestingGuide.rst
    llvm/test/FileCheck/check-count.txt
    llvm/test/FileCheck/check-empty-tag.txt
    llvm/test/FileCheck/check-empty.txt
    llvm/test/FileCheck/check-ignore-case.txt
    llvm/test/FileCheck/check-label-dag.txt
    llvm/test/FileCheck/check-label.txt
    llvm/test/FileCheck/check-multiple-prefixes-nomatch-2.txt
    llvm/test/FileCheck/check-multiple-prefixes-nomatch.txt
    llvm/test/FileCheck/check-not-diaginfo.txt
    llvm/test/FileCheck/check-prefixes.txt
    llvm/test/FileCheck/dump-input-annotations.txt
    llvm/test/FileCheck/dump-input-enable.txt
    llvm/test/FileCheck/envvar-opts.txt
    llvm/test/FileCheck/implicit-check-not.txt
    llvm/test/FileCheck/line-count.txt
    llvm/test/FileCheck/lit.local.cfg
    llvm/test/FileCheck/match-full-lines.txt
    llvm/test/FileCheck/multiple-missing-prefixes.txt
    llvm/test/FileCheck/no-check-file.txt
    llvm/test/FileCheck/no-multi-suffixes.txt
    llvm/test/FileCheck/numeric-defines-diagnostics.txt
    llvm/test/FileCheck/numeric-defines.txt
    llvm/test/FileCheck/numeric-expression.txt
    llvm/test/FileCheck/opt-color.txt
    llvm/test/FileCheck/string-defines-diagnostics.txt
    llvm/test/FileCheck/string-defines.txt
    llvm/test/FileCheck/validate-check-prefix.txt
    llvm/test/FileCheck/var-scope.txt
    llvm/test/FileCheck/verbose.txt

Removed: 
    


################################################################################
diff  --git a/llvm/docs/TestingGuide.rst b/llvm/docs/TestingGuide.rst
index f147a9fbd7ab..7216c7c838ec 100644
--- a/llvm/docs/TestingGuide.rst
+++ b/llvm/docs/TestingGuide.rst
@@ -549,6 +549,13 @@ RUN lines:
    ``i686-pc-mingw32``. This allows a test to run with a specific ABI without
    constraining it to a specific triple.
 
+**FileCheck-specific substitutions:**
+
+``%ProtectFileCheckOutput``
+   This should precede a ``FileCheck`` call if and only if the call's textual
+   output affects test results.  It's usually easy to tell: just look for
+   redirection or piping of the ``FileCheck`` call's stdout or stderr.
+
 To add more substituations, look at ``test/lit.cfg`` or ``lit.local.cfg``.
 
 

diff  --git a/llvm/test/FileCheck/check-count.txt b/llvm/test/FileCheck/check-count.txt
index 1782728949a2..31881687f78c 100644
--- a/llvm/test/FileCheck/check-count.txt
+++ b/llvm/test/FileCheck/check-count.txt
@@ -4,19 +4,27 @@
 
 this is something else
 
-; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK-ERR1 2>&1 | FileCheck %s --check-prefix=ERRCOUNT1
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK-ERR1 2>&1 \
+; RUN: | FileCheck %s --check-prefix=ERRCOUNT1
 CHECK-ERR1-COUNT-xx: this
 ERRCOUNT1: [[@LINE-1]]:18: error: invalid count in -COUNT specification on prefix 'CHECK-ERR1'
 
-; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK-ERR2 2>&1 | FileCheck %s --check-prefix=ERRCOUNT2
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK-ERR2 2>&1 \
+; RUN: | FileCheck %s --check-prefix=ERRCOUNT2
 CHECK-ERR2-COUNT-0x1: something
 ERRCOUNT2: [[@LINE-1]]:19: error: invalid count in -COUNT specification on prefix 'CHECK-ERR2'
 
-; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK-ERR3 2>&1 | FileCheck %s --check-prefix=ERRCOUNT3
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK-ERR3 2>&1 \
+; RUN: | FileCheck %s --check-prefix=ERRCOUNT3
 CHECK-ERR3-COUNT-100x: else
 ERRCOUNT3: [[@LINE-1]]:21: error: invalid count in -COUNT specification on prefix 'CHECK-ERR3'
 
-; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK-ERR4 2>&1 | FileCheck %s --check-prefix=ERRCOUNT4
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK-ERR4 2>&1 \
+; RUN: | FileCheck %s --check-prefix=ERRCOUNT4
 CHECK-ERR4-COUNT-0: else
 ERRCOUNT4: [[@LINE-1]]:19: error: invalid count in -COUNT specification on prefix 'CHECK-ERR4'
 
@@ -80,17 +88,23 @@ CHECK-CNTMANY-EMPTY:
 ; Tests on mismatches:
 ;
 
-; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK-MIS1 2>&1 | FileCheck %s --check-prefix=MISCOUNT1
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK-MIS1 2>&1 \
+; RUN: | FileCheck %s --check-prefix=MISCOUNT1
 CHECK-MIS1-COUNT-3: this is duplicate
 CHECK-MIS1: {{^}}this is not duplicate
 MISCOUNT1: [[@LINE-1]]:13: error: CHECK-MIS1: expected string not found in input
 
-; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK-MIS2 2>&1 | FileCheck %s --check-prefix=MISCOUNT2
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK-MIS2 2>&1 \
+; RUN: | FileCheck %s --check-prefix=MISCOUNT2
 CHECK-MIS2-COUNT-10: {{^this is duplicate}}
 CHECK-MIS2: {{^}}this is not duplicate
 MISCOUNT2: [[@LINE-2]]:22: error: CHECK-MIS2-COUNT: expected string not found in input
 
-; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK-MIS3 2>&1 | FileCheck %s --check-prefix=MISCOUNT3
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK-MIS3 2>&1 \
+; RUN: | FileCheck %s --check-prefix=MISCOUNT3
 CHECK-MIS3-COUNT-5: this is duplicate
 CHECK-MIS3-EMPTY:
 CHECK-MIS3-LABEL: Many-label:

diff  --git a/llvm/test/FileCheck/check-empty-tag.txt b/llvm/test/FileCheck/check-empty-tag.txt
index 70d3afcd9d1e..c398bcf596fc 100644
--- a/llvm/test/FileCheck/check-empty-tag.txt
+++ b/llvm/test/FileCheck/check-empty-tag.txt
@@ -8,32 +8,44 @@ CHECK1-EMPTY:
 CHECK1-NEXT: bar
 
 ; next line must be blank
-; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK2A 2>&1 | FileCheck %s --check-prefix=CHECK2B
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK2A 2>&1 \
+; RUN: | FileCheck %s --check-prefix=CHECK2B
 badger
 CHECK2A: badger
 CHECK2A-EMPTY:
 CHECK2B: CHECK2A-EMPTY: is not on the line after the previous match
 
 ; CHECK-EMPTY must have empty pattern
-; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK3A 2>&1 | FileCheck %s --check-prefix=CHECK3B
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK3A 2>&1 \
+; RUN: | FileCheck %s --check-prefix=CHECK3B
 CHECK3A: foo
 CHECK3A-EMPTY: this is not empty
 CHECK3B: found non-empty check string for empty check with prefix 'CHECK3A:'
 
 ; CHECK-EMPTY cannot be the first check
-; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK4A 2>&1 | FileCheck %s --check-prefix=CHECK4B
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK4A 2>&1 \
+; RUN: | FileCheck %s --check-prefix=CHECK4B
 CHECK4A-EMPTY:
 CHECK4B: found 'CHECK4A-EMPTY' without previous 'CHECK4A: line
 
 ; CHECK-EMPTY-NOT and CHECK-NOT-EMPTY rejected
-; RUN: not FileCheck %s --input-file %s --check-prefixes=CHECK5A 2>&1 | FileCheck %s --check-prefix=CHECK5C
-; RUN: not FileCheck %s --input-file %s --check-prefixes=CHECK5B 2>&1 | FileCheck %s --check-prefix=CHECK5C
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck %s --input-file %s --check-prefixes=CHECK5A 2>&1 \
+; RUN: | FileCheck %s --check-prefix=CHECK5C
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck %s --input-file %s --check-prefixes=CHECK5B 2>&1 \
+; RUN: | FileCheck %s --check-prefix=CHECK5C
 CHECK5A-EMPTY-NOT:
 CHECK5B-NOT-EMPTY:
 CHECK5C: unsupported -NOT combo on prefix 'CHECK5{{A|B}}'
 
 ; whitespace does not count as empty
-; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK6A --match-full-lines 2>&1 | FileCheck %s --check-prefix=CHECK6B
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck %s --input-file %s --check-prefix=CHECK6A --match-full-lines \
+; RUN: 2>&1 | FileCheck %s --check-prefix=CHECK6B
 CHECK6A: the next line has spaces
 CHECK6A-EMPTY:
 CHECK6B: expected string not found in input

diff  --git a/llvm/test/FileCheck/check-empty.txt b/llvm/test/FileCheck/check-empty.txt
index d2c592e501c8..da769583bee0 100644
--- a/llvm/test/FileCheck/check-empty.txt
+++ b/llvm/test/FileCheck/check-empty.txt
@@ -1,7 +1,18 @@
-// RUN: not FileCheck -check-prefix=FOO %s </dev/null 2>&1 | FileCheck -check-prefix=EMPTY-ERR %s
-// RUN: not FileCheck -check-prefix=NOFOO %s </dev/null 2>&1 | FileCheck -check-prefix=EMPTY-ERR %s
-// RUN: not FileCheck -check-prefix=FOO -allow-empty %s </dev/null 2>&1 | FileCheck -check-prefix=NO-EMPTY-ERR -check-prefix=NOT-FOUND %s
-// RUN: FileCheck -check-prefix=NOFOO -allow-empty %s </dev/null 2>&1 | FileCheck -allow-empty -check-prefix=NO-EMPTY-ERR %s
+// RUN: %ProtectFileCheckOutput \
+// RUN: not FileCheck -check-prefix=FOO %s </dev/null 2>&1 \
+// RUN: | FileCheck -check-prefix=EMPTY-ERR %s
+//
+// RUN: %ProtectFileCheckOutput \
+// RUN: not FileCheck -check-prefix=NOFOO %s </dev/null 2>&1 \
+// RUN: | FileCheck -check-prefix=EMPTY-ERR %s
+//
+// RUN: %ProtectFileCheckOutput \
+// RUN: not FileCheck -check-prefix=FOO -allow-empty %s </dev/null 2>&1 \
+// RUN: | FileCheck -check-prefix=NO-EMPTY-ERR -check-prefix=NOT-FOUND %s
+//
+// RUN: %ProtectFileCheckOutput \
+// RUN: FileCheck -check-prefix=NOFOO -allow-empty %s </dev/null 2>&1 \
+// RUN: | FileCheck -allow-empty -check-prefix=NO-EMPTY-ERR %s
 
 ; FOO: foo
 ; NOFOO-NOT: foo

diff  --git a/llvm/test/FileCheck/check-ignore-case.txt b/llvm/test/FileCheck/check-ignore-case.txt
index 6a42a52fc449..c3b4d97ab5e4 100644
--- a/llvm/test/FileCheck/check-ignore-case.txt
+++ b/llvm/test/FileCheck/check-ignore-case.txt
@@ -15,7 +15,10 @@
 
 ## Check that option --implicit-not works case insensitively.
 # RUN: sed '/^#/d' %s | FileCheck --implicit-check-not=sTrInG %s
-# RUN: sed '/^#/d' %s | not FileCheck --ignore-case --implicit-check-not=sTrInG %s 2>&1 | FileCheck --check-prefix=ERROR %s
+# RUN: sed '/^#/d' %s \
+# RUN: | %ProtectFileCheckOutput \
+# RUN:   not FileCheck --ignore-case --implicit-check-not=sTrInG %s 2>&1 \
+# RUN: | FileCheck --check-prefix=ERROR %s
 
 this is the STRING to be matched
 

diff  --git a/llvm/test/FileCheck/check-label-dag.txt b/llvm/test/FileCheck/check-label-dag.txt
index 1ce4a8d2b07e..e52501f8961c 100644
--- a/llvm/test/FileCheck/check-label-dag.txt
+++ b/llvm/test/FileCheck/check-label-dag.txt
@@ -1,4 +1,5 @@
-; RUN: not FileCheck -input-file %s %s 2>&1 | FileCheck --check-prefix=ERROR %s
+; RUN: %ProtectFileCheckOutput not FileCheck -input-file %s %s 2>&1 \
+; RUN: | FileCheck --check-prefix=ERROR %s
 
 bar
 zed

diff  --git a/llvm/test/FileCheck/check-label.txt b/llvm/test/FileCheck/check-label.txt
index 27f0beeb2911..311dfc74459c 100644
--- a/llvm/test/FileCheck/check-label.txt
+++ b/llvm/test/FileCheck/check-label.txt
@@ -1,5 +1,8 @@
 ; RUN: FileCheck -input-file %s %s -check-prefix=CHECKOK
-; RUN: not FileCheck -input-file %s %s -check-prefix=CHECKFAIL 2>&1 | FileCheck %s -check-prefix=CHECKERROR
+;
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck -input-file %s %s -check-prefix=CHECKFAIL 2>&1 \
+; RUN: | FileCheck %s -check-prefix=CHECKERROR
 
 label0:
 a

diff  --git a/llvm/test/FileCheck/check-multiple-prefixes-nomatch-2.txt b/llvm/test/FileCheck/check-multiple-prefixes-nomatch-2.txt
index 55c521123da7..e76cae43fbcf 100644
--- a/llvm/test/FileCheck/check-multiple-prefixes-nomatch-2.txt
+++ b/llvm/test/FileCheck/check-multiple-prefixes-nomatch-2.txt
@@ -1,6 +1,14 @@
-; RUN: not FileCheck -input-file %s %s -check-prefix=FOO -check-prefix=BAR 2>&1 | FileCheck %s
-; RUN: not FileCheck -input-file %s %s -check-prefixes=FOO,BAR 2>&1 | FileCheck %s
-; RUN: not FileCheck -input-file %s %s -check-prefixes=BAR,FOO 2>&1 | FileCheck %s
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck -input-file %s %s -check-prefix=FOO -check-prefix=BAR \
+; RUN: 2>&1 | FileCheck %s
+;
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck -input-file %s %s -check-prefixes=FOO,BAR 2>&1 \
+; RUN: | FileCheck %s
+;
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck -input-file %s %s -check-prefixes=BAR,FOO 2>&1 \
+; RUN: | FileCheck %s
 
 fog
 bar

diff  --git a/llvm/test/FileCheck/check-multiple-prefixes-nomatch.txt b/llvm/test/FileCheck/check-multiple-prefixes-nomatch.txt
index 90a2a3863e57..656cdd67fbdc 100644
--- a/llvm/test/FileCheck/check-multiple-prefixes-nomatch.txt
+++ b/llvm/test/FileCheck/check-multiple-prefixes-nomatch.txt
@@ -1,6 +1,14 @@
-; RUN: not FileCheck -input-file %s %s -check-prefix=FOO -check-prefix=BAR 2>&1 | FileCheck %s
-; RUN: not FileCheck -input-file %s %s -check-prefixes=FOO,BAR 2>&1 | FileCheck %s
-; RUN: not FileCheck -input-file %s %s -check-prefixes=BAR,FOO 2>&1 | FileCheck %s
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck -input-file %s %s -check-prefix=FOO -check-prefix=BAR \
+; RUN: 2>&1 | FileCheck %s
+;
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck -input-file %s %s -check-prefixes=FOO,BAR 2>&1 \
+; RUN: | FileCheck %s
+;
+; RUN: %ProtectFileCheckOutput \
+; RUN: not FileCheck -input-file %s %s -check-prefixes=BAR,FOO 2>&1 \
+; RUN: | FileCheck %s
 
 BAR
 bar

diff  --git a/llvm/test/FileCheck/check-not-diaginfo.txt b/llvm/test/FileCheck/check-not-diaginfo.txt
index 389c1784a2ad..6c1718312eb5 100644
--- a/llvm/test/FileCheck/check-not-diaginfo.txt
+++ b/llvm/test/FileCheck/check-not-diaginfo.txt
@@ -1,4 +1,4 @@
-; RUN: not FileCheck --input-file %s %s 2>&1 \
+; RUN: %ProtectFileCheckOutput not FileCheck --input-file %s %s 2>&1 \
 ; RUN:   | FileCheck --strict-whitespace --check-prefix DIAG %s
 
 CHECK-NOT: test

diff  --git a/llvm/test/FileCheck/check-prefixes.txt b/llvm/test/FileCheck/check-prefixes.txt
index fc7a0435eb70..1e73f481314f 100644
--- a/llvm/test/FileCheck/check-prefixes.txt
+++ b/llvm/test/FileCheck/check-prefixes.txt
@@ -1,5 +1,8 @@
 // RUN: FileCheck -check-prefix=ANOTHER-PREFIX -input-file %s %s
-// RUN: not FileCheck -check-prefix=PREFIX -input-file %s %s 2>&1 | FileCheck -check-prefix=CHECK-NONEXISTENT-PREFIX %s
+//
+// RUN: %ProtectFileCheckOutput \
+// RUN: not FileCheck -check-prefix=PREFIX -input-file %s %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-NONEXISTENT-PREFIX %s
 
 foobar
 ; ANOTHER-PREFIX: foobar

diff  --git a/llvm/test/FileCheck/dump-input-annotations.txt b/llvm/test/FileCheck/dump-input-annotations.txt
index 71bd0fb0a67f..a9072ddcf423 100644
--- a/llvm/test/FileCheck/dump-input-annotations.txt
+++ b/llvm/test/FileCheck/dump-input-annotations.txt
@@ -15,6 +15,7 @@
 ; RUN: echo 'CHECK: hello' > %t.chk
 ; RUN: echo 'CHECK: universe' >> %t.chk
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -v 2>&1 \
 ; RUN: | FileCheck -strict-whitespace -match-full-lines -check-prefix=ALIGN \
 ; RUN:             -implicit-check-not='remark:' %s
@@ -51,12 +52,15 @@
 ; RUN: echo 'CHECK: hello' > %t.chk
 ; RUN: echo 'CHECK: world' >> %t.chk
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefix=CHK \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -v 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=CHK,CHK-V \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -vv 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=CHK,CHK-V \
 ; RUN:             -implicit-check-not='remark:'
@@ -88,12 +92,15 @@
 
 ; RUN: echo 'CHECK-COUNT-3: pete' > %t.chk
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=CNT,CNT-Q \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -v 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=CNT,CNT-V \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -vv 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=CNT,CNT-V \
 ; RUN:             -implicit-check-not='remark:'
@@ -125,12 +132,15 @@
 ; RUN: echo 'CHECK-NEXT: again' >> %t.chk
 ; RUN: echo 'CHECK-NEXT: world' >> %t.chk
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefix=NXT \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -v 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=NXT,NXT-V \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -vv 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=NXT,NXT-V,NXT-VV \
 ; RUN:             -implicit-check-not='remark:'
@@ -153,6 +163,7 @@
 ; RUN: echo 'yonder' >> %t.in
 ; RUN: echo 'world' >> %t.in
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefix=NXT2
 
@@ -178,12 +189,15 @@
 ; RUN: echo 'CHECK-SAME: world' >> %t.chk
 ; RUN: echo 'CHECK-SAME: again' >> %t.chk
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefix=SAM \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -v 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=SAM,SAM-V \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -vv 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=SAM,SAM-V,SAM-VV \
 ; RUN:             -implicit-check-not='remark:'
@@ -203,6 +217,7 @@
 
 ; RUN: echo 'again' >> %t.in
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -v 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=SAM2 \
 ; RUN:             -implicit-check-not='remark:'
@@ -241,12 +256,15 @@
 ; RUN: echo 'CHECK-EMPTY:' >> %t.chk
 ; RUN: echo 'CHECK-LABEL: label' >> %t.chk
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefix=EMP \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -v 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=EMP,EMP-V \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -vv 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=EMP,EMP-V,EMP-VV \
 ; RUN:             -implicit-check-not='remark:'
@@ -275,12 +293,15 @@
 ; RUN: echo 'CHECK: hello' > %t.chk
 ; RUN: echo 'CHECK-EMPTY:' >> %t.chk
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefix=EMP2 \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -v 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=EMP2,EMP2-V \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -vv 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=EMP2,EMP2-V,EMP2-VV \
 ; RUN:             -implicit-check-not='remark:'
@@ -310,12 +331,15 @@
 ; RUN: echo 'CHECK-NOT: goodbye' > %t.chk
 ; RUN: echo 'CHECK-NOT: world' >> %t.chk
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefix=NOT \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -v 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=NOT,NOT-V \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -vv 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=NOT,NOT-V,NOT-VV \
 ; RUN:             -implicit-check-not='remark:'
@@ -340,12 +364,15 @@
 
 ; RUN: echo 'CHECK: ain' >> %t.chk
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefix=NOT2 \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -v 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=NOT2,NOT2-V \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -vv 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=NOT2,NOT2-V,NOT2-VV \
 ; RUN:             -implicit-check-not='remark:'
@@ -387,12 +414,15 @@
 ; DAG-VQ = -v and not -vv
 ; DAG-VV = -vv
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=DAG,DAG-Q \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -v 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=DAG,DAG-V,DAG-VQ \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -vv 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=DAG,DAG-V,DAG-VV \
 ; RUN:             -implicit-check-not='remark:'
@@ -434,12 +464,15 @@
 ; RUN: echo 'CHECK: foo' >> %t.chk
 ; RUN: echo 'CHECK-LABEL: lab2' >> %t.chk
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=LAB \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -v 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=LAB,LAB-V \
 ; RUN:             -implicit-check-not='remark:'
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -dump-input=always -input-file %t.in %t.chk -vv 2>&1 \
 ; RUN: | FileCheck -match-full-lines %s -check-prefixes=LAB,LAB-V,LAB-VV \
 ; RUN:             -implicit-check-not='remark:'

diff  --git a/llvm/test/FileCheck/dump-input-enable.txt b/llvm/test/FileCheck/dump-input-enable.txt
index 8c8a807e0027..511248ea1ac7 100644
--- a/llvm/test/FileCheck/dump-input-enable.txt
+++ b/llvm/test/FileCheck/dump-input-enable.txt
@@ -18,12 +18,13 @@
 ; Check -dump-input=<bad value>.
 ;--------------------------------------------------
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
 ; RUN:               -match-full-lines -dump-input=foobar 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines -check-prefix=BADVAL
 
 ; No positional arg.
-; RUN: not FileCheck -dump-input=foobar 2>&1 \
+; RUN: %ProtectFileCheckOutput not FileCheck -dump-input=foobar 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines -check-prefix=BADVAL
 
 BADVAL: {{F|f}}ile{{C|c}}heck{{.*}}: for the --dump-input option: Cannot find option named 'foobar'!
@@ -33,11 +34,13 @@ BADVAL: {{F|f}}ile{{C|c}}heck{{.*}}: for the --dump-input option: Cannot find op
 ;--------------------------------------------------
 
 ; Appended to normal command line.
+; RUN: %ProtectFileCheckOutput \
 ; RUN: FileCheck -input-file %t.err -color %t.check -dump-input=help \
 ; RUN: | FileCheck %s -check-prefix=HELP
 
 ; No positional arg.
-; RUN: FileCheck -dump-input=help | FileCheck %s -check-prefix=HELP
+; RUN: %ProtectFileCheckOutput FileCheck -dump-input=help \
+; RUN: | FileCheck %s -check-prefix=HELP
 
 HELP-NOT: {{.}}
 HELP: The following description was requested by -dump-input=help
@@ -50,19 +53,23 @@ HELP-NOT: {{.}}
 ; Include the case without -v, which isn't covered elsewhere.
 ;--------------------------------------------------
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
 ; RUN:           -match-full-lines -dump-input=never 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines -allow-empty \
 ; RUN:             -check-prefixes=NOTRACE,NODUMP
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
 ; RUN:               -match-full-lines -dump-input=never 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines -check-prefixes=NOTRACE,ERR,NODUMP
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
 ; RUN:           -match-full-lines -dump-input=never -v 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines -check-prefixes=TRACE,NODUMP
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
 ; RUN:               -match-full-lines -dump-input=never -v 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines -check-prefixes=TRACE,ERR,NODUMP
@@ -71,10 +78,12 @@ HELP-NOT: {{.}}
 ; Check no -dump-input, which defaults to never.
 ;--------------------------------------------------
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
 ; RUN:           -match-full-lines -v 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines -check-prefixes=TRACE,NODUMP
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
 ; RUN:               -match-full-lines -v 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines -check-prefixes=TRACE,ERR,NODUMP
@@ -85,20 +94,24 @@ HELP-NOT: {{.}}
 ; Include the case without -v, which isn't covered elsewhere.
 ;--------------------------------------------------
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
 ; RUN:           -match-full-lines -dump-input=fail 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines -allow-empty \
 ; RUN:             -check-prefixes=NOTRACE,NODUMP
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
 ; RUN:               -match-full-lines -dump-input=fail 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines -check-prefixes=NOTRACE,ERR,DUMP-ERR
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
 ; RUN:           -match-full-lines -dump-input=fail -v 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines -allow-empty \
 ; RUN:             -check-prefixes=NOTRACE,NODUMP
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
 ; RUN:               -match-full-lines -dump-input=fail -v 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines \
@@ -108,23 +121,25 @@ HELP-NOT: {{.}}
 ; Check -dump-input-on-failure.
 ;--------------------------------------------------
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
 ; RUN:           -match-full-lines -dump-input-on-failure -v 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines -allow-empty \
 ; RUN:             -check-prefixes=NOTRACE,NODUMP
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
 ; RUN:               -match-full-lines -dump-input-on-failure -v 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines \
 ; RUN:                -check-prefixes=NOTRACE,ERR,DUMP-ERR,DUMP-ERR-V
 
-; RUN: env FILECHECK_DUMP_INPUT_ON_FAILURE=1 \
+; RUN: %ProtectFileCheckOutput FILECHECK_DUMP_INPUT_ON_FAILURE=1 \
 ; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
 ; RUN:           -match-full-lines -v 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines -allow-empty \
-; RUN:             -check-prefixes=NOTRACE,NODUMP
+; RUN:                -check-prefixes=NOTRACE,NODUMP
 
-; RUN: env FILECHECK_DUMP_INPUT_ON_FAILURE=1 \
+; RUN: %ProtectFileCheckOutput FILECHECK_DUMP_INPUT_ON_FAILURE=1 \
 ; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
 ; RUN:               -match-full-lines -v 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines \
@@ -134,10 +149,12 @@ HELP-NOT: {{.}}
 ; Check -dump-input=always.
 ;--------------------------------------------------
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
 ; RUN:           -match-full-lines -dump-input=always -v 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines -check-prefixes=NOTRACE,DUMP-OK
 
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
 ; RUN:               -match-full-lines -dump-input=always -v 2>&1 \
 ; RUN: | FileCheck %s -match-full-lines \

diff  --git a/llvm/test/FileCheck/envvar-opts.txt b/llvm/test/FileCheck/envvar-opts.txt
index b25ecb89a318..c1a9b2e1b243 100644
--- a/llvm/test/FileCheck/envvar-opts.txt
+++ b/llvm/test/FileCheck/envvar-opts.txt
@@ -3,11 +3,15 @@
 ; CHECK: foo
 ; CHECK: bar
 
-; RUN: env FILECHECK_OPTS= \
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck %s -input-file %t.in 2>&1 \
 ; RUN: | FileCheck -check-prefix QUIET %s
 
-; RUN: env FILECHECK_OPTS=-v \
+; RUN: %ProtectFileCheckOutput FILECHECK_OPTS= \
+; RUN: not FileCheck %s -input-file %t.in 2>&1 \
+; RUN: | FileCheck -check-prefix QUIET %s
+
+; RUN: %ProtectFileCheckOutput FILECHECK_OPTS=-v \
 ; RUN: not FileCheck %s -input-file %t.in 2>&1 \
 ; RUN: | FileCheck -check-prefix VERB %s
 

diff  --git a/llvm/test/FileCheck/implicit-check-not.txt b/llvm/test/FileCheck/implicit-check-not.txt
index 39b758e9a97f..3aea712d6506 100644
--- a/llvm/test/FileCheck/implicit-check-not.txt
+++ b/llvm/test/FileCheck/implicit-check-not.txt
@@ -1,11 +1,11 @@
 ; RUN: sed 's#^;.*##' %s | FileCheck -check-prefix=CHECK-PASS -implicit-check-not=warning: %s
-; RUN: sed 's#^;.*##' %s | not FileCheck -check-prefix=CHECK-FAIL1 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR1
-; RUN: sed 's#^;.*##' %s | not FileCheck -check-prefix=CHECK-FAIL2 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR2
-; RUN: sed 's#^;.*##' %s | not FileCheck -check-prefix=CHECK-FAIL3 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR3
-; RUN: sed 's#^;.*##' %s | not FileCheck -check-prefix=CHECK-FAIL1 -implicit-check-not='{{aaa|bbb|ccc}}' %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR4
-; RUN: sed 's#^;.*##' %s | not FileCheck -check-prefix=CHECK-FAIL1 -implicit-check-not=aaa -implicit-check-not=bbb -implicit-check-not=ccc %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR5
-; RUN: sed 's#^;.*##' %s | not FileCheck -check-prefix=CHECK-FAIL2 -implicit-check-not=aaa -implicit-check-not=bbb -implicit-check-not=ccc %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR6
-; RUN: sed 's#^;.*##' %s | not FileCheck -check-prefix=CHECK-FAIL3 -implicit-check-not=aaa -implicit-check-not=bbb -implicit-check-not=ccc %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR7
+; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL1 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR1
+; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL2 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR2
+; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL3 -implicit-check-not=warning: %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR3
+; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL1 -implicit-check-not='{{aaa|bbb|ccc}}' %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR4
+; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL1 -implicit-check-not=aaa -implicit-check-not=bbb -implicit-check-not=ccc %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR5
+; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL2 -implicit-check-not=aaa -implicit-check-not=bbb -implicit-check-not=ccc %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR6
+; RUN: sed 's#^;.*##' %s | %ProtectFileCheckOutput not FileCheck -check-prefix=CHECK-FAIL3 -implicit-check-not=aaa -implicit-check-not=bbb -implicit-check-not=ccc %s 2>&1 | FileCheck %s -check-prefix CHECK-ERROR7
 
 warning: aaa
 ; CHECK-PASS: warning: aaa

diff  --git a/llvm/test/FileCheck/line-count.txt b/llvm/test/FileCheck/line-count.txt
index 9f95ae530054..5d885d8f9787 100644
--- a/llvm/test/FileCheck/line-count.txt
+++ b/llvm/test/FileCheck/line-count.txt
@@ -1,15 +1,15 @@
 ; RUN: FileCheck -input-file %s %s
-; RUN: not FileCheck -check-prefix BAD1 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR1 %s
-; RUN: not FileCheck -check-prefix BAD2 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR2 %s
-; RUN: not FileCheck -check-prefix BAD3 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR3 %s
-; RUN: not FileCheck -check-prefix BAD4 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR4 %s
-; RUN: not FileCheck -check-prefix BAD5 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR5 %s
-; RUN: not FileCheck -check-prefix BAD6 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR6 %s
-; RUN: not FileCheck -check-prefix BAD7 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR7 %s
-; RUN: not FileCheck -check-prefix BAD8 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR8 %s
-; RUN: not FileCheck -check-prefix BAD9 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR9 %s
-; RUN: not FileCheck -check-prefix BAD10 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR10 %s
-; RUN: not FileCheck -check-prefix BAD11 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR11 %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix BAD1 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR1 %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix BAD2 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR2 %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix BAD3 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR3 %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix BAD4 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR4 %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix BAD5 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR5 %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix BAD6 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR6 %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix BAD7 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR7 %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix BAD8 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR8 %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix BAD9 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR9 %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix BAD10 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR10 %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix BAD11 -input-file %s %s 2>&1 | FileCheck -check-prefix ERR11 %s
 13
 14 aaa
 15 bbb
@@ -55,18 +55,19 @@
 55 BAD11: [[@LINE-1x]]
 56 ERR11: line-count.txt:[[#@LINE-1]]:20: error: unexpected characters at end of expression 'x'
 57
+; RUN: %ProtectFileCheckOutput \
 ; RUN: not FileCheck -check-prefix BAD12 -input-file %s %s 2>&1 \
 ; RUN:   | FileCheck -check-prefix ERR12 %s
-60
-61 BAD12: [[#@LINE-1]] NOT HERE
-62 ERR12: note: with "@LINE-1" equal to "60"
-63
-64 CHECK: [[#@LINE]] CHECK
-65 CHECK: [[# @LINE]] CHECK
-66 CHECK: [[# @LINE ]] CHECK
-67
-68 CHECK: [[#@LINE-1]]
-69 CHECK: [[# @LINE-1]] CHECK
-70 CHECK: [[# @LINE -1]] CHECK
-71 CHECK: [[# @LINE - 1]] CHECK
-72 CHECK: [[# @LINE - 1 ]] CHECK
+61
+62 BAD12: [[#@LINE-1]] NOT HERE
+63 ERR12: note: with "@LINE-1" equal to "61"
+64
+65 CHECK: [[#@LINE]] CHECK
+66 CHECK: [[# @LINE]] CHECK
+67 CHECK: [[# @LINE ]] CHECK
+68
+69 CHECK: [[#@LINE-1]]
+70 CHECK: [[# @LINE-1]] CHECK
+71 CHECK: [[# @LINE -1]] CHECK
+72 CHECK: [[# @LINE - 1]] CHECK
+73 CHECK: [[# @LINE - 1 ]] CHECK

diff  --git a/llvm/test/FileCheck/lit.local.cfg b/llvm/test/FileCheck/lit.local.cfg
index 1191450c6553..65aba149e22d 100644
--- a/llvm/test/FileCheck/lit.local.cfg
+++ b/llvm/test/FileCheck/lit.local.cfg
@@ -3,16 +3,54 @@ import lit
 # Use lit's internal shell to help guarantee test portability.
 config.test_format = lit.formats.ShTest(execute_external=False)
 
-# Unset environment variables that the FileCheck tests
-# expect not to be set.
-file_check_expected_unset_vars = [
-  'FILECHECK_DUMP_INPUT_ON_FAILURE',
-  'FILECHECK_OPTS',
-]
-
-for env_var in file_check_expected_unset_vars:
-  if env_var in config.environment:
-    lit_config.note('Removing {} from environment for FileCheck tests'.format(
-      env_var)
-    )
-    config.environment.pop(env_var)
+# %ProtectFileCheckOutput should precede a FileCheck call if and only if the
+# call's textual output affects test results.  It's usually easy to tell: just
+# look for redirection or piping of the FileCheck call's stdout or stderr.
+#
+# Examples:
+#
+#   ; Test another program, using FileCheck to verify its textual output.
+#   ; Only FileCheck's exit status affects test results, so a bare FileCheck
+#   ; call is sufficient and more convenient for debugging.
+#   ;
+#   ; RUN: %t | FileCheck %s
+#   ; CHECK: {{[0-9]+\.0}}
+#
+#   ; Test FileCheck itself, but only examine its exit status, so a bare
+#   ; FileCheck call is still sufficient and more convenient for debugging.
+#   ;
+#   ; RUN: FileCheck -input-file %s %s
+#   ; CHECK: {{[0-9]+\.0}}
+#   ; 5.0
+#
+#   ; Check that the FileCheck trace is off by default.  The first FileCheck
+#   ; call's textual output affects test results, so it requires
+#   ; %ProtectFileCheckOutput to be safe.
+#   ;
+#   ; RUN: %ProtectFileCheckOutput FileCheck -input-file %s %s 2>&1 \
+#   ; RUN: | FileCheck -allow-empty -check-prefix QUIET %s
+#   ;
+#   ; CHECK: {{[0-9]+\.0}}
+#   ; 5.0
+#   ; QUIET-NOT: expected string found in input
+#
+#   ; Check that the FileCheck trace is on when FILECHECK_OPTS=-v.
+#   ; FILECHECK_OPTS must be set after %ProtectFileCheckOutput, which clears
+#   ; FILECHECK_OPTS beforehand.
+#   ;
+#   ; RUN: %ProtectFileCheckOutput FILECHECK_OPTS=-v \
+#   ; RUN: FileCheck -input-file %s %s 2>&1 \
+#   ; RUN: | FileCheck -check-prefix TRACE %s
+#   ;
+#   ; CHECK: {{[0-9]+\.0}}
+#   ; 5.0
+#   ; TRACE: expected string found in input
+#
+# %ProtectFileCheckOutput's purpose is to ensure correct test results when
+# developers set FileCheck environment variables (e.g.,
+# FILECHECK_OPTS=-dump-input=fail) to tweak the output of FileCheck while
+# debugging tests.  If a developer sets values that affect FileCheck's exit
+# status (e.g., FILECHECK_OPTS=-strict-whitespace), he shouldn't be surprised
+# that test results throughout all test suites are affected.
+config.substitutions.append(('%ProtectFileCheckOutput',
+    'env -u FILECHECK_OPTS -u FILECHECK_DUMP_INPUT_ON_FAILURE'))

diff  --git a/llvm/test/FileCheck/match-full-lines.txt b/llvm/test/FileCheck/match-full-lines.txt
index 1d6a965cd3ea..114f628d8bc9 100644
--- a/llvm/test/FileCheck/match-full-lines.txt
+++ b/llvm/test/FileCheck/match-full-lines.txt
@@ -1,7 +1,10 @@
+// RUN: %ProtectFileCheckOutput \
 // RUN: not FileCheck -match-full-lines -input-file %s %s  2>&1 \
 // RUN:   | FileCheck --check-prefix=ERROR --implicit-check-not=error: %s
-// RUN: not FileCheck -match-full-lines -strict-whitespace -input-file %s %s  2>&1 \
-// RUN:   | FileCheck --check-prefix=ERROR-STRICT --check-prefix=ERROR --implicit-check-not=error: %s
+// RUN: %ProtectFileCheckOutput \
+// RUN: not FileCheck -match-full-lines -strict-whitespace -input-file %s %s \
+// RUN: 2>&1 | FileCheck --check-prefix=ERROR-STRICT --check-prefix=ERROR \
+// RUN:                  --implicit-check-not=error: %s
 
 Label 1
 a line

diff  --git a/llvm/test/FileCheck/multiple-missing-prefixes.txt b/llvm/test/FileCheck/multiple-missing-prefixes.txt
index 0acb8f0b3ed4..ed2007e6272e 100644
--- a/llvm/test/FileCheck/multiple-missing-prefixes.txt
+++ b/llvm/test/FileCheck/multiple-missing-prefixes.txt
@@ -1,6 +1,6 @@
 // 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
-// RUN: not FileCheck -check-prefixes=PREFIX1,PREFIX2 -input-file %s %s 2>&1 | FileCheck -strict-whitespace -check-prefixes=CHECK-NONEXISTENT-PREFIX,ALSO-NONEXISTENT %s
+// RUN: %ProtectFileCheckOutput 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
+// RUN: %ProtectFileCheckOutput not FileCheck -check-prefixes=PREFIX1,PREFIX2 -input-file %s %s 2>&1 | FileCheck -strict-whitespace -check-prefixes=CHECK-NONEXISTENT-PREFIX,ALSO-NONEXISTENT %s
 
 foobar
 ; ANOTHER-PREFIX: foobar

diff  --git a/llvm/test/FileCheck/no-check-file.txt b/llvm/test/FileCheck/no-check-file.txt
index e9325d611af4..ccdc3e3666f0 100644
--- a/llvm/test/FileCheck/no-check-file.txt
+++ b/llvm/test/FileCheck/no-check-file.txt
@@ -1,3 +1,3 @@
-; RUN: not FileCheck 2>&1 | FileCheck %s
+; RUN: %ProtectFileCheckOutput not FileCheck 2>&1 | FileCheck %s
 
 CHECK: <check-file> not specified

diff  --git a/llvm/test/FileCheck/no-multi-suffixes.txt b/llvm/test/FileCheck/no-multi-suffixes.txt
index 812a2956cd25..21bcc59a800b 100644
--- a/llvm/test/FileCheck/no-multi-suffixes.txt
+++ b/llvm/test/FileCheck/no-multi-suffixes.txt
@@ -1,9 +1,9 @@
-; RUN: not FileCheck -check-prefix=DAGNOT -input-file %s %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=DAGNOT-ERROR %s
-; RUN: not FileCheck -check-prefix=NOTDAG -input-file %s %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=NOTDAG-ERROR %s
-; RUN: not FileCheck -check-prefix=NEXTNOT -input-file %s %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=NEXTNOT-ERROR %s
-; RUN: not FileCheck -check-prefix=NOTNEXT -input-file %s %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=NOTNEXT-ERROR %s
-; RUN: not FileCheck -check-prefix=SAMENOT -input-file %s %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=SAMENOT-ERROR %s
-; RUN: not FileCheck -check-prefix=NOTSAME -input-file %s %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=NOTSAME-ERROR %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix=DAGNOT -input-file %s %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=DAGNOT-ERROR %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix=NOTDAG -input-file %s %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=NOTDAG-ERROR %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix=NEXTNOT -input-file %s %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=NEXTNOT-ERROR %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix=NOTNEXT -input-file %s %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=NOTNEXT-ERROR %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix=SAMENOT -input-file %s %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=SAMENOT-ERROR %s
+; RUN: %ProtectFileCheckOutput not FileCheck -check-prefix=NOTSAME -input-file %s %s 2>&1 | FileCheck -check-prefix=ERROR -check-prefix=NOTSAME-ERROR %s
 
 foo
 ; DAGNOT: foo

diff  --git a/llvm/test/FileCheck/numeric-defines-diagnostics.txt b/llvm/test/FileCheck/numeric-defines-diagnostics.txt
index c56ed82738e2..ae4a5012bd95 100644
--- a/llvm/test/FileCheck/numeric-defines-diagnostics.txt
+++ b/llvm/test/FileCheck/numeric-defines-diagnostics.txt
@@ -1,6 +1,7 @@
 ; Test incorrect syntax for -D# option is correctly diagnosed.
 
 ; Invalid variable name: starts with a digit.
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck -D#10VALUE=10 --input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --strict-whitespace --match-full-lines --check-prefix NUMERRCLIFMT
 
@@ -9,6 +10,7 @@ NUMERRCLIFMT-NEXT:Global define #1: #10VALUE=10 (parsed as: {{\[\[#10VALUE:10\]\
     NUMERRCLIFMT-NEXT:                                             ^
 
 ; Invalid definition of pseudo variable.
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck -D#@VALUE=10 --input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --strict-whitespace --match-full-lines --check-prefix NUMERRCLIPSEUDO
 
@@ -17,6 +19,7 @@ NUMERRCLIPSEUDO-NEXT:Global define #1: #@VALUE=10 (parsed as: {{\[\[#@VALUE:10\]
     NUMERRCLIPSEUDO-NEXT:                                            ^
 
 ; Invalid definition of an expression.
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck -D#VALUE+2=10 --input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --strict-whitespace --match-full-lines --check-prefix NUMERRCLITRAIL
 

diff  --git a/llvm/test/FileCheck/numeric-defines.txt b/llvm/test/FileCheck/numeric-defines.txt
index 2ace5bad3f25..2cc9f550916c 100644
--- a/llvm/test/FileCheck/numeric-defines.txt
+++ b/llvm/test/FileCheck/numeric-defines.txt
@@ -2,12 +2,20 @@
 ; value and CHECK directives using them match as expected given the value set.
 
 RUN: FileCheck -D#NUMVAL1=8 -D#NUMVAL2='NUMVAL1 + 4' -check-prefixes CHECKNUM1,CHECKNUM2 -input-file %s %s
+
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck -D#NUMVAL1=7 -D#NUMVAL2=12 -check-prefix CHECKNUM1 -input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --strict-whitespace -check-prefix NUMERRMSG1
+
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck -D#NUMVAL1=8 -D#NUMVAL2=8 -check-prefix CHECKNUM2 -input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --strict-whitespace -check-prefix NUMERRMSG2
+
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck -D#NUMVAL1=8 -D#NUMVAL2=8 -check-prefix NUMNOT -input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --strict-whitespace -check-prefixes NOT-NUMERRMSG1
+
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck -D#NUMVAL1=7 -D#NUMVAL2=12 -check-prefix NUMNOT -input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --strict-whitespace -check-prefixes NOT-NUMERRMSG2
 RUN: FileCheck -D#NUMVAL1=7 -D#NUMVAL2=8 -check-prefixes NUMNOT -input-file %s %s

diff  --git a/llvm/test/FileCheck/numeric-expression.txt b/llvm/test/FileCheck/numeric-expression.txt
index 8bbaca0a4acf..01cd281e48f8 100644
--- a/llvm/test/FileCheck/numeric-expression.txt
+++ b/llvm/test/FileCheck/numeric-expression.txt
@@ -97,6 +97,7 @@ foo 104 bar
 ; CHECK-NEXT: foo [[#]] bar
 
 ; Numeric expression using undefined variables.
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck --check-prefix UNDEF-USE --input-file %s %s 2>&1 \
 RUN:   | FileCheck --strict-whitespace --check-prefix UNDEF-USE-MSG %s
 
@@ -115,7 +116,9 @@ UNDEF-USE-MSG-NEXT:      UNDEFVAR: 11
 UNDEF-USE-MSG-NEXT: {{^}}^{{$}}
 
 ; Numeric expression with unsupported operator.
-RUN: not FileCheck -D#NUMVAR=10 --check-prefix INVAL-OP --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput \
+RUN: not FileCheck -D#NUMVAR=10 --check-prefix INVAL-OP \
+RUN:               --input-file %s %s 2>&1 \
 RUN:   | FileCheck --strict-whitespace --check-prefix INVAL-OP-MSG %s
 
 INVALID OPERATOR
@@ -128,17 +131,29 @@ INVAL-OP-MSG-NEXT:     {{^}}                                  ^{{$}}
 
 ; Name conflict between Numeric variable definition and string variable
 ; definition whether from the command-line or input text.
-RUN: not FileCheck --check-prefixes CONFLICT,CONFLICT1,CONFLICT2 --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput \
+RUN: not FileCheck --check-prefixes CONFLICT,CONFLICT1,CONFLICT2 \
+RUN:               --input-file %s %s 2>&1 \
 RUN:   | FileCheck --strict-whitespace --check-prefix INPUT-STR-CONFLICT %s
-RUN: not FileCheck -D#NUMVAR=42 --check-prefixes CONFLICT,CONFLICT2 --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput \
+RUN: not FileCheck -D#NUMVAR=42 --check-prefixes CONFLICT,CONFLICT2 \
+RUN:               --input-file %s %s 2>&1 \
 RUN:   | FileCheck --strict-whitespace --check-prefix INPUT-STR-CONFLICT %s
-RUN: not FileCheck -D#NUMVAR=42 -DNUMVAR=foobar --check-prefix CONFLICT --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput \
+RUN: not FileCheck -D#NUMVAR=42 -DNUMVAR=foobar --check-prefix CONFLICT \
+RUN:               --input-file %s %s 2>&1 \
 RUN:   | FileCheck --strict-whitespace --check-prefix CLI-STR-CONFLICT %s
-RUN: not FileCheck --check-prefixes CONFLICT,CONFLICT3,CONFLICT4 --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput \
+RUN: not FileCheck --check-prefixes CONFLICT,CONFLICT3,CONFLICT4 \
+RUN:               --input-file %s %s 2>&1 \
 RUN:   | FileCheck --strict-whitespace --check-prefix INPUT-NUM-CONFLICT %s
-RUN: not FileCheck -DSTRVAR=foobar --check-prefixes CONFLICT,CONFLICT4 --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput \
+RUN: not FileCheck -DSTRVAR=foobar --check-prefixes CONFLICT,CONFLICT4 \
+RUN:               --input-file %s %s 2>&1 \
 RUN:   | FileCheck --strict-whitespace --check-prefix INPUT-NUM-CONFLICT %s
-RUN: not FileCheck -DSTRVAR=foobar -D#STRVAR=42 --check-prefix CONFLICT --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput \
+RUN: not FileCheck -DSTRVAR=foobar -D#STRVAR=42 --check-prefix CONFLICT \
+RUN:               --input-file %s %s 2>&1 \
 RUN:   | FileCheck --strict-whitespace --check-prefix CLI-NUM-CONFLICT %s
 
 STRVAR NUMVAR CONFLICT
@@ -164,6 +179,7 @@ CLI-NUM-CONFLICT: Global defines:2:45: error: string variable with name 'STRVAR'
 CLI-NUM-CONFLICT-NEXT: {{^}}                                            ^{{$}}
 
 ; Numeric variable definition with too big value.
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck --check-prefix BIGVAL --input-file %s %s 2>&1 \
 RUN:   | FileCheck --strict-whitespace --check-prefix BIGVAL-MSG %s
 
@@ -177,6 +193,7 @@ BIGVAL-MSG-NEXT: {{^}}        ^{{$}}
 
 ; Verify that when a variable is set to an expression the expression is still
 ; checked.
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck --check-prefix DEF-EXPR-FAIL --input-file %s %s 2>&1 \
 RUN:   | FileCheck --strict-whitespace --check-prefix DEF-EXPR-FAIL-MSG %s
 
@@ -192,8 +209,10 @@ DEF-EXPR-FAIL-MSG-NEXT:   {{^}}                    ^{{$}}
 
 ; Verify that using a numeric variable defined on the same line (whether from
 ; input or from an expression) is rejected.
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck --check-prefix SAME-LINE-USE1 --input-file %s %s 2>&1 \
 RUN:   | FileCheck --strict-whitespace --check-prefix SAME-LINE-USE-MSG1 %s
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck --check-prefix SAME-LINE-USE2 --input-file %s %s 2>&1 \
 RUN:   | FileCheck --strict-whitespace --check-prefix SAME-LINE-USE-MSG2 %s
 

diff  --git a/llvm/test/FileCheck/opt-color.txt b/llvm/test/FileCheck/opt-color.txt
index 9430114bf31e..b12fa768881f 100644
--- a/llvm/test/FileCheck/opt-color.txt
+++ b/llvm/test/FileCheck/opt-color.txt
@@ -4,8 +4,8 @@
 
 ; Run without and with -color.  In the former case, FileCheck should suppress
 ; color in its diagnostics because stderr is a file.
-; RUN: not FileCheck %s < %t.in 2> %t.no-color
-; RUN: not FileCheck -color %s < %t.in 2> %t.color
+; RUN: %ProtectFileCheckOutput not FileCheck %s < %t.in 2> %t.no-color
+; RUN: %ProtectFileCheckOutput not FileCheck -color %s < %t.in 2> %t.color
 
 ; Check whether color was produced.
 ; RUN: FileCheck -check-prefix NO-COLOR %s < %t.no-color

diff  --git a/llvm/test/FileCheck/string-defines-diagnostics.txt b/llvm/test/FileCheck/string-defines-diagnostics.txt
index cc944e0fcee9..b975c3880eb3 100644
--- a/llvm/test/FileCheck/string-defines-diagnostics.txt
+++ b/llvm/test/FileCheck/string-defines-diagnostics.txt
@@ -1,30 +1,31 @@
 ; Test incorrect syntax for -D option is correctly diagnosed.
 
 ; Missing equal sign.
-RUN: not FileCheck -DVALUE10 --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput not FileCheck -DVALUE10 --input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --check-prefix ERRCLIEQ1
 
 ERRCLIEQ1: Missing equal sign in command-line definition '-DVALUE10'
 
 ; Missing definition expression (variable name, equal sign and value).
-RUN: not FileCheck -D --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput not FileCheck -D --input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --check-prefix ERRCLIEQ2
 
 ERRCLIEQ2: {{F|f}}ile{{C|c}}heck{{[^:]*}}: for the -D option: requires a value!
 
 ; Missing variable name.
-RUN: not FileCheck -D=10 --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput not FileCheck -D=10 --input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --check-prefix ERRCLIVAR1
 
 ERRCLIVAR1: Missing variable name in command-line definition '-D=10'
 
 ; Missing variable name.
-RUN: not FileCheck -D= --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput not FileCheck -D= --input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --check-prefix ERRCLIVAR2
 
 ERRCLIVAR2: Missing variable name in command-line definition '-D='
 
 ; Invalid variable name: starts with a digit.
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck -D10VALUE=10 --input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --strict-whitespace --match-full-lines --check-prefix ERRCLIFMT
 
@@ -33,6 +34,7 @@ ERRCLIFMT-NEXT:Global define #1: 10VALUE=10
 ERRCLIFMT-NEXT:                  ^
 
 ; Invalid definition of pseudo variable.
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck -D at VALUE=10 --input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --strict-whitespace --match-full-lines --check-prefix ERRCLIPSEUDO
 
@@ -41,6 +43,7 @@ ERRCLIPSEUDO-NEXT:Global define #1: @VALUE=10
 ERRCLIPSEUDO-NEXT:                  ^
 
 ; Invalid definition of an expression.
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck -D'VALUE + 2=10' --input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --strict-whitespace --check-prefix ERRCLITRAIL
 

diff  --git a/llvm/test/FileCheck/string-defines.txt b/llvm/test/FileCheck/string-defines.txt
index a8514741ddd8..f48392c2b6a0 100644
--- a/llvm/test/FileCheck/string-defines.txt
+++ b/llvm/test/FileCheck/string-defines.txt
@@ -3,8 +3,9 @@
 
 ; String variable correctly defined to a non-empty string.
 RUN: FileCheck -DVALUE=10 --input-file %s %s
-RUN: not FileCheck -DVALUE=20 --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput not FileCheck -DVALUE=20 --input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --check-prefix ERRMSG
+RUN: %ProtectFileCheckOutput \
 RUN: not FileCheck -DVALUE=10 --check-prefix NOT --input-file %s %s 2>&1 \
 RUN:   | FileCheck %s --check-prefix NOT-ERRMSG
 RUN: FileCheck -DVALUE=20 --check-prefix NOT --input-file %s %s

diff  --git a/llvm/test/FileCheck/validate-check-prefix.txt b/llvm/test/FileCheck/validate-check-prefix.txt
index 6efec440d0bc..de6f126fd786 100644
--- a/llvm/test/FileCheck/validate-check-prefix.txt
+++ b/llvm/test/FileCheck/validate-check-prefix.txt
@@ -1,8 +1,8 @@
-// RUN: not FileCheck -check-prefix=A! -input-file %s %s 2>&1 | FileCheck -check-prefix=BAD_PREFIX %s
+// RUN: %ProtectFileCheckOutput 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
-// RUN: not FileCheck -check-prefix= -input-file %s %s 2>&1 | FileCheck -check-prefix=BAD_PREFIX %s
+// RUN: %ProtectFileCheckOutput not FileCheck -check-prefix=REPEAT -check-prefix=REPEAT -input-file %s %s 2>&1 | FileCheck -check-prefix=BAD_PREFIX %s
+// RUN: %ProtectFileCheckOutput not FileCheck -check-prefix=VALID -check-prefix=A! -input-file %s %s 2>&1 | FileCheck -check-prefix=BAD_PREFIX %s
+// RUN: %ProtectFileCheckOutput not FileCheck -check-prefix= -input-file %s %s 2>&1 | FileCheck -check-prefix=BAD_PREFIX %s
 foobar
 ; A1a-B_c: foobar
 

diff  --git a/llvm/test/FileCheck/var-scope.txt b/llvm/test/FileCheck/var-scope.txt
index 3fa8a73e157d..e45610b138ef 100644
--- a/llvm/test/FileCheck/var-scope.txt
+++ b/llvm/test/FileCheck/var-scope.txt
@@ -6,11 +6,11 @@
 RUN: FileCheck --check-prefixes CHECK,LOCAL3,GLOBAL --input-file %s %s
 
 RUN: FileCheck --check-prefixes CHECK,GLOBAL --enable-var-scope --input-file %s %s
-RUN: not FileCheck --check-prefixes CHECK,LOCAL1 --enable-var-scope --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput not FileCheck --check-prefixes CHECK,LOCAL1 --enable-var-scope --input-file %s %s 2>&1 \
 RUN:   | FileCheck --check-prefixes ERRUNDEF,ERRUNDEFLOCAL %s
-RUN: not FileCheck --check-prefixes CHECK,LOCAL2 --enable-var-scope --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput not FileCheck --check-prefixes CHECK,LOCAL2 --enable-var-scope --input-file %s %s 2>&1 \
 RUN:   | FileCheck --check-prefixes ERRUNDEF,ERRUNDEFLOCNUM %s
-RUN: not FileCheck --check-prefixes CHECK,LOCAL3 --enable-var-scope --input-file %s %s 2>&1 \
+RUN: %ProtectFileCheckOutput not FileCheck --check-prefixes CHECK,LOCAL3 --enable-var-scope --input-file %s %s 2>&1 \
 RUN:   | FileCheck --check-prefixes ERRUNDEF,ERRUNDEFLOCAL,ERRUNDEFLOCNUM %s
 
 local1

diff  --git a/llvm/test/FileCheck/verbose.txt b/llvm/test/FileCheck/verbose.txt
index 2594eabdbde2..66c4b1efbe06 100644
--- a/llvm/test/FileCheck/verbose.txt
+++ b/llvm/test/FileCheck/verbose.txt
@@ -1,6 +1,9 @@
-; RUN: FileCheck -input-file %s %s 2>&1 | FileCheck -check-prefix QUIET --allow-empty %s
-; RUN: FileCheck -v -input-file %s %s 2>&1 | FileCheck --strict-whitespace -check-prefix V %s
-; RUN: FileCheck -vv -input-file %s %s 2>&1 | FileCheck --strict-whitespace -check-prefixes V,VV %s
+; RUN: %ProtectFileCheckOutput FileCheck -input-file %s %s 2>&1 \
+; RUN: | FileCheck -check-prefix QUIET --allow-empty %s
+; RUN: %ProtectFileCheckOutput FileCheck -v -input-file %s %s 2>&1 \
+; RUN: | FileCheck --strict-whitespace -check-prefix V %s
+; RUN: %ProtectFileCheckOutput FileCheck -vv -input-file %s %s 2>&1 \
+; RUN: | FileCheck --strict-whitespace -check-prefixes V,VV %s
 
 foo
 bar


        


More information about the llvm-commits mailing list