Skip to content

Commit d86ca58

Browse files
committed
Format multiline AssertionError message with correct padding
1 parent b8528f6 commit d86ca58

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/ex_unit/lib/ex_unit/formatter.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ defmodule ExUnit.Formatter do
171171
end
172172

173173
defp format_banner(value, formatter) do
174+
value = String.replace(value, "\n", "\n" <> @counter_padding)
174175
formatter.(:error_info, value)
175176
end
176177

lib/ex_unit/test/ex_unit/formatter_test.exs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,15 @@ defmodule ExUnit.FormatterTest do
133133
6]
134134
"""
135135
end
136+
137+
test "formats assertions with message with multiple lines" do
138+
message = "Some meaningful error:\nuseful info\nanother useful info"
139+
failure = {:error, catch_assertion(assert(false, message)), []}
140+
assert format_test_case_failure(case(), failure, 1, :infinity, &formatter/2) =~ """
141+
1) Hello: failure on setup_all callback, tests invalidated
142+
Some meaningful error:
143+
useful info
144+
another useful info
145+
"""
146+
end
136147
end

0 commit comments

Comments
 (0)