Skip to content

Commit c6b4bd4

Browse files
committed
Fix lcov 2.0 source file handling
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`).
1 parent 354204a commit c6b4bd4

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/excoveralls/lcov.ex

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ defmodule ExCoveralls.Lcov do
3333

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

3738
lines =
38-
["TN:", "SF:" <> stat.name] ++
39+
["TN:", "SF:" <> sf] ++
3940
da ++
4041
[
4142
"LF:" <> Integer.to_string(lf),

test/lcov_test.exs

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ defmodule ExCoveralls.LcovTest do
55
alias ExCoveralls.Lcov
66

77
@file_name "lcov.info"
8-
@file_size 67
98
@test_output_dir "cover_test/"
109

1110
@content "defmodule Test do\n def test do\n end\nend\n"
1211
@counts [0, 1, nil, nil]
13-
@source_info [%{name: "test/fixtures/test.ex",
12+
@test_file_name "test/fixtures/test.ex"
13+
@source_info [%{name: @test_file_name,
1414
source: @content,
1515
coverage: @counts
1616
}]
@@ -53,18 +53,18 @@ defmodule ExCoveralls.LcovTest do
5353
Lcov.execute(@source_info)
5454
end) =~ @stats_result
5555

56-
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))
57-
%{size: size} = File.stat! report
58-
assert(size == @file_size)
56+
source_file = Path.expand(@test_file_name, ".")
57+
58+
assert(File.read!(report) =~ ~s(TN:\nSF:#{source_file}\nDA:1,0\nDA:2,1\nLF:2\nLH:1\nend_of_record\n))
5959
end
6060

6161
test "generate json file with output_dir parameter", %{report: report} do
6262
assert capture_io(fn ->
6363
Lcov.execute(@source_info, [output_dir: @test_output_dir])
6464
end) =~ @stats_result
6565

66-
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))
67-
%{size: size} = File.stat! report
68-
assert(size == @file_size)
66+
source_file = Path.expand(@test_file_name, ".")
67+
68+
assert(File.read!(report) =~ ~s(TN:\nSF:#{source_file}\nDA:1,0\nDA:2,1\nLF:2\nLH:1\nend_of_record\n))
6969
end
7070
end

0 commit comments

Comments
 (0)