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

Conversation

diogommartins
Copy link
Contributor

Currently, elixir modules mocked using the meck library may leave a trace in the modules list that excoveralls tries to cover which won't have a source key. As mocks, It is expected that those modules wouldn't have a corresponding source file, but excoveralls currently doesn't handle this case. This pull request addresses this issue by improving the bypass logic of modules without a source file.

Examples of the return of module_info/1

Unmocked, compiled and executed module

[
  version: '7.4',
  options: [:no_spawn_compiler_process, :from_core, :no_auto_import],
  source: '/Users/diogo.martins/dev/excoveralls/test_missing.ex'
]

Mocked module

[version: '7.4', options: []]

The mocked module scenario starts breaking when whe assume that every module has a :source at Keyword.get(info, :source). It returns nil and has_compile_info?/1 tries to call File.exists?/1 with nil, resulting in the following stacktrace:

Randomized with seed 319344
** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1    
    
    The following arguments were given to IO.chardata_to_string/1:
    
        # 1
        nil
    
    Attempted function clauses (showing 2 out of 2):
    
        def chardata_to_string(+string+) when -is_binary(string)-
        def chardata_to_string(+list+) when -is_list(list)-
    
    (elixir) lib/io.ex:461: IO.chardata_to_string/1
    (elixir) lib/file.ex:214: File.exists?/2
    lib/excoveralls/cover.ex:34: ExCoveralls.Cover.has_compile_info?/1
    (elixir) lib/enum.ex:2934: Enum.filter_list/2
    (elixir) lib/enum.ex:2935: Enum.filter_list/2
    lib/excoveralls.ex:39: ExCoveralls.execute/2
    (mix) lib/mix/tasks/test.ex:390: Mix.Tasks.Test.run/1
    (mix) lib/mix/task.ex:331: Mix.Task.run_task/3
    (mix) lib/mix/project.ex:348: Mix.Project.in_project/4
    (elixir) lib/file.ex:1506: File.cd!/2
    (mix) lib/mix/task.ex:431: anonymous fn/4 in Mix.Task.recur/1
    (elixir) lib/enum.ex:1940: Enum."-reduce/3-lists^foldl/2-0-"/3
    (mix) lib/mix/task.ex:430: Mix.Task.recur/1
    (mix) lib/mix/project_stack.ex:208: Mix.ProjectStack.recur/1
    lib/mix/tasks.ex:54: Mix.Tasks.Coveralls.do_run/2
    (mix) lib/mix/task.ex:331: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:79: Mix.CLI.run_task/2

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.05%) to 89.778% when pulling 8c55618 on diogommartins:fix/mocked-module-handling into 5f19e75 on parroty:master.

@diogommartins
Copy link
Contributor Author

Hey, @parroty sorry but I was unable to figure out with I lowered the coverage on my PR. Could you help me out?

@parroty
Copy link
Owner

parroty commented Jul 25, 2020

Thanks. I think the coverage change is just within the margin of error.

@parroty parroty merged commit b67c791 into parroty:master Jul 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants