From 8e8efd8defa25d864ec034c3fe45a098b9ad733b Mon Sep 17 00:00:00 2001 From: Shashwat Ganesh Date: Thu, 4 Jun 2020 22:52:32 +0530 Subject: [PATCH 1/3] Move from System.stacktrace to __STACKTRACE__ --- lib/execute.ex | 6 +++--- lib/koans.ex | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/execute.ex b/lib/execute.ex index 4ddebae..485e0c5 100644 --- a/lib/execute.ex +++ b/lib/execute.ex @@ -38,14 +38,14 @@ defmodule Execute do defp expand(:ok, _), do: :ok - defp expand(error, module) do + defp expand({:error, stacktrace, exception}, module) do {file, line} = - System.stacktrace() + stacktrace |> Enum.drop_while(&(!in_koan?(&1, module))) |> List.first() |> extract_file_and_line - %{error: error, file: file, line: line} + %{error: exception, file: file, line: line} end defp in_koan?({module, _, _, _}, koan), do: module == koan diff --git a/lib/koans.ex b/lib/koans.ex index 31fb9de..5ab03b3 100644 --- a/lib/koans.ex +++ b/lib/koans.ex @@ -22,7 +22,7 @@ defmodule Koans do unquote(compiled_body) :ok rescue - e -> e + e -> {:error, __STACKTRACE__, e} end end end @@ -39,7 +39,7 @@ defmodule Koans do unquote(single_var) :ok rescue - e -> e + e -> {:error, __STACKTRACE__, e} end end end @@ -57,7 +57,7 @@ defmodule Koans do unquote(multi_var) :ok rescue - e -> e + e -> {:error, __STACKTRACE__, e} end end end From 0681f5df22a9fb0101dc2dc17b26fd9ee2d1bf8d Mon Sep 17 00:00:00 2001 From: Shashwat Ganesh Date: Thu, 4 Jun 2020 22:54:18 +0530 Subject: [PATCH 2/3] Tests should provide valid error parameters --- test/display/failure_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/display/failure_test.exs b/test/display/failure_test.exs index bea195e..addce2c 100644 --- a/test/display/failure_test.exs +++ b/test/display/failure_test.exs @@ -39,7 +39,7 @@ defmodule FailureTests do test "only offending lines are displayed for errors" do [koan] = SingleArity.all_koans() - error = apply(SingleArity, koan, []) |> error() + error = apply(SingleArity, koan, []) |> Tuple.to_list |> List.last |> error assert Failure.format_failure(error) == """ Assertion failed in some_file.ex:42\nmatch?(:foo, ___) From f999d6c573136ded1ddc45854c3dfa430b0d22bd Mon Sep 17 00:00:00 2001 From: Shashwat Ganesh Date: Thu, 4 Jun 2020 22:55:14 +0530 Subject: [PATCH 3/3] Update the comprehensions test to match the actual koan --- test/koans/comprehensions_koans_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/koans/comprehensions_koans_test.exs b/test/koans/comprehensions_koans_test.exs index bcf7498..22f056f 100644 --- a/test/koans/comprehensions_koans_test.exs +++ b/test/koans/comprehensions_koans_test.exs @@ -9,7 +9,7 @@ defmodule ComprehensionsTests do ["Hello World", "Apple Pie"], ["little dogs", "little cats", "big dogs", "big cats"], [4, 5, 6], - ["Apple Pie", "Pecan Pie", "Pumpkin Pie"], + %{"Pecan" => "Pecan Pie", "Pumpkin" => "Pumpkin Pie"} ] test_all(Comprehensions, answers)