Generate tests through module attributes but local variable can't be found

Seems like your expected value is somehow messing up the AST. Also quickly made the thing a bit more readable.

defmodule PP do
  def impl_abc(i) do
    {[4, 7, 9, 65, 100], [i, 3, 5, 8, 11, 74, 83], 185, 185}
  end
end

defmodule MetaTestsTest do
  use ExUnit.Case
  doctest MetaTests

  @inputs_to_expected_results %{
    1 => {[4, 7, 9, 65, 100], [1, 3, 5, 8, 11, 74, 83], 185, 185},
    2 => {[4, 7, 9, 65, 100], [2, 3, 5, 8, 11, 74, 83], 185, 185}
  }
  @impl_funs Enum.filter(PP.__info__(:functions), fn {n, i} ->
               String.starts_with?("#{n}", "impl_") and i == 1
             end)

  for {name, _} <- @impl_funs,
      {input, expected} <- @inputs_to_expected_results,
      expected = Macro.escape(expected) do
    test inspect(input) do
      assert unquote(expected) == PP.unquote(name)(unquote(input))
    end
  end
end
1 Like