Skip to content

Commit 95783bc

Browse files
bjopeDebadri Basak
authored andcommitted
[lit] Fix to make "RUN: env PATH=..." work as intended (llvm#165308)
There was a bug in llvm-lit related to setting PATH using env in the internal shell. The new PATH wasn't used when looking up the command to be executed. So when doing things like this in a test case RUN: mkdir %t RUN: env PATH=%t program ... the internal shell would search for "program" using the orignal PATH and not the PATH set by env when preceeding the command. It seems like this was a simple mistake in commit 57782ef, since the logic to pick a PATH from the cmd_shenv instead of shenv actually was added in that patch, but the resulting path wasn't used.
1 parent c6fa0e8 commit 95783bc

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
945945
path = (
946946
cmd_shenv.env["PATH"] if "PATH" in cmd_shenv.env else shenv.env["PATH"]
947947
)
948-
executable = lit.util.which(args[0], shenv.env["PATH"])
948+
executable = lit.util.which(args[0], path)
949949
if not executable:
950950
raise InternalShellError(j, "%r: command not found" % args[0])
951951

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import lit.formats
2+
3+
config.name = "shtest-env-path"
4+
config.suffixes = [".txt"]
5+
config.test_format = lit.formats.ShTest()
6+
config.test_source_root = None
7+
config.test_exec_root = None
8+
config.substitutions.append(("%{python}", '"%s"' % (sys.executable)))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Tests env command for setting the PATH variable.
2+
3+
## Check that test.sh can be found using the configured PATH.
4+
#
5+
# RUN: env PATH=%S test.sh | FileCheck --check-prefix=CHECK %s
6+
#
7+
8+
# CHECK: TEST-ENV-PATH-123
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
echo "TEST-ENV-PATH-123"
4+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Tests env command for setting the PATH variable.
2+
3+
# The test is using /bin/sh. Limit to system known to have /bin/sh.
4+
# REQUIRES: system-linux
5+
6+
# RUN: %{lit} -a -v %{inputs}/shtest-env-path/path.txt \
7+
# RUN: | FileCheck -match-full-lines %s
8+
#
9+
# END.
10+
11+
# CHECK: -- Testing: 1 tests{{.*}}
12+
# CHECK: PASS: shtest-env-path :: path.txt (1 of 1)
13+
# CHECK: --

0 commit comments

Comments
 (0)