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/15 09:36:52 UTC

[buildstream] 01/01: tests/format/junctions.py: Test that variables in include files are resolved correctly

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

tvb pushed a commit to branch tristan/validate-cross-project-include-vars
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit ec5e2d5c69107a33251c7a7f9b2f69f0d63c5b0a
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Fri Jul 15 18:35:42 2022 +0900

    tests/format/junctions.py: Test that variables in include files are resolved correctly
    
    Ensure that they are resolved in the context of the project where they are
    declared, rather than in the context of the including project.
---
 tests/format/junctions.py                                   | 13 +++++++++++++
 tests/format/junctions/include-vars/project.conf            |  5 +++++
 tests/format/junctions/include-vars/subproject.bst          |  4 ++++
 tests/format/junctions/include-vars/subproject/include.yml  |  3 +++
 tests/format/junctions/include-vars/subproject/project.conf |  5 +++++
 tests/format/junctions/include-vars/target.bst              |  3 +++
 6 files changed, 33 insertions(+)

diff --git a/tests/format/junctions.py b/tests/format/junctions.py
index d17d47f5e..958ca9e68 100644
--- a/tests/format/junctions.py
+++ b/tests/format/junctions.py
@@ -817,3 +817,16 @@ def test_internal(cli, tmpdir, datafiles, project_dir, expected_files):
     # Check that the checkout contains the expected file
     for expected in expected_files:
         assert os.path.exists(os.path.join(checkoutdir, expected))
+
+
+# This test verifies that variables declared in subproject include files
+# are resolved in their respective subproject, rather than being imported
+# literally and resolved in the including project.
+#
+@pytest.mark.datafiles(DATA_DIR)
+def test_include_vars(cli, datafiles):
+    project = os.path.join(str(datafiles), "include-vars")
+    result = cli.run(project=project, silent=True, args=["show", "--deps", "none", "--format", "%{vars}", "target.bst"])
+    result.assert_success()
+    result_vars = _yaml.load_data(result.output)
+    assert result_vars.get_str("resolved") == "The animal is a horsy"
diff --git a/tests/format/junctions/include-vars/project.conf b/tests/format/junctions/include-vars/project.conf
new file mode 100644
index 000000000..fc19db826
--- /dev/null
+++ b/tests/format/junctions/include-vars/project.conf
@@ -0,0 +1,5 @@
+name: test
+min-version: 2.0
+
+variables:
+  animal: pony
diff --git a/tests/format/junctions/include-vars/subproject.bst b/tests/format/junctions/include-vars/subproject.bst
new file mode 100644
index 000000000..c88189cb0
--- /dev/null
+++ b/tests/format/junctions/include-vars/subproject.bst
@@ -0,0 +1,4 @@
+kind: junction
+sources:
+- kind: local
+  path: subproject
diff --git a/tests/format/junctions/include-vars/subproject/include.yml b/tests/format/junctions/include-vars/subproject/include.yml
new file mode 100644
index 000000000..e56ec5dd3
--- /dev/null
+++ b/tests/format/junctions/include-vars/subproject/include.yml
@@ -0,0 +1,3 @@
+
+variables:
+  resolved: The animal is a %{animal}
diff --git a/tests/format/junctions/include-vars/subproject/project.conf b/tests/format/junctions/include-vars/subproject/project.conf
new file mode 100644
index 000000000..6d73e9e57
--- /dev/null
+++ b/tests/format/junctions/include-vars/subproject/project.conf
@@ -0,0 +1,5 @@
+name: subtest
+min-version: 2.0
+
+variables:
+  animal: horsy
diff --git a/tests/format/junctions/include-vars/target.bst b/tests/format/junctions/include-vars/target.bst
new file mode 100644
index 000000000..7c3ca3c76
--- /dev/null
+++ b/tests/format/junctions/include-vars/target.bst
@@ -0,0 +1,3 @@
+kind: stack
+
+(@): subproject.bst:include.yml