summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan van Berkom <tristan@codethink.co.uk>2020-09-03 18:30:06 +0900
committerTristan van Berkom <tristan@codethink.co.uk>2020-09-18 12:38:49 +0900
commitb0b62bede385ef1be44f167fe432db1d92f3ba1f (patch)
tree8cd01794142802381e2bd5a1ced99d7f9e3d9b76
parent42c5ee0a3a840756aae675a96b7b3c09e06b487d (diff)
downloadbuildstream-b0b62bede385ef1be44f167fe432db1d92f3ba1f.tar.gz
tests/format/dependencies.py: Adding tests for dependency `config` attributes
-rw-r--r--tests/format/dependencies.py31
-rw-r--r--tests/format/dependencies3/elements/dep.bst2
-rw-r--r--tests/format/dependencies3/elements/runtime-error.bst6
-rw-r--r--tests/format/dependencies3/elements/supported1.bst6
-rw-r--r--tests/format/dependencies3/elements/supported2.bst9
-rw-r--r--tests/format/dependencies3/elements/unsupported.bst6
-rw-r--r--tests/format/dependencies3/plugins/configsupported.py29
-rw-r--r--tests/format/dependencies3/plugins/configunsupported.py19
-rw-r--r--tests/format/dependencies3/project.conf11
9 files changed, 119 insertions, 0 deletions
diff --git a/tests/format/dependencies.py b/tests/format/dependencies.py
index 7f5de8684..12eb19d3a 100644
--- a/tests/format/dependencies.py
+++ b/tests/format/dependencies.py
@@ -250,3 +250,34 @@ def test_merge(cli, datafiles, target):
element_list = cli.get_pipeline(project, [target], scope="run")
assert element_list == ["run-build.bst", target]
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_config_unsupported(cli, datafiles):
+ project = os.path.join(str(datafiles), "dependencies3")
+
+ result = cli.run(project=project, args=["show", "unsupported.bst"])
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DEPENDENCY_CONFIG)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize(
+ "target,number", [("supported1.bst", 1), ("supported2.bst", 2),], ids=["one", "two"],
+)
+def test_config_supported(cli, datafiles, target, number):
+ project = os.path.join(str(datafiles), "dependencies3")
+
+ result = cli.run(project=project, args=["show", target])
+ result.assert_success()
+
+ assert "TEST PLUGIN FOUND {} ENABLED DEPENDENCIES".format(number) in result.stderr
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_config_runtime_error(cli, datafiles):
+ project = os.path.join(str(datafiles), "dependencies3")
+
+ # Test that it is considered an error to specify `config` on runtime-only dependencies
+ #
+ result = cli.run(project=project, args=["show", "runtime-error.bst"])
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
diff --git a/tests/format/dependencies3/elements/dep.bst b/tests/format/dependencies3/elements/dep.bst
new file mode 100644
index 000000000..9e5cf96b6
--- /dev/null
+++ b/tests/format/dependencies3/elements/dep.bst
@@ -0,0 +1,2 @@
+kind: manual
+description: Some kinda element
diff --git a/tests/format/dependencies3/elements/runtime-error.bst b/tests/format/dependencies3/elements/runtime-error.bst
new file mode 100644
index 000000000..948997aa9
--- /dev/null
+++ b/tests/format/dependencies3/elements/runtime-error.bst
@@ -0,0 +1,6 @@
+kind: configsupported
+
+runtime-depends:
+- filename: dep.bst
+ config:
+ enabled: true
diff --git a/tests/format/dependencies3/elements/supported1.bst b/tests/format/dependencies3/elements/supported1.bst
new file mode 100644
index 000000000..528475ab0
--- /dev/null
+++ b/tests/format/dependencies3/elements/supported1.bst
@@ -0,0 +1,6 @@
+kind: configsupported
+
+depends:
+- filename: dep.bst
+ config:
+ enabled: true
diff --git a/tests/format/dependencies3/elements/supported2.bst b/tests/format/dependencies3/elements/supported2.bst
new file mode 100644
index 000000000..041ef08c1
--- /dev/null
+++ b/tests/format/dependencies3/elements/supported2.bst
@@ -0,0 +1,9 @@
+kind: configsupported
+
+depends:
+- filename: dep.bst
+ config:
+ enabled: true
+- filename: dep.bst
+ config:
+ enabled: true
diff --git a/tests/format/dependencies3/elements/unsupported.bst b/tests/format/dependencies3/elements/unsupported.bst
new file mode 100644
index 000000000..eca090018
--- /dev/null
+++ b/tests/format/dependencies3/elements/unsupported.bst
@@ -0,0 +1,6 @@
+kind: configunsupported
+
+depends:
+- filename: dep.bst
+ config:
+ enabled: true
diff --git a/tests/format/dependencies3/plugins/configsupported.py b/tests/format/dependencies3/plugins/configsupported.py
new file mode 100644
index 000000000..06f85f7a3
--- /dev/null
+++ b/tests/format/dependencies3/plugins/configsupported.py
@@ -0,0 +1,29 @@
+from buildstream import Element
+
+
+class ConfigSupported(Element):
+ BST_MIN_VERSION = "2.0"
+
+ def configure(self, node):
+ pass
+
+ def configure_dependencies(self, dependencies):
+ self.configs = []
+
+ for dep in dependencies:
+ if dep.config:
+ dep.config.validate_keys(["enabled"])
+ self.configs.append(dep)
+
+ self.info("TEST PLUGIN FOUND {} ENABLED DEPENDENCIES".format(len(self.configs)))
+
+ def preflight(self):
+ pass
+
+ def get_unique_key(self):
+ return {}
+
+
+# Plugin entry point
+def setup():
+ return ConfigSupported
diff --git a/tests/format/dependencies3/plugins/configunsupported.py b/tests/format/dependencies3/plugins/configunsupported.py
new file mode 100644
index 000000000..9dcaca1ee
--- /dev/null
+++ b/tests/format/dependencies3/plugins/configunsupported.py
@@ -0,0 +1,19 @@
+from buildstream import Element
+
+
+class ConfigUnsupported(Element):
+ BST_MIN_VERSION = "2.0"
+
+ def configure(self, node):
+ pass
+
+ def preflight(self):
+ pass
+
+ def get_unique_key(self):
+ return {}
+
+
+# Plugin entry point
+def setup():
+ return ConfigUnsupported
diff --git a/tests/format/dependencies3/project.conf b/tests/format/dependencies3/project.conf
new file mode 100644
index 000000000..c1b99eb12
--- /dev/null
+++ b/tests/format/dependencies3/project.conf
@@ -0,0 +1,11 @@
+# Basic project
+name: test
+min-version: 2.0
+element-path: elements
+
+plugins:
+- origin: local
+ path: plugins
+ elements:
+ - configsupported
+ - configunsupported