File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -628,6 +628,7 @@ defmodule ExUnit.Assertions do
628
628
629
629
cond do
630
630
name == exception ->
631
+ check_error_message ( name , error )
631
632
error
632
633
name == ExUnit.AssertionError ->
633
634
reraise ( error , stacktrace )
@@ -639,6 +640,15 @@ defmodule ExUnit.Assertions do
639
640
end
640
641
end
641
642
643
+ defp check_error_message ( module , error ) do
644
+ module . message ( error )
645
+ catch
646
+ kind , reason ->
647
+ stacktrace = System . stacktrace ( )
648
+
649
+ flunk "Got exception #{ inspect module } but it failed to produce a message with:\n \n " <> Exception . format ( kind , reason , stacktrace )
650
+ end
651
+
642
652
@ doc """
643
653
Asserts that `value1` and `value2` differ by no more than `delta`.
644
654
Original file line number Diff line number Diff line change @@ -6,7 +6,15 @@ defmodule ExUnit.AssertionsTest.Value do
6
6
def truthy , do: true
7
7
end
8
8
9
- alias ExUnit.AssertionsTest.Value
9
+ defmodule ExUnit.AssertionsTest.BrokenError do
10
+ defexception [ :message ]
11
+
12
+ def message ( _ ) do
13
+ raise "error"
14
+ end
15
+ end
16
+
17
+ alias ExUnit.AssertionsTest . { BrokenError , Value }
10
18
11
19
defmodule ExUnit.AssertionsTest do
12
20
use ExUnit.Case , async: true
@@ -548,6 +556,16 @@ defmodule ExUnit.AssertionsTest do
548
556
"\n \" bar\" " = error . message
549
557
end
550
558
559
+ test "assert raise with an exception with bad message/1 implementation" do
560
+ assert_raise BrokenError , fn ->
561
+ raise BrokenError
562
+ end
563
+ rescue
564
+ error in [ ExUnit.AssertionError ] ->
565
+ "Got exception ExUnit.AssertionsTest.BrokenError but it failed to produce a message with:" <>
566
+ "\n \n ** (RuntimeError) error\n " <> _ = error . message
567
+ end
568
+
551
569
test "assert greater than operator" do
552
570
true = assert 2 > 1
553
571
end
You can’t perform that action at this time.
0 commit comments