[llvm] [FileCheck][NFC] Pre-commit test for printing escaped variables (PR #145906)

Mészáros Gergely via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 26 07:47:24 PDT 2025


https://github.com/Maetveis created https://github.com/llvm/llvm-project/pull/145906

For #145865

>From 753c46310d748fafd3de60b7e8f572ce918cf95b Mon Sep 17 00:00:00 2001
From: Gergely Meszaros <gergely.meszaros at intel.com>
Date: Thu, 26 Jun 2025 02:50:47 -0700
Subject: [PATCH 1/2] [FileCheck][NFC] Pre-commit test for printing escaped
 variables

---
 llvm/test/FileCheck/var-escape.txt | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 llvm/test/FileCheck/var-escape.txt

diff --git a/llvm/test/FileCheck/var-escape.txt b/llvm/test/FileCheck/var-escape.txt
new file mode 100644
index 0000000000000..32760bc0c9280
--- /dev/null
+++ b/llvm/test/FileCheck/var-escape.txt
@@ -0,0 +1,17 @@
+; RUN: echo -e "WINPATH=A:\windows\style\path"             >  %t
+; RUN: echo -e "NOT_ESCAPED=shouldn't be escaped [a-Z]\+$" >> %t
+; RUN: echo -e 'ESCAPED=\\ needs\to "be" escaped\000'      >> %t
+
+VARS:      WINPATH=[[WINPATH:.*]]
+VARS:      NOT_ESCAPED=[[NOT_ESCAPED:.*]]
+VARS-NEXT: ESCAPED=[[ESCAPED:.*]]
+; Trigger a failed match, to show variables values
+VARS-NEXT: [[WINPATH]] [[NOT_ESCAPED]] [[ESCAPED]]
+
+; RUN: %ProtectFileCheckOutput not FileCheck \
+; RUN:   -dump-input=never --strict-whitespace --check-prefix=VARS --input-file=%t %s 2>&1 \
+; RUN: | FileCheck %s
+
+CHECK: with "WINPATH" equal to "A:\\\\windows\\\\style\\\\path"
+CHECK: with "NOT_ESCAPED" equal to "shouldn't be escaped \\[a-Z\\]\\\\\\+\\$"
+CHECK: with "ESCAPED" equal to "\\\\ needs\to \"be\" escaped\\\000"

>From 3b70a36202db93edee2117f9fd45b06ac26ba6e1 Mon Sep 17 00:00:00 2001
From: Gergely Meszaros <gergely.meszaros at intel.com>
Date: Thu, 26 Jun 2025 07:18:10 -0700
Subject: [PATCH 2/2] Add more test-cases

---
 llvm/test/FileCheck/var-escape.txt | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/llvm/test/FileCheck/var-escape.txt b/llvm/test/FileCheck/var-escape.txt
index 32760bc0c9280..c3dc0fc7591d7 100644
--- a/llvm/test/FileCheck/var-escape.txt
+++ b/llvm/test/FileCheck/var-escape.txt
@@ -1,17 +1,29 @@
-; RUN: echo -e "WINPATH=A:\windows\style\path"             >  %t
-; RUN: echo -e "NOT_ESCAPED=shouldn't be escaped [a-Z]\+$" >> %t
-; RUN: echo -e 'ESCAPED=\\ needs\to "be" escaped\000'      >> %t
+; RUN: echo -e "WINPATH=A:\windows\style\path"              >  %t.1
+; RUN: echo -e "NOT_ESCAPED=shouldn't be escaped [a-Z]\+$"  >> %t.1
+; RUN: echo -e 'ESCAPED=\\ \f\v needs\to "be" escaped\000'  >> %t.1
+; RUN: echo -e '$NUMERIC=DEADBEEF'                          >> %t.1
 
 VARS:      WINPATH=[[WINPATH:.*]]
-VARS:      NOT_ESCAPED=[[NOT_ESCAPED:.*]]
+VARS-NEXT: NOT_ESCAPED=[[NOT_ESCAPED:.*]]
 VARS-NEXT: ESCAPED=[[ESCAPED:.*]]
+VARS-NEXT: $NUMERIC=[[#%X,$NUMERIC:]]
 ; Trigger a failed match, to show variables values
-VARS-NEXT: [[WINPATH]] [[NOT_ESCAPED]] [[ESCAPED]]
+VARS-NEXT: [[WINPATH]] [[NOT_ESCAPED]] [[ESCAPED]] [[#$NUMERIC + 0]]
 
 ; RUN: %ProtectFileCheckOutput not FileCheck \
-; RUN:   -dump-input=never --strict-whitespace --check-prefix=VARS --input-file=%t %s 2>&1 \
+; RUN:   -dump-input=never --strict-whitespace --check-prefix=VARS --input-file=%t.1 %s 2>&1 \
 ; RUN: | FileCheck %s
 
 CHECK: with "WINPATH" equal to "A:\\\\windows\\\\style\\\\path"
 CHECK: with "NOT_ESCAPED" equal to "shouldn't be escaped \\[a-Z\\]\\\\\\+\\$"
-CHECK: with "ESCAPED" equal to "\\\\ needs\to \"be\" escaped\\\000"
+CHECK: with "ESCAPED" equal to "\\\\ \014\013 needs\to \"be\" escaped\\\000"
+CHECK: with "$NUMERIC + 0" equal to "DEADBEEF"
+
+; Test escaping of the name of a numeric substitution, which might contain
+; characters that need escaping. 
+; RUN: echo -e "VARNAME: [[#%,10\t]]" > %t.2
+; RUN: echo 42 \
+; RUN: | %ProtectFileCheckOutput not FileCheck \
+; RUN:   -dump-input=never -vv --strict-whitespace --check-prefix=VARNAME %t.2 2>&1 \
+; RUN: | FileCheck %s --check-prefix=CHECK-VARNAME
+CHECK-VARNAME: with "%,10\t" equal to "10"



More information about the llvm-commits mailing list