From 428de24010d5aaf4bebd035b8c16c037451385bc Mon Sep 17 00:00:00 2001
From: florian <f.spreckelsen@inidscale.com>
Date: Tue, 4 Oct 2022 16:56:34 +0200
Subject: [PATCH] TST: Add test for multiple circular macro definitions

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

diff --git a/unittests/test_macros.py b/unittests/test_macros.py
index fea76fe9..a6c81e04 100644
--- a/unittests/test_macros.py
+++ b/unittests/test_macros.py
@@ -249,3 +249,38 @@ testnode:
     assert dat["testnode"]["obl"]["replaced1"]["c"]["t2"] == "25"
     assert dat["testnode"]["obl"]["replaced1"]["d"][0] == "a"
     assert dat["testnode"]["obl"]["replaced1"]["d"][1] == "25"
+
+
+def test_circular_macro_definition(register_macros, macro_store_reset):
+    """Test the (ab-)use of macros to create an infinite loop."""
+    cfood = _temp_file_load("""
+---
+metadata:
+  macros:
+    - !defmacro
+      name: test_one
+      params: {}
+      definition: !macro
+        test_two:
+    - !defmacro
+      name: test_two
+      params: {}
+      definition: !macro
+        test_one:
+    - !defmacro
+      name: test_three
+      params: {}
+      definition: !macro
+        test_two:
+---
+extroot: !macro
+  test_one:
+extroot2: !macro
+  test_three:
+    """)
+    # macros in macros can be used, but there are no circles; they stop at the first one.
+    assert "test_one" not in cfood["extroot"]
+    assert cfood["extroot"]["test_two"] is None
+    assert "test_three" not in cfood["extroot2"]
+    assert "test_one" not in cfood["extroot2"]
+    assert cfood["extroot2"]["test_two"] is None
-- 
GitLab