[PATCH] D49328: [FileCheck] Provide an option for FileCheck to dump original input to stderr on failure

George Karpenkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 20 13:27:17 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL337609: [FileCheck] Provide an option for FileCheck to dump original input to stderr on… (authored by george.karpenkov, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D49328?vs=156578&id=156589#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D49328

Files:
  llvm/trunk/docs/CommandGuide/FileCheck.rst
  llvm/trunk/test/FileCheck/verbose_mode.txt
  llvm/trunk/utils/FileCheck/FileCheck.cpp
  llvm/trunk/utils/lit/lit/TestingConfig.py


Index: llvm/trunk/utils/lit/lit/TestingConfig.py
===================================================================
--- llvm/trunk/utils/lit/lit/TestingConfig.py
+++ llvm/trunk/utils/lit/lit/TestingConfig.py
@@ -25,7 +25,8 @@
                      'CLANG', 'LD_PRELOAD', 'ASAN_OPTIONS', 'UBSAN_OPTIONS',
                      'LSAN_OPTIONS', 'ADB', 'ANDROID_SERIAL',
                      'SANITIZER_IGNORE_CVE_2016_2143', 'TMPDIR', 'TMP', 'TEMP',
-                     'TEMPDIR', 'AVRLIT_BOARD', 'AVRLIT_PORT']
+                     'TEMPDIR', 'AVRLIT_BOARD', 'AVRLIT_PORT',
+                     'FILECHECK_DUMP_INPUT_ON_FAILURE']
         for var in pass_vars:
             val = os.environ.get(var, '')
             # Check for empty string as some variables such as LD_PRELOAD cannot be empty
Index: llvm/trunk/utils/FileCheck/FileCheck.cpp
===================================================================
--- llvm/trunk/utils/FileCheck/FileCheck.cpp
+++ llvm/trunk/utils/FileCheck/FileCheck.cpp
@@ -97,6 +97,13 @@
     "vv", cl::init(false),
     cl::desc("Print information helpful in diagnosing internal FileCheck\n"
              "issues.  Implies -v.\n"));
+static const char * DumpInputEnv = "FILECHECK_DUMP_INPUT_ON_FAILURE";
+
+static cl::opt<bool> DumpInputOnFailure(
+    "dump-input-on-failure", cl::init(std::getenv(DumpInputEnv)),
+    cl::desc("Dump original input to stderr before failing.\n"
+             "The value can be also controlled using\n"
+             "FILECHECK_DUMP_INPUT_ON_FAILURE environment variable.\n"));
 
 typedef cl::list<std::string>::const_iterator prefix_iterator;
 
@@ -1605,5 +1612,9 @@
                             InputFileText, InputFile.getBufferIdentifier()),
                         SMLoc());
 
-  return CheckInput(SM, InputFileText, CheckStrings) ? EXIT_SUCCESS : 1;
+  int ExitCode = CheckInput(SM, InputFileText, CheckStrings) ? EXIT_SUCCESS : 1;
+  if (ExitCode == 1 && DumpInputOnFailure)
+    errs() << "Full input was:\n<<<<<<\n" << InputFileText << "\n>>>>>>\n";
+
+  return ExitCode;
 }
Index: llvm/trunk/docs/CommandGuide/FileCheck.rst
===================================================================
--- llvm/trunk/docs/CommandGuide/FileCheck.rst
+++ llvm/trunk/docs/CommandGuide/FileCheck.rst
@@ -77,6 +77,10 @@
   -verify``. With this option FileCheck will verify that input does not contain
   warnings not covered by any ``CHECK:`` patterns.
 
+.. option:: --dump-input-on-failure
+
+  When the check fails, dump all of the original input.
+
 .. option:: --enable-var-scope
 
   Enables scope for regex variables.
Index: llvm/trunk/test/FileCheck/verbose_mode.txt
===================================================================
--- llvm/trunk/test/FileCheck/verbose_mode.txt
+++ llvm/trunk/test/FileCheck/verbose_mode.txt
@@ -0,0 +1,17 @@
+; RUN: not FileCheck -input-file %s %s --check-prefix=CHECK1 --match-full-lines --dump-input-on-failure 2>&1 | FileCheck %s --check-prefix=CHECKERROR --match-full-lines
+; RUN: env FILECHECK_DUMP_INPUT_ON_FAILURE=1 not FileCheck -input-file %s %s --check-prefix=CHECK1 --match-full-lines 2>&1 |  FileCheck %s --check-prefix=CHECKERROR --match-full-lines
+; RUN: env FILECHECK_DUMP_INPUT_ON_FAILURE=1 not FileCheck -input-file %s %s --check-prefix=CHECK1 --match-full-lines --dump-input-on-failure=0 2>&1 |  FileCheck %s --check-prefix=CHECKERRORNOVERBOSE --match-full-lines
+
+hello
+world
+
+; CHECK1: ciao
+; CHECK1-NEXT: world
+
+; CHECKERROR: Full input was:
+; CHECKERROR-NEXT: <<<<<<
+; CHECKERROR: hello
+; CHECKERROR: world
+; CHECKERROR: >>>>>>
+
+; CHECKERRORNOVERBOSE-NOT: <<<<<<


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49328.156589.patch
Type: text/x-patch
Size: 3613 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180720/96ada323/attachment-0001.bin>


More information about the llvm-commits mailing list