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

Fix lcov 2.0 source file handling #315

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/excoveralls/lcov.ex
Original file line number Diff line number Diff line change
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
16 changes: 8 additions & 8 deletions test/lcov_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ defmodule ExCoveralls.LcovTest do
alias ExCoveralls.Lcov

@file_name "lcov.info"
@file_size 67
@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,18 +53,18 @@ 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))
%{size: size} = File.stat! report
assert(size == @file_size)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to remove the file size assertion because with the absolute path being used, it would cause the file size to be different.

We already test the file size via the File.read! and matching it against the string.

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))
end

test "generate json file with output_dir parameter", %{report: report} do
assert capture_io(fn ->
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))
%{size: size} = File.stat! report
assert(size == @file_size)
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))
end
end