Merge pull request #251 from kknives/master

Change usage of System.stacktrace into __STACKTRACE__ and make tests pass
This commit is contained in:
Jay Hayes
2020-06-10 06:40:42 -05:00
committed by GitHub
4 changed files with 8 additions and 8 deletions

View File

@@ -38,14 +38,14 @@ defmodule Execute do
defp expand(:ok, _), do: :ok defp expand(:ok, _), do: :ok
defp expand(error, module) do defp expand({:error, stacktrace, exception}, module) do
{file, line} = {file, line} =
System.stacktrace() stacktrace
|> Enum.drop_while(&(!in_koan?(&1, module))) |> Enum.drop_while(&(!in_koan?(&1, module)))
|> List.first() |> List.first()
|> extract_file_and_line |> extract_file_and_line
%{error: error, file: file, line: line} %{error: exception, file: file, line: line}
end end
defp in_koan?({module, _, _, _}, koan), do: module == koan defp in_koan?({module, _, _, _}, koan), do: module == koan

View File

@@ -22,7 +22,7 @@ defmodule Koans do
unquote(compiled_body) unquote(compiled_body)
:ok :ok
rescue rescue
e -> e e -> {:error, __STACKTRACE__, e}
end end
end end
end end
@@ -39,7 +39,7 @@ defmodule Koans do
unquote(single_var) unquote(single_var)
:ok :ok
rescue rescue
e -> e e -> {:error, __STACKTRACE__, e}
end end
end end
end end
@@ -57,7 +57,7 @@ defmodule Koans do
unquote(multi_var) unquote(multi_var)
:ok :ok
rescue rescue
e -> e e -> {:error, __STACKTRACE__, e}
end end
end end
end end

View File

@@ -39,7 +39,7 @@ defmodule FailureTests do
test "only offending lines are displayed for errors" do test "only offending lines are displayed for errors" do
[koan] = SingleArity.all_koans() [koan] = SingleArity.all_koans()
error = apply(SingleArity, koan, []) |> error() error = apply(SingleArity, koan, []) |> Tuple.to_list |> List.last |> error
assert Failure.format_failure(error) == """ assert Failure.format_failure(error) == """
Assertion failed in some_file.ex:42\nmatch?(:foo, ___) Assertion failed in some_file.ex:42\nmatch?(:foo, ___)

View File

@@ -9,7 +9,7 @@ defmodule ComprehensionsTests do
["Hello World", "Apple Pie"], ["Hello World", "Apple Pie"],
["little dogs", "little cats", "big dogs", "big cats"], ["little dogs", "little cats", "big dogs", "big cats"],
[4, 5, 6], [4, 5, 6],
["Apple Pie", "Pecan Pie", "Pumpkin Pie"], %{"Pecan" => "Pecan Pie", "Pumpkin" => "Pumpkin Pie"}
] ]
test_all(Comprehensions, answers) test_all(Comprehensions, answers)