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

Handle coverage the same was as exunit #8

Merged
merged 3 commits into from
Aug 26, 2016

Conversation

toland
Copy link
Contributor

@toland toland commented Aug 11, 2016

This allows the end user to use custom coverage tools.

This allows the end user to use custom coverage tools.
test_modules(post_config[:erlc_paths], options[:patterns])
|> Enum.map(&module_name_from_path/1)
|> Enum.drop_while(fn(m) ->
tests_pass?(m, options[:eunit_opts] ++ post_config[:eunit_opts]) end)
if(options[:cover], do: cover_analyse())

cover && cover.()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get how this works. It looks like cover is either nil or a Keyword. How would cover.() work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cover is either nil or a function. Cover.start/2 returns a function that does the analysis and writes the output.

The code for the default Cover module is here: https://github.com/elixir-lang/elixir/blob/master/lib/mix/lib/mix/tasks/test.ex#L2

Copy link
Owner

@dantswain dantswain Aug 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so I think this is just a bit of funkyness with variable names (like having a couple things named cover). Can we do something like

def run(args) do
   # .. existing code

  # line 55
  cover_callback = start_cover_tool(options[:cover], project)

  # lines 63-66 same

  # line 68
  execute_cover_callback(cover_callback)
end

# no cover tool specified
defp start_cover_tool(nil, _project), do: nil
# set up the cover tool
defp start_cover_tool(cover_tool, project) do
  compile_path = Mix.Project.compile_path(project)
  cover = Keyword.merge(@cover, project[:test_coverage] || [])
  # returns a callback
  cover[:tool].start(compile_path, cover)
end

# no cover tool was specified
defp execute_cover_callback(nil), do: :ok
# run the cover callback
defp execute_cover_callback(cb), do: cb.()

Phil Toland added 2 commits August 25, 2016 12:34
* master:
  Replace List.keymember? with Keyword.has_key?
  Add eunit_formatters for better output
  Make sure test failures cause the task to fail
  Run the tests all at once rather than individually

# Conflicts:
#	lib/mix/tasks/eunit.ex
@toland
Copy link
Contributor Author

toland commented Aug 26, 2016

@dantswain Done. Let me know what you think.

@dantswain
Copy link
Owner

👍 :shipit: and Thanks!

@dantswain dantswain merged commit 38631a4 into dantswain:master Aug 26, 2016
@toland toland deleted the coverage_like_exunit branch August 26, 2016 05:27
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.

2 participants