llvm.org GIT mirror llvm / 5b06a93
Add -match-full-lines argument to FileCheck. This is useful for some tests where more-exact matching is useful, such as clang's Preprocessor tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260540 91177308-0d34-0410-b5e6-96231b3b80d8 James Y Knight 3 years ago
2 changed file(s) with 44 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
4040 .. option:: --input-file filename
4141
4242 File to check (defaults to stdin).
43
44 .. option:: --match-full-lines
45
46 By default, FileCheck allows matches of anywhere on a line. This
47 option will require all positive matches to cover an entire
48 line. Leading and trailing whitespace is ignored, unless
49 :option:`--strict-whitespace` is also specified. (Note: negative
50 matches from ``CHECK-NOT`` are not affected by this option!)
51
52 Passing this option is equivalent to inserting ``{{^ *}}`` or
53 ``{{^}}`` before, and ``{{ *$}}`` or ``{{$}}`` after every positive
54 check pattern.
4355
4456 .. option:: --strict-whitespace
4557
6161 cl::desc("Allow the input file to be empty. This is useful when making\n"
6262 "checks that some error message does not occur, for example."));
6363
64 static cl::opt MatchFullLines(
65 "match-full-lines", cl::init(false),
66 cl::desc("Require all positive matches to cover an entire input line.\n"
67 "Allows leading and trailing whitespace if --strict-whitespace\n"
68 "is not also passed."));
69
6470 typedef cl::list::const_iterator prefix_iterator;
6571
6672 //===----------------------------------------------------------------------===//
173179 StringRef Prefix,
174180 SourceMgr &SM,
175181 unsigned LineNumber) {
182 bool MatchFullLinesHere = MatchFullLines && CheckTy != Check::CheckNot;
183
176184 this->LineNumber = LineNumber;
177185 PatternLoc = SMLoc::getFromPointer(PatternStr.data());
178186
190198 }
191199
192200 // Check to see if this is a fixed string, or if it has regex pieces.
193 if (PatternStr.size() < 2 ||
194 (PatternStr.find("{{") == StringRef::npos &&
195 PatternStr.find("[[") == StringRef::npos)) {
201 if (!MatchFullLinesHere &&
202 (PatternStr.size() < 2 || (PatternStr.find("{{") == StringRef::npos &&
203 PatternStr.find("[[") == StringRef::npos))) {
196204 FixedStr = PatternStr;
197205 return false;
206 }
207
208 if (MatchFullLinesHere) {
209 RegExStr += '^';
210 if (!NoCanonicalizeWhiteSpace)
211 RegExStr += " *";
198212 }
199213
200214 // Paren value #0 is for the fully matched string. Any new parenthesized
326340 FixedMatchEnd = std::min(FixedMatchEnd, PatternStr.find("[["));
327341 RegExStr += Regex::escape(PatternStr.substr(0, FixedMatchEnd));
328342 PatternStr = PatternStr.substr(FixedMatchEnd);
343 }
344
345 if (MatchFullLinesHere) {
346 if (!NoCanonicalizeWhiteSpace)
347 RegExStr += " *";
348 RegExStr += '$';
329349 }
330350
331351 return false;
597617
598618 /// CheckTy - Specify what kind of check this is. e.g. CHECK-NEXT: directive,
599619 /// as opposed to a CHECK: directive.
600 Check::CheckType CheckTy;
620 // Check::CheckType CheckTy;
601621
602622 /// DagNotStrings - These are all of the strings that are disallowed from
603623 /// occurring between this match string and the previous one (or start of
604624 /// file).
605625 std::vector DagNotStrings;
606626
607
608 CheckString(const Pattern &P,
609 StringRef S,
610 SMLoc L,
611 Check::CheckType Ty)
612 : Pat(P), Prefix(S), Loc(L), CheckTy(Ty) {}
627 CheckString(const Pattern &P, StringRef S, SMLoc L)
628 : Pat(P), Prefix(S), Loc(L) {}
613629
614630 /// Check - Match check string and its "not strings" and/or "dag strings".
615631 size_t Check(const SourceMgr &SM, StringRef Buffer, bool IsLabelScanMode,
941957 }
942958
943959 // Okay, add the string we captured to the output vector and move on.
944 CheckStrings.emplace_back(P, UsedPrefix, PatternLoc, CheckTy);
960 CheckStrings.emplace_back(P, UsedPrefix, PatternLoc);
945961 std::swap(DagNotMatches, CheckStrings.back().DagNotStrings);
946962 DagNotMatches = ImplicitNegativeChecks;
947963 }
950966 // prefix as a filler for the error message.
951967 if (!DagNotMatches.empty()) {
952968 CheckStrings.emplace_back(Pattern(Check::CheckEOF), *CheckPrefixes.begin(),
953 SMLoc::getFromPointer(Buffer.data()),
954 Check::CheckEOF);
969 SMLoc::getFromPointer(Buffer.data()));
955970 std::swap(DagNotMatches, CheckStrings.back().DagNotStrings);
956971 }
957972
964979 errs() << "\'" << *I << ":'";
965980 ++I;
966981 }
967 for (; I != E; ++I)
982 for (; I != E; ++I)
968983 errs() << ", \'" << *I << ":'";
969984
970985 errs() << '\n';
10721087 }
10731088
10741089 bool CheckString::CheckNext(const SourceMgr &SM, StringRef Buffer) const {
1075 if (CheckTy != Check::CheckNext)
1090 if (Pat.getCheckTy() != Check::CheckNext)
10761091 return false;
10771092
10781093 // Count the number of newlines between the previous match and this one.
11111126 }
11121127
11131128 bool CheckString::CheckSame(const SourceMgr &SM, StringRef Buffer) const {
1114 if (CheckTy != Check::CheckSame)
1129 if (Pat.getCheckTy() != Check::CheckSame)
11151130 return false;
11161131
11171132 // Count the number of newlines between the previous match and this one.
13251340 CheckRegion = Buffer;
13261341 } else {
13271342 const CheckString &CheckLabelStr = CheckStrings[j];
1328 if (CheckLabelStr.CheckTy != Check::CheckLabel) {
1343 if (CheckLabelStr.Pat.getCheckTy() != Check::CheckLabel) {
13291344 ++j;
13301345 continue;
13311346 }