Skip to content

Commit 0dadb08

Browse files
committed
Allow capturing deprecated log level, closes #12605
1 parent 832c8da commit 0dadb08

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/ex_unit/lib/ex_unit/capture_log.ex

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,14 @@ defmodule ExUnit.CaptureLog do
9696
@doc since: "1.13.0"
9797
@spec with_log(keyword, (-> result)) :: {result, String.t()} when result: any
9898
def with_log(opts \\ [], fun) when is_list(opts) do
99-
opts = Keyword.put_new(opts, :level, nil)
99+
opts =
100+
if opts[:level] == :warn do
101+
IO.warn("level: :warn is deprecated, please use :warning instead")
102+
Keyword.put(opts, :level, :warning)
103+
else
104+
opts
105+
end
106+
100107
{:ok, string_io} = StringIO.open("")
101108

102109
try do

lib/ex_unit/test/ex_unit/capture_log_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ defmodule ExUnit.CaptureLogTest do
7878
end
7979
end
8080

81+
test "deprecated log level" do
82+
ExUnit.CaptureIO.capture_io(:stderr, fn ->
83+
output =
84+
capture_log([level: :warn], fn ->
85+
Logger.log(:warn, "ABC")
86+
Logger.log(:warning, "DEF")
87+
end)
88+
89+
assert output =~ "ABC"
90+
assert output =~ "DEF"
91+
end)
92+
end
93+
8194
describe "with_log/2" do
8295
test "returns the result and the log" do
8396
{result, log} =

0 commit comments

Comments
 (0)