Elixir: ExUnit @moduletag broken (or mis-documented)

Created on 8 Feb 2016  Â·  11Comments  Â·  Source: elixir-lang/elixir

According to the documentation for ExUnit tags, the following is possible:

defmodule TempTest do
  @moduletag :integration # This does not work
  @moduletag integration: true # This does not work
  # @moduletag [:integration] # This works
  # @moduletag [integration: true] # This works
  use ExUnit.Case
  doctest Temp

  # @tag :integration # This works
  # @tag integration: true # This works
  test "the truth" do
    assert 1 + 1 == 2
  end
end

When using the @moduletag :integration form, running the tests yields the following error:

$ mix test
** (FunctionClauseError) no function clause matching in :lists.reverse/1
    (stdlib) lists.erl:146: :lists.reverse([[async: false] | :integration])
    (ex_unit) lib/ex_unit/case.ex:331: ExUnit.Case.normalize_tags/1
    (ex_unit) lib/ex_unit/case.ex:307: ExUnit.Case.__on_definition__/3
    test/temp_test.exs:7: (module)
    (stdlib) erl_eval.erl:669: :erl_eval.do_apply/6

When using the @moduletag integration: true form, running the tests yields the following error:

$ mix test
** (FunctionClauseError) no function clause matching in anonymous fn/2 in ExUnit.Case.normalize_tags/1
    (ex_unit) lib/ex_unit/case.ex:331: anonymous fn({:integration, true}, %{}) in ExUnit.Case.normalize_tags/1
    (elixir) lib/enum.ex:1473: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ex_unit) lib/ex_unit/case.ex:307: ExUnit.Case.__on_definition__/3
    test/temp_test.exs:7: (module)
    (stdlib) erl_eval.erl:669: :erl_eval.do_apply/6

(These can both be reproduced in a new project created with mix new temp and where the test/temp_test.exs file is replaced with the above definition)

The documentation states:

Module tags

A tag can be set for all tests in a module by setting @moduletag:

@moduletag :external

Elixir 1.2.2, Erlang 18.2.1, OS X

Most helpful comment

Ah, everything is much simpler – we can't have @moduletag set before use ExUnit.Case.

All 11 comments

It should already be fixed in master.

@lexmag we need to make sure it is fixed on v1.2 too so we ship v1.2.3. Do you know when this regression happened?

@josevalim I'm looking into.

Ah, everything is much simpler – we can't have @moduletag set before use ExUnit.Case.

@josevalim looks like we need to check reserved attributes in ExUnit.Case.__using__ that they are not set.

Can confirm that it works as expected with the @moduletags after use ExUnit.Case.

@josevalim Will the fix be included in 1.2.3?

@eproxus doesn't it just work on 1.2.3 as well? The error is because you were defining them before use ExUnit.Case. This doesn't seem to be a regression, so likely we won't add any checking to 1.2.3.

@josevalim Ah, ok. Assumed that was the "bug".

Just curious, why is it like this? Shouldn't the use just pick up the existing module tags?

It is because @moduletag and @tag can be used multiple times, so we change its internal structure. We should either raise if something is set or initialize it to empty. But no need to backport because it isn't a new regression, it has been there since the beginning.

Ah, I see. Makes sense. Thanks for the explanation.

Was this page helpful?
0 / 5 - 0 ratings