[llvm] r369620 - [lit] Diagnose insufficient args to internal env
Joel E. Denny via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 21 20:42:02 PDT 2019
Author: jdenny
Date: Wed Aug 21 20:42:01 2019
New Revision: 369620
URL: http://llvm.org/viewvc/llvm-project?rev=369620&view=rev
Log:
[lit] Diagnose insufficient args to internal env
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.
Reviewed By: stella.stamenova
Differential Revision: https://reviews.llvm.org/D66482
Added:
llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-assign.txt
llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u-arg.txt
llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u.txt
llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-none.txt
Modified:
llvm/trunk/utils/lit/lit/TestRunner.py
llvm/trunk/utils/lit/tests/shtest-env.py
Modified: llvm/trunk/utils/lit/lit/TestRunner.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/TestRunner.py?rev=369620&r1=369619&r2=369620&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/TestRunner.py (original)
+++ llvm/trunk/utils/lit/lit/TestRunner.py Wed Aug 21 20:42:01 2019
@@ -238,7 +238,7 @@ def quote_windows_command(seq):
# 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 @@ def updateEnv(env, args):
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,9 @@ def _executeShCmd(cmd, shenv, results, t
# 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 InternalShellError(j,
+ "Error: 'env' requires a subcommand")
stdin, stdout, stderr = processRedirects(j, default_stdin, cmd_shenv,
opened_files)
Added: llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-assign.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-assign.txt?rev=369620&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-assign.txt (added)
+++ llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-assign.txt Wed Aug 21 20:42:01 2019
@@ -0,0 +1 @@
+# RUN: env FOO=1
Added: llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u-arg.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u-arg.txt?rev=369620&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u-arg.txt (added)
+++ llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u-arg.txt Wed Aug 21 20:42:01 2019
@@ -0,0 +1 @@
+# RUN: env -u FOO
Added: llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u.txt?rev=369620&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u.txt (added)
+++ llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u.txt Wed Aug 21 20:42:01 2019
@@ -0,0 +1 @@
+# RUN: env -u
Added: llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-none.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-none.txt?rev=369620&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-none.txt (added)
+++ llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-args-none.txt Wed Aug 21 20:42:01 2019
@@ -0,0 +1 @@
+# RUN: env
Modified: llvm/trunk/utils/lit/tests/shtest-env.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/shtest-env.py?rev=369620&r1=369619&r2=369620&view=diff
==============================================================================
--- llvm/trunk/utils/lit/tests/shtest-env.py (original)
+++ llvm/trunk/utils/lit/tests/shtest-env.py Wed Aug 21 20:42:01 2019
@@ -1,12 +1,30 @@
# 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: FAIL: shtest-env :: env-args-last-is-assign.txt ({{[^)]*}})
+# CHECK: Error: 'env' requires a subcommand
+# CHECK: error: command failed with exit status: {{.*}}
+
+# CHECK: FAIL: shtest-env :: env-args-last-is-u-arg.txt ({{[^)]*}})
+# CHECK: Error: 'env' requires a subcommand
+# CHECK: error: command failed with exit status: {{.*}}
+
+# CHECK: FAIL: shtest-env :: env-args-last-is-u.txt ({{[^)]*}})
+# CHECK: Error: 'env' requires a subcommand
+# CHECK: error: command failed with exit status: {{.*}}
+
+# CHECK: FAIL: shtest-env :: env-args-none.txt ({{[^)]*}})
+# CHECK: Error: 'env' requires a subcommand
+# CHECK: error: command failed with exit status: {{.*}}
+
# CHECK: PASS: shtest-env :: env-u.txt ({{[^)]*}})
# CHECK: $ "{{[^"]*}}" "print_environment.py"
# CHECK: $ "env" "-u" "FOO" "{{[^"]*}}" "print_environment.py"
@@ -21,3 +39,5 @@
# CHECK: $ "env" "A_FOO=1" "-u" "FOO" "B_BAR=2" "-u" "BAR" "C_OOF=3" "{{[^"]*}}" "print_environment.py"
# CHECK: Expected Passes : 3
+# CHECK: Unexpected Failures: 4
+# CHECK-NOT: {{.}}
More information about the llvm-commits
mailing list