]> granicus.if.org Git - llvm/commitdiff
[FileCheck] Annotate input dump (7/7)
authorJoel E. Denny <jdenny.ornl@gmail.com>
Tue, 18 Dec 2018 00:03:36 +0000 (00:03 +0000)
committerJoel E. Denny <jdenny.ornl@gmail.com>
Tue, 18 Dec 2018 00:03:36 +0000 (00:03 +0000)
This patch implements annotations for diagnostics reporting CHECK-NOT
failed matches.  These diagnostics are enabled by -vv.  As for
diagnostics reporting failed matches for other directives, these
annotations mark the search ranges using `X~~`.  The difference here
is that failed matches for CHECK-NOT are successes not errors, so they
are green not red when colors are enabled.

For example:

```
$ FileCheck -dump-input=help
The following description was requested by -dump-input=help to
explain the input annotations printed by -dump-input=always and
-dump-input=fail:

  - L:     labels line number L of the input file
  - T:L    labels the only match result for a pattern of type T from line L of
           the check file
  - T:L'N  labels the Nth match result for a pattern of type T from line L of
           the check file
  - ^~~    marks good match (reported if -v)
  - !~~    marks bad match, such as:
           - CHECK-NEXT on same line as previous match (error)
           - CHECK-NOT found (error)
           - CHECK-DAG overlapping match (discarded, reported if -vv)
  - X~~    marks search range when no match is found, such as:
           - CHECK-NEXT not found (error)
           - CHECK-NOT not found (success, reported if -vv)
           - CHECK-DAG not found after discarded matches (error)
  - ?      marks fuzzy match when no match is found
  - colors success, error, fuzzy match, discarded match, unmatched input

If you are not seeing color above or in input dumps, try: -color

$ FileCheck -vv -dump-input=always check5 < input5 |& sed -n '/^<<<</,$p'
<<<<<<
         1: abcdef
check:1     ^~~
not:2          X~~
         2: ghijkl
not:2       ~~~
check:3        ^~~
         3: mnopqr
not:4       X~~~~~
         4: stuvwx
not:4       ~~~~~~
         5:
eof:4       ^
>>>>>>

$ cat check5
CHECK: abc
CHECK-NOT: foobar
CHECK: jkl
CHECK-NOT: foobar

$ cat input5
abcdef
ghijkl
mnopqr
stuvwx
```

Reviewed By: george.karpenkov, probinson

Differential Revision: https://reviews.llvm.org/D53899

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349424 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/FileCheck.h
lib/Support/FileCheck.cpp
test/FileCheck/dump-input-annotations.txt
utils/FileCheck/FileCheck.cpp

index c79e9cb683ed1fd12b9b953bd1dc64fe933e63bc..edc5424bd217b2c51f4c27df4fd5f6f59fbb1038 100644 (file)
@@ -173,14 +173,15 @@ struct FileCheckDiag {
     MatchFinalButWrongLine,
     /// Indicates a discarded match for an expected pattern.
     MatchDiscard,
+    /// Indicates no match for an excluded pattern.
+    MatchNoneAndExcluded,
     /// Indicates no match for an expected pattern.
     MatchNoneButExpected,
     /// Indicates a possible intended match because there's no perfect match.
     MatchFuzzy,
-    MatchTypeCount,
   } MatchTy;
-  /// The match range if MatchTy is not MatchNoneButExpected, or the search
-  /// range otherwise.
+  /// The match range if MatchTy is not MatchNoneAndExcluded or
+  /// MatchNoneButExpected, or the search range otherwise.
   unsigned InputStartLine, InputStartCol, InputEndLine, InputEndCol;
   FileCheckDiag(const SourceMgr &SM, const Check::FileCheckType &CheckTy,
                 SMLoc CheckLoc, MatchType MatchTy, SMRange InputRange);
index 52da7e9865d65cf253f61e81b2da2314ef6355f1..cf377bd92e2b63af09789173c208efad5accbb82 100644 (file)
@@ -421,9 +421,7 @@ static SMRange ProcessMatchResult(FileCheckDiag::MatchType MatchTy,
   SMLoc Start = SMLoc::getFromPointer(Buffer.data() + Pos);
   SMLoc End = SMLoc::getFromPointer(Buffer.data() + Pos + Len);
   SMRange Range(Start, End);
-  // TODO: The second condition will disappear when we extend this to handle
-  // more match types.
-  if (Diags && MatchTy != FileCheckDiag::MatchTypeCount) {
+  if (Diags) {
     if (AdjustPrevDiag)
       Diags->rbegin()->MatchTy = MatchTy;
     else
@@ -962,12 +960,13 @@ static void PrintNoMatch(bool ExpectedMatch, const SourceMgr &SM,
   Buffer = Buffer.substr(Buffer.find_first_not_of(" \t\n\r"));
   SMRange SearchRange = ProcessMatchResult(
       ExpectedMatch ? FileCheckDiag::MatchNoneButExpected
-                    : FileCheckDiag::MatchTypeCount,
+                    : FileCheckDiag::MatchNoneAndExcluded,
       SM, Loc, Pat.getCheckTy(), Buffer, 0, Buffer.size(), Diags);
   SM.PrintMessage(SearchRange.Start, SourceMgr::DK_Note, "scanning from here");
 
   // Allow the pattern to print additional information if desired.
   Pat.PrintVariableUses(SM, Buffer, VariableTable);
+
   if (ExpectedMatch)
     Pat.PrintFuzzyMatch(SM, Buffer, VariableTable, Diags);
 }
@@ -1176,7 +1175,7 @@ bool FileCheckString::CheckNot(
 
     if (Pos == StringRef::npos) {
       PrintNoMatch(false, SM, Prefix, Pat->getLoc(), *Pat, 1, Buffer,
-                   VariableTable, Req.VerboseVerbose, nullptr);
+                   VariableTable, Req.VerboseVerbose, Diags);
       continue;
     }
 
index 205988098516b452caca81c806149cfa48cda0ba..3dc7f908aa2c02045d8c3b7b597667bd8b987a55 100644 (file)
 ; EMP2-NOT:    {{.}}
 
 ;--------------------------------------------------
-; CHECK-NOT (also: EOF pattern)
+; CHECK-NOT (also: EOF pattern, and multiline range that ends before EOL)
 ;--------------------------------------------------
 
 ; No match (success) and unexpected match (error).
 
 ; NOT:         <<<<<<
 ; NOT-NEXT:           1: hello
+; NOT-VV-NEXT: not:1     X~~~~
 ; NOT-NEXT:           2: world
+; NOT-VV-NEXT: not:1     ~~~~~
 ; NOT-NEXT:    not:2     !~~~~ error: no match expected
 ; NOT-NEXT:           3: again
+; NOT-VV-NEXT: not:1     ~~~~~
 ; NOT-VV-NEXT:        4:
 ; NOT-VV-NEXT: eof:2     ^
 ; NOT-NEXT:    >>>>>>
 
 ; NOT2:         <<<<<<
 ; NOT2-NEXT:             1: hello
+; NOT2-VV-NEXT: not:1       X~~~~
 ; NOT2-NEXT:             2: world
+; NOT2-VV-NEXT: not:1       ~~~~~
 ; NOT2-NEXT:    not:2       !~~~~ error: no match expected
 ; NOT2-NEXT:             3: again
+; NOT2-VV-NEXT: not:1       ~~
 ; NOT2-V-NEXT:  check:3       ^~~
 ; NOT2-NEXT:    >>>>>>
 ; NOT2-NOT:     {{.}}
index cde9bb95706abcdca5457034ba6e0e26a52ab537..6f4cf31ec8316c3fc150f22864871d366dcd8416 100644 (file)
@@ -153,12 +153,12 @@ static MarkerStyle GetMarker(FileCheckDiag::MatchType MatchTy) {
   case FileCheckDiag::MatchDiscard:
     return MarkerStyle('!', raw_ostream::CYAN,
                        "discard: overlaps earlier match");
+  case FileCheckDiag::MatchNoneAndExcluded:
+    return MarkerStyle('X', raw_ostream::GREEN);
   case FileCheckDiag::MatchNoneButExpected:
     return MarkerStyle('X', raw_ostream::RED, "error: no match found");
   case FileCheckDiag::MatchFuzzy:
     return MarkerStyle('?', raw_ostream::MAGENTA, "possible intended match");
-  case FileCheckDiag::MatchTypeCount:
-    llvm_unreachable_internal("unexpected match type");
   }
   llvm_unreachable_internal("unexpected match type");
 }
@@ -200,6 +200,7 @@ static void DumpInputAnnotationHelp(raw_ostream &OS) {
   WithColor(OS, raw_ostream::SAVEDCOLOR, true) << "X~~";
   OS << "    marks search range when no match is found, such as:\n"
      << "           - CHECK-NEXT not found (error)\n"
+     << "           - CHECK-NOT not found (success, reported if -vv)\n"
      << "           - CHECK-DAG not found after discarded matches (error)\n"
      << "  - ";
   WithColor(OS, raw_ostream::SAVEDCOLOR, true) << "?";