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(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

View File

@@ -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

View File

@@ -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, ___)

View File

@@ -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)