Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macros are ignored #59

Open
sobolevn opened this issue Jul 19, 2016 · 7 comments
Open

macros are ignored #59

sobolevn opened this issue Jul 19, 2016 · 7 comments

Comments

@sobolevn
Copy link

Does it supposed to be this way?

mix.exs:

defp deps do
    [
       ...
      {:excoveralls, "~> 0.5", only: :test}
    ]
  end

Result:

$ mix coveralls.html
.............

Finished in 0.1 seconds (0.1s on load, 0.02s on tests)
13 tests, 0 failures

Randomized with seed 989620
----------------
COV    FILE                                        LINES RELEVANT   MISSED
  0.0% lib/ecto_autoslug_field.ex                      2        0        0
100.0% lib/ecto_autoslug_field/slug.ex                35        2        0
  0.0% lib/ecto_autoslug_field/slug_generator.e       48        0        0
  0.0% lib/ecto_autoslug_field/type.ex                14        0        0
[TOTAL] 100.0%
----------------
Generating report...

2016-07-19 18 33 45

@parroty
Copy link
Owner

parroty commented Aug 5, 2016

Thanks for the report. It's kind of limitation around it's based on erlang's cover module and elixir's macro precomipling is not reflected well (haven't been able to find good workaround).

@nathany
Copy link
Contributor

nathany commented Aug 26, 2016

Is this related to coverage sometimes missing on all or part of the with macro in Elixir and the schema macro in Ecto?

@ctrlShiftBryan
Copy link

@nathany yes, it appears so since elixir implements those using macros.

@idyll
Copy link

idyll commented Sep 15, 2017

Have the changes in Elixir 1.5 helped with this or are we still unable to see coverage on macros?

@tim2CF
Copy link

tim2CF commented Feb 28, 2018

it seems macros still have test coverage = 0

@BlueHotDog
Copy link

Hey, any idea if this is fixable? @parroty

@josevalim
Copy link
Contributor

josevalim commented Jan 27, 2025

This should work fine, as long as the macros are invoked during your tests (not in test/support but in your test files, either within the test module or a test itself):

# lib/foo.ex
defmodule Foo do
  defmacro __using__(mod) do
    mod = Module.concat([mod])

    quote do
      import unquote(mod)
    end
  end
end

# test/foo_test.exs
defmodule FooTest do
  use ExUnit.Case

  test "greets the world" do
    defmodule FooTest do
      use Foo, "List"
      assert flatten([]) == []
    end
  end
end
Image

Cover is not going to track any code before your tests start running (and that's where most macro expansion happens).

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

No branches or pull requests

8 participants