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

Lines wrongly reported as uncovered #8867

Closed
albertored opened this issue Sep 27, 2024 · 2 comments · Fixed by #8919
Closed

Lines wrongly reported as uncovered #8867

albertored opened this issue Sep 27, 2024 · 2 comments · Fixed by #8919
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@albertored
Copy link
Contributor

albertored commented Sep 27, 2024

This is a follow up of elixir-lang/elixir#13863.

I had a problem on elixir where some lines of my code was reported as uncovered also if tests correctly cover them. I was able to reproduce the problem also with plain Erlang code so I'm opening the bug here.

This the module under test

-module(cover_bug).

-export([myfun/2]).

myfun(Arg1, <<"bar", _>>) when Arg1 == arg1 orelse Arg1 == arg2 ->
    nil;
myfun(arg3, Arg2) ->
    case lists:sum([10, 2]) of
        12 ->
            Res = Arg2,
            Res
    end.

and this is the test

?assertEqual(cover_bug:myfun(arg3, <<"foo">>), <<"foo">>)

After running that test the second clause of the function is wrongly reported as uncovered. As better explained in the linked Elixir issue almost every change to the code makes the cover report correct again.

Affected versions
This happens with OTP 27.1, I've tried also with OTP 26.2.5 and in that case the behaviour is correct.

@albertored albertored added the bug Issue is reported as a bug label Sep 27, 2024
@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label Sep 28, 2024
@alexslade
Copy link

I'm also hitting this in Elixir running on Erlang 27. (Works as expected on Erlang 26).

defmodule Neg do
  def hello("Prefix." <> name) do
    dbg("Find called with prefix")
    name
  end

  def hello(name) do
    dbg("Find called without prefix")
    "Hello" <> name
  end
end

defmodule NegTest do
  use ExUnit.Case

  test "code covers all lines" do
    assert Neg.hello("Prefix.Alex") == "Alex"
    assert Neg.hello("Alex") == "Hello Alex"
  end
end

Screenshot 2024-10-08 at 20 16 39

@bjorng
Copy link
Contributor

bjorng commented Oct 9, 2024

Thanks for the bug report.

I've fixed the problem in the linked pull request. I expect it to be included in Erlang/OTP 27.2.

bjorng added a commit that referenced this issue Oct 10, 2024
cover: Fix lines wrongly reported as uncovered
@bjorng bjorng closed this as completed in 60323db Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants