Clears display on failures based on options map
This commit is contained in:
@@ -2,8 +2,9 @@ defmodule Display do
|
||||
alias IO.ANSI
|
||||
@current_dir File.cwd!
|
||||
|
||||
def show_failure(%{expr: expr}, module, name) do
|
||||
clear_screen
|
||||
def show_failure(%{expr: expr}, module, name, options) do
|
||||
clear_screen(options)
|
||||
|
||||
IO.puts("Now meditate upon #{display_module(module)}")
|
||||
IO.puts("---------------------------------------")
|
||||
IO.puts(format_cyan(display_failed_assertion(module, expr)))
|
||||
@@ -15,7 +16,8 @@ defmodule Display do
|
||||
IO.puts("Considering #{display_module(module)}...")
|
||||
end
|
||||
|
||||
def clear_screen do
|
||||
def clear_screen(%{ clear_screen: false }), do: false
|
||||
def clear_screen(_) do
|
||||
IO.puts(ANSI.clear)
|
||||
IO.puts(ANSI.home)
|
||||
end
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
defmodule Mix.Tasks.Meditate do
|
||||
use Mix.Task
|
||||
alias Options
|
||||
|
||||
def run(_) do
|
||||
def run(args) do
|
||||
Application.ensure_all_started(:elixir_koans)
|
||||
Code.compiler_options(ignore_module_conflict: true)
|
||||
Watcher.start
|
||||
Runner.run
|
||||
|
||||
options = Options.parse(args)
|
||||
Runner.run(options)
|
||||
|
||||
:timer.sleep(:infinity)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,25 +8,25 @@ defmodule Runner do
|
||||
Enums
|
||||
]
|
||||
|
||||
def run do
|
||||
run(Equalities)
|
||||
def run(options) do
|
||||
run(Equalities, options)
|
||||
end
|
||||
|
||||
def run(start_module) do
|
||||
def run(start_module, options) do
|
||||
start_idx = Enum.find_index(@modules, &(&1 == start_module))
|
||||
Enum.drop(@modules, start_idx)
|
||||
|> Enum.take_while(fn(mod) ->
|
||||
run_module(mod) == :passed
|
||||
run_module(mod, options) == :passed
|
||||
end)
|
||||
end
|
||||
|
||||
def run_module(module) do
|
||||
def run_module(module, options) do
|
||||
Display.considering(module)
|
||||
|
||||
koans = extract_koans_from(module)
|
||||
|
||||
passed = Enum.take_while(koans, fn(name) ->
|
||||
run_koan(module, name) == :passed
|
||||
run_koan(module, name, options) == :passed
|
||||
end)
|
||||
|
||||
if Enum.count(koans) == Enum.count(passed) do
|
||||
@@ -36,11 +36,11 @@ defmodule Runner do
|
||||
end
|
||||
end
|
||||
|
||||
def run_koan(module, name) do
|
||||
def run_koan(module, name, options) do
|
||||
case apply(module, name, []) do
|
||||
:ok -> :passed
|
||||
error ->
|
||||
Display.show_failure(error, module, name)
|
||||
Display.show_failure(error, module, name, options)
|
||||
:failed
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user