Index: llvm/trunk/utils/lit/lit/TestRunner.py =================================================================== --- llvm/trunk/utils/lit/lit/TestRunner.py +++ llvm/trunk/utils/lit/lit/TestRunner.py @@ -217,7 +217,20 @@ # cmd is export or env def updateEnv(env, cmd): arg_idx = 1 + unset_next_env_var = False for arg_idx, arg in enumerate(cmd.args[1:]): + # Support for the -u flag (unsetting) for env command + # e.g., env -u FOO -u BAR will remove both FOO and BAR + # from the environment. + if arg == '-u': + unset_next_env_var = True + continue + if unset_next_env_var: + unset_next_env_var = False + if arg in env.env: + del env.env[arg] + continue + # Partition the string into KEY=VALUE. key, eq, val = arg.partition('=') # Stop if there was no equals. Index: llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-u.txt =================================================================== --- llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-u.txt +++ llvm/trunk/utils/lit/tests/Inputs/shtest-env/env-u.txt @@ -0,0 +1,23 @@ +# Check and make sure preset environment variable were set in lit.cfg +# +# RUN: %{python} print_environment.py \ +# RUN: | FileCheck --check-prefix=CHECK-ENV-PRESET %s +# +# Check single unset of environment variable +# +# RUN: env -u FOO %{python} print_environment.py \ +# RUN: | FileCheck --check-prefix=CHECK-ENV-UNSET-1 %s +# +# Check multiple unsets of environment variables +# +# RUN: env -u FOO -u BAR %{python} print_environment.py \ +# RUN: | FileCheck --check-prefix=CHECK-ENV-UNSET-MULTIPLE %s + +# CHECK-ENV-PRESET: BAR = 2 +# CHECK-ENV-PRESET: FOO = 1 + +# CHECK-ENV-UNSET-1: BAR = 2 +# CHECK-ENV-UNSET-1-NOT: FOO + +# CHECK-ENV-UNSET-MULTIPLE-NOT: BAR +# CHECK-ENV-UNSET-MULTIPLE-NOT: FOO Index: llvm/trunk/utils/lit/tests/Inputs/shtest-env/env.txt =================================================================== --- llvm/trunk/utils/lit/tests/Inputs/shtest-env/env.txt +++ llvm/trunk/utils/lit/tests/Inputs/shtest-env/env.txt @@ -0,0 +1,15 @@ +# Check for simple one environment variable setting +# +# RUN: env A_FOO=999 %{python} print_environment.py \ +# RUN: | FileCheck --check-prefix=CHECK-ENV-1 %s +# +# Check for multiple environment variable settings +# +# RUN: env A_FOO=1 B_BAR=2 C_OOF=3 %{python} print_environment.py \ +# RUN: | FileCheck --check-prefix=CHECK-ENV-MULTIPLE %s + +# CHECK-ENV-1: A_FOO = 999 + +# CHECK-ENV-MULTIPLE: A_FOO = 1 +# CHECK-ENV-MULTIPLE: B_BAR = 2 +# CHECK-ENV-MULTIPLE: C_OOF = 3 Index: llvm/trunk/utils/lit/tests/Inputs/shtest-env/lit.cfg =================================================================== --- llvm/trunk/utils/lit/tests/Inputs/shtest-env/lit.cfg +++ llvm/trunk/utils/lit/tests/Inputs/shtest-env/lit.cfg @@ -0,0 +1,9 @@ +import lit.formats +config.name = 'shtest-env' +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}', sys.executable)) Index: llvm/trunk/utils/lit/tests/Inputs/shtest-env/mixed.txt =================================================================== --- llvm/trunk/utils/lit/tests/Inputs/shtest-env/mixed.txt +++ llvm/trunk/utils/lit/tests/Inputs/shtest-env/mixed.txt @@ -0,0 +1,18 @@ +# Check for setting and removing one environment variable +# +# RUN: env A_FOO=999 -u FOO %{python} print_environment.py \ +# RUN: | FileCheck --check-prefix=CHECK-ENV-1 %s +# +# Check for setting/unsetting multiple environment variables +# +# RUN: env A_FOO=1 -u FOO B_BAR=2 -u BAR C_OOF=3 %{python} print_environment.py \ +# RUN: | FileCheck --check-prefix=CHECK-ENV-MULTIPLE %s + +# CHECK-ENV-1: A_FOO = 999 +# CHECK-ENV-1-NOT: FOO + +# CHECK-ENV-MULTIPLE: A_FOO = 1 +# CHECK-ENV-MULTIPLE-NOT: BAR +# CHECK-ENV-MULTIPLE: B_BAR = 2 +# CHECK-ENV-MULTIPLE: C_OOF = 3 +# CHECK-ENV-MULTIPLE-NOT: FOO Index: llvm/trunk/utils/lit/tests/Inputs/shtest-env/print_environment.py =================================================================== --- llvm/trunk/utils/lit/tests/Inputs/shtest-env/print_environment.py +++ llvm/trunk/utils/lit/tests/Inputs/shtest-env/print_environment.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python + +import os + +sorted_environment = sorted(os.environ.items()) + +for name,value in sorted_environment: + print name,'=',value Index: llvm/trunk/utils/lit/tests/Inputs/shtest-env/shtest-env.py =================================================================== --- llvm/trunk/utils/lit/tests/Inputs/shtest-env/shtest-env.py +++ llvm/trunk/utils/lit/tests/Inputs/shtest-env/shtest-env.py @@ -0,0 +1,3 @@ +# Check the env command +# +# RUN: %{lit} -a -v %{inputs}/shtest-env