Skip to content

Commit

Permalink
Merge pull request #30 from dmt/master
Browse files Browse the repository at this point in the history
Add test case for subprocesses crashing
  • Loading branch information
victorolinasc committed Dec 28, 2017
2 parents 393a9de + bbcfbb4 commit 268e3ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ defmodule JUnitFormatter do
%{message: message} -> message
other -> inspect(other)
end
[{:failure, [message: Atom.to_string(kind) <> ": " <> message], [String.to_charlist(formatted_stack)]}]
exception_kind =
case kind do
error when is_atom(error) -> Atom.to_string(error)
other -> inspect(other)
end
[{:failure, [message: exception_kind <> ": " <> message], [String.to_charlist(formatted_stack)]}]
end
defp generate_test_body(%ExUnit.Test{state: {:invalid, module}}) do
[{:error, [message: "Invalid module #{inspect module}"], []}]
Expand Down
16 changes: 16 additions & 0 deletions test/formatter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ defmodule FormatterTest do
assert output =~ "<testcase classname=\"Elixir.FormatterTest.RaiseWithNoReason\" name=\"test it raises without reason\" ><failure message=\"throw: nil\"> test/formatter_test.exs FormatterTest.RaiseWithNoReason.\"test it raises without reason\"/1\n</failure></testcase>"
end

@tag :capture_log
test "it can handle crashed process" do
defmodule RaiseCrash do
use ExUnit.Case

test "it crashes" do
spawn_link(fn -> raise ArgumentError end)
receive do end
end
end

output = run_and_capture_output() |> strip_time_and_line_number

assert output =~ ~r/<testcase classname=\"Elixir.FormatterTest.RaiseCrash\" name=\"test it crashes\" ><failure message=\"{:EXIT, #PID&lt;0.\d+.0>}: {%ArgumentError{message: &quot;argument error&quot;}, .*?\">\n<\/failure><\/testcase>/
end

test "it can handle empty message" do
defmodule NilMessageError do
defexception [message: nil, customMessage: "A custom error occured !"]
Expand Down

0 comments on commit 268e3ae

Please sign in to comment.