Skip to content

Commit

Permalink
Merge branch 'replace-gen-event-with-gen-server'
Browse files Browse the repository at this point in the history
* replace-gen-event-with-gen-server:
  Fix tests for GenEvent -> GenServer swap
  Fix deprecation warning about GenEvent
  • Loading branch information
joshwlewis committed Nov 9, 2017
2 parents 24f3bbc + cea607d commit 9b07228
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions lib/tapex.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Tapex do

use GenEvent
use GenServer

alias ExUnit.{Formatter}
alias Tapex.Tap
Expand Down Expand Up @@ -32,33 +32,33 @@ 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))
IO.puts(format_counts(config))

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
Expand Down
6 changes: 3 additions & 3 deletions test/tapex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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")
Expand Down

0 comments on commit 9b07228

Please sign in to comment.