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

Fixing mocked modules coverage handling #226

Merged
merged 1 commit into from
Jul 25, 2020
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: 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