You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2022/07/22 05:30:14 UTC

[buildstream] 02/02: tests/format/optionprojectroot.py: Test option resolution in element overrides

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tristan/resolve-conditionals-project-root
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit fcf78edfe6785df4370cdb26cbdc6115ebce5b95
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Fri Jul 22 14:27:31 2022 +0900

    tests/format/optionprojectroot.py: Test option resolution in element overrides
    
    This already appears to be working fine, but let's just add another test
    to be sure.
---
 tests/format/option-element-override/element.bst  |  1 +
 tests/format/option-element-override/project.conf | 24 +++++++++++++++++++++++
 tests/format/optionprojectroot.py                 | 17 ++++++++++++++++
 3 files changed, 42 insertions(+)

diff --git a/tests/format/option-element-override/element.bst b/tests/format/option-element-override/element.bst
new file mode 100644
index 000000000..4d7f70266
--- /dev/null
+++ b/tests/format/option-element-override/element.bst
@@ -0,0 +1 @@
+kind: manual
diff --git a/tests/format/option-element-override/project.conf b/tests/format/option-element-override/project.conf
new file mode 100644
index 000000000..63df718a6
--- /dev/null
+++ b/tests/format/option-element-override/project.conf
@@ -0,0 +1,24 @@
+name: test
+min-version: 2.0
+
+options:
+  animal:
+    type: enum
+    description: The kind of animal
+    values:
+    - pony
+    - horsy
+    default: pony
+
+variables:
+  result: "a sloppy joe"
+
+elements:
+  manual:
+    (?):
+    - animal == "pony":
+        variables:
+          result: "a pony"
+    - animal == "horsy":
+        variables:
+          result: "a horsy"
diff --git a/tests/format/optionprojectroot.py b/tests/format/optionprojectroot.py
index 5ea3508ab..44eb2abc8 100644
--- a/tests/format/optionprojectroot.py
+++ b/tests/format/optionprojectroot.py
@@ -26,3 +26,20 @@ def test_resolve_project_root_conditional(cli, datafiles, value, expected):
     result.assert_success()
     loaded = _yaml.load_data(result.output)
     assert loaded.get_str("result") == expected
+
+
+#
+# Test that project option conditionals can be resolved in element overrides
+#
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("value,expected", [("pony", "a pony"), ("horsy", "a horsy")], ids=["pony", "horsy"])
+def test_resolve_element_override_conditional(cli, datafiles, value, expected):
+    project = os.path.join(datafiles.dirname, datafiles.basename, "option-element-override")
+    result = cli.run(
+        project=project,
+        silent=True,
+        args=["--option", "animal", value, "show", "--deps", "none", "--format", "%{vars}", "element.bst"],
+    )
+    result.assert_success()
+    loaded = _yaml.load_data(result.output)
+    assert loaded.get_str("result") == expected