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

Minimum threshold support for json output #286

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
0.14.6
------
#### Changes
- Survive coveralls maintenance and outagle (#283).
- Survive coveralls maintenance and outage (#283).
- Better handling of coveralls.io errors (ex. 405, 500 status codes).

0.14.5
Expand Down
2 changes: 2 additions & 0 deletions lib/excoveralls/json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ defmodule ExCoveralls.Json do
generate_json(stats, Enum.into(options, %{})) |> write_file(options[:output_dir])

ExCoveralls.Local.print_summary(stats)

ExCoveralls.Stats.ensure_minimum_coverage(stats)
end

def generate_json(stats, _options) do
Expand Down
32 changes: 32 additions & 0 deletions test/json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,36 @@ defmodule ExCoveralls.JsonTest do
%{size: size} = File.stat! report
assert(size == @file_size)
end

test_with_mock "exit status code is 1 when actual coverage does not reach the minimum",
ExCoveralls.Settings, [
get_coverage_options: fn -> coverage_options(100) end,
get_file_col_width: fn -> 40 end,
get_print_summary: fn -> true end,
get_print_files: fn -> true end
] do
output = capture_io(fn ->
assert catch_exit(Json.execute(@source_info)) == {:shutdown, 1}
end)
assert String.contains?(output, "FAILED: Expected minimum coverage of 100%, got 50%.")
end

test_with_mock "exit status code is 0 when actual coverage reaches the minimum",
ExCoveralls.Settings, [
get_coverage_options: fn -> coverage_options(49.9) end,
get_file_col_width: fn -> 40 end,
get_print_summary: fn -> true end,
get_print_files: fn -> true end
] do
assert capture_io(fn ->
Json.execute(@source_info)
end) =~ @stats_result
end

defp coverage_options(minimum_coverage) do
%{
"minimum_coverage" => minimum_coverage,
"output_dir" => @test_output_dir,
}
end
end
6 changes: 4 additions & 2 deletions test/mix/tasks_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ defmodule Mix.Tasks.CoverallsTest do
end

test_with_mock "doesn't pass through coveralls args", Runner, [run: fn(_, _) -> nil end] do
Mix.Tasks.Coveralls.run(["--include", "remote", "-x", "--unknown", "value", "--verbose", "-u", "--filter", "x"])
assert(called Runner.run("test", ["--cover", "--include", "remote", "-x", "--unknown", "value"]))
capture_io(fn ->
Mix.Tasks.Coveralls.run(["--include", "remote", "-x", "--unknown", "value", "--verbose", "-u", "--filter", "x"])
assert(called Runner.run("test", ["--cover", "--include", "remote", "-x", "--unknown", "value"]))
end)
end

test_with_mock "detail", Runner, [run: fn(_, _) -> nil end] do
Expand Down