From b9b56a8cc6955bb58a3befd6e4da3963c33e09de Mon Sep 17 00:00:00 2001
From: Simon Rose <simon.rose@ess.eu>
Date: Thu, 6 Apr 2023 09:22:47 +0200
Subject: [PATCH] Add test for substitution/template priority

---
 tests/test_build.py | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/tests/test_build.py b/tests/test_build.py
index 8af46ae1..bd1be083 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -539,6 +539,37 @@ def test_expand_db_files(wrapper: Wrapper):
     )
 
 
+def test_substitution_template_priority(wrapper: Wrapper):
+    """Test that the automated template/substitution file expansion works."""
+
+    wrapper.add_var_to_module_makefile("TMPS", "a.template")
+    wrapper.add_var_to_module_makefile("SUBS", "a.substitutions")
+
+    template_file = wrapper.module_dir / "a.template"
+    template_file_contents = "record (ai, $(FOO)) {}"
+    template_file.write_text(template_file_contents)
+
+    substitution_file = wrapper.module_dir / "a.substitutions"
+    substitution_file.write_text(
+        """file "a.template"
+{
+  pattern { FOO }
+          { "$(BAR)" }
+}
+"""
+    )
+
+    base_version = wrapper.get_env_var("EPICS_VERSION_NUMBER")
+    common_dir = wrapper.module_dir / f"O.{base_version}_Common"
+
+    rc, *_ = wrapper.run_make("db_internal")
+    assert rc == 0
+
+    expanded_template_file = common_dir / "a.db"
+    assert "BAR" in expanded_template_file.read_text()
+    assert "FOO" not in expanded_template_file.read_text()
+
+
 @pytest.mark.parametrize(
     "installed_archs, param, expected",
     [
-- 
GitLab