Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions llvm/utils/lit/lit/TestRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,14 @@ def executeBuiltinColon(cmd, cmd_shenv):
return ShellCommandResult(cmd, "", "", 0, False)


def executeBuiltinUnset(cmd, shenv):
"""executeBuiltinUnset - Handle the 'unset' command."""
raise InternalShellError(
cmd,
"'unset' command is not supported by the lit internal shell. Please use 'env -u VARIABLE' to unset environment variables.",
)


def processRedirects(cmd, stdin_source, cmd_shenv, opened_files):
"""Return the standard fds for cmd after applying redirects

Expand Down Expand Up @@ -720,6 +728,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
"pushd": executeBuiltinPushd,
"rm": executeBuiltinRm,
":": executeBuiltinColon,
"unset": executeBuiltinUnset,
}
# To avoid deadlock, we use a single stderr stream for piped
# output. This is null until we have seen some output using
Expand Down
10 changes: 10 additions & 0 deletions llvm/utils/lit/tests/Inputs/shtest-unset/lit.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import lit.formats

config.name = "shtest-unset"
config.suffixes = [".txt"]
config.test_format = lit.formats.ShTest()
config.test_source_root = None
config.test_exec_root = None
config.environment["FOO"] = "1"
config.environment["BAR"] = "2"
config.substitutions.append(("%{python}", '"%s"' % (sys.executable)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Tests the 'unset' command with multiple variables.

# RUN: unset FOO BAR
3 changes: 3 additions & 0 deletions llvm/utils/lit/tests/Inputs/shtest-unset/unset-no-args.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Tests the 'unset' command when no arguments are provided.

# RUN: unset
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Test the behavior of the 'unset' command when trying to unset a variable that does not exist.

# RUN: unset NONEXISTENT
3 changes: 3 additions & 0 deletions llvm/utils/lit/tests/Inputs/shtest-unset/unset-variable.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Tests the 'unset' command with a single variable

# RUN: unset FOO
42 changes: 42 additions & 0 deletions llvm/utils/lit/tests/shtest-unset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## Check that the 'unset' command fails as expected for various tests.

# RUN: not %{lit} -a -v %{inputs}/shtest-unset \
# RUN: | FileCheck -match-full-lines %s
#
# END.

## Check that the 'unset' command's expected failures.

# CHECK: -- Testing: 4 tests{{.*}}

# CHECK: FAIL: shtest-unset :: unset-multiple-variables.txt{{.*}}
# CHECK: unset FOO BAR
# CHECK-NEXT: # executed command: unset FOO BAR
# CHECK-NEXT: # .---command stderr------------
# CHECK-NEXT: # | 'unset' command is not supported by the lit internal shell. Please use 'env -u VARIABLE' to unset environment variables.
# CHECK: # error: command failed with exit status: 127

# CHECK: FAIL: shtest-unset :: unset-no-args.txt{{.*}}
# CHECK: unset
# CHECK-NEXT: # executed command: unset
# CHECK-NEXT: # .---command stderr------------
# CHECK-NEXT: # | 'unset' command is not supported by the lit internal shell. Please use 'env -u VARIABLE' to unset environment variables.
# CHECK: # error: command failed with exit status: 127

# CHECK: FAIL: shtest-unset :: unset-nonexistent-variable.txt{{.*}}
# CHECK: unset NONEXISTENT
# CHECK-NEXT: # executed command: unset NONEXISTENT
# CHECK-NEXT: # .---command stderr------------
# CHECK-NEXT: # | 'unset' command is not supported by the lit internal shell. Please use 'env -u VARIABLE' to unset environment variables.
# CHECK: # error: command failed with exit status: 127

# CHECK: FAIL: shtest-unset :: unset-variable.txt{{.*}}
# CHECK: unset FOO
# CHECK-NEXT: # executed command: unset FOO
# CHECK-NEXT: # .---command stderr------------
# CHECK-NEXT: # | 'unset' command is not supported by the lit internal shell. Please use 'env -u VARIABLE' to unset environment variables.
# CHECK: # error: command failed with exit status: 127

# CHECK: Total Discovered Tests: 4
# CHECK: Failed: 4 {{\([0-9]*\.[0-9]*%\)}}
# CHECK-NOT: {{.}}