[PATCH] D72913: [FileCheck] Make Match unittest more flexible

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 17 03:57:56 PST 2020


thopre created this revision.
thopre added reviewers: jhenderson, jdenny, probinson, grimar, arichardson, rnk.
thopre added a project: LLVM.
thopre added a parent revision: D72912: [FileCheck] Clean and improve unit tests.
thopre added a child revision: D72914: [FileCheck] Strengthen error checks in unit tests.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72913

Files:
  llvm/unittests/Support/FileCheckTest.cpp


Index: llvm/unittests/Support/FileCheckTest.cpp
===================================================================
--- llvm/unittests/Support/FileCheckTest.cpp
+++ llvm/unittests/Support/FileCheckTest.cpp
@@ -215,7 +215,7 @@
   SourceMgr SM;
   FileCheckRequest Req;
   FileCheckPatternContext Context;
-  Pattern P{Check::CheckPlain, &Context, LineNumber++};
+  Pattern P{Check::CheckPlain, &Context, LineNumber};
 
 public:
   PatternTester() {
@@ -236,15 +236,17 @@
   }
 
   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());
   }
 
@@ -412,16 +414,16 @@
   // 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 still matches the current 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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72913.238735.patch
Type: text/x-patch
Size: 2116 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200117/41d86948/attachment.bin>


More information about the llvm-commits mailing list