Skip to content

Commit

Permalink
Improve logging for a case with the missing source file (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
thgala committed Nov 27, 2022
1 parent 6eee044 commit 09c93ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
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

0 comments on commit 09c93ad

Please sign in to comment.