summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPhillip Smyth <phillip.smyth@codethink.co.uk>2018-11-30 11:33:16 +0000
committerPhillip Smyth <phillip.smyth@codethink.co.uk>2018-11-30 16:50:35 +0000
commitac0bc4c0ef755ba5577b4c34356171397f3f3908 (patch)
tree7fe99f794ad7158dd5e4e8d23d278005dca2bcac /tests
parent2d6ec07d2cf20c20e9b9269334ba9599d588c410 (diff)
downloadbuildstream-ac0bc4c0ef755ba5577b4c34356171397f3f3908.tar.gz
Added tests for .bst suffix and completions
buildcheckout.py: Add mandatory .bst suffix tests completions.py: Add test for fail on invalid suffix Added required files for testing integration/source-determinism.py: renamed test elements to end with .bst loader/__init__.py: initialised context properly with load and a message handler
Diffstat (limited to 'tests')
-rw-r--r--tests/completions/completions.py44
-rw-r--r--tests/frontend/buildcheckout.py25
-rw-r--r--tests/frontend/project/elements/target.foo4
-rw-r--r--tests/frontend/project/elements/target2.bst7
-rw-r--r--tests/frontend/project/project.conf3
-rw-r--r--tests/integration/source-determinism.py4
-rw-r--r--tests/loader/__init__.py10
7 files changed, 91 insertions, 6 deletions
diff --git a/tests/completions/completions.py b/tests/completions/completions.py
index 7b63e67fe..af35fb23a 100644
--- a/tests/completions/completions.py
+++ b/tests/completions/completions.py
@@ -66,6 +66,13 @@ PROJECT_ELEMENTS = [
"target.bst"
]
+INVALID_ELEMENTS = [
+ "target.foo"
+ "target.bst.bar"
+]
+
+MIXED_ELEMENTS = PROJECT_ELEMENTS + INVALID_ELEMENTS
+
def assert_completion(cli, cmd, word_idx, expected, cwd=None):
result = cli.run(cwd=cwd, env={
@@ -85,6 +92,24 @@ def assert_completion(cli, cmd, word_idx, expected, cwd=None):
assert words == expected
+def assert_completion_failed(cli, cmd, word_idx, expected, cwd=None):
+ result = cli.run(cwd=cwd, env={
+ '_BST_COMPLETION': 'complete',
+ 'COMP_WORDS': cmd,
+ 'COMP_CWORD': str(word_idx)
+ })
+ words = []
+ if result.output:
+ words = result.output.splitlines()
+
+ # The order is meaningless, bash will
+ # take the results and order it by its
+ # own little heuristics
+ words = sorted(words)
+ expected = sorted(expected)
+ assert words != expected
+
+
@pytest.mark.parametrize("cmd,word_idx,expected", [
('bst', 0, []),
('bst ', 1, MAIN_COMMANDS),
@@ -193,19 +218,19 @@ def test_option_directory(datafiles, cli, cmd, word_idx, expected, subdir):
# When running in the project directory
('no-element-path', 'bst show ', 2,
- [e + ' ' for e in (PROJECT_ELEMENTS + ['project.conf'])] + ['files/'], None),
+ [e + ' ' for e in PROJECT_ELEMENTS] + ['files/'], None),
('no-element-path', 'bst build com', 2,
['compose-all.bst ', 'compose-include-bin.bst ', 'compose-exclude-dev.bst '], None),
# When running from the files subdir
('no-element-path', 'bst show ', 2,
- [e + ' ' for e in (PROJECT_ELEMENTS + ['project.conf'])] + ['files/'], 'files'),
+ [e + ' ' for e in PROJECT_ELEMENTS] + ['files/'], 'files'),
('no-element-path', 'bst build com', 2,
['compose-all.bst ', 'compose-include-bin.bst ', 'compose-exclude-dev.bst '], 'files'),
# When passing the project directory
('no-element-path', 'bst --directory ../ show ', 4,
- [e + ' ' for e in (PROJECT_ELEMENTS + ['project.conf'])] + ['files/'], 'files'),
+ [e + ' ' for e in PROJECT_ELEMENTS] + ['files/'], 'files'),
('no-element-path', 'bst --directory ../ show f', 4, ['files/'], 'files'),
('no-element-path', 'bst --directory ../ show files/', 4, ['files/bin-files/', 'files/dev-files/'], 'files'),
('no-element-path', 'bst --directory ../ build com', 4,
@@ -226,6 +251,19 @@ def test_argument_element(datafiles, cli, project, cmd, word_idx, expected, subd
assert_completion(cli, cmd, word_idx, expected, cwd=cwd)
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("project,cmd,word_idx,expected,subdir", [
+
+ # When element has invalid suffix
+ ('project', 'bst --directory ../ show ', 4, [e + ' ' for e in MIXED_ELEMENTS], 'files')
+])
+def test_argument_element_invalid(datafiles, cli, project, cmd, word_idx, expected, subdir):
+ cwd = os.path.join(str(datafiles), project)
+ if subdir:
+ cwd = os.path.join(cwd, subdir)
+ assert_completion_failed(cli, cmd, word_idx, expected, cwd=cwd)
+
+
@pytest.mark.parametrize("cmd,word_idx,expected", [
('bst he', 1, ['help ']),
('bst help ', 2, MAIN_COMMANDS),
diff --git a/tests/frontend/buildcheckout.py b/tests/frontend/buildcheckout.py
index 159af2d74..1299fa190 100644
--- a/tests/frontend/buildcheckout.py
+++ b/tests/frontend/buildcheckout.py
@@ -61,6 +61,31 @@ def test_build_checkout(datafiles, cli, strict, hardlinks):
@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("strict,hardlinks", [
+ ("non-strict", "hardlinks"),
+])
+def test_build_invalid_suffix(datafiles, cli, strict, hardlinks):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ checkout = os.path.join(cli.directory, 'checkout')
+
+ result = cli.run(project=project, args=strict_args(['build', 'target.foo'], strict))
+ result.assert_main_error(ErrorDomain.LOAD, "bad-element-suffix")
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("strict,hardlinks", [
+ ("non-strict", "hardlinks"),
+])
+def test_build_invalid_suffix_dep(datafiles, cli, strict, hardlinks):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ checkout = os.path.join(cli.directory, 'checkout')
+
+ # target2.bst depends on an element called target.foo
+ result = cli.run(project=project, args=strict_args(['build', 'target2.bst'], strict))
+ result.assert_main_error(ErrorDomain.LOAD, "bad-element-suffix")
+
+
+@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.parametrize("deps", [("run"), ("none")])
def test_build_checkout_deps(datafiles, cli, deps):
project = os.path.join(datafiles.dirname, datafiles.basename)
diff --git a/tests/frontend/project/elements/target.foo b/tests/frontend/project/elements/target.foo
new file mode 100644
index 000000000..d644c89ba
--- /dev/null
+++ b/tests/frontend/project/elements/target.foo
@@ -0,0 +1,4 @@
+kind: stack
+description: |
+
+ Main stack target for the bst build test
diff --git a/tests/frontend/project/elements/target2.bst b/tests/frontend/project/elements/target2.bst
new file mode 100644
index 000000000..259819f59
--- /dev/null
+++ b/tests/frontend/project/elements/target2.bst
@@ -0,0 +1,7 @@
+kind: stack
+description: |
+
+ Main stack target for the bst build test
+
+depends:
+- target.foo
diff --git a/tests/frontend/project/project.conf b/tests/frontend/project/project.conf
index 854e38693..a7e4a023c 100644
--- a/tests/frontend/project/project.conf
+++ b/tests/frontend/project/project.conf
@@ -2,3 +2,6 @@
name: test
element-path: elements
+
+fatal-warnings:
+- bad-element-suffix
diff --git a/tests/integration/source-determinism.py b/tests/integration/source-determinism.py
index a970c7dc9..fa12593df 100644
--- a/tests/integration/source-determinism.py
+++ b/tests/integration/source-determinism.py
@@ -33,7 +33,7 @@ def create_test_directory(*path, mode=0o644):
@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
def test_deterministic_source_umask(cli, tmpdir, datafiles, kind, integration_cache):
project = str(datafiles)
- element_name = 'list'
+ element_name = 'list.bst'
element_path = os.path.join(project, 'elements', element_name)
repodir = os.path.join(str(tmpdir), 'repo')
sourcedir = os.path.join(project, 'source')
@@ -108,7 +108,7 @@ def test_deterministic_source_local(cli, tmpdir, datafiles, integration_cache):
"""Only user rights should be considered for local source.
"""
project = str(datafiles)
- element_name = 'test'
+ element_name = 'test.bst'
element_path = os.path.join(project, 'elements', element_name)
sourcedir = os.path.join(project, 'source')
diff --git a/tests/loader/__init__.py b/tests/loader/__init__.py
index fcefdacf5..812888181 100644
--- a/tests/loader/__init__.py
+++ b/tests/loader/__init__.py
@@ -1,14 +1,22 @@
+import os
from buildstream._context import Context
from buildstream._project import Project
from buildstream._loader import Loader
-
#
# This is used by the loader test modules, these should
# be removed in favor of testing the functionality via
# the CLI like in the frontend tests anyway.
#
+
+
+def dummy_handler(message, context):
+ pass
+
+
def make_loader(basedir):
context = Context()
+ context.load(config=os.devnull)
+ context.set_message_handler(dummy_handler)
project = Project(basedir, context)
return project.loader