aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/FileCheckTest.cpp
diff options
context:
space:
mode:
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>2020-05-27 15:13:42 +0100
committerAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>2020-05-27 16:31:39 +0100
commit3be5e53f208d63135bb4e8499abdc1ac8a2b3266 (patch)
tree9ff1a65cad37aa549f62150d86d6ecb88ea377c4 /llvm/unittests/Support/FileCheckTest.cpp
parent461af57de78155ee5d1dc1969b81dd019d228538 (diff)
downloadllvm-3be5e53f208d63135bb4e8499abdc1ac8a2b3266.zip
llvm-3be5e53f208d63135bb4e8499abdc1ac8a2b3266.tar.gz
llvm-3be5e53f208d63135bb4e8499abdc1ac8a2b3266.tar.bz2
[FileCheck] Allow parenthesized expressions
With this change it is be possible to write FileCheck expressions such as [[#(VAR+1)-2]]. Currently, the only supported arithmetic operators are plus and minus, so this is not particularly useful yet. However, it our CHERI fork we have tests that benefit from having multiplication in FileCheck expressions. Allowing parenthesized expressions is the simplest way for us to work around the current lack of operator precedence in FileCheck expressions. Reviewed By: thopre, jhenderson Differential Revision: https://reviews.llvm.org/D77383
Diffstat (limited to 'llvm/unittests/Support/FileCheckTest.cpp')
-rw-r--r--llvm/unittests/Support/FileCheckTest.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/llvm/unittests/Support/FileCheckTest.cpp b/llvm/unittests/Support/FileCheckTest.cpp
index 6b0eee4..75b7fba 100644
--- a/llvm/unittests/Support/FileCheckTest.cpp
+++ b/llvm/unittests/Support/FileCheckTest.cpp
@@ -724,6 +724,46 @@ TEST_F(FileCheckTest, ParseNumericSubstitutionBlock) {
"implicit format conflict between 'FOO' (%u) and "
"'VAR_LOWER_HEX' (%x), need an explicit format specifier",
Tester.parseSubst("FOO+VAR_LOWER_HEX").takeError());
+
+ // Simple parenthesized expressions:
+ EXPECT_THAT_EXPECTED(Tester.parseSubst("(1)"), Succeeded());
+ EXPECT_THAT_EXPECTED(Tester.parseSubst("(1+1)"), Succeeded());
+ EXPECT_THAT_EXPECTED(Tester.parseSubst("(1)+1"), Succeeded());
+ EXPECT_THAT_EXPECTED(Tester.parseSubst("((1)+1)"), Succeeded());
+ EXPECT_THAT_EXPECTED(Tester.parseSubst("((1)+X)"), Succeeded());
+ EXPECT_THAT_EXPECTED(Tester.parseSubst("((X)+Y)"), Succeeded());
+
+ expectDiagnosticError("missing operand in expression",
+ Tester.parseSubst("(").takeError());
+ expectDiagnosticError("missing ')' at end of nested expression",
+ Tester.parseSubst("(1").takeError());
+ expectDiagnosticError("missing operand in expression",
+ Tester.parseSubst("(1+").takeError());
+ expectDiagnosticError("missing ')' at end of nested expression",
+ Tester.parseSubst("(1+1").takeError());
+ expectDiagnosticError("missing ')' at end of nested expression",
+ Tester.parseSubst("((1+2+3").takeError());
+ expectDiagnosticError("missing ')' at end of nested expression",
+ Tester.parseSubst("((1+2)+3").takeError());
+
+ // Test missing operation between operands:
+ expectDiagnosticError("unsupported operation '('",
+ Tester.parseSubst("(1)(2)").takeError());
+ expectDiagnosticError("unsupported operation '('",
+ Tester.parseSubst("2(X)").takeError());
+
+ // Test more closing than opening parentheses. The diagnostic messages are
+ // not ideal, but for now simply check that we reject invalid input.
+ expectDiagnosticError("invalid operand format ')'",
+ Tester.parseSubst(")").takeError());
+ expectDiagnosticError("unsupported operation ')'",
+ Tester.parseSubst("1)").takeError());
+ expectDiagnosticError("unsupported operation ')'",
+ Tester.parseSubst("(1+2))").takeError());
+ expectDiagnosticError("unsupported operation ')'",
+ Tester.parseSubst("(2))").takeError());
+ expectDiagnosticError("unsupported operation ')'",
+ Tester.parseSubst("(1))(").takeError());
}
TEST_F(FileCheckTest, ParsePattern) {
@@ -844,6 +884,52 @@ TEST_F(FileCheckTest, Match) {
Succeeded());
}
+TEST_F(FileCheckTest, MatchParen) {
+ PatternTester Tester;
+ // Check simple parenthesized expressions
+ Tester.initNextPattern();
+ ASSERT_FALSE(Tester.parsePattern("[[#NUMVAR:]]"));
+ expectNotFoundError(Tester.match("FAIL").takeError());
+ expectNotFoundError(Tester.match("").takeError());
+ EXPECT_THAT_EXPECTED(Tester.match("18"), Succeeded());
+
+ Tester.initNextPattern();
+ ASSERT_FALSE(Tester.parsePattern("[[#NUMVAR + (2 + 2)]]"));
+ expectNotFoundError(Tester.match("21").takeError());
+ EXPECT_THAT_EXPECTED(Tester.match("22"), Succeeded());
+ Tester.initNextPattern();
+ ASSERT_FALSE(Tester.parsePattern("[[#NUMVAR + (2)]]"));
+ EXPECT_THAT_EXPECTED(Tester.match("20"), Succeeded());
+ Tester.initNextPattern();
+ ASSERT_FALSE(Tester.parsePattern("[[#NUMVAR+(2)]]"));
+ EXPECT_THAT_EXPECTED(Tester.match("20"), Succeeded());
+ Tester.initNextPattern();
+ ASSERT_FALSE(Tester.parsePattern("[[#NUMVAR+(NUMVAR)]]"));
+ EXPECT_THAT_EXPECTED(Tester.match("36"), Succeeded());
+
+ // Check nested parenthesized expressions:
+ Tester.initNextPattern();
+ ASSERT_FALSE(Tester.parsePattern("[[#NUMVAR+(2+(2))]]"));
+ EXPECT_THAT_EXPECTED(Tester.match("22"), Succeeded());
+ Tester.initNextPattern();
+ ASSERT_FALSE(Tester.parsePattern("[[#NUMVAR+(2+(NUMVAR))]]"));
+ EXPECT_THAT_EXPECTED(Tester.match("38"), Succeeded());
+ Tester.initNextPattern();
+ ASSERT_FALSE(Tester.parsePattern("[[#NUMVAR+((((NUMVAR))))]]"));
+ EXPECT_THAT_EXPECTED(Tester.match("36"), Succeeded());
+ Tester.initNextPattern();
+ ASSERT_FALSE(Tester.parsePattern("[[#NUMVAR+((((NUMVAR)))-1)-1]]"));
+ EXPECT_THAT_EXPECTED(Tester.match("34"), Succeeded());
+
+ // Parentheses can also be the first character after the '#':
+ Tester.initNextPattern();
+ ASSERT_FALSE(Tester.parsePattern("[[#(NUMVAR)]]"));
+ EXPECT_THAT_EXPECTED(Tester.match("18"), Succeeded());
+ Tester.initNextPattern();
+ ASSERT_FALSE(Tester.parsePattern("[[#(NUMVAR+2)]]"));
+ EXPECT_THAT_EXPECTED(Tester.match("20"), Succeeded());
+}
+
TEST_F(FileCheckTest, Substitution) {
SourceMgr SM;
FileCheckPatternContext Context;