diff options
author | Tristan Maat <tm@tlater.net> | 2018-01-11 08:25:37 +0000 |
---|---|---|
committer | Tristan Maat <tristan.maat@codethink.co.uk> | 2018-02-07 16:14:11 +0000 |
commit | eeed9f62eec752e3071211ccbdca1139e6e3448b (patch) | |
tree | 2d246fa3c02358d53037a2c7a41c18d2acefdf90 /tests/integration/shell.py | |
parent | 11c8f386bbf2c416705f4b6399b20b49f33dbde2 (diff) | |
download | buildstream-eeed9f62eec752e3071211ccbdca1139e6e3448b.tar.gz |
Merge integration tests into general tests
Diffstat (limited to 'tests/integration/shell.py')
-rw-r--r-- | tests/integration/shell.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/integration/shell.py b/tests/integration/shell.py new file mode 100644 index 000000000..1e14f736c --- /dev/null +++ b/tests/integration/shell.py @@ -0,0 +1,81 @@ +import os +import shlex +import pytest + +from buildstream import _yaml + +from tests.testutils import cli_integration as cli + + +pytestmark = pytest.mark.integration + + +DATA_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "project" +) + + +def execute_shell(cli, project, string, element='base.bst'): + # 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, '--'] + shlex.split(string)) + + +# Test running something through a shell, allowing it to find the +# executable +@pytest.mark.datafiles(DATA_DIR) +def test_shell(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + + result = execute_shell(cli, project, "echo Ponies!") + assert result.exit_code == 0 + assert result.output == "Ponies!\n" + + +# Test running an executable directly +@pytest.mark.datafiles(DATA_DIR) +def test_executable(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + + result = execute_shell(cli, project, "/bin/echo Horseys!") + assert result.exit_code == 0 + assert result.output == "Horseys!\n" + + +# Test running an executable in a runtime with no shell (i.e., no +# /bin/sh) +@pytest.mark.datafiles(DATA_DIR) +def test_no_shell(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + element_path = os.path.join(project, 'elements') + element_name = 'shell/no-shell.bst' + + # Create an element that removes /bin/sh from the base runtime + element = { + 'kind': 'script', + 'depends': [{ + 'filename': 'base.bst', + 'type': 'build' + }], + 'variables': { + 'install-root': '/' + }, + 'config': { + 'commands': [ + 'rm /bin/sh' + ] + } + } + os.makedirs(os.path.dirname(os.path.join(element_path, element_name)), exist_ok=True) + _yaml.dump(element, os.path.join(element_path, element_name)) + + result = cli.run(project=project, args=['build', element_name]) + assert result.exit_code == 0 + + result = execute_shell(cli, project, '/usr/bin/echo Pegasissies!', element=element_name) + assert result.exit_code == 0 + assert result.output == "Pegasissies!\n" |