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.