From 5a22b50df328c5280062c3f248dbdbbb5065a60b Mon Sep 17 00:00:00 2001
From: Simon Rose <simon.rose@ess.eu>
Date: Fri, 16 Jun 2023 15:40:08 +0200
Subject: [PATCH] Add test for recursive database dependency loading

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

diff --git a/tests/test_build.py b/tests/test_build.py
index 072c20c3..5a412897 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -539,6 +539,43 @@ def test_expand_db_files(wrapper: Wrapper):
     )
 
 
+def test_recursive_db_dependency(wrappers):
+    wrapper_main: Wrapper = wrappers.get()
+    wrapper_dep: Wrapper = wrappers.get()
+
+    cell_path = wrapper_main.path / "cellMods"
+    common_dir = wrapper_main.module_dir / f"O.{wrapper_main.base_version}_Common"
+
+    wrapper_main.add_var_to_config_module(
+        f"{wrapper_dep.name}_DEP_VERSION", wrapper_dep.version
+    )
+    substitution_file = wrapper_main.module_dir / "a.substitutions"
+    substitution_file.write_text(
+        """file "b.template"
+{
+    pattern { PATTERN }
+            { SUBST }
+}"""
+    )
+    wrapper_main.add_var_to_module_makefile("SUBS", "a.substitutions")
+    wrapper_main.add_var_to_module_makefile(
+        "USR_DBFLAGS",
+        f"-I $(EPICS_MODULES)/{wrapper_dep.name}/$({wrapper_dep.name}_VERSION)/db",
+    )
+
+    template_file = wrapper_dep.module_dir / "b.template"
+    template_file.write_text("record(ai, $(PATTERN)) {}")
+    wrapper_dep.add_var_to_module_makefile("TEMPLATES", "b.template")
+
+    rc, *_ = wrapper_dep.run_make("install", cell_path=cell_path)
+    assert rc == 0
+
+    rc, *_ = wrapper_main.run_make("cellbuild", cell_path=cell_path)
+    assert rc == 0
+
+    assert "SUBST" in (common_dir / "a.db").read_text()
+
+
 def test_substitution_template_priority(wrapper: Wrapper):
     """Test that the automated template/substitution file expansion works."""
 
-- 
GitLab