Skip to content

Commit

Permalink
Fix lcov 2.0 source file handling
Browse files Browse the repository at this point in the history
Prior to 2.0 being released, `genhtml` was much better about handling 
source files from the following paths:

* `test/support/some_helper.ex`
* `lib/foo/bar.ex`

But after 2.0 was released, when rendering with `genhtml` the paths 
would be mangled and look like the following:

* `test/support/test/support/some_helper.ex`
* `lib/foo/lib/foo/bar.ex`

I have tried in vain with many permutations of `--prefix` when running
`genhtml` but the ultimate fix that made all of this go away was using
the absolute path for the source file (`SF`).
  • Loading branch information
warmwaffles committed Jul 24, 2023
1 parent 354204a commit 3633ecf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/excoveralls/lcov.ex
Expand Up @@ -33,9 +33,10 @@ defmodule ExCoveralls.Lcov do

lf = foundlines |> Enum.count()
lh = foundlines |> Enum.filter(fn v -> v > 0 end) |> Enum.count()
sf = Path.expand(stat.name, ".")

lines =
["TN:", "SF:" <> stat.name] ++
["TN:", "SF:" <> sf] ++
da ++
[
"LF:" <> Integer.to_string(lf),
Expand Down
13 changes: 9 additions & 4 deletions test/lcov_test.exs
Expand Up @@ -5,12 +5,13 @@ defmodule ExCoveralls.LcovTest do
alias ExCoveralls.Lcov

@file_name "lcov.info"
@file_size 67
@file_size 124
@test_output_dir "cover_test/"

@content "defmodule Test do\n def test do\n end\nend\n"
@counts [0, 1, nil, nil]
@source_info [%{name: "test/fixtures/test.ex",
@test_file_name "test/fixtures/test.ex"
@source_info [%{name: @test_file_name,
source: @content,
coverage: @counts
}]
Expand Down Expand Up @@ -53,7 +54,9 @@ defmodule ExCoveralls.LcovTest do
Lcov.execute(@source_info)
end) =~ @stats_result

assert(File.read!(report) =~ ~s(TN:\nSF:test/fixtures/test.ex\nDA:1,0\nDA:2,1\nLF:2\nLH:1\nend_of_record\n))
source_file = Path.expand(@test_file_name, ".")

assert(File.read!(report) =~ ~s(TN:\nSF:#{source_file}\nDA:1,0\nDA:2,1\nLF:2\nLH:1\nend_of_record\n))
%{size: size} = File.stat! report
assert(size == @file_size)
end
Expand All @@ -63,7 +66,9 @@ defmodule ExCoveralls.LcovTest do
Lcov.execute(@source_info, [output_dir: @test_output_dir])
end) =~ @stats_result

assert(File.read!(report) =~ ~s(TN:\nSF:test/fixtures/test.ex\nDA:1,0\nDA:2,1\nLF:2\nLH:1\nend_of_record\n))
source_file = Path.expand(@test_file_name, ".")

assert(File.read!(report) =~ ~s(TN:\nSF:#{source_file}\nDA:1,0\nDA:2,1\nLF:2\nLH:1\nend_of_record\n))
%{size: size} = File.stat! report
assert(size == @file_size)
end
Expand Down

0 comments on commit 3633ecf

Please sign in to comment.