Skip to content

Commit

Permalink
Fixing mocked modules coverage handling
Browse files Browse the repository at this point in the history
  • Loading branch information
diogommartins committed Jul 7, 2020
1 parent 5f19e75 commit 8c55618
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/excoveralls/cover.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ defmodule ExCoveralls.Cover do
end

def has_compile_info?(module) do
case module.module_info(:compile) do
nil -> false
info ->
path = Keyword.get(info, :source)
if File.exists?(path) do
true
else
log_missing_source(module)
false
end
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
else
_e ->
log_missing_source(module)
false
end
rescue
_e ->
Expand Down
8 changes: 8 additions & 0 deletions test/cover_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ defmodule CoverTest do
end) =~ "[warning] skipping the module 'Elixir.TestMissing' because source information for the module is not available."
end

test "has_compile_info?/1 with a mocked module raises warning and returns false" do
:ok = :meck.new(MockedModule, [:non_strict])

assert capture_io(:stderr, fn ->
refute Cover.has_compile_info?(MockedModule)
end) =~ "[warning] skipping the module 'Elixir.MockedModule' because source information for the module is not available."
end

test "has_compile_info?/1 with existing source returns true" do
assert Cover.has_compile_info?(TestMissing)
end
Expand Down

0 comments on commit 8c55618

Please sign in to comment.