Move error line detection into runner itself due to processes.
This commit is contained in:
@@ -14,25 +14,23 @@ defmodule Runner do
|
||||
Tasks,
|
||||
]
|
||||
|
||||
def koan?(module) do
|
||||
Enum.member?(@modules, module)
|
||||
end
|
||||
def koan?(koan), do: Enum.member?(@modules, koan)
|
||||
|
||||
def run do
|
||||
Options.initial_koan
|
||||
|>run
|
||||
end
|
||||
|
||||
def run(start_module) when start_module in @modules do
|
||||
def run(start_module) when start_module in @modules, do: run(start_module, @modules)
|
||||
def run(start_module), do: Display.invalid_koan(start_module, @modules)
|
||||
|
||||
def run(start_module, modules) do
|
||||
Display.clear_screen()
|
||||
|
||||
start_idx = Enum.find_index(@modules, &(&1 == start_module))
|
||||
|
||||
@modules
|
||||
|> Enum.drop(start_idx)
|
||||
modules
|
||||
|> Enum.drop_while( &(&1 != start_module))
|
||||
|> Enum.take_while( &(run_module(&1) == :passed))
|
||||
end
|
||||
def run(koan), do: Display.invalid_koan(koan, @modules)
|
||||
|
||||
def run_module(module) do
|
||||
Display.considering(module)
|
||||
@@ -64,7 +62,22 @@ defmodule Runner do
|
||||
|
||||
def exec(module, name, args, parent) do
|
||||
result = apply(module, name, args)
|
||||
send parent, result
|
||||
send parent, expand(result)
|
||||
Process.exit(self(), :kill)
|
||||
end
|
||||
|
||||
def expand(:ok), do: :ok
|
||||
def expand(error) do
|
||||
{file, line} = System.stacktrace
|
||||
|> Enum.drop_while(&in_ex_unit?/1)
|
||||
|> List.first
|
||||
|> extract_file_and_line
|
||||
|
||||
%{error: error, file: file, line: line}
|
||||
end
|
||||
|
||||
defp in_ex_unit?({ExUnit.Assertions, _, _, _}), do: true
|
||||
defp in_ex_unit?(_), do: false
|
||||
|
||||
defp extract_file_and_line({_, _, _, [file: file, line: line]}), do: {file, line}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user