Skip to content

Commit de26484

Browse files
author
José Valim
committed
Normalize IEx and ExUnit configurations
1 parent cbef7e9 commit de26484

25 files changed

+376
-280
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@
3333
* [Process] `Process.spawn/1`, `Process.spawn/3`, `Process.spawn_link/1`, `Process.spawn_link/3`, `Process.spawn_monitor/1`, `Process.spawn_monitor/3`, `Process.send/2` and `Process.self/0` are deprecated in favor of the ones in `Kernel`
3434

3535
* Deprecations
36+
* [IEx] IEx.Options is deprecated in favor of `IEx.configure/1` and `IEx.configuration/0`
3637
* [Kernel] `lc` and `bc` comprehensions are deprecated in favor of `for`
3738
* [Macro] `Macro.safe_terms/1` is deprecated
3839
* [Process] `Process.delete/0` is deprecated
3940
* [Regex] Deprecate `:global` option in `Regex.split/3` in favor of `parts: :infinity`
4041
* [String] Deprecate `:global` option in `String.split/3` in favor of `parts: :infinity`
4142

4243
* Backwards incompatible changes
44+
* [IEx] IEx no longer loads an `.iex.exs` file at the current path. Instead, IEx should be configured via the new Mix config
4345
* [ExUnit] `ExUnit.Test` and `ExUnit.TestCase` has been converted to structs
4446
* [ExUnit] The test and callback context has been converted to maps
4547
* [Kernel] `File.Stat`, `HashDict`, `HashSet`, `Inspect.Opts`, `Macro.Env`, `Range`, `Regex` and `Version.Requirement` have been converted to structs. This means `is_record/2` checks will no longer work, instead, you can pattern match on them using `%Range{}` and similar

bin/iex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if [ $# -gt 0 ] && ([ "$1" = "--help" ] || [ "$1" = "-h" ]); then
1818
--detached Starts the Erlang VM detached from console
1919
--gen-debug Turns on default debugging for all GenServers
2020
--remsh \"name\" Connects to a node using a remote shell
21-
--dot-iex \"path\" Overrides default .iex.exs file and uses path instead;
21+
--dot-iex \"path\" Overrides default ~/.iex.exs file and uses path instead;
2222
path can be empty, then no file will be loaded
2323
2424
** Options marked with (*) can be given more than once

lib/elixir/lib/application.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ defmodule Application do
111111
@type value :: term
112112
@type start_type :: :permanent | :transient | :temporary
113113

114+
@doc """
115+
Returns all key-value pairs for `app`.
116+
"""
117+
@spec get_all_env(app) :: [{key,value}]
118+
def get_all_env(app) do
119+
:application.get_all_env(app)
120+
end
121+
114122
@doc """
115123
Returns the value for `key` in `app`'s environment.
116124

lib/elixir/lib/io/ansi.ex

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ defmodule IO.ANSI.Sequence do
77
"\e[#{unquote(code)}#{unquote(terminator)}"
88
end
99

10-
defp escape_sequence(<< unquote(atom_to_binary(name)), rest :: binary >>) do
11-
{"\e[#{unquote(code)}#{unquote(terminator)}", rest}
10+
defp escape_sequence(unquote(atom_to_list(name))) do
11+
unquote(name)()
1212
end
1313
end
1414
end
@@ -130,15 +130,8 @@ defmodule IO.ANSI do
130130
@doc "Clear screen"
131131
defsequence :clear, "2", "J"
132132

133-
134-
# Catch spaces between codes
135-
defp escape_sequence(<< ?\s, rest :: binary >>) do
136-
escape_sequence(rest)
137-
end
138-
139133
defp escape_sequence(other) do
140-
[spec|_] = String.split(other, ~r/(,|\})/)
141-
raise ArgumentError, message: "invalid ANSI sequence specification: #{spec}"
134+
raise ArgumentError, message: "invalid ANSI sequence specification: #{other}"
142135
end
143136

144137
@doc ~S"""
@@ -163,8 +156,8 @@ defmodule IO.ANSI do
163156
"""
164157
@spec escape(String.t, emit :: boolean) :: String.t
165158
def escape(string, emit \\ terminal?) do
166-
{rendered, emitted} = do_escape(string, false, emit, false, [])
167-
if emitted and emit do
159+
{rendered, emitted} = do_escape(string, emit, false, nil, [])
160+
if emitted do
168161
rendered <> reset
169162
else
170163
rendered
@@ -193,34 +186,43 @@ defmodule IO.ANSI do
193186
"""
194187
@spec escape_fragment(String.t, emit :: boolean) :: String.t
195188
def escape_fragment(string, emit \\ terminal?) do
196-
{rendered, _emitted} = do_escape(string, false, emit, false, [])
197-
rendered
189+
{escaped, _emitted} = do_escape(string, emit, false, nil, [])
190+
escaped
198191
end
199192

200-
defp do_escape(<< ?%, ?{, rest :: binary >>, false, emit, _emitted, acc) do
201-
do_escape_sequence(rest, emit, acc)
202-
end
203-
defp do_escape(<< ?,, rest :: binary >>, true, emit, _emitted, acc) do
204-
do_escape_sequence(rest, emit, acc)
193+
defp do_escape(<<?}, t :: binary>>, emit, emitted, buffer, acc) when is_list(buffer) do
194+
sequences =
195+
buffer
196+
|> Enum.reverse()
197+
|> :string.tokens(',')
198+
|> Enum.map(&(&1 |> :string.strip |> escape_sequence))
199+
|> Enum.reverse()
200+
201+
if emit and sequences != [] do
202+
do_escape(t, emit, true, nil, sequences ++ acc)
203+
else
204+
do_escape(t, emit, emitted, nil, acc)
205+
end
205206
end
206-
defp do_escape(<< ?\s, rest :: binary >>, true, emit, emitted, acc) do
207-
do_escape(rest, true, emit, emitted, acc)
207+
208+
defp do_escape(<<h, t :: binary>>, emit, emitted, buffer, acc) when is_list(buffer) do
209+
do_escape(t, emit, emitted, [h|buffer], acc)
208210
end
209-
defp do_escape(<< ?}, rest :: binary >>, true, emit, emitted, acc) do
210-
do_escape(rest, false, emit, emitted, acc)
211+
212+
defp do_escape(<<>>, _emit, _emitted, buffer, _acc) when is_list(buffer) do
213+
buffer = iodata_to_binary Enum.reverse(buffer)
214+
raise ArgumentError, message: "missing } for escape fragment #{buffer}"
211215
end
212-
defp do_escape(<< x :: [binary, size(1)], rest :: binary>>, false, emit, emitted, acc) do
213-
do_escape(rest, false, emit, emitted, [x|acc])
216+
217+
defp do_escape(<<?%, ?{, t :: binary>>, emit, emitted, nil, acc) do
218+
do_escape(t, emit, emitted, [], acc)
214219
end
215-
defp do_escape("", false, _emit, emitted, acc) do
216-
{iodata_to_binary(Enum.reverse(acc)), emitted}
220+
221+
defp do_escape(<<h, t :: binary>>, emit, emitted, nil, acc) do
222+
do_escape(t, emit, emitted, nil, [h|acc])
217223
end
218224

219-
defp do_escape_sequence(rest, emit, acc) do
220-
{code, rest} = escape_sequence(rest)
221-
if emit do
222-
acc = [code|acc]
223-
end
224-
do_escape(rest, true, emit, true, acc)
225+
defp do_escape(<<>>, _emit, emitted, nil, acc) do
226+
{iodata_to_binary(Enum.reverse(acc)), emitted}
225227
end
226228
end

lib/elixir/test/elixir/application_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ defmodule ApplicationTest do
1111
assert Application.put_env(:elixir, :unknown, :known) == :ok
1212
assert Application.fetch_env(:elixir, :unknown) == {:ok, :known}
1313
assert Application.get_env(:elixir, :unknown, :default) == :known
14+
assert {:unknown, :known} in Application.get_all_env(:elixir)
1415

1516
assert Application.delete_env(:elixir, :unknown) == :ok
1617
assert Application.get_env(:elixir, :unknown, :default) == :default

lib/elixir/test/elixir/io/ansi_test.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ defmodule IO.ANSITest do
2727
end
2828

2929
test :no_emit do
30+
assert IO.ANSI.escape("Hello, %{}world!", false) ==
31+
"Hello, world!"
32+
3033
assert IO.ANSI.escape("Hello, %{red,bright}world!", false) ==
3134
"Hello, world!"
3235
end

lib/ex_unit/lib/ex_unit.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ defmodule ExUnit do
163163
"""
164164
def configure(options) do
165165
Enum.each options, fn {k, v} ->
166-
:application.set_env(:ex_unit, k, v)
166+
Application.put_env(:ex_unit, k, v)
167167
end
168168
end
169169

170170
@doc """
171171
Returns ExUnit configuration.
172172
"""
173173
def configuration do
174-
:application.get_all_env(:ex_unit)
174+
Application.get_all_env(:ex_unit)
175175
end
176176

177177
@doc """

0 commit comments

Comments
 (0)