Merge pull request #25 from ukutaht/clear-screen
Clear screen on every run.
This commit is contained in:
@@ -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
|
||||||
IO.puts("")
|
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,9 +16,10 @@ defmodule Display do
|
|||||||
IO.puts("Considering #{display_module(module)}...")
|
IO.puts("Considering #{display_module(module)}...")
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_run do
|
def clear_screen(%{ clear_screen: false }), do: false
|
||||||
IO.puts("")
|
def clear_screen(_) do
|
||||||
IO.puts("")
|
IO.puts(ANSI.clear)
|
||||||
|
IO.puts(ANSI.home)
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_failed_assertion(module, expr) do
|
def display_failed_assertion(module, expr) do
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
16
lib/options.ex
Normal file
16
lib/options.ex
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
defmodule Options do
|
||||||
|
|
||||||
|
def parse([]), do: defaults
|
||||||
|
def parse(args) do
|
||||||
|
Enum.reduce(args, defaults, fn(arg, acc) ->
|
||||||
|
Map.merge(acc, parse_argument(arg))
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_argument("--clear-screen"), do: %{ clear_screen: true}
|
||||||
|
def parse_argument(_), do: %{}
|
||||||
|
|
||||||
|
defp defaults do
|
||||||
|
%{ clear_screen: false}
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -8,27 +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
|
||||||
Display.before_run
|
|
||||||
|
|
||||||
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
|
||||||
@@ -38,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
|
||||||
|
|||||||
18
test/options_test.exs
Normal file
18
test/options_test.exs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
defmodule OptionTest do
|
||||||
|
use ExUnit.Case, async: true
|
||||||
|
|
||||||
|
test "has default options" do
|
||||||
|
options = Options.parse([])
|
||||||
|
refute Map.fetch!(options, :clear_screen)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "override clearing of screen" do
|
||||||
|
options = Options.parse(["--clear-screen"])
|
||||||
|
assert Map.fetch!(options, :clear_screen)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "ignores unknown options" do
|
||||||
|
options = Options.parse(["--foo"])
|
||||||
|
refute Map.fetch!(options, :clear_screen)
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user