[llvm] [lit] Add LIT_CURRENT_TESTCASE environment variable when running tests (PR #168762)
Andrew Haberlandt via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 19 12:35:51 PST 2025
https://github.com/ndrewh updated https://github.com/llvm/llvm-project/pull/168762
>From 271130cc0a9dd1a4d3dfa2c1463c0e77c607c3c2 Mon Sep 17 00:00:00 2001
From: Andrew Haberlandt <ahaberlandt at apple.com>
Date: Wed, 19 Nov 2025 11:12:06 -0800
Subject: [PATCH 1/2] [lit] Add LIT_CURRENT_TESTCASE environment variable when
running tests
---
llvm/utils/lit/lit/TestRunner.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 64148c6098327..9525320f133c6 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -1226,6 +1226,8 @@ def executeScriptInternal(
results = []
timeoutInfo = None
shenv = ShellEnvironment(cwd, test.config.environment)
+ shenv.env["LIT_CURRENT_TESTCASE"] = test.getFullName()
+
exitCode, timeoutInfo = executeShCmd(
cmd, shenv, results, timeout=litConfig.maxIndividualTestTime
)
@@ -1425,11 +1427,13 @@ def executeScript(test, litConfig, tmpBase, commands, cwd):
# run on clang with no real loss.
command = litConfig.valgrindArgs + command
+ env = dict(test.config.environment)
+ env["LIT_CURRENT_TESTCASE"] = test.getFullName()
try:
out, err, exitCode = lit.util.executeCommand(
command,
cwd=cwd,
- env=test.config.environment,
+ env=env,
timeout=litConfig.maxIndividualTestTime,
)
return (out, err, exitCode, None)
>From 018cfdc4ea5653428219ae12ce3be3fbced48931 Mon Sep 17 00:00:00 2001
From: Andrew Haberlandt <ahaberlandt at apple.com>
Date: Wed, 19 Nov 2025 12:35:39 -0800
Subject: [PATCH 2/2] Add testcase
---
.../shtest-env-positive/env-current-testcase.txt | 6 ++++++
.../Inputs/shtest-env-positive/env-no-subcommand.txt | 1 +
llvm/utils/lit/tests/shtest-env-positive.py | 11 ++++++++---
3 files changed, 15 insertions(+), 3 deletions(-)
create mode 100644 llvm/utils/lit/tests/Inputs/shtest-env-positive/env-current-testcase.txt
diff --git a/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-current-testcase.txt b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-current-testcase.txt
new file mode 100644
index 0000000000000..37c36814ccbbb
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-current-testcase.txt
@@ -0,0 +1,6 @@
+## Tests that the LIT_CURRENT_TESTCASE variable is set to the name of the currently executing testcase
+
+## Check default environment.
+# RUN: bash -c 'echo $LIT_CURRENT_TESTCASE' | FileCheck --match-full-lines %s
+#
+# CHECK: shtest-env :: env-current-testcase.txt
diff --git a/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-no-subcommand.txt b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-no-subcommand.txt
index 761a8061a0b0d..dded9069c44f2 100644
--- a/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-no-subcommand.txt
+++ b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-no-subcommand.txt
@@ -1,4 +1,5 @@
## Tests the env command in various scenarios: without arguments, setting, unsetting, and mixing envrionment variables.
+# FIXME: All of these tests are broken and will not even call FileCheck.
## Check default environment.
# RUN: env | FileCheck -check-prefix=NO-ARGS %s
diff --git a/llvm/utils/lit/tests/shtest-env-positive.py b/llvm/utils/lit/tests/shtest-env-positive.py
index 089acd308c5c5..62e15dd9ad492 100644
--- a/llvm/utils/lit/tests/shtest-env-positive.py
+++ b/llvm/utils/lit/tests/shtest-env-positive.py
@@ -7,7 +7,7 @@
## Test the env command's successful executions.
-# CHECK: -- Testing: 10 tests{{.*}}
+# CHECK: -- Testing: 11 tests{{.*}}
# CHECK: PASS: shtest-env :: env-args-last-is-assign.txt ({{[^)]*}})
# CHECK: env FOO=1
@@ -39,6 +39,11 @@
# CHECK-NOT: # error:
# CHECK: --
+# CHECK: PASS: shtest-env :: env-current-testcase.txt ({{[^)]*}})
+# CHECK: # executed command: bash -c 'echo $LIT_CURRENT_TESTCASE'
+# CHECK-NOT: # error:
+# CHECK: --
+
# CHECK: PASS: shtest-env :: env-i.txt ({{[^)]*}})
# CHECK: env -i | {{.*}}
# CHECK: # executed command: env -i
@@ -71,6 +76,6 @@
# CHECK-NOT: # error:
# CHECK: --
-# CHECK: Total Discovered Tests: 10
-# CHECK: Passed: 10 {{\([0-9]*\.[0-9]*%\)}}
+# CHECK: Total Discovered Tests: 11
+# CHECK: Passed: 11 {{\([0-9]*\.[0-9]*%\)}}
# CHECK-NOT: {{.}}
More information about the llvm-commits
mailing list