Move error line detection into runner itself due to processes.
This commit is contained in:
@@ -42,36 +42,20 @@ defmodule Display do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp format_failure(%ExUnit.AssertionError{expr: expr}) do
|
defp format_failure(%{error: %ExUnit.AssertionError{expr: expr}, file: file, line: line}) do
|
||||||
"""
|
"""
|
||||||
#{format_cyan("Assertion failed in #{last_failure_location}")}
|
#{format_cyan("Assertion failed in #{file}:#{line}")}
|
||||||
#{format_red(Macro.to_string(expr))}
|
#{format_red(Macro.to_string(expr))}
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
defp format_failure(error) do
|
defp format_failure(%{error: error, file: file, line: line}) do
|
||||||
"""
|
"""
|
||||||
#{format_cyan("Error in #{last_failure_location}")}
|
#{format_cyan("Error in #{file}:#{line}")}
|
||||||
#{format_error(error)}
|
#{format_error(error)}
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
defp last_failure_location do
|
|
||||||
{file, line} = System.stacktrace
|
|
||||||
|> Enum.drop_while(&in_ex_unit?/1)
|
|
||||||
|> List.first
|
|
||||||
|> extract_file_and_line
|
|
||||||
|
|
||||||
"#{file}:#{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
|
|
||||||
|
|
||||||
defp format_error(error) do
|
defp format_error(error) do
|
||||||
trace = System.stacktrace |> Enum.take(2)
|
trace = System.stacktrace |> Enum.take(2)
|
||||||
format_red(Exception.format(:error, error, trace))
|
format_red(Exception.format(:error, error, trace))
|
||||||
|
|||||||
@@ -14,25 +14,23 @@ defmodule Runner do
|
|||||||
Tasks,
|
Tasks,
|
||||||
]
|
]
|
||||||
|
|
||||||
def koan?(module) do
|
def koan?(koan), do: Enum.member?(@modules, koan)
|
||||||
Enum.member?(@modules, module)
|
|
||||||
end
|
|
||||||
|
|
||||||
def run do
|
def run do
|
||||||
Options.initial_koan
|
Options.initial_koan
|
||||||
|>run
|
|>run
|
||||||
end
|
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()
|
Display.clear_screen()
|
||||||
|
|
||||||
start_idx = Enum.find_index(@modules, &(&1 == start_module))
|
modules
|
||||||
|
|> Enum.drop_while( &(&1 != start_module))
|
||||||
@modules
|
|
||||||
|> Enum.drop(start_idx)
|
|
||||||
|> Enum.take_while( &(run_module(&1) == :passed))
|
|> Enum.take_while( &(run_module(&1) == :passed))
|
||||||
end
|
end
|
||||||
def run(koan), do: Display.invalid_koan(koan, @modules)
|
|
||||||
|
|
||||||
def run_module(module) do
|
def run_module(module) do
|
||||||
Display.considering(module)
|
Display.considering(module)
|
||||||
@@ -64,7 +62,22 @@ defmodule Runner do
|
|||||||
|
|
||||||
def exec(module, name, args, parent) do
|
def exec(module, name, args, parent) do
|
||||||
result = apply(module, name, args)
|
result = apply(module, name, args)
|
||||||
send parent, result
|
send parent, expand(result)
|
||||||
Process.exit(self(), :kill)
|
Process.exit(self(), :kill)
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user