Skip to content

Commit

Permalink
Add coveralls.multiple command (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertored authored Mar 2, 2023
1 parent 6890fdc commit e2e3653
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/excoveralls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ defmodule ExCoveralls do
if options[:umbrella] do
store_stats(stats, options, compile_path)
else
Stats.update_paths(stats, options) |>
analyze(options[:type] || "local", options)
types = List.wrap(options[:type] || "local")
stats = Stats.update_paths(stats, options)
Enum.each(types, &analyze(stats, &1, options))
end
after
if name = opts[:export] do
Expand Down
14 changes: 14 additions & 0 deletions lib/excoveralls/conf_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule ExCoveralls.ConfServer do

@ets_table :excoveralls_conf_server
@ets_key :config_key
@ets_summary_key :summary_key

@doc """
Initialize the data-store table.
Expand Down Expand Up @@ -41,4 +42,17 @@ defmodule ExCoveralls.ConfServer do
:ets.insert(@ets_table, {@ets_key, value})
value
end

def summary_printed do
start()
:ets.insert(@ets_table, {@ets_summary_key, true})
end

def summary_printed? do
start()

@ets_table
|> :ets.lookup(@ets_summary_key)
|> Keyword.get(@ets_summary_key, false)
end
end
7 changes: 5 additions & 2 deletions lib/excoveralls/local.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ defmodule ExCoveralls.Local do
@moduledoc """
Locally displays the result to screen.
"""



defmodule Count do
@moduledoc """
Expand Down Expand Up @@ -44,8 +46,9 @@ defmodule ExCoveralls.Local do
"""
def print_summary(stats, options \\ []) do
enabled = ExCoveralls.Settings.get_print_summary
if enabled do
coverage(stats, options) |> IO.puts
if enabled and not ExCoveralls.ConfServer.summary_printed?() do
coverage(stats, options) |> IO.puts()
ExCoveralls.ConfServer.summary_printed()
end
end

Expand Down
7 changes: 7 additions & 0 deletions lib/excoveralls/task/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ Usage: mix coveralls.post <Options>
-s (--sha) Commit SHA (required when not using Travis)
--build Service number ('BUILDS' column at coveralls.io page)
--parallel coveralls.io 'parallel' option (See coveralls.io API Reference)
Usage: mix coveralls.multiple
Used to perform multiple coveralls task at once without need of re-running tests.
<Options>
--type Coveralls task to execute (can be given multiple times)
e.g. 'mix coveralls.multiple --type html --type json'
"""
end
end
35 changes: 35 additions & 0 deletions lib/mix/tasks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,39 @@ defmodule Mix.Tasks.Coveralls do
end
end
end

defmodule Multiple do
@moduledoc """
Provides an entry point for executing multiple coveralls
task at once without re-running tests
"""

use Mix.Task

@preferred_cli_env :test

def run(args) do
{parsed, _, _} = OptionParser.parse(args, strict: [type: :keep])

args = remove_type_args(args)

case Keyword.get_values(parsed, :type) do
[] -> raise ExCoveralls.InvalidOptionError, message: "type argument is required"
types -> Mix.Tasks.Coveralls.do_run(args, type: types)
end
end

defp remove_type_args(args) do
{res, _} =
Enum.reduce(args, {[], nil}, fn entry, {buffer, acc} ->
case {entry, acc} do
{_, "--type" }-> {buffer, nil}
{"--type", _} -> {buffer, "--type"}
{el, _} -> {[el | buffer], nil}
end
end)

Enum.reverse(res)
end
end
end
3 changes: 3 additions & 0 deletions test/html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ defmodule ExCoveralls.HtmlTest do
"----------------\n"

setup do
ExCoveralls.ConfServer.clear()
path = Path.expand(@file_name, @test_output_dir)

# Assert does not exist prior to write
Expand All @@ -34,6 +35,8 @@ defmodule ExCoveralls.HtmlTest do
File.rm!(path)
File.rmdir!(@test_output_dir)
end

ExCoveralls.ConfServer.clear()
end

{:ok, report: path}
Expand Down
3 changes: 3 additions & 0 deletions test/json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ defmodule ExCoveralls.JsonTest do
"----------------\n"

setup do
ExCoveralls.ConfServer.clear()
path = Path.expand(@file_name, @test_output_dir)

# Assert does not exist prior to write
Expand All @@ -33,6 +34,8 @@ defmodule ExCoveralls.JsonTest do
File.rm!(path)
File.rmdir!(@test_output_dir)
end

ExCoveralls.ConfServer.clear()
end

{:ok, report: path}
Expand Down
3 changes: 3 additions & 0 deletions test/lcov_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ defmodule ExCoveralls.LcovTest do
"----------------\n"

setup do
ExCoveralls.ConfServer.clear()
path = Path.expand(@file_name, @test_output_dir)

# Assert does not exist prior to write
Expand All @@ -33,6 +34,8 @@ defmodule ExCoveralls.LcovTest do
File.rm!(path)
File.rmdir!(@test_output_dir)
end

ExCoveralls.ConfServer.clear()
end

{:ok, report: path}
Expand Down
6 changes: 6 additions & 0 deletions test/local_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ defmodule ExCoveralls.LocalTest do
"\e[31mdefmodule Test do\e[m\n\e[32m def test do\e[m\n" <>
" end\n" <>
"end"

setup do
ExCoveralls.ConfServer.clear()
on_exit(fn -> ExCoveralls.ConfServer.clear() end)
:ok
end

test "display source information" do
assert(Local.source(@source_info) =~ @source_result)
Expand Down
7 changes: 7 additions & 0 deletions test/mix/tasks_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ defmodule Mix.Tasks.CoverallsTest do
assert(ExCoveralls.ConfServer.get == [type: "html", args: []])
end

test_with_mock "multiple", Runner, [run: fn(_, _) -> nil end] do
Mix.Tasks.Coveralls.Multiple.run(["--type", "html", "--type", "json", "--export-coverage", "cover", "test/foo_test.exs"])
assert(called Runner.run("test", ["--cover", "--export-coverage", "cover", "test/foo_test.exs"]))
assert(ExCoveralls.ConfServer.get()[:type] == ["html", "json"])
assert(ExCoveralls.ConfServer.get()[:args] == ["--export-coverage", "cover", "test/foo_test.exs"])
end

test_with_mock "json", Runner, [run: fn(_, _) -> nil end] do
Mix.Tasks.Coveralls.Json.run([])
assert(called Runner.run("test", ["--cover"]))
Expand Down
3 changes: 3 additions & 0 deletions test/xml_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defmodule ExCoveralls.XmlTest do
"----------------\n"

setup do
ExCoveralls.ConfServer.clear()
path = Path.expand(@file_name, @test_output_dir)

# Assert does not exist prior to write
Expand All @@ -32,6 +33,8 @@ defmodule ExCoveralls.XmlTest do
File.rm!(path)
File.rmdir!(@test_output_dir)
end

ExCoveralls.ConfServer.clear()
end

{:ok, report: path}
Expand Down

0 comments on commit e2e3653

Please sign in to comment.