[llvm] [llvm-lit] Add precommit test to verify current behavior of glob expansion in lit's internal shell (PR #106325)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 29 23:19:15 PDT 2024
https://github.com/Harini0924 updated https://github.com/llvm/llvm-project/pull/106325
>From 36c5ece458b0038e2127e8be4d517f2ec5dc9181 Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Wed, 28 Aug 2024 01:48:41 +0000
Subject: [PATCH 1/4] [llvm-lit] Add shtest-glob.py test to verify glob pattern
handling
This commit introduces a new test file, shtest-glob.py, to the lit testing framework. The test is designed to verify the handling of glob patterns within the internal shell, specifically checking the behavior of commands like echo when glob patterns are present. The test includes example files, example_file1.txt and example_file2.txt, which are used to validate whether the glob expansion is correctly performed or remains unexpanded as expected in certain cases. This addition helps ensure that glob pattern processing behaves consistently across different shell commands in lit.
---
.../utils/lit/tests/Inputs/shtest-glob/example_file1.txt | 2 ++
.../utils/lit/tests/Inputs/shtest-glob/example_file2.txt | 2 ++
llvm/utils/lit/tests/Inputs/shtest-glob/glob-echo.txt | 2 ++
llvm/utils/lit/tests/shtest-glob.py | 9 +++++++++
4 files changed, 15 insertions(+)
create mode 100644 llvm/utils/lit/tests/Inputs/shtest-glob/example_file1.txt
create mode 100644 llvm/utils/lit/tests/Inputs/shtest-glob/example_file2.txt
create mode 100644 llvm/utils/lit/tests/Inputs/shtest-glob/glob-echo.txt
create mode 100644 llvm/utils/lit/tests/shtest-glob.py
diff --git a/llvm/utils/lit/tests/Inputs/shtest-glob/example_file1.txt b/llvm/utils/lit/tests/Inputs/shtest-glob/example_file1.txt
new file mode 100644
index 00000000000000..1bf50291a824a6
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-glob/example_file1.txt
@@ -0,0 +1,2 @@
+## This is the first example file used for testing glob pattern matching.
+RUN: This is the first example file.
diff --git a/llvm/utils/lit/tests/Inputs/shtest-glob/example_file2.txt b/llvm/utils/lit/tests/Inputs/shtest-glob/example_file2.txt
new file mode 100644
index 00000000000000..7263ea1dccf4a8
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-glob/example_file2.txt
@@ -0,0 +1,2 @@
+## This is the second example file used for testing glob pattern matching.
+RUN: This is the second example file.
diff --git a/llvm/utils/lit/tests/Inputs/shtest-glob/glob-echo.txt b/llvm/utils/lit/tests/Inputs/shtest-glob/glob-echo.txt
new file mode 100644
index 00000000000000..31fc03f22bd5f9
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-glob/glob-echo.txt
@@ -0,0 +1,2 @@
+## Tests glob pattern expansion by listing matching files.
+# RUN: echo %{inputs}/shtest-glob/example_file*.txt
diff --git a/llvm/utils/lit/tests/shtest-glob.py b/llvm/utils/lit/tests/shtest-glob.py
new file mode 100644
index 00000000000000..3d59e681cca4f9
--- /dev/null
+++ b/llvm/utils/lit/tests/shtest-glob.py
@@ -0,0 +1,9 @@
+## Tests glob pattern handling in echo command.
+
+# RUN: not %{lit} -a -v %{inputs}/shtest-glob \
+# RUN: | FileCheck -dump-input=fail -match-full-lines %s
+#
+# END.
+
+# CHECK: UNRESOLVED: shtest-glob :: glob-echo.txt ({{[^)]*}})
+# CHECK: TypeError: string argument expected, got 'GlobItem'
>From 9e193b27dc48850fc0b4c32ebe7ffce785b3e0a6 Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Wed, 28 Aug 2024 02:21:59 +0000
Subject: [PATCH 2/4] Added the lit.cfg file
I forgot to add the lit.cfg file in my previous commit.
---
llvm/utils/lit/tests/Inputs/shtest-glob/lit.cfg | 8 ++++++++
1 file changed, 8 insertions(+)
create mode 100644 llvm/utils/lit/tests/Inputs/shtest-glob/lit.cfg
diff --git a/llvm/utils/lit/tests/Inputs/shtest-glob/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-glob/lit.cfg
new file mode 100644
index 00000000000000..4e5f4cac4c4653
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-glob/lit.cfg
@@ -0,0 +1,8 @@
+import lit.formats
+
+config.name = "shtest-glob"
+config.suffixes = [".txt"]
+config.test_format = lit.formats.ShTest()
+config.test_source_root = None
+config.test_exec_root = None
+config.substitutions.append(("%{python}", '"%s"' % (sys.executable)))
>From 5ab823247210e13527330eede84227d6ddc978c3 Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Wed, 28 Aug 2024 05:58:53 +0000
Subject: [PATCH 3/4] [llvm-lit] Rename and update test files for glob pattern
handling
Renamed `example_file1.txt` and `example_file2.txt` to `.input` files to avoid `RUN` lines in test files and ensure they are not executed as test scripts. Added `glob-mkdir.txt` to test `mkdir` with glob patterns, ensuring failure when directories exist. Modified `shtest-glob.py` to include checks for both `echo` and `mkdir` command tests. Ensured that the `mkdir` command test is expected to fail, confirming proper error handling for existing paths.
---
.../shtest-glob/{example_file1.txt => example_file1.input} | 2 +-
.../shtest-glob/{example_file2.txt => example_file2.input} | 2 +-
llvm/utils/lit/tests/Inputs/shtest-glob/glob-echo.txt | 2 +-
llvm/utils/lit/tests/Inputs/shtest-glob/glob-mkdir.txt | 2 ++
llvm/utils/lit/tests/shtest-glob.py | 4 ++++
5 files changed, 9 insertions(+), 3 deletions(-)
rename llvm/utils/lit/tests/Inputs/shtest-glob/{example_file1.txt => example_file1.input} (66%)
rename llvm/utils/lit/tests/Inputs/shtest-glob/{example_file2.txt => example_file2.input} (66%)
create mode 100644 llvm/utils/lit/tests/Inputs/shtest-glob/glob-mkdir.txt
diff --git a/llvm/utils/lit/tests/Inputs/shtest-glob/example_file1.txt b/llvm/utils/lit/tests/Inputs/shtest-glob/example_file1.input
similarity index 66%
rename from llvm/utils/lit/tests/Inputs/shtest-glob/example_file1.txt
rename to llvm/utils/lit/tests/Inputs/shtest-glob/example_file1.input
index 1bf50291a824a6..0987c9081ca1f3 100644
--- a/llvm/utils/lit/tests/Inputs/shtest-glob/example_file1.txt
+++ b/llvm/utils/lit/tests/Inputs/shtest-glob/example_file1.input
@@ -1,2 +1,2 @@
## This is the first example file used for testing glob pattern matching.
-RUN: This is the first example file.
+This is the first example file.
diff --git a/llvm/utils/lit/tests/Inputs/shtest-glob/example_file2.txt b/llvm/utils/lit/tests/Inputs/shtest-glob/example_file2.input
similarity index 66%
rename from llvm/utils/lit/tests/Inputs/shtest-glob/example_file2.txt
rename to llvm/utils/lit/tests/Inputs/shtest-glob/example_file2.input
index 7263ea1dccf4a8..f1a843f308262e 100644
--- a/llvm/utils/lit/tests/Inputs/shtest-glob/example_file2.txt
+++ b/llvm/utils/lit/tests/Inputs/shtest-glob/example_file2.input
@@ -1,2 +1,2 @@
## This is the second example file used for testing glob pattern matching.
-RUN: This is the second example file.
+This is the second example file.
diff --git a/llvm/utils/lit/tests/Inputs/shtest-glob/glob-echo.txt b/llvm/utils/lit/tests/Inputs/shtest-glob/glob-echo.txt
index 31fc03f22bd5f9..b69f5e74fd7281 100644
--- a/llvm/utils/lit/tests/Inputs/shtest-glob/glob-echo.txt
+++ b/llvm/utils/lit/tests/Inputs/shtest-glob/glob-echo.txt
@@ -1,2 +1,2 @@
## Tests glob pattern expansion by listing matching files.
-# RUN: echo %{inputs}/shtest-glob/example_file*.txt
+# RUN: echo %S/example_file*.input
diff --git a/llvm/utils/lit/tests/Inputs/shtest-glob/glob-mkdir.txt b/llvm/utils/lit/tests/Inputs/shtest-glob/glob-mkdir.txt
new file mode 100644
index 00000000000000..d1329f5dbfaaed
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-glob/glob-mkdir.txt
@@ -0,0 +1,2 @@
+## Tests glob pattern handling in the mkdir command.
+# RUN: not mkdir %S/example_file*.input
diff --git a/llvm/utils/lit/tests/shtest-glob.py b/llvm/utils/lit/tests/shtest-glob.py
index 3d59e681cca4f9..f8f2e806893390 100644
--- a/llvm/utils/lit/tests/shtest-glob.py
+++ b/llvm/utils/lit/tests/shtest-glob.py
@@ -7,3 +7,7 @@
# CHECK: UNRESOLVED: shtest-glob :: glob-echo.txt ({{[^)]*}})
# CHECK: TypeError: string argument expected, got 'GlobItem'
+
+# CHECK: FAIL: shtest-glob :: glob-mkdir.txt ({{[^)]*}})
+# CHECK: # error: command failed with exit status: 1
+
>From 4e0657c8e63d34af5327cfc8c491361f86807d94 Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Fri, 30 Aug 2024 06:18:30 +0000
Subject: [PATCH 4/4] Fixed the trailing whitespace
---
llvm/utils/lit/tests/shtest-glob.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/llvm/utils/lit/tests/shtest-glob.py b/llvm/utils/lit/tests/shtest-glob.py
index f8f2e806893390..551331cb38e259 100644
--- a/llvm/utils/lit/tests/shtest-glob.py
+++ b/llvm/utils/lit/tests/shtest-glob.py
@@ -1,6 +1,6 @@
## Tests glob pattern handling in echo command.
-# RUN: not %{lit} -a -v %{inputs}/shtest-glob \
+# RUN: not %{lit} -a -v %{inputs}/shtest-glob \
# RUN: | FileCheck -dump-input=fail -match-full-lines %s
#
# END.
@@ -8,6 +8,5 @@
# CHECK: UNRESOLVED: shtest-glob :: glob-echo.txt ({{[^)]*}})
# CHECK: TypeError: string argument expected, got 'GlobItem'
-# CHECK: FAIL: shtest-glob :: glob-mkdir.txt ({{[^)]*}})
+# CHECK: FAIL: shtest-glob :: glob-mkdir.txt ({{[^)]*}}
# CHECK: # error: command failed with exit status: 1
-
More information about the llvm-commits
mailing list