diff --git a/lib/tapex.ex b/lib/tapex.ex index e3b96c4..40b2f1f 100644 --- a/lib/tapex.ex +++ b/lib/tapex.ex @@ -1,6 +1,6 @@ defmodule Tapex do - use GenEvent + use GenServer alias ExUnit.{Formatter} alias Tapex.Tap @@ -32,7 +32,7 @@ defmodule Tapex do {:ok, config} end - def handle_event({:suite_finished, run_time, load_time}, %{test_count: count, seed: seed}=config) do + def handle_cast({:suite_finished, run_time, load_time}, %{test_count: count, seed: seed}=config) do IO.puts(Tap.format_plan(count)) IO.puts("") IO.puts(Formatter.format_time(run_time, load_time)) @@ -40,25 +40,25 @@ defmodule Tapex do IO.puts("\nRandomized with seed #{seed}") - :remove_handler + {:noreply, config} end - def handle_event({:test_finished, %{}=test}, %{colorize: colorize}=config) do + def handle_cast({:test_finished, %{}=test}, %{colorize: colorize}=config) do %{test_count: number} = config = increment_counters(config, test) print_line(test, number, colorize) print_diagnostic(test, get_in(config, [:state_counter, :failed]) || 0, colorize) - {:ok, config} + {:noreply, config} end - def handle_event({:case_finished, case}, %{colorize: colorize}=config) do + def handle_cast({:case_finished, case}, %{colorize: colorize}=config) do %{test_count: number} = config = increment_counters(config, case) print_line(case, number, colorize) print_diagnostic(case, get_in(config, [:state_counter, :failed]) || 0, colorize) - {:ok, config} + {:noreply, config} end - def handle_event(_, config) do - {:ok, config} + def handle_cast(_, config) do + {:noreply, config} end defp increment_counters(%{}=config, %{}=test) do diff --git a/test/tapex_test.exs b/test/tapex_test.exs index 0e0f296..7e06094 100644 --- a/test/tapex_test.exs +++ b/test/tapex_test.exs @@ -36,7 +36,7 @@ defmodule TapexTest do } output = capture_io fn -> - {:ok, _} = Tapex.handle_event({:test_finished, test}, config) + {:noreply, _} = Tapex.handle_cast({:test_finished, test}, config) end assert Regex.match?(~r/^ok/, output) @@ -57,7 +57,7 @@ defmodule TapexTest do } output = capture_io fn -> - {:ok, _} = Tapex.handle_event({:case_finished, case}, config) + {:noreply, _} = Tapex.handle_cast({:case_finished, case}, config) end assert Regex.match?(~r/^not ok/, output) @@ -77,7 +77,7 @@ defmodule TapexTest do output = capture_io fn -> time = 500000 - :remove_handler = Tapex.handle_event({:suite_finished, time, time}, config) + {:noreply, _} = Tapex.handle_cast({:suite_finished, time, time}, config) end assert String.contains?(output, "1..5\n")