@@ -2,8 +2,8 @@ defmodule Display do
|
|||||||
alias IO.ANSI
|
alias IO.ANSI
|
||||||
@current_dir File.cwd!
|
@current_dir File.cwd!
|
||||||
|
|
||||||
def show_failure(%{expr: expr}, module, name, options) do
|
def show_failure(%{expr: expr}, module, name) do
|
||||||
clear_screen(options)
|
clear_screen()
|
||||||
|
|
||||||
IO.puts("Now meditate upon #{display_module(module)}")
|
IO.puts("Now meditate upon #{display_module(module)}")
|
||||||
IO.puts("---------------------------------------")
|
IO.puts("---------------------------------------")
|
||||||
@@ -16,10 +16,11 @@ defmodule Display do
|
|||||||
IO.puts("Considering #{display_module(module)}...")
|
IO.puts("Considering #{display_module(module)}...")
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_screen(%{ clear_screen: false }), do: false
|
def clear_screen() do
|
||||||
def clear_screen(_) do
|
if Options.clear_screen? do
|
||||||
IO.puts(ANSI.clear)
|
IO.puts(ANSI.clear)
|
||||||
IO.puts(ANSI.home)
|
IO.puts(ANSI.home)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_failed_assertion(module, expr) do
|
def display_failed_assertion(module, expr) do
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ defmodule Mix.Tasks.Meditate do
|
|||||||
Code.compiler_options(ignore_module_conflict: true)
|
Code.compiler_options(ignore_module_conflict: true)
|
||||||
Watcher.start
|
Watcher.start
|
||||||
|
|
||||||
options = Options.parse(args)
|
Options.start(args)
|
||||||
Runner.run(options)
|
Runner.run
|
||||||
|
|
||||||
:timer.sleep(:infinity)
|
:timer.sleep(:infinity)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,16 +1,24 @@
|
|||||||
defmodule Options do
|
defmodule Options do
|
||||||
|
@defaults %{
|
||||||
|
clear_screen: false
|
||||||
|
}
|
||||||
|
|
||||||
def parse([]), do: defaults
|
def start(args) do
|
||||||
def parse(args) do
|
Agent.start_link(fn -> parse(args) end, name: __MODULE__)
|
||||||
Enum.reduce(args, defaults, fn(arg, acc) ->
|
end
|
||||||
|
|
||||||
|
def clear_screen? do
|
||||||
|
Agent.get(__MODULE__, fn(options) ->
|
||||||
|
Map.fetch!(options, :clear_screen)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp parse(args) do
|
||||||
|
Enum.reduce(args, @defaults, fn(arg, acc) ->
|
||||||
Map.merge(acc, parse_argument(arg))
|
Map.merge(acc, parse_argument(arg))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_argument("--clear-screen"), do: %{ clear_screen: true}
|
def parse_argument("--clear-screen"), do: %{ clear_screen: true}
|
||||||
def parse_argument(_), do: %{}
|
def parse_argument(_), do: %{}
|
||||||
|
|
||||||
defp defaults do
|
|
||||||
%{ clear_screen: false}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,25 +10,25 @@ defmodule Runner do
|
|||||||
Structs
|
Structs
|
||||||
]
|
]
|
||||||
|
|
||||||
def run(options) do
|
def run do
|
||||||
run(Equalities, options)
|
run(Equalities)
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(start_module, options) do
|
def run(start_module) 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, options) == :passed
|
run_module(mod) == :passed
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_module(module, options) do
|
def run_module(module) 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, options) == :passed
|
run_koan(module, name) == :passed
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if Enum.count(koans) == Enum.count(passed) do
|
if Enum.count(koans) == Enum.count(passed) do
|
||||||
@@ -38,11 +38,11 @@ defmodule Runner do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_koan(module, name, options) do
|
def run_koan(module, name) do
|
||||||
case apply(module, name, []) do
|
case apply(module, name, []) do
|
||||||
:ok -> :passed
|
:ok -> :passed
|
||||||
error ->
|
error ->
|
||||||
Display.show_failure(error, module, name, options)
|
Display.show_failure(error, module, name)
|
||||||
:failed
|
:failed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,17 +2,17 @@ defmodule OptionTest do
|
|||||||
use ExUnit.Case, async: true
|
use ExUnit.Case, async: true
|
||||||
|
|
||||||
test "has default options" do
|
test "has default options" do
|
||||||
options = Options.parse([])
|
Options.start([])
|
||||||
refute Map.fetch!(options, :clear_screen)
|
refute Options.clear_screen?
|
||||||
end
|
end
|
||||||
|
|
||||||
test "override clearing of screen" do
|
test "override clearing of screen" do
|
||||||
options = Options.parse(["--clear-screen"])
|
Options.start(["--clear-screen"])
|
||||||
assert Map.fetch!(options, :clear_screen)
|
assert Options.clear_screen?
|
||||||
end
|
end
|
||||||
|
|
||||||
test "ignores unknown options" do
|
test "ignores unknown options" do
|
||||||
options = Options.parse(["--foo"])
|
Options.start(["--foo"])
|
||||||
refute Map.fetch!(options, :clear_screen)
|
refute Options.clear_screen?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user