Skip to content
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
1 change: 1 addition & 0 deletions lib/ex_unit/lib/ex_unit/capture_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ defmodule ExUnit.CaptureServer do
Process.register(pid, name)
rescue
ArgumentError ->
close_string_io(pid)
{:reply, {:error, :no_device}, config}
else
_ ->
Expand Down
11 changes: 11 additions & 0 deletions lib/ex_unit/test/ex_unit/capture_io_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,17 @@ defmodule ExUnit.CaptureIOTest do
end
end

test "does not leak StringIO when named device does not exist" do
capture_server = Process.whereis(ExUnit.CaptureServer)
{:monitored_by, monitored_by} = Process.info(capture_server, :monitored_by)

assert_raise RuntimeError, "could not find IO device registered at :unknown_device", fn ->
capture_io(:unknown_device, fn -> :ok end)
end

assert Process.info(capture_server, :monitored_by) == {:monitored_by, monitored_by}
end

test "no leakage on failures" do
parent = self()

Expand Down
Loading