llvm.org GIT mirror llvm / 7c37aa1
Add a -D flag to FileCheck to define variables Summary: This makes it very easy to test files that only differ in a constant value somewhere in the test case. Reviewers: jlebar, hfinkel, chandlerc, probinson Reviewed By: probinson Subscribers: probinson, llvm-commits Differential Revision: https://reviews.llvm.org/D39629 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317572 91177308-0d34-0410-b5e6-96231b3b80d8 Alexander Richardson 1 year, 9 months ago
3 changed file(s) with 21 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
8484 remain set throughout the file.
8585
8686 All other variables get undefined after each encountered ``CHECK-LABEL``.
87
88 .. option:: -D
89
90 Sets a filecheck variable ``VAR`` with value ``VALUE`` that can be used in
91 ``CHECK:`` lines.
8792
8893 .. option:: -version
8994
0 ; RUN: FileCheck -DVALUE=10 -input-file %s %s
1 ; RUN: not FileCheck -DVALUE=20 -input-file %s %s 2>&1 | FileCheck %s -check-prefix ERRMSG
2
3 Value = 10
4 ; CHECK: Value = [[VALUE]]
5
6 ; ERRMSG: defines.txt:5:10: error: expected string not found in input
7 ; ERRMSG: defines.txt:1:1: note: with variable "VALUE" equal to "20"
8 ; ERRMSG: defines.txt:4:1: note: possible intended match here
6060 "positive check. This can be used to ensure that no instances of\n"
6161 "this pattern occur which are not matched by a positive pattern"),
6262 cl::value_desc("pattern"));
63
64 static cl::list GlobalDefines("D", cl::Prefix,
65 cl::desc("Define a variable to be used in capture patterns."),
66 cl::value_desc("VAR=VALUE"));
6367
6468 static cl::opt AllowEmptyInput(
6569 "allow-empty", cl::init(false),
12941298 /// VariableTable - This holds all the current filecheck variables.
12951299 StringMap VariableTable;
12961300
1301 for (const auto& Def : GlobalDefines)
1302 VariableTable.insert(StringRef(Def).split('='));
1303
12971304 unsigned i = 0, j = 0, e = CheckStrings.size();
12981305 while (true) {
12991306 StringRef CheckRegion;