Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

Can't call module attribute or method from do block #12

Open
dylan-chong opened this issue Oct 2, 2017 · 4 comments
Open

Can't call module attribute or method from do block #12

dylan-chong opened this issue Oct 2, 2017 · 4 comments

Comments

@dylan-chong
Copy link

dylan-chong commented Oct 2, 2017

  test_with_params "good", fn p -> p end, do: [{1}]
  @params [{1}]
  test_with_params "bad", fn p -> p end, do: @params

The bad tests throws this error:

(Protocol.UndefinedError) protocol Enumerable not implemented for {:@, [line: 12], [{:params, [line: 12], nil}]}. 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-20170801-16561-1c6hni3/elixir-1.5.1/lib/elixir/lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir) /private/tmp/elixir-20170801-16561-1c6hni3/elixir-1.5.1/lib/elixir/lib/enum.ex:145: Enumerable.count/1
    (elixir) lib/enum.ex:497: Enum.count/1
    (ex_parameterized) lib/ex_parameterized/params.ex:54: ExUnit.Parameterized.Params.param_with_index/1
    (ex_parameterized) lib/ex_parameterized/params.ex:24: ExUnit.Parameterized.Params.do_test_with/3
    (ex_parameterized) expanding macro: ExUnit.Parameterized.Params.test_with_params/3
    test/kt_solver_test.exs:12: Part1KTSolverTest (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

A second bad test throws a similar error:

  def params2, do: [{1}]
  test_with_params "bad", fn p -> p end, do: params2
** (Protocol.UndefinedError) protocol Enumerable not implemented for {:params2, [line: 12], nil}. 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-20170801-16561-1c6hni3/elixir-1.5.1/lib/elixir/lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir) /private/tmp/elixir-20170801-16561-1c6hni3/elixir-1.5.1/lib/elixir/lib/enum.ex:145: Enumerable.count/1
    (elixir) lib/enum.ex:497: Enum.count/1
    (ex_parameterized) lib/ex_parameterized/params.ex:54: ExUnit.Parameterized.Params.param_with_index/1
    (ex_parameterized) lib/ex_parameterized/params.ex:24: ExUnit.Parameterized.Params.do_test_with/3
    (ex_parameterized) expanding macro: ExUnit.Parameterized.Params.test_with_params/3
    test/kt_solver_test.exs:12: Part1KTSolverTest (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

My purpose for extracting the parameters out is because i want my tests to run on multiple modules that are very similar (I am testing different algorithms that each should output the same results). I don't want to have to copy paste the list of modules i want to test for each test.

@dylan-chong dylan-chong changed the title Can't call module attribute or method from if + { Can't call module attribute or method from do block Oct 2, 2017
@dylan-chong
Copy link
Author

My current workaround for this is to create a new module above the test module, and in this new model create a method that returns the list of models that i want to test.

@KazuCocoa
Copy link
Owner

thanks.

Yeah, @hoge create special AST.

idea https://github.com/KazuCocoa/ex_parameterized/tree/fix_private_attribute

@KazuCocoa
Copy link
Owner

I've tried to fix this issue, but it looks difficult to manage correctly, and eventually, I've reverted #17

@dylan-chong
Copy link
Author

I might have a play with this sometime

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants