From 84ef28038f052dd1b45746c7e4d26dcdb2d0285a Mon Sep 17 00:00:00 2001 From: Felipe Sere Date: Fri, 8 Apr 2016 22:40:34 +0100 Subject: [PATCH] Enable running each koan in an isolated process --- lib/runner.ex | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/runner.ex b/lib/runner.ex index 2c84c1b..c06968d 100644 --- a/lib/runner.ex +++ b/lib/runner.ex @@ -25,11 +25,12 @@ defmodule Runner do def run(start_module) when start_module in @modules do Display.clear_screen() + start_idx = Enum.find_index(@modules, &(&1 == start_module)) - Enum.drop(@modules, start_idx) - |> Enum.take_while(fn(mod) -> - run_module(mod) == :passed - end) + + @modules + |> Enum.drop(start_idx) + |> Enum.take_while( &(run_module(&1) == :passed)) end def run(koan), do: Display.invalid_koan(koan, @modules) @@ -53,9 +54,17 @@ defmodule Runner do end def run_koan(module, name, args \\ []) do - case apply(module, name, args) do + parent = self() + spawn fn -> exec(module, name, args, parent) end + receive do :ok -> :passed error -> {:failed, error, module, name} end end + + def exec(module, name, args, parent) do + result = apply(module, name, args) + send parent, result + Process.exit(self(), :kill) + end end