Skip to content

Change usage of System.stacktrace into __STACKTRACE__ and make tests pass #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/execute.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/koans.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Koans do
unquote(compiled_body)
:ok
rescue
e -> e
e -> {:error, __STACKTRACE__, e}
end
end
end
Expand All @@ -39,7 +39,7 @@ defmodule Koans do
unquote(single_var)
:ok
rescue
e -> e
e -> {:error, __STACKTRACE__, e}
end
end
end
Expand All @@ -57,7 +57,7 @@ defmodule Koans do
unquote(multi_var)
:ok
rescue
e -> e
e -> {:error, __STACKTRACE__, e}
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/display/failure_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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, ___)
Expand Down
2 changes: 1 addition & 1 deletion test/koans/comprehensions_koans_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down