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

Improve logging for a case with the missing source file #295

Merged
merged 1 commit into from Nov 27, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/excoveralls/cover.ex
Expand Up @@ -28,9 +28,8 @@ defmodule ExCoveralls.Cover do

def has_compile_info?(module) do
with info when not is_nil(info) <- module.module_info(:compile),
path when not is_nil(path) <- Keyword.get(info, :source),
true <- File.exists?(path) do
true
path when not is_nil(path) <- Keyword.get(info, :source) do
file_exist?(module, path)
else
_e ->
log_missing_source(module)
Expand All @@ -53,7 +52,20 @@ defmodule ExCoveralls.Cover do
defp string_to_charlist(string), do: String.to_charlist(string)
end

defp file_exist?(module, path) do
if File.exists?(path) do
true
else
log_missing_file(module, path)
false
end
end

defp log_missing_source(module) do
IO.puts :stderr, "[warning] skipping the module '#{module}' because source information for the module is not available."
end

defp log_missing_file(module, path) do
IO.puts :stderr, "[warning] skipping the module '#{module}' because source file with '#{path}' path does not exist"
end
end
2 changes: 1 addition & 1 deletion test/cover_test.exs
Expand Up @@ -29,7 +29,7 @@ defmodule CoverTest do

assert capture_io(:stderr, fn ->
refute Cover.has_compile_info?(TestMissing)
end) =~ "[warning] skipping the module 'Elixir.TestMissing' because source information for the module is not available."
end) =~ "[warning] skipping the module 'Elixir.TestMissing' because source file with '#{__DIR__}/fixtures/test_missing.ex' path does not exist"
end

test "has_compile_info?/1 with a mocked module raises warning and returns false" do
Expand Down