diff --git a/unittests/test_macros.py b/unittests/test_macros.py index fea76fe9b031c8b82964e7ab41b4c26486fbba43..a6c81e0432a47b778ee43a968e9467b334435f16 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