Skip to content

Commit

Permalink
Fix bug in test count reporting when using ExCheck in umbrella apps
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-tielen committed Nov 23, 2016
1 parent 4b8ab92 commit 82e8822
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/excheck/error_agent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ defmodule ExCheck.ErrorAgent do
end)
end

@doc "Clears all errors stored by this agent."
def clear_errors(agent) do
agent |> Agent.update(fn(_) -> %{} end)
end

@doc "Stops the agent."
def stop(agent) do
Agent.stop(agent)
Expand Down
8 changes: 6 additions & 2 deletions lib/excheck/formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ defmodule ExCheck.Formatter do
end

defp update_tests_counter(tests_counter) when is_integer(tests_counter) do
tests_counter + ExCheck.IOServer.total_tests
total_tests = tests_counter + ExCheck.IOServer.total_tests
ExCheck.IOServer.reset_test_count
total_tests
end
defp update_tests_counter(tests_counter) when is_map(tests_counter) do
%{tests_counter | test: tests_counter.test + ExCheck.IOServer.total_tests}
total_tests = %{tests_counter | test: tests_counter.test + ExCheck.IOServer.total_tests}
ExCheck.IOServer.reset_test_count
total_tests
end
end
9 changes: 9 additions & 0 deletions lib/excheck/io_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ defmodule ExCheck.IOServer do
@server |> GenServer.call(:total_tests)
end

@doc "Resets the test count."
def reset_test_count do
@server |> GenServer.call(:reset_test_count)
end

@doc "Returns all error loggings from property tests"
def errors do
@server |> GenServer.call(:errors)
Expand Down Expand Up @@ -65,6 +70,10 @@ defmodule ExCheck.IOServer do
def handle_call(:total_tests, _from, state = %State{tests: tests}) do
{:reply, tests, state}
end
def handle_call(:reset_test_count, _from, state = %State{agent: agent}) do
agent |> ErrAgent.clear_errors
{:reply, :ok, %State{state | tests: 0}}
end
def handle_call(:errors, _from, state = %State{agent: agent}) do
response = ErrAgent.errors(agent)
{:reply, response, state}
Expand Down

0 comments on commit 82e8822

Please sign in to comment.