Using map/loops in macros to generate tests

I am creating a system where I have code in another language that then gets interpreted by my Elixir system. I am writing tests in that language as that is what fundamentally needs to be tested.

I would like to find all the files of that type and use macros to generate tests for each file. I’ve got a macro working that will run a single test when passed a filename. However, I really want to be able to generate them all:

  defmacro all_lua_tests do
    lua_tests = Path.wildcard("test/**/_test.lua")

    for t <- lua_tests do
      test_name = File.read!(t) |> String.split("\n") |> hd()

      quote do
        lua_test(unquote(test_name), unquote(t))
      end
    end
  end

In the example here, lua_test is another macro that calls test macro. This of course does not work. I can’t really get my head around how a for loop can/should be used in a macro.

How and where are you using the all_lua_tests macro exactly? In metaprogramming land this matters a lot.

In my case I just create a test .exs file and use for ... comprehension to generate tests directly on the module level. This saves me part of the headaches with quoting / unquoting.

Thanks! I was running it from .exs but your suggestion led me to realize that my glob was wrong…! Thank you!