diff --git a/README.md b/README.md index f53a6d33..a618e2f4 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/excoveralls.ex b/lib/excoveralls.ex index b97c65e4..6d653d46 100644 --- a/lib/excoveralls.ex +++ b/lib/excoveralls.ex @@ -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() |> @@ -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 diff --git a/mix.exs b/mix.exs index 51d61a59..e89f7606 100644 --- a/mix.exs +++ b/mix.exs @@ -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(),