summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-10-07 18:06:24 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-10-10 19:29:59 +0900
commit6819bb8c50126538ce8877b8f8c5fb98120001db (patch)
tree71d251b4435c17d32bd8b34f74e3076932818524
parent7371f57cf421a97430687e77a7477c429b742e61 (diff)
downloadbuildstream-6819bb8c50126538ce8877b8f8c5fb98120001db.tar.gz
tests/format/optioneltmask.py: Added element-mask option specific test cases
-rw-r--r--tests/format/option-element-mask-invalid/pony.bst6
-rw-r--r--tests/format/option-element-mask-invalid/project.conf12
-rw-r--r--tests/format/option-element-mask/giraffy.bst6
-rw-r--r--tests/format/option-element-mask/horsy.bst6
-rw-r--r--tests/format/option-element-mask/pony.bst6
-rw-r--r--tests/format/option-element-mask/project.conf6
-rw-r--r--tests/format/option-element-mask/zebry.bst6
-rw-r--r--tests/format/optioneltmask.py87
8 files changed, 135 insertions, 0 deletions
diff --git a/tests/format/option-element-mask-invalid/pony.bst b/tests/format/option-element-mask-invalid/pony.bst
new file mode 100644
index 000000000..209ae1481
--- /dev/null
+++ b/tests/format/option-element-mask-invalid/pony.bst
@@ -0,0 +1,6 @@
+kind: autotools
+variables:
+ debug: False
+ (?):
+ - ("pony.bst" in debug_elements):
+ debug: True
diff --git a/tests/format/option-element-mask-invalid/project.conf b/tests/format/option-element-mask-invalid/project.conf
new file mode 100644
index 000000000..a3d381855
--- /dev/null
+++ b/tests/format/option-element-mask-invalid/project.conf
@@ -0,0 +1,12 @@
+name: test
+
+options:
+ debug_elements:
+ type: element-mask
+ description: The elements to build in debug mode
+
+ # Values are not allowed to be declared on element mask options
+ values:
+ - pony
+ - horsy
+ - zebry
diff --git a/tests/format/option-element-mask/giraffy.bst b/tests/format/option-element-mask/giraffy.bst
new file mode 100644
index 000000000..1cb7109dd
--- /dev/null
+++ b/tests/format/option-element-mask/giraffy.bst
@@ -0,0 +1,6 @@
+kind: autotools
+variables:
+ debug: False
+ (?):
+ - ("giraffy.bst" in debug_elements):
+ debug: True
diff --git a/tests/format/option-element-mask/horsy.bst b/tests/format/option-element-mask/horsy.bst
new file mode 100644
index 000000000..75e90a16b
--- /dev/null
+++ b/tests/format/option-element-mask/horsy.bst
@@ -0,0 +1,6 @@
+kind: autotools
+variables:
+ debug: False
+ (?):
+ - ("horsy.bst" in debug_elements):
+ debug: True
diff --git a/tests/format/option-element-mask/pony.bst b/tests/format/option-element-mask/pony.bst
new file mode 100644
index 000000000..209ae1481
--- /dev/null
+++ b/tests/format/option-element-mask/pony.bst
@@ -0,0 +1,6 @@
+kind: autotools
+variables:
+ debug: False
+ (?):
+ - ("pony.bst" in debug_elements):
+ debug: True
diff --git a/tests/format/option-element-mask/project.conf b/tests/format/option-element-mask/project.conf
new file mode 100644
index 000000000..ede07fbdd
--- /dev/null
+++ b/tests/format/option-element-mask/project.conf
@@ -0,0 +1,6 @@
+name: test
+
+options:
+ debug_elements:
+ type: element-mask
+ description: The elements to build in debug mode
diff --git a/tests/format/option-element-mask/zebry.bst b/tests/format/option-element-mask/zebry.bst
new file mode 100644
index 000000000..e1eccb376
--- /dev/null
+++ b/tests/format/option-element-mask/zebry.bst
@@ -0,0 +1,6 @@
+kind: autotools
+variables:
+ debug: False
+ (?):
+ - ("zebry.bst" in debug_elements):
+ debug: True
diff --git a/tests/format/optioneltmask.py b/tests/format/optioneltmask.py
new file mode 100644
index 000000000..83ccf8b6f
--- /dev/null
+++ b/tests/format/optioneltmask.py
@@ -0,0 +1,87 @@
+import os
+import pytest
+from buildstream import _yaml
+from buildstream import LoadError, LoadErrorReason
+from tests.testutils.runcli import cli
+
+# Project directory
+DATA_DIR = os.path.dirname(os.path.realpath(__file__))
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("target,value,expected", [
+ ('pony.bst', 'pony.bst', 'True'),
+ ('horsy.bst', 'pony.bst, horsy.bst', 'True'),
+ ('zebry.bst', 'pony.bst, horsy.bst', 'False'),
+])
+def test_conditional_cli(cli, datafiles, target, value, expected):
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-element-mask')
+ result = cli.run(project=project, silent=True, args=[
+ '--option', 'debug_elements', value,
+ 'show',
+ '--deps', 'none',
+ '--format', '%{vars}',
+ target])
+
+ assert result.exit_code == 0
+ loaded = _yaml.load_data(result.output)
+ assert loaded['debug'] == expected
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("target,value,expected", [
+ ('pony.bst', ['pony.bst'], 'True'),
+ ('horsy.bst', ['pony.bst', 'horsy.bst'], 'True'),
+ ('zebry.bst', ['pony.bst', 'horsy.bst'], 'False'),
+])
+def test_conditional_config(cli, datafiles, target, value, expected):
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-element-mask')
+ cli.configure({
+ 'projects': {
+ 'test': {
+ 'options': {
+ 'debug_elements': value
+ }
+ }
+ }
+ })
+ result = cli.run(project=project, silent=True, args=[
+ 'show',
+ '--deps', 'none',
+ '--format', '%{vars}',
+ target])
+
+ assert result.exit_code == 0
+ loaded = _yaml.load_data(result.output)
+ assert loaded['debug'] == expected
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_invalid_declaration(cli, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-element-mask-invalid')
+ result = cli.run(project=project, silent=True, args=[
+ 'show',
+ '--deps', 'none',
+ '--format', '%{vars}',
+ 'pony.bst'])
+
+ assert result.exit_code != 0
+ assert result.exception
+ assert isinstance(result.exception, LoadError)
+ assert result.exception.reason == LoadErrorReason.INVALID_DATA
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_invalid_value(cli, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-element-mask')
+ result = cli.run(project=project, silent=True, args=[
+ '--option', 'debug_elements', 'kitten.bst',
+ 'show',
+ '--deps', 'none',
+ '--format', '%{vars}',
+ 'pony.bst'])
+
+ assert result.exit_code != 0
+ assert result.exception
+ assert isinstance(result.exception, LoadError)
+ assert result.exception.reason == LoadErrorReason.INVALID_DATA