pmonson711
Surprising lines missing from coverage results
Hey Elixir-land!
It’s been a while since I’ve been around. Getting back into lots of elixir work and I found something unexpected regarding the coverage system. Essentially function calls wrapped in literals don’t seem to get counted as coverable statements.
Steps to reproduce:
- run
mix new coverage_why - paste in
lib/coverage_why.ex
defmodule CoverageWhy do
def hello do
:world
end
def i_has_coverage do
hello()
end
def i_has_no_coverage do
{:ok, hello()}
end
def i_has_no_coverage_as_well do
[hello()]
end
def i_has_no_coverage_as_either do
[hello()]
:ok
end
end
- run
mix test --cover
I get the results of
Expectations
I would expect all the lines except the original def hello... to be uncovered. If I had to guess the wrapping the call in a literal causes the function call to be inlined somehow. Is this the expected coverage results and is it documented anywhere?
Marked As Solved
josevalim
Please open up a bug report, we can likely fix the tuple and list ones, but not the atom because literals do not have line numbers in the AST.
EDIT: I have fixed this locally and I will push it soon.
Also Liked
josevalim
Yup, I could reproduce it. Fixes coming to Elixir master shortly.
josevalim
They are not missing per se. If the pattern was covered, then by definition what immediately follows the pattern is being covered too. We can’t highlight it because we don’t have precise line information, but the coverage of the pattern is enough in those cases.
pmonson711
Amazed with your response!
josevalim
What is your Elixir version? We have improved this in more recent releases.
semmitmondo
I tried it with Elixir 1.12.2 and 1.12.3 (on Erlang/OTP 23.2.3). Also tried it with 1.12.3 on Erlang/OTP 24.0.6.
:ok and {:error, :reason} lines are not included in coverage reports on these versions for me. 








