Skip to content

Commit 284e75d

Browse files
author
José Valim
committed
Remove warnings from the test suite
1 parent c1d63e4 commit 284e75d

File tree

21 files changed

+106
-113
lines changed

21 files changed

+106
-113
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
* [Kernel] Ensure private functions are not exported
1818
* [Protocol] Do not expose protocol convention on `assert_impl!/2`
1919
* [Regex] Do not consider subpatterns on `Regex.split/3`
20-
* [Stream] Implement the Inspect protocol for Streams so we do not leak the Stream representation
20+
* [Stream] Implement the `Inspect` protocol for Streams so we do not leak the Stream representation
2121

2222
* Deprecations
23+
* [IEx] IEx color configuration expects a list of atoms instead of a string with colors separated by comma
2324
* [Inspect] `Inspect.Algebra.pretty/2` is deprecated in favor of `Inspect.Algebra.format/2` that instead returns iodata. This function was used only by documentation examples and it is unlikely to affect actual code
2425
* [IO] `IO.ANSI.escape/2` and `IO.ANSI.escape_fragment/2` is deprecated in favor of `IO.ANSI.format/2` and `IO.ANSI.format_fragment/2`
2526
* [Kernel] Leading `0` for octals is deprecated in favor of `0o`
2627
* [Kernel] `0X` for hexadecimals is deprecated in favor of `0x`
2728
* [Kernel] `0B` for binaries is deprecated in favor of `0b`
29+
* [Mix] Mix color configuration expects a list of atoms instead of a string with colors separated by comma
2830
* [String] `\NNN`, `\NN` and `\N` for octals are deprecated inside string, sigils and chars in favor of hexadecimal entries with `\x`
2931

3032
* Backwards incompatible changes

lib/elixir/lib/io/ansi.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ defmodule IO.ANSI do
2828

2929
import IO.ANSI.Sequence
3030

31+
@typep ansicode :: atom()
32+
@typep ansilist :: maybe_improper_list(char() | ansicode() | binary() | ansilist(), binary() | ansicode() | [])
33+
@type ansidata :: ansilist() | ansicode() | binary()
34+
3135
@doc """
3236
Checks whether the default I/O device is a terminal or a file.
3337
@@ -159,7 +163,7 @@ defmodule IO.ANSI do
159163
## Examples
160164
161165
iex> IO.ANSI.format(["Hello, ", :red, :bright, "world!"], true)
162-
[[[[[[], "Hello, "], "\e[31m"], "\e[1m"], "world!"] | "\e[0m"]
166+
[[[[[[], "Hello, "] | "\e[31m"] | "\e[1m"], "world!"] | "\e[0m"]
163167
164168
"""
165169
def format(chardata, emit \\ terminal?) when is_boolean(emit) do
@@ -180,7 +184,7 @@ defmodule IO.ANSI do
180184
## Examples
181185
182186
iex> IO.ANSI.format_fragment([:bright, 'Word'], true)
183-
[[[[[[], "\e[1m"], 87], 111], 114], 100]
187+
[[[[[[] | "\e[1m"], 87], 111], 114], 100]
184188
185189
"""
186190
def format_fragment(chardata, emit \\ terminal?) when is_boolean(emit) do

lib/elixir/lib/io/ansi/docs.ex

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ defmodule IO.ANSI.Docs do
2121
comma-separated ANSI values.
2222
"""
2323
def default_options do
24-
[enabled: true,
25-
doc_code: "cyan,bright",
26-
doc_inline_code: "cyan",
27-
doc_headings: "yellow,bright",
28-
doc_title: "reverse,yellow,bright",
29-
doc_bold: "bright",
30-
doc_underline: "underline",
24+
[doc_code: [:cyan, :bright],
25+
doc_inline_code: [:cyan],
26+
doc_headings: [:yellow, :bright],
27+
doc_title: [:reverse, :yellow, :bright],
28+
doc_bold: [:bright],
29+
doc_underline: [:underline],
3130
width: 80]
3231
end
3332

@@ -224,7 +223,7 @@ defmodule IO.ANSI.Docs do
224223
## Helpers
225224

226225
defp write(style, string, options) do
227-
IO.puts color(style, options) <> string <> IO.ANSI.reset
226+
IO.puts [color(style, options), string, IO.ANSI.reset]
228227
IO.puts IO.ANSI.reset
229228
end
230229

@@ -370,7 +369,11 @@ defmodule IO.ANSI.Docs do
370369

371370
defp color(style, colors) do
372371
color = colors[style]
373-
enabled = colors[:enabled]
374-
IO.ANSI.escape_fragment("%{#{color}}", enabled)
372+
if is_binary(color) do
373+
IO.puts :stderr, "warning: ANSI colors as strings is deprecated, " <>
374+
"they now must be a list of atoms, got #{inspect color} for #{inspect style}"
375+
color = String.split(color, ",") |> Enum.map(&String.to_atom/1)
376+
end
377+
IO.ANSI.format_fragment(color, true)
375378
end
376379
end

lib/elixir/test/elixir/gen_event_test.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ defmodule GenEventTest do
8888
end
8989

9090
test "bad calls" do
91-
:error_logger.tty(false)
91+
Logger.remove_backend(:console)
9292
{:ok, pid} = GenEvent.start_link()
9393
assert GenEvent.add_handler(pid, LoggerHandler, []) == :ok
9494
assert GenEvent.call(pid, UnknownHandler, :messages) ==
@@ -98,7 +98,8 @@ defmodule GenEventTest do
9898
assert GenEvent.which_handlers(pid) == []
9999
assert GenEvent.stop(pid) == :ok
100100
after
101-
:error_logger.tty(true)
101+
:gen_event.which_handlers(:error_logger)
102+
Logger.add_backend(:console)
102103
end
103104

104105
test "sync stream/2" do

lib/elixir/test/elixir/task/supervisor_test.exs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ defmodule Task.SupervisorTest do
99
end
1010

1111
setup do
12-
:error_logger.tty(false)
13-
on_exit fn -> :error_logger.tty(true) end
12+
Logger.remove_backend(:console)
13+
on_exit fn ->
14+
:gen_event.which_handlers(:error_logger)
15+
Logger.add_backend(:console)
16+
end
1417
:ok
1518
end
1619

lib/elixir/test/elixir/task_test.exs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ defmodule TaskTest do
44
use ExUnit.Case, async: true
55

66
setup do
7-
:error_logger.tty(false)
8-
on_exit fn -> :error_logger.tty(true) end
7+
Logger.remove_backend(:console)
8+
on_exit fn ->
9+
:gen_event.which_handlers(:error_logger)
10+
Logger.add_backend(:console)
11+
end
912
:ok
1013
end
1114

lib/ex_unit/lib/ex_unit/cli_formatter.ex

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,26 +167,26 @@ defmodule ExUnit.CLIFormatter do
167167
# Color styles
168168

169169
defp colorize(escape, string, %{color: color}) do
170-
IO.ANSI.escape_fragment("%{#{escape}}", color)
171-
<> string
172-
<> IO.ANSI.escape_fragment("%{reset}", color)
170+
[IO.ANSI.format_fragment(escape, color),
171+
string,
172+
IO.ANSI.format_fragment(:reset, color)] |> IO.iodata_to_binary
173173
end
174174

175175
defp success(msg, config) do
176-
colorize("green", msg, config)
176+
colorize([:green], msg, config)
177177
end
178178

179179
defp invalid(msg, config) do
180-
colorize("yellow", msg, config)
180+
colorize([:yellow], msg, config)
181181
end
182182

183183
defp failure(msg, config) do
184-
colorize("red", msg, config)
184+
colorize([:red], msg, config)
185185
end
186186

187-
defp formatter(:error_info, msg, config), do: colorize("red", msg, config)
188-
defp formatter(:extra_info, msg, config), do: colorize("cyan", msg, config)
189-
defp formatter(:location_info, msg, config), do: colorize("bright,black", msg, config)
187+
defp formatter(:error_info, msg, config), do: colorize([:red], msg, config)
188+
defp formatter(:extra_info, msg, config), do: colorize([:cyan], msg, config)
189+
defp formatter(:location_info, msg, config), do: colorize([:bright, :black], msg, config)
190190
defp formatter(_, msg, _config), do: msg
191191

192192
defp get_terminal_width do

lib/iex/lib/iex.ex

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,14 @@ defmodule IEx do
333333

334334
if colors[:enabled] do
335335
ansi = Keyword.get(colors, color, default_color(color))
336-
IO.ANSI.escape_fragment("%{#{ansi}}", true) <> string <>
337-
IO.ANSI.escape_fragment("%{reset}", true)
336+
337+
if is_binary(ansi) do
338+
IO.puts :stderr, "warning: ANSI colors as strings is deprecated, " <>
339+
"they now must be a list of atoms, got #{inspect ansi} for #{inspect color}"
340+
ansi = String.split(ansi, ",") |> Enum.map(&String.to_atom/1)
341+
end
342+
343+
IO.iodata_to_binary(IO.ANSI.format_fragment(ansi, true)) <> string <> IO.ANSI.reset
338344
else
339345
string
340346
end
@@ -507,22 +513,22 @@ defmodule IEx do
507513
end
508514

509515
# Used by default on evaluation cycle
510-
defp default_color(:eval_interrupt), do: "yellow"
511-
defp default_color(:eval_result), do: "yellow"
512-
defp default_color(:eval_error), do: "red"
513-
defp default_color(:eval_info), do: "normal"
514-
defp default_color(:stack_app), do: "red,bright"
515-
defp default_color(:stack_info), do: "red"
516+
defp default_color(:eval_interrupt), do: [:yellow]
517+
defp default_color(:eval_result), do: [:yellow]
518+
defp default_color(:eval_error), do: [:red]
519+
defp default_color(:eval_info), do: [:normal]
520+
defp default_color(:stack_app), do: [:red, :bright]
521+
defp default_color(:stack_info), do: [:red]
516522

517523
# Used by ls
518-
defp default_color(:ls_directory), do: "blue"
519-
defp default_color(:ls_device), do: "green"
524+
defp default_color(:ls_directory), do: [:blue]
525+
defp default_color(:ls_device), do: [:green]
520526

521527
# Used by ansi docs
522-
defp default_color(:doc_bold), do: "bright"
523-
defp default_color(:doc_code), do: "cyan,bright"
524-
defp default_color(:doc_headings), do: "yellow,bright"
525-
defp default_color(:doc_inline_code), do: "cyan"
526-
defp default_color(:doc_underline), do: "underline"
527-
defp default_color(:doc_title), do: "reverse,yellow,bright"
528+
defp default_color(:doc_bold), do: [:bright]
529+
defp default_color(:doc_code), do: [:cyan, :bright]
530+
defp default_color(:doc_headings), do: [:yellow, :bright]
531+
defp default_color(:doc_inline_code), do: [:cyan]
532+
defp default_color(:doc_underline), do: [:underline]
533+
defp default_color(:doc_title), do: [:reverse, :yellow, :bright]
528534
end

lib/iex/test/iex/interaction_test.exs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,10 @@ defmodule IEx.InteractionTest do
9494

9595
unless match?({:win32,_}, :os.type) do
9696
test "color" do
97-
opts = [colors: [enabled: true, eval_result: "red"]]
97+
opts = [colors: [enabled: true, eval_result: [:red]]]
9898
assert capture_iex("1 + 2", opts) == "\e[31m3\e[0m"
99-
100-
# Sanity checks
101-
assert capture_iex("IO.ANSI.escape(\"%{blue}hello\", true)", opts)
102-
== "\e[31m\"\\e[34mhello\\e[0m\"\e[0m"
103-
assert capture_iex("IO.puts IO.ANSI.escape(\"%{blue}hello\", true)", opts)
104-
== "\e[34mhello\e[0m\n\e[31m:ok\e[0m"
105-
assert capture_iex("IO.puts IO.ANSI.escape(\"%{blue}hello\", true)", [colors: [enabled: false]])
106-
== "\e[34mhello\e[0m\n:ok"
99+
assert capture_iex("IO.ANSI.blue", opts)
100+
== "\e[31m\"\\e[34m\"\e[0m"
107101
end
108102
end
109103

lib/logger/lib/logger/watcher.ex

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ defmodule Logger.Watcher do
2525
Removes the given handler.
2626
"""
2727
def unwatch(mod, handler) do
28-
case Supervisor.terminate_child(@name, {mod, handler}) do
29-
:ok -> Supervisor.delete_child(@name, {mod, handler})
30-
res -> res
31-
end
28+
GenEvent.remove_handler(mod, handler, :ok)
3229
end
3330

3431
@doc """
@@ -63,7 +60,7 @@ defmodule Logger.Watcher do
6360
## Callbacks
6461

6562
def init({mod, handler, args}) do
66-
case :gen_event.add_sup_handler(mod, handler, args) do
63+
case GenEvent.add_handler(mod, handler, args, link: true) do
6764
:ok -> {:ok, {mod, handler}}
6865
{:error, :ignore} -> :ignore
6966
{:error, reason} -> {:stop, reason}

0 commit comments

Comments
 (0)