summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-02-23 21:26:46 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-02-25 00:34:39 +0900
commit9632eafb970cab601cc647b4df05f92518882d25 (patch)
treec69e5a6460b2072947c5f2f47d82777eda89eba4 /tests
parent0d5ba30e9a917d9f574f0c468678148136a7f2e5 (diff)
downloadbuildstream-9632eafb970cab601cc647b4df05f92518882d25.tar.gz
tests/integration/shell.py: Added tests for inheriting environment variables
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/project/project.conf7
-rw-r--r--tests/integration/shell.py40
2 files changed, 44 insertions, 3 deletions
diff --git a/tests/integration/project/project.conf b/tests/integration/project/project.conf
index a677129fb..3aae4fd0e 100644
--- a/tests/integration/project/project.conf
+++ b/tests/integration/project/project.conf
@@ -14,3 +14,10 @@ split-rules:
test:
- |
/tests/*
+
+# Allow inheriting a host environment variable
+# in `bst shell` for the shell test
+#
+shell:
+ environment-inherit:
+ - ANIMAL
diff --git a/tests/integration/shell.py b/tests/integration/shell.py
index 7e9c5afd3..8c47d7718 100644
--- a/tests/integration/shell.py
+++ b/tests/integration/shell.py
@@ -24,14 +24,19 @@ DATA_DIR = os.path.join(
# project (str): The project directory
# command (list): The command argv list
# element (str): The element to build and run a shell with
+# isolate (bool): Whether to pass --isolate to `bst shell`
#
-def execute_shell(cli, project, command, element='base.bst'):
+def execute_shell(cli, project, command, element='base.bst', isolate=False):
# Ensure the element is built
result = cli.run(project=project, args=['build', element])
assert result.exit_code == 0
- return cli.run(project=project,
- args=['shell', element, '--'] + command)
+ args = ['shell']
+ if isolate:
+ args += ['--isolate']
+ args += [element, '--'] + command
+
+ return cli.run(project=project, args=args)
# Test running something through a shell, allowing it to find the
@@ -55,6 +60,35 @@ def test_executable(cli, tmpdir, datafiles):
assert result.output == "Horseys!\n"
+# Test host environment variable inheritance
+@pytest.mark.parametrize("animal", [("Horse"), ("Pony")])
+@pytest.mark.datafiles(DATA_DIR)
+def test_inherit(cli, tmpdir, datafiles, animal):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+
+ # Set the env var, and expect the same with added newline
+ os.environ['ANIMAL'] = animal
+ expected = animal + '\n'
+
+ result = execute_shell(cli, project, ['/bin/sh', '-c', 'echo ${ANIMAL}'])
+ assert result.exit_code == 0
+ assert result.output == expected
+
+
+# Test that environment variable inheritance is disabled with --isolate
+@pytest.mark.parametrize("animal", [("Horse"), ("Pony")])
+@pytest.mark.datafiles(DATA_DIR)
+def test_isolated_no_inherit(cli, tmpdir, datafiles, animal):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+
+ # Set the env var, but expect that it is not applied
+ os.environ['ANIMAL'] = animal
+
+ result = execute_shell(cli, project, ['/bin/sh', '-c', 'echo ${ANIMAL}'], isolate=True)
+ assert result.exit_code == 0
+ assert result.output == '\n'
+
+
# Test running an executable in a runtime with no shell (i.e., no
# /bin/sh)
@pytest.mark.datafiles(DATA_DIR)