diff options
author | Ben Dunbobbin <bd1976llvm@gmail.com> | 2017-08-18 17:32:57 +0000 |
---|---|---|
committer | Ben Dunbobbin <bd1976llvm@gmail.com> | 2017-08-18 17:32:57 +0000 |
commit | 7b76de2dcb17920b5afeed97efa878527a454c09 (patch) | |
tree | 1e3d37cc56b2525bb8e4f91eb24b36383d3e9585 /llvm/utils/lit/tests | |
parent | f5d826a294d59b32d0057d4e8fffd878f37d4592 (diff) | |
download | bcm5719-llvm-7b76de2dcb17920b5afeed97efa878527a454c09.tar.gz bcm5719-llvm-7b76de2dcb17920b5afeed97efa878527a454c09.zip |
[lit] support unsetting env variables (again!)
This is an updated version of https://reviews.llvm.org/D22144 by @jlpeyton.
The patch was accepted but not landed.
This is useful functionality and I would like to use this to enable lit tests for environment variable behaviour.
Differential Revision: https://reviews.llvm.org/D36403
llvm-svn: 311180
Diffstat (limited to 'llvm/utils/lit/tests')
6 files changed, 76 insertions, 0 deletions
diff --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-u.txt b/llvm/utils/lit/tests/Inputs/shtest-env/env-u.txt new file mode 100644 index 00000000000..9cdf9d08850 --- /dev/null +++ b/llvm/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 diff --git a/llvm/utils/lit/tests/Inputs/shtest-env/env.txt b/llvm/utils/lit/tests/Inputs/shtest-env/env.txt new file mode 100644 index 00000000000..aa697b0c408 --- /dev/null +++ b/llvm/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 diff --git a/llvm/utils/lit/tests/Inputs/shtest-env/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-env/lit.cfg new file mode 100644 index 00000000000..23ef60a4b21 --- /dev/null +++ b/llvm/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)) diff --git a/llvm/utils/lit/tests/Inputs/shtest-env/mixed.txt b/llvm/utils/lit/tests/Inputs/shtest-env/mixed.txt new file mode 100644 index 00000000000..be32d458843 --- /dev/null +++ b/llvm/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 diff --git a/llvm/utils/lit/tests/Inputs/shtest-env/print_environment.py b/llvm/utils/lit/tests/Inputs/shtest-env/print_environment.py new file mode 100644 index 00000000000..1add4079d58 --- /dev/null +++ b/llvm/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 diff --git a/llvm/utils/lit/tests/Inputs/shtest-env/shtest-env.py b/llvm/utils/lit/tests/Inputs/shtest-env/shtest-env.py new file mode 100644 index 00000000000..fc5f973e676 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/shtest-env/shtest-env.py @@ -0,0 +1,3 @@ +# Check the env command +# +# RUN: %{lit} -a -v %{inputs}/shtest-env |