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

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 20 05:49:31 PST 2020


thopre updated this revision to Diff 239096.
thopre marked an inline comment as done.
thopre added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72913/new/

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());
   }
 
@@ -414,16 +416,17 @@
   // 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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72913.239096.patch
Type: text/x-patch
Size: 2153 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200120/8dfb66de/attachment.bin>


More information about the llvm-commits mailing list