Merge pull request #89 from iamvery/assert-koan-test-results
Assert koan test results
This commit is contained in:
16
lib/koans.ex
16
lib/koans.ex
@@ -33,8 +33,12 @@ defmodule Koans do
|
|||||||
single_var = Blanks.replace(body, Macro.var(:answer, Koans))
|
single_var = Blanks.replace(body, Macro.var(:answer, Koans))
|
||||||
quote do
|
quote do
|
||||||
def unquote(name)(answer) do
|
def unquote(name)(answer) do
|
||||||
unquote(single_var)
|
try do
|
||||||
:ok
|
unquote(single_var)
|
||||||
|
:ok
|
||||||
|
rescue
|
||||||
|
e in _ -> e
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -44,8 +48,12 @@ defmodule Koans do
|
|||||||
quote do
|
quote do
|
||||||
def unquote(name)({:multiple, answers}) do
|
def unquote(name)({:multiple, answers}) do
|
||||||
converted = List.to_tuple(answers)
|
converted = List.to_tuple(answers)
|
||||||
unquote(multi_var)
|
try do
|
||||||
:ok
|
unquote(multi_var)
|
||||||
|
:ok
|
||||||
|
rescue
|
||||||
|
e in _ -> e
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
ExUnit.start()
|
ExUnit.start()
|
||||||
|
|
||||||
defmodule TestHarness do
|
defmodule TestHarness do
|
||||||
|
import ExUnit.Assertions
|
||||||
|
|
||||||
def test_all(module, answers) do
|
def test_all(module, answers) do
|
||||||
module.all_koans
|
module.all_koans
|
||||||
|> check_answer_count(answers, module)
|
|> check_answer_count(answers, module)
|
||||||
|> Enum.zip(answers)
|
|> Enum.zip(answers)
|
||||||
|> run_all(module)
|
|> run_all(module)
|
||||||
|
|> check_results
|
||||||
end
|
end
|
||||||
|
|
||||||
defp check_answer_count(koans, answers, module) do
|
defp check_answer_count(koans, answers, module) do
|
||||||
@@ -19,6 +22,10 @@ defmodule TestHarness do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp check_results(results) do
|
||||||
|
Enum.each(results, &(assert &1 == :passed))
|
||||||
|
end
|
||||||
|
|
||||||
def run_all(pairs, module) do
|
def run_all(pairs, module) do
|
||||||
Enum.map(pairs, fn ({koan, answer}) -> Execute.run_koan(module, koan, [answer]) end)
|
Enum.map(pairs, fn ({koan, answer}) -> Execute.run_koan(module, koan, [answer]) end)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user