[llvm] a81e044 - [FileCheck] Make Match unittest more flexible

Thomas Preud'homme via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 20 08:21:43 PST 2020


Author: Thomas Preud'homme
Date: 2020-01-20T16:21:35Z
New Revision: a81e0442bdb1fafb9219b338176e00f4c9054377

URL: https://github.com/llvm/llvm-project/commit/a81e0442bdb1fafb9219b338176e00f4c9054377
DIFF: https://github.com/llvm/llvm-project/commit/a81e0442bdb1fafb9219b338176e00f4c9054377.diff

LOG: [FileCheck] Make Match unittest more flexible

Summary:
FileCheck's Match unittest needs updating whenever some call to
initNextPattern() is inserted before its final block of checks. This
commit change usage of LineNumber inside the Tester object so that the
line number of the current pattern can be queries, thereby making the
Match test more solid.

Reviewers: jhenderson, jdenny, probinson, grimar, arichardson, rnk

Reviewed By: jhenderson

Subscribers: llvm-commits

Tags: #llvm

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

Added: 
    

Modified: 
    llvm/unittests/Support/FileCheckTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/Support/FileCheckTest.cpp b/llvm/unittests/Support/FileCheckTest.cpp
index 69fc95aedb12..9be02c1f377f 100644
--- a/llvm/unittests/Support/FileCheckTest.cpp
+++ b/llvm/unittests/Support/FileCheckTest.cpp
@@ -215,7 +215,7 @@ class PatternTester {
   SourceMgr SM;
   FileCheckRequest Req;
   FileCheckPatternContext Context;
-  Pattern P{Check::CheckPlain, &Context, LineNumber++};
+  Pattern P{Check::CheckPlain, &Context, LineNumber};
 
 public:
   PatternTester() {
@@ -236,15 +236,17 @@ class PatternTester {
   }
 
   void initNextPattern() {
-    P = Pattern(Check::CheckPlain, &Context, LineNumber++);
+    P = Pattern(Check::CheckPlain, &Context, ++LineNumber);
   }
 
+  size_t getLineNumber() const { return LineNumber; }
+
   bool parseSubstExpect(StringRef Expr, bool IsLegacyLineExpr = false) {
     StringRef ExprBufferRef = bufferize(SM, Expr);
     Optional<NumericVariable *> DefinedNumericVariable;
     return errorToBool(P.parseNumericSubstitutionBlock(
                             ExprBufferRef, DefinedNumericVariable,
-                            IsLegacyLineExpr, LineNumber - 1, &Context, SM)
+                            IsLegacyLineExpr, LineNumber, &Context, SM)
                            .takeError());
   }
 
@@ -414,16 +416,17 @@ TEST_F(FileCheckTest, Match) {
   // the correct value for @LINE.
   Tester.initNextPattern();
   EXPECT_FALSE(Tester.parsePatternExpect("[[#@LINE]]"));
-  // Ok, @LINE is 7 now.
-  EXPECT_FALSE(Tester.matchExpect("7"));
+  // Ok, @LINE matches the current line number.
+  EXPECT_FALSE(Tester.matchExpect(std::to_string(Tester.getLineNumber())));
   Tester.initNextPattern();
-  // @LINE is now 8, match with substitution failure.
+  // Match with substitution failure.
   EXPECT_FALSE(Tester.parsePatternExpect("[[#UNKNOWN]]"));
   EXPECT_TRUE(Tester.matchExpect("FOO"));
   Tester.initNextPattern();
-  // Check that @LINE is 9 as expected.
+  // Check that @LINE matches the later (given the calls to initNextPattern())
+  // line number.
   EXPECT_FALSE(Tester.parsePatternExpect("[[#@LINE]]"));
-  EXPECT_FALSE(Tester.matchExpect("9"));
+  EXPECT_FALSE(Tester.matchExpect(std::to_string(Tester.getLineNumber())));
 }
 
 TEST_F(FileCheckTest, Substitution) {


        


More information about the llvm-commits mailing list