llvm.org GIT mirror llvm / b7c9534
FileCheck: Add a flag to allow checking empty input Currently FileCheck errors out on empty input. This is usually the right thing to do, but makes testing things like "this command does not emit some error message" hard to test. This usually leads to people using "command 2>&1 | count 0" instead, and then the bots that use guard malloc fail a few hours later. By adding a flag to FileCheck that allows empty inputs, we can make tests that consist entirely of "CHECK-NOT" lines feasible. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215127 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Bogner 5 years ago
2 changed file(s) with 17 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
0 // RUN: not FileCheck -check-prefix=FOO %s &1 | FileCheck -check-prefix=EMPTY-ERR %s
1 // RUN: not FileCheck -check-prefix=NOFOO %s &1 | FileCheck -check-prefix=EMPTY-ERR %s
2 // RUN: not FileCheck -check-prefix=FOO -allow-empty %s &1 | FileCheck -check-prefix=NO-EMPTY-ERR -check-prefix=NOT-FOUND %s
3 // RUN: FileCheck -check-prefix=NOFOO -allow-empty %s &1 | FileCheck -allow-empty -check-prefix=NO-EMPTY-ERR %s
4
5 ; FOO: foo
6 ; NOFOO-NOT: foo
7
8 ; EMPTY-ERR: FileCheck error: '-' is empty.
9 ; NO-EMPTY-ERR-NOT: FileCheck error: '-' is empty.
10 ; NOT-FOUND: error: expected string not found in input
5555 "positive check. This can be used to ensure that no instances of\n"
5656 "this pattern occur which are not matched by a positive pattern"),
5757 cl::value_desc("pattern"));
58
59 static cl::opt AllowEmptyInput(
60 "allow-empty", cl::init(false),
61 cl::desc("Allow the input file to be empty. This is useful when making\n"
62 "checks that some error message does not occur, for example."));
5863
5964 typedef cl::list::const_iterator prefix_iterator;
6065
12591264 }
12601265 std::unique_ptr &File = FileOrErr.get();
12611266
1262 if (File->getBufferSize() == 0) {
1267 if (File->getBufferSize() == 0 && !AllowEmptyInput) {
12631268 errs() << "FileCheck error: '" << InputFilename << "' is empty.\n";
12641269 return 2;
12651270 }