llvm.org GIT mirror llvm / 55c65a7
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369620 91177308-0d34-0410-b5e6-96231b3b80d8 Joel E. Denny 27 days ago
6 changed file(s) with 31 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
237237 # args are from 'export' or 'env' command.
238238 # Returns copy of args without those commands or their arguments.
239239 def updateEnv(env, args):
240 arg_idx = 1
240 arg_idx_next = len(args)
241241 unset_next_env_var = False
242242 for arg_idx, arg in enumerate(args[1:]):
243243 # Support for the -u flag (unsetting) for env command
256256 key, eq, val = arg.partition('=')
257257 # Stop if there was no equals.
258258 if eq == '':
259 arg_idx_next = arg_idx + 1
259260 break
260261 env.env[key] = val
261 return args[arg_idx+1:]
262 return args[arg_idx_next:]
262263
263264 def executeBuiltinEcho(cmd, shenv):
264265 """Interpret a redirected echo command"""
879880 # env FOO=1 llc < %s | env BAR=2 llvm-mc | FileCheck %s
880881 cmd_shenv = ShellEnvironment(shenv.cwd, shenv.env)
881882 args = updateEnv(cmd_shenv, j.args)
883 if not args:
884 raise InternalShellError(j,
885 "Error: 'env' requires a subcommand")
882886
883887 stdin, stdout, stderr = processRedirects(j, default_stdin, cmd_shenv,
884888 opened_files)
0 # Check the env command
11 #
2 # RUN: %{lit} -j 1 -a -v %{inputs}/shtest-env \
2 # RUN: not %{lit} -j 1 -a -v %{inputs}/shtest-env \
33 # RUN: | FileCheck -match-full-lines %s
44 #
55 # END.
66
77 # Make sure env commands are included in printed commands.
8
9 # CHECK: -- Testing: 7 tests{{.*}}
10
11 # CHECK: FAIL: shtest-env :: env-args-last-is-assign.txt ({{[^)]*}})
12 # CHECK: Error: 'env' requires a subcommand
13 # CHECK: error: command failed with exit status: {{.*}}
14
15 # CHECK: FAIL: shtest-env :: env-args-last-is-u-arg.txt ({{[^)]*}})
16 # CHECK: Error: 'env' requires a subcommand
17 # CHECK: error: command failed with exit status: {{.*}}
18
19 # CHECK: FAIL: shtest-env :: env-args-last-is-u.txt ({{[^)]*}})
20 # CHECK: Error: 'env' requires a subcommand
21 # CHECK: error: command failed with exit status: {{.*}}
22
23 # CHECK: FAIL: shtest-env :: env-args-none.txt ({{[^)]*}})
24 # CHECK: Error: 'env' requires a subcommand
25 # CHECK: error: command failed with exit status: {{.*}}
826
927 # CHECK: PASS: shtest-env :: env-u.txt ({{[^)]*}})
1028 # CHECK: $ "{{[^"]*}}" "print_environment.py"
2038 # CHECK: $ "env" "A_FOO=1" "-u" "FOO" "B_BAR=2" "-u" "BAR" "C_OOF=3" "{{[^"]*}}" "print_environment.py"
2139
2240 # CHECK: Expected Passes : 3
41 # CHECK: Unexpected Failures: 4
42 # CHECK-NOT: {{.}}