-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[lit] Add support for env -i #156939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lit] Add support for env -i #156939
Conversation
env -i is needed for some lit tests. The feature requires a minimal amount of work to support and there is no easy way to rewrite the tests that require it. At least two tests that need this: 1. clang/test/Driver/env.c 2. lldb/test/Shell/Host/TestCustomShell.test
@llvm/pr-subscribers-clang @llvm/pr-subscribers-testing-tools Author: Aiden Grossman (boomanaiden154) Changesenv -i is needed for some lit tests. The feature requires a minimal amount of work to support and there is no easy way to rewrite the tests that require it. At least two tests that need this:
Full diff: https://github.com/llvm/llvm-project/pull/156939.diff 3 Files Affected:
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 36c19c1c86c75..69ca80008e2f9 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -326,6 +326,10 @@ def updateEnv(env, args):
if arg == "-u":
unset_next_env_var = True
continue
+ # Support for the -i flag which clears the environment
+ if arg == "-i":
+ env.env = {}
+ continue
if unset_next_env_var:
unset_next_env_var = False
if arg in env.env:
@@ -890,7 +894,12 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
if os.path.isfile(exe_in_cwd):
executable = exe_in_cwd
if not executable:
- executable = lit.util.which(args[0], cmd_shenv.env["PATH"])
+ # Use the path from cmd_shenv by default, but if the environment variable
+ # is unset (like if the user is using env -i), use the standard path.
+ path = (
+ cmd_shenv.env["PATH"] if "PATH" in cmd_shenv.env else shenv.env["PATH"]
+ )
+ executable = lit.util.which(args[0], shenv.env["PATH"])
if not executable:
raise InternalShellError(j, "%r: command not found" % args[0])
diff --git a/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-i.txt b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-i.txt
new file mode 100644
index 0000000000000..2a66db1d48d05
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-i.txt
@@ -0,0 +1,23 @@
+## Tests env command for clearing the environment
+
+## Check and make sure preset environment variable were set in lit.cfg.
+#
+# RUN: env | FileCheck --check-prefix=CHECK-ENV-PRESET %s
+## Check clearing the entire environment.
+#
+# RUN: env -i | FileCheck --check-prefix=CHECK-ENV-CLEAR-1 %s
+#
+## Check setting a variable in a clear environment.
+#
+# RUN: env -i BAZ=3 | FileCheck --check-prefix=CHECK-ENV-ONE-1 %s
+#
+
+# CHECK-ENV-PRESET: BAR = 2
+# CHECK-ENV-PRESET: FOO = 1
+
+# CHECK-ENV-CLEAR-NOT: BAR
+# CHECK-ENV-CLEAR-NOT: FOO
+
+# CHECK-ENV-ONE-NOT: BAR
+# CHECK-ENV-ONE: BAZ = 3
+# CHECK-ENV-ONE-NOT: FOO
diff --git a/llvm/utils/lit/tests/shtest-env-positive.py b/llvm/utils/lit/tests/shtest-env-positive.py
index 863fbda8c5b6d..4f07b69ecc7d3 100644
--- a/llvm/utils/lit/tests/shtest-env-positive.py
+++ b/llvm/utils/lit/tests/shtest-env-positive.py
@@ -1,13 +1,13 @@
## Test the env command (passing tests).
# RUN: %{lit} -a -v %{inputs}/shtest-env-positive \
-# RUN: | FileCheck -match-full-lines %s
+# RUN: | FileCheck -match-full-lines %s
#
# END.
## Test the env command's successful executions.
-# CHECK: -- Testing: 9 tests{{.*}}
+# CHECK: -- Testing: 10 tests{{.*}}
# CHECK: PASS: shtest-env :: env-args-last-is-assign.txt ({{[^)]*}})
# CHECK: env FOO=1
@@ -39,6 +39,12 @@
# CHECK-NOT: # error:
# CHECK: --
+# CHECK: PASS: shtest-env :: env-i.txt ({{[^)]*}})
+# CHECK: env -i | {{.*}}
+# CHECK: # executed command: env -i
+# CHECK-NOT: # error:
+# CHECK: --
+
# CHECK: PASS: shtest-env :: env-no-subcommand.txt ({{[^)]*}})
# CHECK: env | {{.*}}
# CHECK: # executed command: env
@@ -65,6 +71,6 @@
# CHECK-NOT: # error:
# CHECK: --
-# CHECK: Total Discovered Tests: 9
-# CHECK: Passed: 9 {{\([0-9]*\.[0-9]*%\)}}
+# CHECK: Total Discovered Tests: 10
+# CHECK: Passed: 10 {{\([0-9]*\.[0-9]*%\)}}
# CHECK-NOT: {{.}}
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/46/builds/22797 Here is the relevant piece of the build log for the reference
|
env -i is needed for some lit tests. The feature requires a minimal amount of work to support and there is no easy way to rewrite the tests that require it.
At least two tests that need this: