KazuCocoa / ex_parameterized

This library support parameterized test with test_with_params macro.
https://github.com/KazuCocoa/ex_parameterized
MIT License
29 stars 7 forks source link

Misleading error when calling local fn without dot #18

Closed dylan-chong closed 6 years ago

dylan-chong commented 6 years ago
  test_with_params "bad with function", fn p -> p end do
    make = fn a -> a + 1 end
    [
      {make(1)},
      {make(2)}
    ]
  end

** (Protocol.UndefinedError) protocol Enumerable not implemented for {:__block__, [], [{:=, [line: 131], [{:make, [line: 131], nil}, {:fn, [line: 131], [{:->, [line: 131], [[{:a, [line: 131], nil}], {:+, [line: 131], [{:a, [line: 131], nil}, 1]}]}]}]}, [{:{}, [line: 133], [{:make, [line: 133], [1]}]}, {:{}, [line: 134], [{:make, [line: 134], [2]}]}]]}. This protocol is implemented for: Date.Range, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Range, Stream
    (elixir) /private/tmp/elixir-20171219-79248-1tthq3/elixir-1.5.3/lib/elixir/lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir) /private/tmp/elixir-20171219-79248-1tthq3/elixir-1.5.3/lib/elixir/lib/enum.ex:145: Enumerable.count/1
    (elixir) lib/enum.ex:500: Enum.count/1
    lib/ex_parameterized/params.ex:54: ExUnit.Parameterized.Params.param_with_index/1
    lib/ex_parameterized/params.ex:24: ExUnit.Parameterized.Params.do_test_with/3
    expanding macro: ExUnit.Parameterized.Params.test_with_params/3
    test/ex_composer_bot/pitch_test.exs:130: ExComposerBotTest.Pitch (module)
    (elixir) lib/code.ex:376: Code.require_file/2
    (elixir) lib/kernel/parallel_require.ex:59: anonymous fn/2 in Kernel.ParallelRequire.spawn_requires/5

make(1) should be make.(1)

KazuCocoa commented 6 years ago

It's difficult to handle error cases in AST, but just raise an error to show AST itself is wrong.