Skip to content

Commit

Permalink
add .coverdata file export (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandorbedo committed Jan 9, 2023
1 parent 4ab3cec commit bd08a50
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
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

0 comments on commit bd08a50

Please # to comment.