numso

numso

Code Coverage incorrect for function with multiple clauses

Hi all!

I noticed something odd while testing one of my LiveViews today. I wrote a test for one of the handle_event/3 function clauses. Made the test pass. Verified that the assigns were getting set correctly. Then discovered that code coverage wasn’t marking that code as having been run. I added an IO.inspect/2, saw the log in my test output, but code coverage still says that IO.inspect line was never run.

I was able to make a very minimal reproduction in a brand new mix new project:

elixir 1.17.3-otp-27
erlang 27.1

defmodule CoverageBug do
  def hello do
    check("target", nil)
    :world
  end

  def check("one", _) do
    nil
  end

  def check("two", _) do
    nil
  end

  def check(_, %{some_match: :three}) do
    nil
  end

  def check("four", _) do
    nil
  end

  def check("target", _) do
    IO.inspect("This line is run but not covered")
    nil
  end
end

defmodule CoverageBugTest do
  use ExUnit.Case

  test "greets the world" do
    assert CoverageBug.hello() == :world
  end
end

When running mix test --cover, you’ll see the IO.inspect line logged out in the test output. But it won’t show up as covered in the test coverage report. If you delete any of those first 4 check function clauses, then the IO.inspect in the 5th clause will start being reported as covered. Has anyone experienced anything like this? Am I missing something obvious?

Marked As Solved

numso

numso

I ended up trying this with a different version of erlang and it worked:

elixir 1.17.3-otp-26
erlang 26.2.5.3

So looks like this was a regression in the latest erlang major release.

Last Post!

zorn

zorn

Thanks for sharing. I don’t personally look at these numbers, but I know we have CI tools at work that do – and they output curious results, so this might be related.

Appriciate your signal.

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130579 1222
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New

We're in Beta

About us Mission Statement