[PATCH] D73793: Improve error message of FileCheck when stdin is empty

Dave Bozier via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 31 09:59:01 PST 2020


davidb created this revision.
Herald added subscribers: llvm-commits, thopre.
Herald added a project: LLVM.
davidb added reviewers: jhenderson, probinson, jdenny, grimar, arichardson.
davidb marked an inline comment as done.
davidb added inline comments.


================
Comment at: llvm/utils/FileCheck/FileCheck.cpp:619
+      MemoryBuffer::getFileOrSTDIN(
+          (InputFilename == "<stdin>" ? "-" : InputFilename.getValue()));
   if (std::error_code EC = InputFileOrErr.getError()) {
----------------
I found it the least intrusive and confusing to change the InputFilename of stdin here, than in the other 3 places that the InputFilename is printed.


Replace '-' in the error message with <stdin>. This is also consistent with another error message in the code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73793

Files:
  llvm/test/FileCheck/check-empty.txt
  llvm/utils/FileCheck/FileCheck.cpp


Index: llvm/utils/FileCheck/FileCheck.cpp
===================================================================
--- llvm/utils/FileCheck/FileCheck.cpp
+++ llvm/utils/FileCheck/FileCheck.cpp
@@ -33,7 +33,7 @@
 
 static cl::opt<std::string>
     InputFilename("input-file", cl::desc("File to check (defaults to stdin)"),
-                  cl::init("-"), cl::value_desc("filename"));
+                  cl::init("<stdin>"), cl::value_desc("filename"));
 
 static cl::list<std::string> CheckPrefixes(
     "check-prefix",
@@ -615,7 +615,8 @@
 
   // Open the file to check and add it to SourceMgr.
   ErrorOr<std::unique_ptr<MemoryBuffer>> InputFileOrErr =
-      MemoryBuffer::getFileOrSTDIN(InputFilename);
+      MemoryBuffer::getFileOrSTDIN(
+          (InputFilename == "<stdin>" ? "-" : InputFilename.getValue()));
   if (std::error_code EC = InputFileOrErr.getError()) {
     errs() << "Could not open input file '" << InputFilename
            << "': " << EC.message() << '\n';
@@ -648,7 +649,7 @@
       (ExitCode == 1 && DumpInput == DumpInputFail)) {
     errs() << "\n"
            << "Input file: "
-           << (InputFilename == "-" ? "<stdin>" : InputFilename.getValue())
+           << InputFilename
            << "\n"
            << "Check file: " << CheckFilename << "\n"
            << "\n"
Index: llvm/test/FileCheck/check-empty.txt
===================================================================
--- llvm/test/FileCheck/check-empty.txt
+++ llvm/test/FileCheck/check-empty.txt
@@ -17,7 +17,7 @@
 ; FOO: foo
 ; NOFOO-NOT: foo
 
-; EMPTY-ERR: FileCheck error: '-' is empty.
+; EMPTY-ERR: FileCheck error: '<stdin>' is empty.
 ; EMPTY-ERR-NEXT: FileCheck command line: {{.*}}{{F|f}}ile{{C|c}}heck{{.*}}-check-prefix={{.*}}FOO {{.*}}check-empty.txt
-; NO-EMPTY-ERR-NOT: FileCheck error: '-' is empty.
+; NO-EMPTY-ERR-NOT: FileCheck error: '<stdin>' is empty.
 ; NOT-FOUND: error: FOO: expected string not found in input


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73793.241760.patch
Type: text/x-patch
Size: 1938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200131/5c872582/attachment.bin>


More information about the llvm-commits mailing list