Skip to content

Commit 2f8ecec

Browse files
favetelinguisJosé Valim
authored andcommitted
Clarify how to assert on exits from linked processes (#7904)
Signed-off-by: José Valim <[email protected]>
1 parent 4354938 commit 2f8ecec

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/ex_unit/lib/ex_unit/assertions.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ defmodule ExUnit.Assertions do
745745

746746
@doc """
747747
Asserts `expression` will throw a value.
748+
748749
Returns the thrown value or fails otherwise.
749750
750751
## Examples
@@ -758,11 +759,19 @@ defmodule ExUnit.Assertions do
758759

759760
@doc """
760761
Asserts `expression` will exit.
761-
Returns the exit status/message or fails otherwise.
762+
763+
Returns the exit status/message of the current process or fails otherwise.
762764
763765
## Examples
764766
765767
assert catch_exit(exit 1) == 1
768+
769+
To assert exits from linked processes started from the test, trap exits
770+
with `Process.flag/2` and assert the exit message with `assert_received/2`.
771+
772+
Process.flag(:trap_exit, true)
773+
pid = spawn_link(fn -> Process.exit(self(), :normal) end)
774+
assert_receive {:EXIT, ^pid, :normal}
766775
767776
"""
768777
defmacro catch_exit(expression) do
@@ -771,6 +780,7 @@ defmodule ExUnit.Assertions do
771780

772781
@doc """
773782
Asserts `expression` will cause an error.
783+
774784
Returns the error or fails otherwise.
775785
776786
## Examples

0 commit comments

Comments
 (0)