summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-10-06 16:27:23 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-10-10 19:29:59 +0900
commit7371f57cf421a97430687e77a7477c429b742e61 (patch)
tree00576ea9cc565c4c2ea2d0d0a9cba973f79866c3
parent5d6cad8f5f76be2e46c748f9eb770b84ec18f7e1 (diff)
downloadbuildstream-7371f57cf421a97430687e77a7477c429b742e61.tar.gz
tests/format/optionflags.py: Added flags option specific test cases
-rw-r--r--tests/format/option-flags-missing/element.bst1
-rw-r--r--tests/format/option-flags-missing/project.conf7
-rw-r--r--tests/format/option-flags/element-in.bst10
-rw-r--r--tests/format/option-flags/element.bst10
-rw-r--r--tests/format/option-flags/project.conf22
-rw-r--r--tests/format/optionflags.py130
6 files changed, 180 insertions, 0 deletions
diff --git a/tests/format/option-flags-missing/element.bst b/tests/format/option-flags-missing/element.bst
new file mode 100644
index 000000000..3c29b4ea1
--- /dev/null
+++ b/tests/format/option-flags-missing/element.bst
@@ -0,0 +1 @@
+kind: autotools
diff --git a/tests/format/option-flags-missing/project.conf b/tests/format/option-flags-missing/project.conf
new file mode 100644
index 000000000..6554022e4
--- /dev/null
+++ b/tests/format/option-flags-missing/project.conf
@@ -0,0 +1,7 @@
+name: test
+
+options:
+ empty:
+ type: flags
+ description: Invalid because no values are defined
+ values: []
diff --git a/tests/format/option-flags/element-in.bst b/tests/format/option-flags/element-in.bst
new file mode 100644
index 000000000..d8565e603
--- /dev/null
+++ b/tests/format/option-flags/element-in.bst
@@ -0,0 +1,10 @@
+kind: autotools
+variables:
+ result: "a pony"
+ (?):
+ - ("zebry" in farm):
+ result: "a zebry"
+ - ("pony" not in farm):
+ result: "no pony"
+ - (animal not in farm):
+ result: "no horsy"
diff --git a/tests/format/option-flags/element.bst b/tests/format/option-flags/element.bst
new file mode 100644
index 000000000..fde971050
--- /dev/null
+++ b/tests/format/option-flags/element.bst
@@ -0,0 +1,10 @@
+kind: autotools
+variables:
+ result: "a pony"
+ (?):
+ - farm == [ "zebry" ]:
+ result: "a zebry"
+ - farm == [ "horsy", "pony" ]:
+ result: "a pony and a horsy"
+ - farm == [ "horsy", "pony", "zebry" ]:
+ result: "all the animals"
diff --git a/tests/format/option-flags/project.conf b/tests/format/option-flags/project.conf
new file mode 100644
index 000000000..1cab9e315
--- /dev/null
+++ b/tests/format/option-flags/project.conf
@@ -0,0 +1,22 @@
+name: test
+
+options:
+ # Include an enum option here so we can compare it
+ animal:
+ type: enum
+ description: The kind of animal
+ values:
+ - pony
+ - horsy
+ - zebry
+ default: horsy
+ # A flags value to test
+ farm:
+ type: flags
+ description: The kinds of animals on this farm
+ values:
+ - pony
+ - horsy
+ - zebry
+ default:
+ - pony
diff --git a/tests/format/optionflags.py b/tests/format/optionflags.py
new file mode 100644
index 000000000..7ad5f2485
--- /dev/null
+++ b/tests/format/optionflags.py
@@ -0,0 +1,130 @@
+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,option,value,expected", [
+ # Test (var == [ "foo" ]) syntax
+ ('element.bst', 'farm', 'pony', 'a pony'),
+ ('element.bst', 'farm', 'zebry', 'a zebry'),
+ ('element.bst', 'farm', 'pony, horsy', 'a pony and a horsy'),
+ ('element.bst', 'farm', 'zebry,horsy , pony', 'all the animals'),
+
+ # Test ("literal" in var) syntax
+ ('element-in.bst', 'farm', 'zebry, horsy, pony', 'a zebry'),
+
+ # Test ("literal" not in var) syntax
+ ('element-in.bst', 'farm', 'zebry, horsy', 'no pony'),
+
+ # Test (var1 not in var2) syntax (where var1 is enum and var2 is flags)
+ ('element-in.bst', 'farm', 'zebry, pony', 'no horsy'),
+])
+def test_conditional_cli(cli, datafiles, target, option, value, expected):
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-flags')
+ result = cli.run(project=project, silent=True, args=[
+ '--option', option, value,
+ 'show',
+ '--deps', 'none',
+ '--format', '%{vars}',
+ target])
+
+ assert result.exit_code == 0
+ loaded = _yaml.load_data(result.output)
+ assert loaded['result'] == expected
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("target,option,value,expected", [
+ # Test 'var == [ "foo" ]' syntax
+ ('element.bst', 'farm', ['pony'], 'a pony'),
+ ('element.bst', 'farm', ['zebry'], 'a zebry'),
+ ('element.bst', 'farm', ['pony', 'horsy'], 'a pony and a horsy'),
+ ('element.bst', 'farm', ['zebry', 'horsy', 'pony'], 'all the animals'),
+])
+def test_conditional_config(cli, datafiles, target, option, value, expected):
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-flags')
+ cli.configure({
+ 'projects': {
+ 'test': {
+ 'options': {
+ option: 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['result'] == expected
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("cli_option", [
+ ('giraffy'), # Not a valid animal for the farm option
+ ('horsy pony') # Does not include comma separators
+])
+def test_invalid_value_cli(cli, datafiles, cli_option):
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-flags')
+ result = cli.run(project=project, silent=True, args=[
+ '--option', 'farm', cli_option,
+ 'show',
+ '--deps', 'none',
+ '--format', '%{vars}',
+ 'element.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)
+@pytest.mark.parametrize("config_option", [
+ ('pony'), # Not specified as a list
+ (['horsy', 'pony', 'giraffy']), # Invalid giraffy animal for farm option
+ ({'dic': 'tionary'}) # Dicts also dont make sense in the config for flags
+])
+def test_invalid_value_config(cli, datafiles, config_option):
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-flags')
+ cli.configure({
+ 'projects': {
+ 'test': {
+ 'options': {
+ 'farm': config_option
+ }
+ }
+ }
+ })
+ result = cli.run(project=project, silent=True, args=[
+ 'show',
+ '--deps', 'none',
+ '--format', '%{vars}',
+ 'element.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_missing_values(cli, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename, 'option-flags-missing')
+ result = cli.run(project=project, silent=True, args=[
+ 'show',
+ '--deps', 'none',
+ '--format', '%{vars}',
+ 'element.bst'])
+ assert result.exit_code != 0
+ assert result.exception
+ assert isinstance(result.exception, LoadError)
+ assert result.exception.reason == LoadErrorReason.INVALID_DATA