Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add .coverdata file export #298

Merged
merged 1 commit into from
Jan 9, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The following are example projects.
Add the following parameters.

- `test_coverage: [tool: ExCoveralls]` for using ExCoveralls for coverage reporting.
- `test_coverage: [tool: ExCoveralls, export: "cov"]` for exporting data to `cover/cov.coverdata`
- `preferred_cli_env: [coveralls: :test]` for running `mix coveralls` in `:test` env by default
- It's an optional setting for skipping `MIX_ENV=test` part when executing `mix coveralls` tasks.
- `test_coverage: [test_task: "espec"]` if you use Espec instead of default ExUnit.
Expand Down
23 changes: 20 additions & 3 deletions lib/excoveralls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ defmodule ExCoveralls do
@doc """
This method will be called from mix to trigger coverage analysis.
"""
def start(compile_path, _opts) do
def start(compile_path, opts) do
Cover.compile(compile_path)
fn() ->
execute(ConfServer.get, compile_path)
execute(ConfServer.get, compile_path, opts)
end
end

def execute(options, compile_path) do
def execute(options, compile_path, opts) do
stats =
Cover.modules() |>
Stats.report() |>
Expand All @@ -55,6 +55,23 @@ defmodule ExCoveralls do
Stats.update_paths(stats, options) |>
analyze(options[:type] || "local", options)
end
after
if name = opts[:export] do
export_coverdata_file(name, opts)
end
end

defp export_coverdata_file(name, opts) do
output = Keyword.get(opts, :output, "cover")
File.mkdir_p!(output)

case :cover.export('#{output}/#{name}.coverdata') do
:ok ->
Mix.shell().info("Coverage data exported.")

{:error, reason} ->
Mix.shell().error("Export failed with reason: #{inspect(reason)}")
end
end

defp store_stats(stats, options, compile_path) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule ExCoveralls.Mixfile do
def project do
[
app: :excoveralls,
version: "0.15.1",
version: "0.15.2",
elixir: "~> 1.3",
elixirc_paths: elixirc_paths(Mix.env()),
deps: deps(),
Expand Down