[PATCH] D66482: [lit] Diagnose insufficient args to internal env
Joel E. Denny via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 20 09:24:54 PDT 2019
jdenny created this revision.
jdenny added reviewers: probinson, stella.stamenova, bd1976llvm, jlpeyton, rnk, mgorny.
Herald added a subscriber: delcypher.
Herald added a project: LLVM.
Without this patch, failing to provide a subcommand to lit's internal
`env` results in either a python `IndexError` or an attempt to execute
the final `env` argument, such as `FOO=1`, as a command. This patch
diagnoses those cases with a more helpful message.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D66482
Files:
llvm/utils/lit/lit/TestRunner.py
llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-assign.txt
llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u-arg.txt
llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u.txt
llvm/utils/lit/tests/Inputs/shtest-env/env-args-none.txt
llvm/utils/lit/tests/shtest-env.py
Index: llvm/utils/lit/tests/shtest-env.py
===================================================================
--- llvm/utils/lit/tests/shtest-env.py
+++ llvm/utils/lit/tests/shtest-env.py
@@ -1,12 +1,26 @@
# Check the env command
#
-# RUN: %{lit} -j 1 -a -v %{inputs}/shtest-env \
+# RUN: not %{lit} -j 1 -a -v %{inputs}/shtest-env \
# RUN: | FileCheck -match-full-lines %s
#
# END.
# Make sure env commands are included in printed commands.
+# CHECK: -- Testing: 7 tests{{.*}}
+
+# CHECK: UNRESOLVED: shtest-env :: env-args-last-is-assign.txt ({{[^)]*}})
+# CHECK: ValueError: 'env' requires a subcommand
+
+# CHECK: UNRESOLVED: shtest-env :: env-args-last-is-u-arg.txt ({{[^)]*}})
+# CHECK: ValueError: 'env' requires a subcommand
+
+# CHECK: UNRESOLVED: shtest-env :: env-args-last-is-u.txt ({{[^)]*}})
+# CHECK: ValueError: 'env' requires a subcommand
+
+# CHECK: UNRESOLVED: shtest-env :: env-args-none.txt ({{[^)]*}})
+# CHECK: ValueError: 'env' requires a subcommand
+
# CHECK: PASS: shtest-env :: env-u.txt ({{[^)]*}})
# CHECK: $ "{{[^"]*}}" "print_environment.py"
# CHECK: $ "env" "-u" "FOO" "{{[^"]*}}" "print_environment.py"
@@ -21,3 +35,5 @@
# CHECK: $ "env" "A_FOO=1" "-u" "FOO" "B_BAR=2" "-u" "BAR" "C_OOF=3" "{{[^"]*}}" "print_environment.py"
# CHECK: Expected Passes : 3
+# CHECK: Unresolved Tests : 4
+# CHECK-NOT: {{.}}
Index: llvm/utils/lit/tests/Inputs/shtest-env/env-args-none.txt
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/shtest-env/env-args-none.txt
@@ -0,0 +1 @@
+# RUN: env
Index: llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u.txt
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u.txt
@@ -0,0 +1 @@
+# RUN: env -u
Index: llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u-arg.txt
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u-arg.txt
@@ -0,0 +1 @@
+# RUN: env -u FOO
Index: llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-assign.txt
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-assign.txt
@@ -0,0 +1 @@
+# RUN: env FOO=1
Index: llvm/utils/lit/lit/TestRunner.py
===================================================================
--- llvm/utils/lit/lit/TestRunner.py
+++ llvm/utils/lit/lit/TestRunner.py
@@ -238,7 +238,7 @@
# args are from 'export' or 'env' command.
# Returns copy of args without those commands or their arguments.
def updateEnv(env, args):
- arg_idx = 1
+ arg_idx_next = len(args)
unset_next_env_var = False
for arg_idx, arg in enumerate(args[1:]):
# Support for the -u flag (unsetting) for env command
@@ -257,9 +257,10 @@
key, eq, val = arg.partition('=')
# Stop if there was no equals.
if eq == '':
+ arg_idx_next = arg_idx + 1
break
env.env[key] = val
- return args[arg_idx+1:]
+ return args[arg_idx_next:]
def executeBuiltinEcho(cmd, shenv):
"""Interpret a redirected echo command"""
@@ -880,6 +881,8 @@
# env FOO=1 llc < %s | env BAR=2 llvm-mc | FileCheck %s
cmd_shenv = ShellEnvironment(shenv.cwd, shenv.env)
args = updateEnv(cmd_shenv, j.args)
+ if not args:
+ raise ValueError("'env' requires a subcommand")
stdin, stdout, stderr = processRedirects(j, default_stdin, cmd_shenv,
opened_files)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66482.216179.patch
Type: text/x-patch
Size: 3679 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190820/a849919d/attachment.bin>
More information about the llvm-commits
mailing list