Skip to content

Commit 8c14d3a

Browse files
committed
Add newline after inspection, closes #14819
1 parent 9e10ea8 commit 8c14d3a

File tree

6 files changed

+32
-32
lines changed

6 files changed

+32
-32
lines changed

lib/elixir/lib/exception.ex

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,12 @@ defmodule Exception do
188188
term
189189
|> inspect(pretty: true)
190190
|> String.split("\n")
191-
|> Enum.map(fn
191+
|> Enum.map_intersperse("\n", fn
192192
"" -> ""
193193
line -> " " <> line
194194
end)
195-
|> Enum.join("\n")
196195

197-
message <> "\n\n" <> inspected
196+
IO.iodata_to_binary([message, "\n\n", inspected, "\n"])
198197
end
199198

200199
@doc """
@@ -1912,7 +1911,7 @@ defmodule UndefinedFunctionError do
19121911
end
19131912

19141913
defp format_fa({_dist, fun, arity}) do
1915-
[" * ", Macro.inspect_atom(:remote_call, fun), ?/, Integer.to_string(arity), ?\n]
1914+
[" * ", Macro.inspect_atom(:remote_call, fun), ?/, Integer.to_string(arity), ?\n]
19161915
end
19171916

19181917
defp exports_for(module) do
@@ -2244,7 +2243,7 @@ defmodule KeyError do
22442243

22452244
case suggestions do
22462245
[] -> []
2247-
suggestions -> ["\n\nDid you mean:\n\n" | format_suggestions(suggestions)]
2246+
suggestions -> ["\nDid you mean:\n\n" | format_suggestions(suggestions)]
22482247
end
22492248
end
22502249

@@ -2253,7 +2252,7 @@ defmodule KeyError do
22532252
|> Enum.sort(&(elem(&1, 0) >= elem(&2, 0)))
22542253
|> Enum.take(@max_suggestions)
22552254
|> Enum.sort(&(elem(&1, 1) <= elem(&2, 1)))
2256-
|> Enum.map(fn {_, key} -> [" * ", inspect(key), ?\n] end)
2255+
|> Enum.map(fn {_, key} -> [" * ", inspect(key), ?\n] end)
22572256
end
22582257
end
22592258

lib/elixir/test/elixir/exception_test.exs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -608,17 +608,17 @@ defmodule ExceptionTest do
608608
assert blame_message(Enum, & &1.map(:ok)) == """
609609
function Enum.map/1 is undefined or private. Did you mean:
610610
611-
* map/2
611+
* map/2
612612
"""
613613

614614
assert blame_message(Enum, & &1.man(:ok)) == """
615615
function Enum.man/1 is undefined or private. Did you mean:
616616
617-
* map/2
618-
* max/1
619-
* max/2
620-
* max/3
621-
* min/1
617+
* map/2
618+
* max/1
619+
* max/2
620+
* max/3
621+
* min/1
622622
"""
623623

624624
message = blame_message(:erlang, & &1.gt_cookie())
@@ -731,22 +731,23 @@ defmodule ExceptionTest do
731731
test "annotates key error with suggestions if keys are atoms" do
732732
message = blame_message(%{first: nil, second: nil}, fn map -> map.firts end)
733733

734-
assert message == """
735-
key :firts not found in:
734+
assert message ==
735+
"""
736+
key :firts not found in:
736737
737-
%{first: nil, second: nil}
738+
%{first: nil, second: nil}
738739
739-
Did you mean:
740+
Did you mean:
740741
741742
* :first
742-
"""
743+
"""
743744

744745
message = blame_message(%{"first" => nil, "second" => nil}, fn map -> map.firts end)
745746

746747
assert message == """
747748
key :firts not found in:
748749
749-
%{"first" => nil, "second" => nil}\
750+
%{"first" => nil, "second" => nil}
750751
"""
751752

752753
message =
@@ -756,7 +757,7 @@ defmodule ExceptionTest do
756757
"""
757758
key "firts" not found in:
758759
759-
%{"first" => nil, "second" => nil}\
760+
%{"first" => nil, "second" => nil}
760761
"""
761762

762763
message =
@@ -786,9 +787,9 @@ defmodule ExceptionTest do
786787
787788
Did you mean:
788789
789-
* :created_at
790-
* :finished_at
791-
* :started_at
790+
* :created_at
791+
* :finished_at
792+
* :started_at
792793
"""
793794
end
794795

lib/elixir/test/elixir/kernel/raise_test.exs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ defmodule Kernel.RaiseTest do
459459
no match of right hand side value:
460460
461461
[1000000, 1000001, 1000002, 1000003, 1000004, 1000005, 1000006, 1000007,
462-
1000008, 1000009]\
462+
1000008, 1000009]
463463
"""
464464
end
465465

@@ -480,7 +480,7 @@ defmodule Kernel.RaiseTest do
480480
x in [KeyError] -> Exception.message(x)
481481
end
482482

483-
assert result == "key :foo not found in:\n\n %{}"
483+
assert result == "key :foo not found in:\n\n %{}\n"
484484
end
485485

486486
test "bad map error" do
@@ -491,7 +491,7 @@ defmodule Kernel.RaiseTest do
491491
x in [BadMapError] -> Exception.message(x)
492492
end
493493

494-
assert result == "expected a map, got:\n\n 0"
494+
assert result == "expected a map, got:\n\n 0\n"
495495
end
496496

497497
test "bad boolean error" do
@@ -502,7 +502,7 @@ defmodule Kernel.RaiseTest do
502502
x in [BadBooleanError] -> Exception.message(x)
503503
end
504504

505-
assert result == "expected a boolean on left-side of \"and\", got:\n\n 1"
505+
assert result == "expected a boolean on left-side of \"and\", got:\n\n 1\n"
506506
end
507507

508508
test "case clause error" do
@@ -517,7 +517,7 @@ defmodule Kernel.RaiseTest do
517517
x in [CaseClauseError] -> Exception.message(x)
518518
end
519519

520-
assert result == "no case clause matching:\n\n 0"
520+
assert result == "no case clause matching:\n\n 0\n"
521521
end
522522

523523
test "cond clause error" do
@@ -549,7 +549,7 @@ defmodule Kernel.RaiseTest do
549549
x in [TryClauseError] -> Exception.message(x)
550550
end
551551

552-
assert result == "no try clause matching:\n\n :example"
552+
assert result == "no try clause matching:\n\n :example\n"
553553
end
554554

555555
test "undefined function error as Erlang error" do

lib/elixir/test/elixir/kernel/with_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ defmodule Kernel.WithTest do
153153
end
154154

155155
test "else conditions with match error" do
156-
assert_raise WithClauseError, "no with clause matching:\n\n :error", fn ->
156+
assert_raise WithClauseError, "no with clause matching:\n\n :error\n", fn ->
157157
with({:ok, res} <- error(), do: res, else: ({:error, error} -> error))
158158
end
159159
end

lib/elixir/test/elixir/keyword_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ defmodule KeywordTest do
7070
assert Keyword.replace!([a: 1, b: 2, a: 3, b: 4], :a, 1) == [a: 1, b: 2, b: 4]
7171
assert Keyword.replace!([a: 1, b: 2, c: 3, b: 4], :b, :new) == [a: 1, b: :new, c: 3]
7272

73-
assert_raise KeyError, "key :b not found in:\n\n []", fn ->
73+
assert_raise KeyError, "key :b not found in:\n\n []\n", fn ->
7474
Keyword.replace!([], :b, :new)
7575
end
7676

77-
assert_raise KeyError, "key :c not found in:\n\n [a: 1, b: 2, a: 3]", fn ->
77+
assert_raise KeyError, "key :c not found in:\n\n [a: 1, b: 2, a: 3]\n", fn ->
7878
Keyword.replace!([a: 1, b: 2, a: 3], :c, :new)
7979
end
8080
end

lib/elixir/test/elixir/map_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ defmodule MapTest do
229229
Map.replace!(map, :x, 10)
230230
end
231231

232-
assert_raise KeyError, "key :x not found in:\n\n %{}", fn ->
232+
assert_raise KeyError, "key :x not found in:\n\n %{}\n", fn ->
233233
Map.replace!(%{}, :x, 10)
234234
end
235235
end

0 commit comments

Comments
 (0)