From a532cb430773d66f947109873f680cac74aaab0a Mon Sep 17 00:00:00 2001
From: florian <f.spreckelsen@inidscale.com>
Date: Mon, 10 Oct 2022 11:57:27 +0200
Subject: [PATCH] TST: Add failing unit test for multiple macro usage

---
 unittests/test_macros.py | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/unittests/test_macros.py b/unittests/test_macros.py
index 98fdf642..29b59290 100644
--- a/unittests/test_macros.py
+++ b/unittests/test_macros.py
@@ -293,3 +293,39 @@ extroot3: !macro
     assert cfood["extroot2"]["test_two"] is None
     # No recursion
     assert cfood["extroot3"]["test_four"] is None
+
+
+@pytest.mark.xfail(reason="Fix multiple usage of the same macro.")
+def test_use_macro_twice():
+    """Test that the same macro can be used twice with different parameters in
+    the same CFood element if the name depends on the parameters.
+
+    """
+
+    cfood = _temp_file_load("""
+---
+metadata:
+  macros:
+    - !defmacro
+      name: test_twice
+      params:
+        macro_name: default_name
+        a: 4
+      definition:
+        $macro_name:
+          something:
+            a: $a
+---
+extroot: !macro
+  test_twice:
+    macro_name: once
+  test_twice:
+    macro_name: twice
+    a: 5
+  test_twice:
+    """)
+    for name in ["once", "twice", "default_name"]:
+        assert name in cfood["extroot"]
+    assert cfood["extroot"]["once"]["something"]["a"] == 4
+    assert cfood["extroot"]["twice"]["something"]["a"] == 5
+    assert cfood["extroot"]["default_name"]["something"]["a"] == 4
-- 
GitLab