Clears display on failures based on options map

This commit is contained in:
Felipe Sere
2016-03-06 14:56:13 +00:00
parent 4281c63ab1
commit 53815ed759
3 changed files with 19 additions and 13 deletions

View File

@@ -2,8 +2,9 @@ defmodule Display do
alias IO.ANSI alias IO.ANSI
@current_dir File.cwd! @current_dir File.cwd!
def show_failure(%{expr: expr}, module, name) do def show_failure(%{expr: expr}, module, name, options) do
clear_screen clear_screen(options)
IO.puts("Now meditate upon #{display_module(module)}") IO.puts("Now meditate upon #{display_module(module)}")
IO.puts("---------------------------------------") IO.puts("---------------------------------------")
IO.puts(format_cyan(display_failed_assertion(module, expr))) IO.puts(format_cyan(display_failed_assertion(module, expr)))
@@ -15,7 +16,8 @@ defmodule Display do
IO.puts("Considering #{display_module(module)}...") IO.puts("Considering #{display_module(module)}...")
end end
def clear_screen do def clear_screen(%{ clear_screen: false }), do: false
def clear_screen(_) do
IO.puts(ANSI.clear) IO.puts(ANSI.clear)
IO.puts(ANSI.home) IO.puts(ANSI.home)
end end

View File

@@ -1,11 +1,15 @@
defmodule Mix.Tasks.Meditate do defmodule Mix.Tasks.Meditate do
use Mix.Task use Mix.Task
alias Options
def run(_) do def run(args) do
Application.ensure_all_started(:elixir_koans) Application.ensure_all_started(:elixir_koans)
Code.compiler_options(ignore_module_conflict: true) Code.compiler_options(ignore_module_conflict: true)
Watcher.start Watcher.start
Runner.run
options = Options.parse(args)
Runner.run(options)
:timer.sleep(:infinity) :timer.sleep(:infinity)
end end
end end

View File

@@ -8,25 +8,25 @@ defmodule Runner do
Enums Enums
] ]
def run do def run(options) do
run(Equalities) run(Equalities, options)
end end
def run(start_module) do def run(start_module, options) do
start_idx = Enum.find_index(@modules, &(&1 == start_module)) start_idx = Enum.find_index(@modules, &(&1 == start_module))
Enum.drop(@modules, start_idx) Enum.drop(@modules, start_idx)
|> Enum.take_while(fn(mod) -> |> Enum.take_while(fn(mod) ->
run_module(mod) == :passed run_module(mod, options) == :passed
end) end)
end end
def run_module(module) do def run_module(module, options) do
Display.considering(module) Display.considering(module)
koans = extract_koans_from(module) koans = extract_koans_from(module)
passed = Enum.take_while(koans, fn(name) -> passed = Enum.take_while(koans, fn(name) ->
run_koan(module, name) == :passed run_koan(module, name, options) == :passed
end) end)
if Enum.count(koans) == Enum.count(passed) do if Enum.count(koans) == Enum.count(passed) do
@@ -36,11 +36,11 @@ defmodule Runner do
end end
end end
def run_koan(module, name) do def run_koan(module, name, options) do
case apply(module, name, []) do case apply(module, name, []) do
:ok -> :passed :ok -> :passed
error -> error ->
Display.show_failure(error, module, name) Display.show_failure(error, module, name, options)
:failed :failed
end end
end end