From a43ab74e0f5bf22b0312d6c39622ee246c7be79d Mon Sep 17 00:00:00 2001 From: Aleksei Magusev Date: Thu, 9 Jun 2016 01:50:26 +0200 Subject: [PATCH] Emit warning when variable is being expanded to function call --- lib/eex/lib/eex.ex | 4 +- lib/eex/test/eex_test.exs | 6 +- lib/elixir/lib/dict.ex | 4 +- lib/elixir/lib/exception.ex | 2 +- lib/elixir/lib/file.ex | 2 +- lib/elixir/lib/inspect/algebra.ex | 4 +- lib/elixir/lib/io.ex | 2 +- lib/elixir/lib/io/ansi.ex | 4 +- lib/elixir/lib/io/ansi/docs.ex | 14 ++--- lib/elixir/lib/kernel/cli.ex | 8 +-- lib/elixir/lib/kernel/error_handler.ex | 2 +- lib/elixir/lib/path.ex | 4 +- lib/elixir/lib/protocol.ex | 10 ++-- lib/elixir/lib/stream.ex | 2 +- lib/elixir/lib/system.ex | 26 ++++----- lib/elixir/lib/task.ex | 4 +- lib/elixir/lib/task/supervised.ex | 2 +- lib/elixir/lib/task/supervisor.ex | 2 +- lib/elixir/src/elixir_exp.erl | 11 ++-- lib/elixir/test/elixir/agent_test.exs | 2 +- lib/elixir/test/elixir/application_test.exs | 2 +- lib/elixir/test/elixir/enum_test.exs | 2 +- lib/elixir/test/elixir/exception_test.exs | 6 +- lib/elixir/test/elixir/file_test.exs | 28 +++++----- lib/elixir/test/elixir/gen_event_test.exs | 2 +- lib/elixir/test/elixir/gen_server_test.exs | 12 ++-- .../test/elixir/inspect/algebra_test.exs | 46 +++++++-------- lib/elixir/test/elixir/inspect_test.exs | 8 +-- .../test/elixir/kernel/comprehension_test.exs | 4 +- lib/elixir/test/elixir/kernel/errors_test.exs | 12 ++-- .../test/elixir/kernel/expansion_test.exs | 9 ++- lib/elixir/test/elixir/kernel/import_test.exs | 8 +-- lib/elixir/test/elixir/kernel/macros_test.exs | 4 +- .../test/elixir/kernel/overridable_test.exs | 14 ++--- lib/elixir/test/elixir/kernel/quote_test.exs | 38 ++++++------- lib/elixir/test/elixir/kernel/raise_test.exs | 2 +- .../test/elixir/kernel/warning_test.exs | 25 +++++++-- lib/elixir/test/elixir/kernel_test.exs | 6 +- lib/elixir/test/elixir/path_test.exs | 4 +- lib/elixir/test/elixir/process_test.exs | 12 ++-- lib/elixir/test/elixir/protocol_test.exs | 24 ++++---- lib/elixir/test/elixir/stream_test.exs | 2 +- lib/elixir/test/elixir/supervisor_test.exs | 2 +- lib/elixir/test/elixir/system_test.exs | 2 +- .../test/elixir/task/supervisor_test.exs | 8 +-- lib/elixir/test/elixir/task_test.exs | 24 ++++---- lib/elixir/test/elixir/test_helper.exs | 12 ++-- lib/ex_unit/examples/one_of_each.exs | 4 +- lib/ex_unit/lib/ex_unit/assertions.ex | 10 ++-- lib/ex_unit/lib/ex_unit/callbacks.ex | 4 +- lib/ex_unit/lib/ex_unit/case.ex | 2 +- lib/ex_unit/lib/ex_unit/doc_test.ex | 2 +- lib/ex_unit/lib/ex_unit/runner.ex | 14 ++--- lib/ex_unit/test/ex_unit/assertions_test.exs | 16 +++--- lib/ex_unit/test/ex_unit/callbacks_test.exs | 12 ++-- lib/ex_unit/test/ex_unit/capture_io_test.exs | 6 +- lib/ex_unit/test/ex_unit/doc_test_test.exs | 20 +++---- lib/ex_unit/test/ex_unit/formatter_test.exs | 4 +- lib/iex/lib/iex.ex | 10 ++-- lib/iex/lib/iex/cli.ex | 10 ++-- lib/iex/lib/iex/config.ex | 2 +- lib/iex/lib/iex/evaluator.ex | 6 +- lib/iex/lib/iex/helpers.ex | 18 +++--- lib/iex/lib/iex/introspection.ex | 30 +++++----- lib/iex/lib/iex/server.ex | 20 +++---- lib/iex/test/iex/helpers_test.exs | 56 ++++++++++--------- lib/iex/test/iex/info_test.exs | 2 +- lib/iex/test/iex/interaction_test.exs | 6 +- lib/iex/test/iex/server_test.exs | 2 +- lib/logger/lib/logger.ex | 2 +- lib/mix/lib/mix.ex | 2 +- lib/mix/lib/mix/dep.ex | 6 +- lib/mix/lib/mix/dep/lock.ex | 10 ++-- lib/mix/lib/mix/dep/umbrella.ex | 2 +- lib/mix/lib/mix/generator.ex | 4 +- lib/mix/lib/mix/project.ex | 6 +- lib/mix/lib/mix/shell/io.ex | 8 +-- lib/mix/lib/mix/shell/process.ex | 20 +++---- lib/mix/lib/mix/tasks/clean.ex | 2 +- lib/mix/lib/mix/tasks/compile.elixir.ex | 2 +- lib/mix/lib/mix/tasks/compile.erlang.ex | 2 +- lib/mix/lib/mix/tasks/compile.ex | 2 +- lib/mix/lib/mix/tasks/compile.leex.ex | 2 +- lib/mix/lib/mix/tasks/compile.xref.ex | 2 +- lib/mix/lib/mix/tasks/compile.yecc.ex | 2 +- lib/mix/lib/mix/tasks/help.ex | 10 ++-- lib/mix/lib/mix/tasks/new.ex | 12 ++-- lib/mix/lib/mix/utils.ex | 4 +- lib/mix/test/fixtures/umbrella_dep/mix.exs | 2 +- lib/mix/test/mix/dep_test.exs | 2 +- lib/mix/test/mix/generator_test.exs | 8 +-- lib/mix/test/mix/shell_test.exs | 6 +- lib/mix/test/mix/tasks/archive_test.exs | 20 +++---- lib/mix/test/mix/tasks/cmd_test.exs | 2 +- .../test/mix/tasks/compile.protocols_test.exs | 14 ++--- lib/mix/test/mix/tasks/deps.git_test.exs | 10 ++-- lib/mix/test/mix/tasks/escript_test.exs | 8 +-- .../test/mix/tasks/local.public_keys_test.exs | 6 +- lib/mix/test/mix/tasks/profile.fprof_test.exs | 4 +- lib/mix/test/mix/tasks/run_test.exs | 12 ++-- lib/mix/test/mix/utils_test.exs | 2 +- lib/mix/test/test_helper.exs | 14 ++--- 102 files changed, 465 insertions(+), 434 deletions(-) diff --git a/lib/eex/lib/eex.ex b/lib/eex/lib/eex.ex index aca68f777df..2a20726ec15 100644 --- a/lib/eex/lib/eex.ex +++ b/lib/eex/lib/eex.ex @@ -111,7 +111,7 @@ defmodule EEx do """ defmacro function_from_string(kind, name, source, args \\ [], options \\ []) do - quote bind_quoted: binding do + quote bind_quoted: binding() do info = Keyword.merge [file: __ENV__.file, line: __ENV__.line], options args = Enum.map args, fn arg -> {arg, [line: info[:line]], nil} end compiled = EEx.compile_string(source, info) @@ -148,7 +148,7 @@ defmodule EEx do """ defmacro function_from_file(kind, name, file, args \\ [], options \\ []) do - quote bind_quoted: binding do + quote bind_quoted: binding() do info = Keyword.merge options, [file: file, line: 1] args = Enum.map args, fn arg -> {arg, [line: 1], nil} end compiled = EEx.compile_file(file, info) diff --git a/lib/eex/test/eex_test.exs b/lib/eex/test/eex_test.exs index dc1c9adb93a..977cb5fd775 100644 --- a/lib/eex/test/eex_test.exs +++ b/lib/eex/test/eex_test.exs @@ -4,7 +4,7 @@ require EEx defmodule EExTest.Compiled do def before_compile do - fill_in_stacktrace + fill_in_stacktrace() {__ENV__.line, hd(tl(System.stacktrace))} end @@ -19,13 +19,13 @@ defmodule EExTest.Compiled do def file_sample(arg), do: private_file_sample(arg) def after_compile do - fill_in_stacktrace + fill_in_stacktrace() {__ENV__.line, hd(tl(System.stacktrace))} end @file "unknown" def unknown do - fill_in_stacktrace + fill_in_stacktrace() {__ENV__.line, hd(tl(System.stacktrace))} end diff --git a/lib/elixir/lib/dict.ex b/lib/elixir/lib/dict.ex index 819b4fe7481..3b2ffce0670 100644 --- a/lib/elixir/lib/dict.ex +++ b/lib/elixir/lib/dict.ex @@ -72,7 +72,7 @@ defmodule Dict do end def take(dict, keys) do - Enum.reduce(keys, new, fn key, acc -> + Enum.reduce(keys, new(), fn key, acc -> case fetch(dict, key) do {:ok, value} -> put(acc, key, value) :error -> acc @@ -166,7 +166,7 @@ defmodule Dict do end def split(dict, keys) do - Enum.reduce(keys, {new, dict}, fn key, {inc, exc} = acc -> + Enum.reduce(keys, {new(), dict}, fn key, {inc, exc} = acc -> case fetch(exc, key) do {:ok, value} -> {put(inc, key, value), delete(exc, key)} diff --git a/lib/elixir/lib/exception.ex b/lib/elixir/lib/exception.ex index d20fe5d7638..786316a7d40 100644 --- a/lib/elixir/lib/exception.ex +++ b/lib/elixir/lib/exception.ex @@ -380,7 +380,7 @@ defmodule Exception do is retrieved from `Process.info/2`. """ def format_stacktrace(trace \\ nil) do - trace = trace || case Process.info(self, :current_stacktrace) do + trace = trace || case Process.info(self(), :current_stacktrace) do {:current_stacktrace, t} -> Enum.drop(t, 3) end diff --git a/lib/elixir/lib/file.ex b/lib/elixir/lib/file.ex index 3d63046f46b..539ebecf4c4 100644 --- a/lib/elixir/lib/file.ex +++ b/lib/elixir/lib/file.ex @@ -1139,7 +1139,7 @@ defmodule File do """ @spec cd!(Path.t, (() -> res)) :: res | no_return when res: var def cd!(path, function) do - old = cwd! + old = cwd!() cd!(path) try do function.() diff --git a/lib/elixir/lib/inspect/algebra.ex b/lib/elixir/lib/inspect/algebra.ex index 2630a192b17..15f654129d6 100644 --- a/lib/elixir/lib/inspect/algebra.ex +++ b/lib/elixir/lib/inspect/algebra.ex @@ -337,7 +337,7 @@ defmodule Inspect.Algebra do Inserts a break between two docs. See `break/1` for more info. """ @spec glue(t, t) :: doc_cons - def glue(x, y), do: concat(x, concat(break, y)) + def glue(x, y), do: concat(x, concat(break(), y)) @doc """ Inserts a break, passed as the second argument, between two docs, @@ -420,7 +420,7 @@ defmodule Inspect.Algebra do """ @spec fold_doc([t], ((t, t) -> t)) :: t def fold_doc(list, fun) - def fold_doc([], _), do: empty + def fold_doc([], _), do: empty() def fold_doc([doc], _), do: doc def fold_doc([d | ds], fun), do: fun.(d, fold_doc(ds, fun)) diff --git a/lib/elixir/lib/io.ex b/lib/elixir/lib/io.ex index a49c8b22199..ec237aa3690 100644 --- a/lib/elixir/lib/io.ex +++ b/lib/elixir/lib/io.ex @@ -277,7 +277,7 @@ defmodule IO do def getn(prompt, count \\ 1) def getn(prompt, count) when is_integer(count) and count > 0 do - getn(group_leader, prompt, count) + getn(group_leader(), prompt, count) end def getn(device, prompt) when not is_integer(prompt) do diff --git a/lib/elixir/lib/io/ansi.ex b/lib/elixir/lib/io/ansi.ex index 3110512d2af..5be0fbd50b5 100644 --- a/lib/elixir/lib/io/ansi.ex +++ b/lib/elixir/lib/io/ansi.ex @@ -186,7 +186,7 @@ defmodule IO.ANSI do [[[[[[], "Hello, "] | "\e[31m"] | "\e[1m"], "world!"] | "\e[0m"] """ - def format(chardata, emit? \\ enabled?) when is_boolean(emit?) do + def format(chardata, emit? \\ enabled?()) when is_boolean(emit?) do do_format(chardata, [], [], emit?, :maybe) end @@ -206,7 +206,7 @@ defmodule IO.ANSI do [[[[[[] | "\e[1m"], 87], 111], 114], 100] """ - def format_fragment(chardata, emit? \\ enabled?) when is_boolean(emit?) do + def format_fragment(chardata, emit? \\ enabled?()) when is_boolean(emit?) do do_format(chardata, [], [], emit?, false) end diff --git a/lib/elixir/lib/io/ansi/docs.ex b/lib/elixir/lib/io/ansi/docs.ex index b16b8c7bb15..3c7f0849baa 100644 --- a/lib/elixir/lib/io/ansi/docs.ex +++ b/lib/elixir/lib/io/ansi/docs.ex @@ -40,12 +40,12 @@ defmodule IO.ANSI.Docs do """ def print_heading(heading, options \\ []) do IO.puts IO.ANSI.reset - options = Keyword.merge(default_options, options) + options = Keyword.merge(default_options(), options) width = options[:width] padding = div(width + String.length(heading), 2) heading = heading |> String.pad_leading(padding) |> String.pad_trailing(width) write(:doc_title, heading, options) - newline_after_block + newline_after_block() end @doc """ @@ -55,7 +55,7 @@ defmodule IO.ANSI.Docs do defined in `default_options/1`. """ def print(doc, options \\ []) do - options = Keyword.merge(default_options, options) + options = Keyword.merge(default_options(), options) doc |> String.split(["\r\n", "\n"], trim: false) |> Enum.map(&String.trim_trailing/1) @@ -124,13 +124,13 @@ defmodule IO.ANSI.Docs do defp write_h2(heading, options) do write(:doc_headings, heading, options) - newline_after_block + newline_after_block() end defp write_h3(heading, indent, options) do IO.write(indent) write(:doc_headings, heading, options) - newline_after_block + newline_after_block() end ## Lists @@ -256,7 +256,7 @@ defmodule IO.ANSI.Docs do defp write_code(code, indent, options) do write(:doc_code, "#{indent}┃ #{Enum.join(Enum.reverse(code), "\n#{indent}┃ ")}", options) - newline_after_block + newline_after_block() end ## Tables @@ -264,7 +264,7 @@ defmodule IO.ANSI.Docs do defp process_table(lines, indent, options) do {table, rest} = Enum.split_while(lines, &table_line?/1) table_lines(table, options) - newline_after_block + newline_after_block() process(rest, [], indent, options) end diff --git a/lib/elixir/lib/kernel/cli.ex b/lib/elixir/lib/kernel/cli.ex index 1e8e7a77c82..47e7efa45ff 100644 --- a/lib/elixir/lib/kernel/cli.ex +++ b/lib/elixir/lib/kernel/cli.ex @@ -76,22 +76,22 @@ defmodule Kernel.CLI do fun.(elem(res, 1)) catch :exit, {:shutdown, int} when is_integer(int) -> - send parent, {self, {:shutdown, int}} + send parent, {self(), {:shutdown, int}} exit({:shutdown, int}) :exit, reason when reason == :normal when reason == :shutdown when tuple_size(reason) == 2 and elem(reason, 0) == :shutdown -> - send parent, {self, {:shutdown, 0}} + send parent, {self(), {:shutdown, 0}} exit(reason) kind, reason -> stack = System.stacktrace print_error(kind, reason, stack) - send parent, {self, {:shutdown, 1}} + send parent, {self(), {:shutdown, 1}} exit(to_exit(kind, reason, stack)) else _ -> - send parent, {self, res} + send parent, {self(), res} end end) diff --git a/lib/elixir/lib/kernel/error_handler.ex b/lib/elixir/lib/kernel/error_handler.ex index 906dc3aeb40..bd10d1a66f9 100644 --- a/lib/elixir/lib/kernel/error_handler.ex +++ b/lib/elixir/lib/kernel/error_handler.ex @@ -28,7 +28,7 @@ defmodule Kernel.ErrorHandler do parent = :erlang.get(:elixir_compiler_pid) ref = :erlang.make_ref send parent, {:waiting, kind, self(), ref, module, :elixir_module.compiler_modules()} - :erlang.garbage_collect(self) + :erlang.garbage_collect(self()) receive do {^ref, :found} -> true {^ref, :not_found} -> false diff --git a/lib/elixir/lib/path.ex b/lib/elixir/lib/path.ex index 33ac22dbf1d..b99586b6b7a 100644 --- a/lib/elixir/lib/path.ex +++ b/lib/elixir/lib/path.ex @@ -187,7 +187,7 @@ defmodule Path do """ @spec type(t) :: :absolute | :relative | :volumerelative def type(name) when is_list(name) or is_binary(name) do - pathtype(name, major_os_type) |> elem(0) + pathtype(name, major_os_type()) |> elem(0) end @doc """ @@ -625,7 +625,7 @@ defmodule Path do defp resolve_home(""), do: System.user_home! defp resolve_home(rest) do - case {rest, major_os_type} do + case {rest, major_os_type()} do {"\\" <> _, :win32} -> System.user_home! <> rest {"/" <> _, _} -> diff --git a/lib/elixir/lib/protocol.ex b/lib/elixir/lib/protocol.ex index 78e1858aab1..be2863acf5e 100644 --- a/lib/elixir/lib/protocol.ex +++ b/lib/elixir/lib/protocol.ex @@ -420,7 +420,7 @@ defmodule Protocol do _ = unquote(block) # Finalize expansion - unquote(after_defprotocol) + unquote(after_defprotocol()) end end end @@ -446,7 +446,7 @@ defmodule Protocol do Kernel.def impl_for(data) when :erlang.unquote(guard)(data) do case impl_for?(unquote(target)) do true -> unquote(target).__impl__(:target) - false -> any_impl_for + false -> any_impl_for() end end end, builtin) @@ -459,9 +459,9 @@ defmodule Protocol do # Internal handler for Any if @fallback_to_any do - Kernel.defp any_impl_for, do: __MODULE__.Any.__impl__(:target) + Kernel.defp any_impl_for(), do: __MODULE__.Any.__impl__(:target) else - Kernel.defp any_impl_for, do: nil + Kernel.defp any_impl_for(), do: nil end # Internal handler for Structs @@ -469,7 +469,7 @@ defmodule Protocol do target = Module.concat(__MODULE__, struct) case impl_for?(target) do true -> target.__impl__(:target) - false -> any_impl_for + false -> any_impl_for() end end diff --git a/lib/elixir/lib/stream.ex b/lib/elixir/lib/stream.ex index 018c6d86dc7..48a01ce667f 100644 --- a/lib/elixir/lib/stream.ex +++ b/lib/elixir/lib/stream.ex @@ -340,7 +340,7 @@ defmodule Stream do ## Examples - iex> stream = Stream.each([1, 2, 3], fn(x) -> send self, x end) + iex> stream = Stream.each([1, 2, 3], fn(x) -> send self(), x end) iex> Enum.to_list(stream) iex> receive do: (x when is_integer(x) -> x) 1 diff --git a/lib/elixir/lib/system.ex b/lib/elixir/lib/system.ex index e4e192b17a0..fac0b03ca12 100644 --- a/lib/elixir/lib/system.ex +++ b/lib/elixir/lib/system.ex @@ -117,7 +117,7 @@ defmodule System do |> strip end - defp revision, do: get_revision + defp revision, do: get_revision() # Get the date at compilation time. defmacrop get_date do @@ -145,7 +145,7 @@ defmodule System do Returns Elixir's version as binary. """ @spec version() :: String.t - def version, do: get_version + def version, do: get_version() @doc """ Elixir build information. @@ -154,22 +154,22 @@ defmodule System do """ @spec build_info() :: map def build_info do - %{build: build, - date: get_date, - revision: revision, - version: version, + %{build: build(), + date: get_date(), + revision: revision(), + version: version(), } end # Returns a string of the build info defp build do - {:ok, v} = Version.parse(version) + {:ok, v} = Version.parse(version()) cond do - ([] == v.pre) or ("" == revision) -> - version + ([] == v.pre) or ("" == revision()) -> + version() true -> - "#{version} (#{revision})" + "#{version()} (#{revision()})" end end @@ -222,7 +222,7 @@ defmodule System do Returns the current working directory or raises `RuntimeError`. """ def cwd! do - cwd || + cwd() || raise RuntimeError, message: "could not get a current working directory, the current location is not accessible" end @@ -242,7 +242,7 @@ defmodule System do instead of returning `nil` if no user home is set. """ def user_home! do - user_home || + user_home() || raise RuntimeError, message: "could not find the user home, please set the HOME environment variable" end @@ -275,7 +275,7 @@ defmodule System do instead of returning `nil` if no temp dir is set. """ def tmp_dir! do - tmp_dir || + tmp_dir() || raise RuntimeError, message: "could not get a writable temporary directory, " <> "please set the TMPDIR environment variable" end diff --git a/lib/elixir/lib/task.ex b/lib/elixir/lib/task.ex index 785ec68af23..31677f9047b 100644 --- a/lib/elixir/lib/task.ex +++ b/lib/elixir/lib/task.ex @@ -165,7 +165,7 @@ defmodule Task do """ @spec start_link(module, atom, [term]) :: {:ok, pid} def start_link(mod, fun, args) do - Task.Supervised.start_link(get_info(self), {mod, fun, args}) + Task.Supervised.start_link(get_info(self()), {mod, fun, args}) end @doc """ @@ -189,7 +189,7 @@ defmodule Task do """ @spec start(module, atom, [term]) :: {:ok, pid} def start(mod, fun, args) do - Task.Supervised.start(get_info(self), {mod, fun, args}) + Task.Supervised.start(get_info(self()), {mod, fun, args}) end @doc """ diff --git a/lib/elixir/lib/task/supervised.ex b/lib/elixir/lib/task/supervised.ex index 81a271db53c..9e11d049b8f 100644 --- a/lib/elixir/lib/task/supervised.ex +++ b/lib/elixir/lib/task/supervised.ex @@ -120,7 +120,7 @@ defmodule Task.Supervised do '** When function == ~p~n' ++ '** arguments == ~p~n' ++ '** Reason for termination == ~n' ++ - '** ~p~n', [self, get_from(info), fun, args, get_reason(log_reason)]) + '** ~p~n', [self(), get_from(info), fun, args, get_reason(log_reason)]) exit(reason) end diff --git a/lib/elixir/lib/task/supervisor.ex b/lib/elixir/lib/task/supervisor.ex index c0449f3dcd4..979fb5cefc2 100644 --- a/lib/elixir/lib/task/supervisor.ex +++ b/lib/elixir/lib/task/supervisor.ex @@ -144,7 +144,7 @@ defmodule Task.Supervisor do """ @spec start_child(Supervisor.supervisor, module, atom, [term]) :: {:ok, pid} def start_child(supervisor, module, fun, args) do - Supervisor.start_child(supervisor, [get_info(self), {module, fun, args}]) + Supervisor.start_child(supervisor, [get_info(self()), {module, fun, args}]) end defp get_info(self) do diff --git a/lib/elixir/src/elixir_exp.erl b/lib/elixir/src/elixir_exp.erl index f7432e97a88..b9e50c975fb 100644 --- a/lib/elixir/src/elixir_exp.erl +++ b/lib/elixir/src/elixir_exp.erl @@ -304,12 +304,15 @@ expand({Name, Meta, Kind} = Var, #{vars := Vars} = E) when is_atom(Name), is_ato true -> {Var, E}; false -> - VarMeta = lists:keyfind(var, 1, Meta), - if - VarMeta == {var, true} -> + case lists:keyfind(var, 1, Meta) of + {var, true} -> compile_error(Meta, ?m(E, file), "expected var \"~ts\"~ts to expand to an existing variable " "or be part of a match", [Name, elixir_scope:context_info(Kind)]); - true -> + _ -> + Message = + io_lib:format("variable \"~ts\" does not exist and is being expanded to \"~ts()\"," + " please use parentheses to remove the ambiguity or change the variable name", [Name, Name]), + elixir_errors:warn(?line(Meta), ?m(E, file), Message), expand({Name, Meta, []}, E) end end; diff --git a/lib/elixir/test/elixir/agent_test.exs b/lib/elixir/test/elixir/agent_test.exs index a1f6751771d..494742b5379 100644 --- a/lib/elixir/test/elixir/agent_test.exs +++ b/lib/elixir/test/elixir/agent_test.exs @@ -10,7 +10,7 @@ defmodule AgentTest do test "start_link/2 workflow with unregistered name and anonymous functions" do {:ok, pid} = Agent.start_link(&Map.new/0) - {:links, links} = Process.info(self, :links) + {:links, links} = Process.info(self(), :links) assert pid in links assert :proc_lib.translate_initial_call(pid) == {Map, :new, 0} diff --git a/lib/elixir/test/elixir/application_test.exs b/lib/elixir/test/elixir/application_test.exs index 692d531feb5..6ba5bd89a4f 100644 --- a/lib/elixir/test/elixir/application_test.exs +++ b/lib/elixir/test/elixir/application_test.exs @@ -66,7 +66,7 @@ defmodule ApplicationTest do end end - if windows? do + if windows?() do defp normalize_app_dir(path) do path |> String.downcase |> Path.expand end diff --git a/lib/elixir/test/elixir/enum_test.exs b/lib/elixir/test/elixir/enum_test.exs index 640247a9800..67b0de28b0d 100644 --- a/lib/elixir/test/elixir/enum_test.exs +++ b/lib/elixir/test/elixir/enum_test.exs @@ -599,7 +599,7 @@ defmodule EnumTest do assert Enum.take_random([1, 2, 3], 129) == [3, 2, 1] # assert that every item in the sample comes from the input list - list = for _<-1..100, do: make_ref + list = for _<-1..100, do: make_ref() for x <- Enum.take_random(list, 50) do assert x in list end diff --git a/lib/elixir/test/elixir/exception_test.exs b/lib/elixir/test/elixir/exception_test.exs index de3e3dee2f5..a863ed73dfd 100644 --- a/lib/elixir/test/elixir/exception_test.exs +++ b/lib/elixir/test/elixir/exception_test.exs @@ -45,7 +45,7 @@ defmodule ExceptionTest do test "normalize" do assert Exception.normalize(:throw, :badarg) == :badarg assert Exception.normalize(:exit, :badarg) == :badarg - assert Exception.normalize({:EXIT, self}, :badarg) == :badarg + assert Exception.normalize({:EXIT, self()}, :badarg) == :badarg assert Exception.normalize(:error, :badarg).__struct__ == ArgumentError assert Exception.normalize(:error, %ArgumentError{}).__struct__ == ArgumentError end @@ -61,14 +61,14 @@ defmodule ExceptionTest do end test "format with EXIT has no stacktrace" do - assert Exception.format({:EXIT, self}, :badarg) == "** (EXIT from #{inspect self}) :badarg" + assert Exception.format({:EXIT, self()}, :badarg) == "** (EXIT from #{inspect self()}) :badarg" end test "format_banner" do assert Exception.format_banner(:error, :badarg) == "** (ArgumentError) argument error" assert Exception.format_banner(:throw, :badarg) == "** (throw) :badarg" assert Exception.format_banner(:exit, :badarg) == "** (exit) :badarg" - assert Exception.format_banner({:EXIT, self}, :badarg) == "** (EXIT from #{inspect self}) :badarg" + assert Exception.format_banner({:EXIT, self()}, :badarg) == "** (EXIT from #{inspect self()}) :badarg" end test "format_stacktrace from file" do diff --git a/lib/elixir/test/elixir/file_test.exs b/lib/elixir/test/elixir/file_test.exs index 98a70263f73..1eab55d9328 100644 --- a/lib/elixir/test/elixir/file_test.exs +++ b/lib/elixir/test/elixir/file_test.exs @@ -11,8 +11,8 @@ defmodule Elixir.FileCase do end setup do - File.mkdir_p!(tmp_path) - on_exit(fn -> File.rm_rf(tmp_path) end) + File.mkdir_p!(tmp_path()) + on_exit(fn -> File.rm_rf(tmp_path()) end) :ok end end @@ -697,7 +697,7 @@ defmodule FileTest do test "exists" do assert File.exists?(__ENV__.file) - assert File.exists?(fixture_path) + assert File.exists?(fixture_path()) assert File.exists?(fixture_path("file.txt")) refute File.exists?(fixture_path("missing.txt")) @@ -706,7 +706,7 @@ defmodule FileTest do end test "ls" do - {:ok, value} = File.ls(fixture_path) + {:ok, value} = File.ls(fixture_path()) assert "code_sample.exs" in value assert "file.txt" in value @@ -714,7 +714,7 @@ defmodule FileTest do end test "ls!" do - value = File.ls!(fixture_path) + value = File.ls!(fixture_path()) assert "code_sample.exs" in value assert "file.txt" in value @@ -1026,7 +1026,7 @@ defmodule FileTest do end test "rm file with dir" do - assert File.rm(fixture_path) == {:error, :eperm} + assert File.rm(fixture_path()) == {:error, :eperm} end test "rm nonexistent file" do @@ -1102,7 +1102,7 @@ defmodule FileTest do File.write!(Path.join(to, "hello"), "world") :file.make_symlink(to, from) - if File.exists?(from) or not windows? do + if File.exists?(from) or not windows?() do assert File.exists?(from) {:ok, files} = File.rm_rf(from) @@ -1494,7 +1494,7 @@ defmodule FileTest do test "cwd and cd" do {:ok, current} = File.cwd try do - assert File.cd(fixture_path) == :ok + assert File.cd(fixture_path()) == :ok assert File.exists?("file.txt") after File.cd!(current) @@ -1525,7 +1525,7 @@ defmodule FileTest do end test "cd with function" do - assert File.cd!(fixture_path, fn -> + assert File.cd!(fixture_path(), fn -> assert File.exists?("file.txt") :cd_result end) == :cd_result @@ -1552,7 +1552,7 @@ defmodule FileTest do assert File.touch!(fixture) == :ok stat = File.stat!(fixture) - assert File.touch!(fixture, last_year) == :ok + assert File.touch!(fixture, last_year()) == :ok assert stat.mtime > File.stat!(fixture).mtime after File.rm(fixture) @@ -1560,7 +1560,7 @@ defmodule FileTest do end test "touch with dir" do - assert File.touch(fixture_path) == :ok + assert File.touch(fixture_path()) == :ok end test "touch with failure" do @@ -1569,7 +1569,7 @@ defmodule FileTest do end test "touch! with success" do - assert File.touch!(fixture_path) == :ok + assert File.touch!(fixture_path()) == :ok end test "touch! with failure" do @@ -1588,7 +1588,7 @@ defmodule FileTest do stat = File.stat!(fixture) assert stat.mode == 0o100666 - unless windows? do + unless windows?() do assert File.chmod(fixture, 0o100777) == :ok stat = File.stat!(fixture) assert stat.mode == 0o100777 @@ -1607,7 +1607,7 @@ defmodule FileTest do stat = File.stat!(fixture) assert stat.mode == 0o100666 - unless windows? do + unless windows?() do assert File.chmod!(fixture, 0o100777) == :ok stat = File.stat!(fixture) assert stat.mode == 0o100777 diff --git a/lib/elixir/test/elixir/gen_event_test.exs b/lib/elixir/test/elixir/gen_event_test.exs index 1bba31fb869..de07b98654b 100644 --- a/lib/elixir/test/elixir/gen_event_test.exs +++ b/lib/elixir/test/elixir/gen_event_test.exs @@ -338,7 +338,7 @@ defmodule GenEventTest do test "notify/2 with bad args" do assert GenEvent.notify({:global, :foo}, :bar) == :ok assert GenEvent.notify({:foo, :bar}, :bar) == :ok - assert GenEvent.notify(self, :bar) == :ok + assert GenEvent.notify(self(), :bar) == :ok assert_raise ArgumentError, fn -> GenEvent.notify(:foo, :bar) diff --git a/lib/elixir/test/elixir/gen_server_test.exs b/lib/elixir/test/elixir/gen_server_test.exs index fd5c4260d56..6702a58f0f2 100644 --- a/lib/elixir/test/elixir/gen_server_test.exs +++ b/lib/elixir/test/elixir/gen_server_test.exs @@ -30,7 +30,7 @@ defmodule GenServerTest do # There is a race condition if the agent is # restarted too fast and it is registered. try do - self |> Process.info(:registered_name) |> elem(1) |> Process.unregister + self() |> Process.info(:registered_name) |> elem(1) |> Process.unregister rescue _ -> :ok end @@ -41,7 +41,7 @@ defmodule GenServerTest do test "start_link/2, call/2 and cast/2" do {:ok, pid} = GenServer.start_link(Stack, [:hello]) - {:links, links} = Process.info(self, :links) + {:links, links} = Process.info(self(), :links) assert pid in links assert GenServer.call(pid, :pop) == :hello @@ -80,7 +80,7 @@ defmodule GenServerTest do test "start/2" do {:ok, pid} = GenServer.start(Stack, [:hello]) - {:links, links} = Process.info(self, :links) + {:links, links} = Process.info(self(), :links) refute pid in links GenServer.stop(pid) end @@ -91,7 +91,7 @@ defmodule GenServerTest do assert GenServer.abcast(:stack, {:push, :hello}) == :abcast assert GenServer.call({:stack, node()}, :pop) == :hello - assert GenServer.abcast([node, :foo@bar], :stack, {:push, :world}) == :abcast + assert GenServer.abcast([node(), :foo@bar], :stack, {:push, :world}) == :abcast assert GenServer.call(:stack, :pop) == :world GenServer.stop(:stack) @@ -102,8 +102,8 @@ defmodule GenServerTest do assert GenServer.multi_call(:stack, :pop) == {[{node(), :hello}], []} - assert GenServer.multi_call([node, :foo@bar], :stack, :pop) == - {[{node, :world}], [:foo@bar]} + assert GenServer.multi_call([node(), :foo@bar], :stack, :pop) == + {[{node(), :world}], [:foo@bar]} GenServer.stop(:stack) end diff --git a/lib/elixir/test/elixir/inspect/algebra_test.exs b/lib/elixir/test/elixir/inspect/algebra_test.exs index 3bb8fc73011..3eaa17d5449 100644 --- a/lib/elixir/test/elixir/inspect/algebra_test.exs +++ b/lib/elixir/test/elixir/inspect/algebra_test.exs @@ -27,13 +27,13 @@ defmodule Inspect.AlgebraTest do test "empty doc" do # Consistence with definitions - assert empty == :doc_nil + assert empty() == :doc_nil # Consistence of corresponding sdoc - assert sdoc(empty) == [] + assert sdoc(empty()) == [] # Consistent formatting - assert render(empty, 80) == "" + assert render(empty(), 80) == "" end test "break doc" do @@ -79,11 +79,11 @@ defmodule Inspect.AlgebraTest do test "nest doc" do # Consistence with definitions - assert nest(empty, 1) == {:doc_nest, empty, 1} - assert nest(empty, 0) == :doc_nil + assert nest(empty(), 1) == {:doc_nest, empty(), 1} + assert nest(empty(), 0) == :doc_nil # Wrong argument type - assert_raise FunctionClauseError, fn -> nest("foo", empty) end + assert_raise FunctionClauseError, fn -> nest("foo", empty()) end # Consistence of corresponding sdoc assert sdoc(nest("a", 1)) == ["a"] @@ -109,15 +109,15 @@ defmodule Inspect.AlgebraTest do test "group doc" do # Consistency with definitions assert group(glue("a", "b")) == - {:doc_group, {:doc_cons, "a", concat(break, "b")}} - assert group(empty) == {:doc_group, empty} + {:doc_group, {:doc_cons, "a", concat(break(), "b")}} + assert group(empty()) == {:doc_group, empty()} # Consistence of corresponding sdoc assert sdoc(glue("a", "b")) == ["a", " ", "b"] # Consistent formatting - assert render(helloabcd, 5) == "hello\na b\ncd" - assert render(helloabcd, 80) == "hello a b cd" + assert render(helloabcd(), 5) == "hello\na b\ncd" + assert render(helloabcd(), 80) == "hello a b cd" end test "formatting with infinity" do @@ -131,18 +131,18 @@ defmodule Inspect.AlgebraTest do test "formatting surround_many with empty" do sm = &surround_many("[", &1, "]", %Inspect.Opts{}, fn(d, _) -> d end, ",") - assert sm.([]) |> render(80) == "[]" - assert sm.([empty]) |> render(80) == "[]" - assert sm.([empty, empty]) |> render(80) == "[]" - assert sm.(["a"]) |> render(80) == "[a]" - assert sm.(["a", empty]) |> render(80) == "[a]" - assert sm.([empty, "a"]) |> render(80) == "[a]" - assert sm.(["a", empty, "b"]) |> render(80) == "[a, b]" - assert sm.([empty, "a", "b"]) |> render(80) == "[a, b]" - assert sm.(["a", "b", empty]) |> render(80) == "[a, b]" - assert sm.(["a", "b" | "c"]) |> render(80) == "[a, b | c]" - assert sm.(["a" | "b"]) |> render(80) == "[a | b]" - assert sm.(["a" | empty]) |> render(80) == "[a]" - assert sm.([empty | "b"]) |> render(80) == "[b]" + assert sm.([]) |> render(80) == "[]" + assert sm.([empty()]) |> render(80) == "[]" + assert sm.([empty(), empty()]) |> render(80) == "[]" + assert sm.(["a"]) |> render(80) == "[a]" + assert sm.(["a", empty()]) |> render(80) == "[a]" + assert sm.([empty(), "a"]) |> render(80) == "[a]" + assert sm.(["a", empty(), "b"]) |> render(80) == "[a, b]" + assert sm.([empty(), "a", "b"]) |> render(80) == "[a, b]" + assert sm.(["a", "b", empty()]) |> render(80) == "[a, b]" + assert sm.(["a", "b" | "c"]) |> render(80) == "[a, b | c]" + assert sm.(["a" | "b"]) |> render(80) == "[a | b]" + assert sm.(["a" | empty()]) |> render(80) == "[a]" + assert sm.([empty() | "b"]) |> render(80) == "[b]" end end diff --git a/lib/elixir/test/elixir/inspect_test.exs b/lib/elixir/test/elixir/inspect_test.exs index 0b34bb807de..aad3da64a99 100644 --- a/lib/elixir/test/elixir/inspect_test.exs +++ b/lib/elixir/test/elixir/inspect_test.exs @@ -326,7 +326,7 @@ end defmodule Inspect.OthersTest do use ExUnit.Case, async: true - def f do + def fun() do fn() -> :ok end end @@ -365,7 +365,7 @@ defmodule Inspect.OthersTest do test "other funs" do assert "#Function<" <> _ = inspect(fn(x) -> x + 1 end) - assert "#Function<" <> _ = inspect(f) + assert "#Function<" <> _ = inspect(fun()) end test "map set" do @@ -373,11 +373,11 @@ defmodule Inspect.OthersTest do end test "pids" do - assert "#PID<" <> _ = inspect(self) + assert "#PID<" <> _ = inspect(self()) end test "references" do - assert "#Reference<" <> _ = inspect(make_ref) + assert "#Reference<" <> _ = inspect(make_ref()) end test "regex" do diff --git a/lib/elixir/test/elixir/kernel/comprehension_test.exs b/lib/elixir/test/elixir/kernel/comprehension_test.exs index 374fd350ba3..033155150a4 100644 --- a/lib/elixir/test/elixir/kernel/comprehension_test.exs +++ b/lib/elixir/test/elixir/kernel/comprehension_test.exs @@ -63,7 +63,7 @@ defmodule Kernel.ComprehensionTest do end test "for comprehensions with nilly filters" do - assert for(x <- 1..3, nilly, do: x * 2) == [] + assert for(x <- 1..3, nilly(), do: x * 2) == [] end test "for comprehensions with errors on filters" do @@ -178,7 +178,7 @@ defmodule Kernel.ComprehensionTest do end test "list for comprehensions with nilly filters" do - assert for(x <- [1, 2, 3], nilly, do: x * 2) == [] + assert for(x <- [1, 2, 3], nilly(), do: x * 2) == [] end test "list for comprehensions with errors on filters" do diff --git a/lib/elixir/test/elixir/kernel/errors_test.exs b/lib/elixir/test/elixir/kernel/errors_test.exs index 8f422ebeb11..b2d87bced12 100644 --- a/lib/elixir/test/elixir/kernel/errors_test.exs +++ b/lib/elixir/test/elixir/kernel/errors_test.exs @@ -215,7 +215,7 @@ defmodule Kernel.ErrorsTest do "nofile:2: undefined function foo/0", ~C''' defmodule Kernel.ErrorsTest.ClauseWithDefaults3 do - def hello(foo, bar \\ foo) + def hello(foo, bar \\ foo()) def hello(foo, bar), do: foo + bar end ''' @@ -256,7 +256,7 @@ defmodule Kernel.ErrorsTest do "nofile:2: undefined function bar/0", ''' defmodule Kernel.ErrorsTest.BadForm do - def foo, do: bar + def foo, do: bar() end ''' end @@ -416,7 +416,7 @@ defmodule Kernel.ErrorsTest do ''' defmodule Kernel.ErrorsTest.UnhandledStab do def fun do - casea foo, do: (bar -> baz) + casea foo(), do: (bar -> baz) end end ''' @@ -513,7 +513,7 @@ defmodule Kernel.ErrorsTest do defmodule Kernel.ErrorsTest.PrivateMacro do defmacrop foo, do: 1 defmacro bar, do: __MODULE__.foo - defmacro baz, do: bar + defmacro baz, do: bar() end ''' end @@ -627,7 +627,7 @@ defmodule Kernel.ErrorsTest do {:foo, :bar, :baz, :bat} end - def test, do: oops + def test, do: oops() end ''' end @@ -857,7 +857,7 @@ defmodule Kernel.ErrorsTest do defmodule Kernel.ErrorsTest.InvalidVarOrFunctionOnGuard do def bar do case [] do - [] when something_that_does_not_exist == [] -> :ok + [] when something_that_does_not_exist() == [] -> :ok end end end diff --git a/lib/elixir/test/elixir/kernel/expansion_test.exs b/lib/elixir/test/elixir/kernel/expansion_test.exs index 589bc479928..4b743cf593b 100644 --- a/lib/elixir/test/elixir/kernel/expansion_test.exs +++ b/lib/elixir/test/elixir/kernel/expansion_test.exs @@ -5,7 +5,7 @@ defmodule Kernel.ExpansionTarget do end defmodule Kernel.ExpansionTest do - use ExUnit.Case, async: true + use ExUnit.Case, async: false ## __block__ @@ -553,6 +553,11 @@ defmodule Kernel.ExpansionTest do end defp expand_env(expr, env) do - :elixir_exp.expand(expr, env) + ExUnit.CaptureIO.capture_io(:stderr, fn -> + send self(), {:expand_env, :elixir_exp.expand(expr, env)} + end) + receive do + {:expand_env, result} -> result + end end end diff --git a/lib/elixir/test/elixir/kernel/import_test.exs b/lib/elixir/test/elixir/kernel/import_test.exs index a17b044e42e..c9beb60cd5e 100644 --- a/lib/elixir/test/elixir/kernel/import_test.exs +++ b/lib/elixir/test/elixir/kernel/import_test.exs @@ -58,7 +58,7 @@ defmodule Kernel.ImportTest do end test "import with options via macro" do - import :lists, dynamic_opts + import :lists, dynamic_opts() assert flatten([1, [2], 3]) == [1, 2, 3] end @@ -154,7 +154,7 @@ defmodule Kernel.ImportTest do if false do import List flatten([1, [2], 3]) - flunk + flunk() else # Buggy local duplicate is untouched assert duplicate([1], 2) == [1] @@ -166,7 +166,7 @@ defmodule Kernel.ImportTest do false -> import List flatten([1, [2], 3]) - flunk + flunk() true -> # Buggy local duplicate is untouched assert duplicate([1], 2) == [1] @@ -177,7 +177,7 @@ defmodule Kernel.ImportTest do try do import List flatten([1, [2], 3]) - flunk + flunk() catch _, _ -> # Buggy local duplicate is untouched diff --git a/lib/elixir/test/elixir/kernel/macros_test.exs b/lib/elixir/test/elixir/kernel/macros_test.exs index 199bd644926..a74678eb068 100644 --- a/lib/elixir/test/elixir/kernel/macros_test.exs +++ b/lib/elixir/test/elixir/kernel/macros_test.exs @@ -36,11 +36,11 @@ defmodule Kernel.MacrosTest do end test "local but private macro" do - assert my_private_macro == 4 + assert my_private_macro() == 4 end test "local with defaults macro" do - assert my_macro_with_default == 6 + assert my_macro_with_default() == 6 end test "macros cannot be called dynamically" do diff --git a/lib/elixir/test/elixir/kernel/overridable_test.exs b/lib/elixir/test/elixir/kernel/overridable_test.exs index 3d828689008..fb0ec3eb10c 100644 --- a/lib/elixir/test/elixir/kernel/overridable_test.exs +++ b/lib/elixir/test/elixir/kernel/overridable_test.exs @@ -18,7 +18,7 @@ defmodule Kernel.Overridable do end def explicit_nested_super do - {super?, 2} + {super?(), 2} end false = Module.overridable? __MODULE__, {:explicit_nested_super, 0} @@ -28,7 +28,7 @@ defmodule Kernel.Overridable do true = Module.overridable? __MODULE__, {:explicit_nested_super, 0} def explicit_nested_super do - {super, super?, 1} + {super(), super?(), 1} end true = Module.overridable? __MODULE__, {:explicit_nested_super, 0} @@ -38,13 +38,13 @@ defmodule Kernel.Overridable do true = Module.overridable? __MODULE__, {:explicit_nested_super, 0} def implicit_nested_super do - {super?, 1} + {super?(), 1} end defoverridable [implicit_nested_super: 0] def implicit_nested_super do - {super, super?, 0} + {super(), super?(), 0} end def super_with_explicit_args(x, y) do @@ -71,11 +71,11 @@ defmodule Kernel.Overridable do end def no_overridable do - {:no_overridable, super?} + {:no_overridable, super?()} end def explicit_nested_super do - {super, super?, 0} + {super(), super?(), 0} end def super_with_explicit_args(x, y) do @@ -161,7 +161,7 @@ defmodule Kernel.OverridableTest do test "invalid super call" do try do - :elixir.eval 'defmodule Foo.Forwarding do\ndef bar, do: 1\ndefoverridable [bar: 0]\ndef foo, do: super\nend', [] + :elixir.eval 'defmodule Foo.Forwarding do\ndef bar, do: 1\ndefoverridable [bar: 0]\ndef foo, do: super()\nend', [] flunk "expected eval to fail" rescue error -> diff --git a/lib/elixir/test/elixir/kernel/quote_test.exs b/lib/elixir/test/elixir/kernel/quote_test.exs index 45341ec784e..c7c2cadbccc 100644 --- a/lib/elixir/test/elixir/kernel/quote_test.exs +++ b/lib/elixir/test/elixir/kernel/quote_test.exs @@ -64,7 +64,7 @@ defmodule Kernel.QuoteTest do end test "nested quote in macro" do - assert nested_quote_in_macro == 1 + assert nested_quote_in_macro() == 1 end Enum.each [foo: 1, bar: 2, baz: 3], fn {k, v} -> @@ -158,7 +158,7 @@ defmodule Kernel.QuoteTest do end test "with dynamic opts" do - assert quote(dynamic_opts, do: bar(1, 2, 3)) == {:bar, [line: 3], [1, 2, 3]} + assert quote(dynamic_opts(), do: bar(1, 2, 3)) == {:bar, [line: 3], [1, 2, 3]} end test "unary with integer precedence" do @@ -211,7 +211,7 @@ defmodule Kernel.QuoteTest.ErrorsTest do import Kernel.QuoteTest.Errors # Defines the add function - defadd + defadd() test "inside function error" do assert_raise ArithmeticError, fn -> @@ -225,7 +225,7 @@ defmodule Kernel.QuoteTest.ErrorsTest do test "outside function error" do assert_raise RuntimeError, fn -> - will_raise + will_raise() end mod = Kernel.QuoteTest.ErrorsTest @@ -282,24 +282,24 @@ defmodule Kernel.QuoteTest.VarHygieneTest do test "no interference" do a = 10 - no_interference + no_interference() assert a == 10 end test "cross module interference" do - cross_module_no_interference - cross_module_interference - assert read_cross_module == 1 + cross_module_no_interference() + cross_module_interference() + assert read_cross_module() == 1 end test "write interference" do - write_interference + write_interference() assert a == 1 end test "read interference" do a = 10 - read_interference + read_interference() end test "nested" do @@ -311,7 +311,7 @@ defmodule Kernel.QuoteTest.VarHygieneTest do end test "hat" do - assert hat == 1 + assert hat() == 1 end end @@ -387,9 +387,9 @@ defmodule Kernel.QuoteTest.ImportsHygieneTest do test "expand imports" do import Kernel, except: [length: 1] - assert get_list_length == 5 - assert get_list_length_with_partial == 5 - assert get_list_length_with_function == 5 + assert get_list_length() == 5 + assert get_list_length_with_partial() == 5 + assert get_list_length_with_function() == 5 end defmacrop get_string_length do @@ -403,16 +403,16 @@ defmodule Kernel.QuoteTest.ImportsHygieneTest do test "lazy expand imports" do import Kernel, except: [length: 1] import String, only: [length: 1] - assert get_string_length == 5 + assert get_string_length() == 5 end test "lazy expand imports no conflicts" do import Kernel, except: [length: 1] import String, only: [length: 1] - assert get_list_length == 5 - assert get_list_length_with_partial == 5 - assert get_list_length_with_function == 5 + assert get_list_length() == 5 + assert get_list_length_with_partial() == 5 + assert get_list_length_with_function() == 5 end defmacrop with_length do @@ -424,7 +424,7 @@ defmodule Kernel.QuoteTest.ImportsHygieneTest do end test "explicitly overridden imports" do - assert with_length == 5 + assert with_length() == 5 end end diff --git a/lib/elixir/test/elixir/kernel/raise_test.exs b/lib/elixir/test/elixir/kernel/raise_test.exs index 7bd275257f8..8915b1d9264 100644 --- a/lib/elixir/test/elixir/kernel/raise_test.exs +++ b/lib/elixir/test/elixir/kernel/raise_test.exs @@ -391,7 +391,7 @@ defmodule Kernel.RaiseTest do result = try do DoNotExist.for_sure() rescue - x in exceptions -> Exception.message(x) + x in exceptions() -> Exception.message(x) end assert result == "function DoNotExist.for_sure/0 is undefined (module DoNotExist is not available)" diff --git a/lib/elixir/test/elixir/kernel/warning_test.exs b/lib/elixir/test/elixir/kernel/warning_test.exs index bb5843f2db6..b23216f997e 100644 --- a/lib/elixir/test/elixir/kernel/warning_test.exs +++ b/lib/elixir/test/elixir/kernel/warning_test.exs @@ -172,8 +172,8 @@ defmodule Kernel.WarningTest do assert capture_err(fn -> Code.eval_string """ defmodule Sample do - defp a, do: b - defp b, do: a + defp a, do: b() + defp b, do: a() end """ end) =~ "function a/0 is unused" @@ -383,7 +383,7 @@ defmodule Kernel.WarningTest do defmodule Sample2 do import Sample1 - generate + generate() end """ end) == "" @@ -434,7 +434,7 @@ defmodule Kernel.WarningTest do assert capture_err(fn -> Code.eval_string """ defmodule Sample do - def hello, do: world + def hello, do: world() defp world, do: :ok defoverridable [hello: 0] def hello, do: :ok @@ -449,7 +449,7 @@ defmodule Kernel.WarningTest do assert capture_err(fn -> Code.eval_string """ defmodule Sample do - def hello, do: world + def hello, do: world() defp world, do: :ok defoverridable [hello: 0, world: 0] end @@ -702,6 +702,21 @@ defmodule Kernel.WarningTest do end) =~ "parentheses are required when piping into a function call" end + test "variable is being expanded to function call" do + output = capture_err(fn -> + Code.eval_string """ + self + defmodule Sample do + def my_node(), do: node + end + """ + end) + assert output =~ "variable \"self\" does not exist and is being expanded to \"self()\"" + assert output =~ "variable \"node\" does not exist and is being expanded to \"node()\"" + after + purge Sample + end + defp purge(list) when is_list(list) do Enum.each list, &purge/1 end diff --git a/lib/elixir/test/elixir/kernel_test.exs b/lib/elixir/test/elixir/kernel_test.exs index 0ccb21b11ed..11777db77f6 100644 --- a/lib/elixir/test/elixir/kernel_test.exs +++ b/lib/elixir/test/elixir/kernel_test.exs @@ -255,7 +255,7 @@ defmodule KernelTest do assert is_list Kernel.__info__(:exports) end - def exported?, do: not_exported? + def exported?, do: not_exported?() defp not_exported?, do: true test "function_exported?/3" do @@ -731,7 +731,7 @@ defmodule KernelTest do end test "nil values" do - destructure [a, b, c], a_nil + destructure [a, b, c], a_nil() assert a == nil assert b == nil assert c == nil @@ -740,7 +740,7 @@ defmodule KernelTest do test "invalid match" do a = List.first([3]) assert_raise MatchError, fn -> - destructure [^a, _b, _c], a_list + destructure [^a, _b, _c], a_list() end end diff --git a/lib/elixir/test/elixir/path_test.exs b/lib/elixir/test/elixir/path_test.exs index 1aefe67a59c..7368bab68a6 100644 --- a/lib/elixir/test/elixir/path_test.exs +++ b/lib/elixir/test/elixir/path_test.exs @@ -32,7 +32,7 @@ defmodule PathTest do File.rm_rf tmp_path("wildcard") end - if windows? do + if windows?() do test "relative win" do assert Path.relative("C:/usr/local/bin") == "usr/local/bin" assert Path.relative("C:\\usr\\local\\bin") == "usr\\local\\bin" @@ -237,7 +237,7 @@ defmodule PathTest do assert Path.split([?/, "foo/bar"]) == ["/", "foo", "bar"] end - if windows? do + if windows?() do defp strip_drive_letter_if_windows([_d, ?: | rest]), do: rest defp strip_drive_letter_if_windows(<<_d, ?:, rest::binary>>), do: rest else diff --git a/lib/elixir/test/elixir/process_test.exs b/lib/elixir/test/elixir/process_test.exs index 722469ba94d..736f807bff9 100644 --- a/lib/elixir/test/elixir/process_test.exs +++ b/lib/elixir/test/elixir/process_test.exs @@ -20,7 +20,7 @@ defmodule ProcessTest do test "group_leader/2 and group_leader/0" do another = spawn_link(fn -> :timer.sleep(1000) end) - assert Process.group_leader(self, another) + assert Process.group_leader(self(), another) assert Process.group_leader == another end @@ -51,15 +51,15 @@ defmodule ProcessTest do assert Process.info(pid, [:registered_name]) == nil - assert Process.info(self, :registered_name) == + assert Process.info(self(), :registered_name) == {:registered_name, []} - assert Process.info(self, [:registered_name]) == + assert Process.info(self(), [:registered_name]) == [registered_name: []] - Process.register(self, __MODULE__) - assert Process.info(self, :registered_name) == + Process.register(self(), __MODULE__) + assert Process.info(self(), :registered_name) == {:registered_name, __MODULE__} - assert Process.info(self, [:registered_name]) == + assert Process.info(self(), [:registered_name]) == [registered_name: __MODULE__] end diff --git a/lib/elixir/test/elixir/protocol_test.exs b/lib/elixir/test/elixir/protocol_test.exs index 85246820139..33b881999f2 100644 --- a/lib/elixir/test/elixir/protocol_test.exs +++ b/lib/elixir/test/elixir/protocol_test.exs @@ -77,9 +77,9 @@ defmodule ProtocolTest do assert is_nil Sample.impl_for("foo") assert is_nil Sample.impl_for(<<1>>) assert is_nil Sample.impl_for(%{}) - assert is_nil Sample.impl_for(self) + assert is_nil Sample.impl_for(self()) assert is_nil Sample.impl_for(hd(:erlang.ports)) - assert is_nil Sample.impl_for(make_ref) + assert is_nil Sample.impl_for(make_ref()) assert Sample.impl_for(%ImplStruct{}) == Sample.ProtocolTest.ImplStruct @@ -88,11 +88,11 @@ defmodule ProtocolTest do end test "protocol implementation with any and structs fallback" do - assert WithAny.impl_for(%NoImplStruct{}) == WithAny.Any - assert WithAny.impl_for(%ImplStruct{}) == WithAny.Any # Derived + assert WithAny.impl_for(%NoImplStruct{}) == WithAny.Any + assert WithAny.impl_for(%ImplStruct{}) == WithAny.Any # Derived assert WithAny.impl_for(%{__struct__: "foo"}) == WithAny.Map - assert WithAny.impl_for(%{}) == WithAny.Map - assert WithAny.impl_for(self) == WithAny.Any + assert WithAny.impl_for(%{}) == WithAny.Map + assert WithAny.impl_for(self()) == WithAny.Any end test "protocol not implemented" do @@ -341,10 +341,10 @@ defmodule Protocol.ConsolidationTest do assert is_nil Sample.impl_for({1, 2, 3}) assert is_nil Sample.impl_for("foo") assert is_nil Sample.impl_for(<<1>>) - assert is_nil Sample.impl_for(self) + assert is_nil Sample.impl_for(self()) assert is_nil Sample.impl_for(%{}) assert is_nil Sample.impl_for(hd(:erlang.ports)) - assert is_nil Sample.impl_for(make_ref) + assert is_nil Sample.impl_for(make_ref()) assert Sample.impl_for(%ImplStruct{}) == Sample.Protocol.ConsolidationTest.ImplStruct @@ -353,11 +353,11 @@ defmodule Protocol.ConsolidationTest do end test "consolidated implementations with any and tuple fallback" do - assert WithAny.impl_for(%NoImplStruct{}) == WithAny.Any - assert WithAny.impl_for(%ImplStruct{}) == WithAny.Any # Derived + assert WithAny.impl_for(%NoImplStruct{}) == WithAny.Any + assert WithAny.impl_for(%ImplStruct{}) == WithAny.Any # Derived assert WithAny.impl_for(%{__struct__: "foo"}) == WithAny.Map - assert WithAny.impl_for(%{}) == WithAny.Map - assert WithAny.impl_for(self) == WithAny.Any + assert WithAny.impl_for(%{}) == WithAny.Map + assert WithAny.impl_for(self()) == WithAny.Any end test "consolidation keeps docs" do diff --git a/lib/elixir/test/elixir/stream_test.exs b/lib/elixir/test/elixir/stream_test.exs index df4f2442a7e..1c8a24798fa 100644 --- a/lib/elixir/test/elixir/stream_test.exs +++ b/lib/elixir/test/elixir/stream_test.exs @@ -200,7 +200,7 @@ defmodule StreamTest do end test "drop/2 with negative count stream entries" do - par = self + par = self() pid = spawn_link fn -> Enum.each Stream.drop(&inbox_stream/2, -3), fn x -> send par, {:stream, x} end diff --git a/lib/elixir/test/elixir/supervisor_test.exs b/lib/elixir/test/elixir/supervisor_test.exs index 36ca3b3ffb7..7f257ecc04f 100644 --- a/lib/elixir/test/elixir/supervisor_test.exs +++ b/lib/elixir/test/elixir/supervisor_test.exs @@ -18,7 +18,7 @@ defmodule SupervisorTest do # There is a race condition between genserver terminations. # So we will explicitly unregister it here. try do - self |> Process.info(:registered_name) |> elem(1) |> Process.unregister + self() |> Process.info(:registered_name) |> elem(1) |> Process.unregister rescue _ -> :ok end diff --git a/lib/elixir/test/elixir/system_test.exs b/lib/elixir/test/elixir/system_test.exs index a0ab6f0528b..2a1609b16b7 100644 --- a/lib/elixir/test/elixir/system_test.exs +++ b/lib/elixir/test/elixir/system_test.exs @@ -75,7 +75,7 @@ defmodule SystemTest do assert System.get_env(@test_var) == "OTHER_SAMPLE" end - if windows? do + if windows?() do test "cmd/2 win" do assert {"hello\r\n", 0} = System.cmd "cmd", ~w[/c echo hello] end diff --git a/lib/elixir/test/elixir/task/supervisor_test.exs b/lib/elixir/test/elixir/task/supervisor_test.exs index 2886094392d..f2ce9682301 100644 --- a/lib/elixir/test/elixir/task/supervisor_test.exs +++ b/lib/elixir/test/elixir/task/supervisor_test.exs @@ -33,7 +33,7 @@ defmodule Task.SupervisorTest do assert is_reference task.ref # Assert the link - {:links, links} = Process.info(self, :links) + {:links, links} = Process.info(self(), :links) assert task.pid in links receive do: (:ready -> :ok) @@ -76,7 +76,7 @@ defmodule Task.SupervisorTest do assert is_reference task.ref # Refute the link - {:links, links} = Process.info(self, :links) + {:links, links} = Process.info(self(), :links) refute task.pid in links receive do: (:ready -> :ok) @@ -112,7 +112,7 @@ defmodule Task.SupervisorTest do {:ok, pid} = Task.Supervisor.start_child(config[:supervisor], fun) assert Task.Supervisor.children(config[:supervisor]) == [pid] - {:links, links} = Process.info(self, :links) + {:links, links} = Process.info(self(), :links) refute pid in links receive do: (:ready -> :ok) @@ -127,7 +127,7 @@ defmodule Task.SupervisorTest do {:ok, pid} = Task.Supervisor.start_child(config[:supervisor], __MODULE__, :wait_and_send, [self(), :done]) assert Task.Supervisor.children(config[:supervisor]) == [pid] - {:links, links} = Process.info(self, :links) + {:links, links} = Process.info(self(), :links) refute pid in links receive do: (:ready -> :ok) diff --git a/lib/elixir/test/elixir/task_test.exs b/lib/elixir/test/elixir/task_test.exs index 9eaf2231460..65a9874daac 100644 --- a/lib/elixir/test/elixir/task_test.exs +++ b/lib/elixir/test/elixir/task_test.exs @@ -22,7 +22,7 @@ defmodule TaskTest do end defp create_dummy_task do - %Task{ref: make_ref, pid: spawn(fn() -> :ok end), owner: self()} + %Task{ref: make_ref(), pid: spawn(fn() -> :ok end), owner: self()} end test "async/1" do @@ -36,7 +36,7 @@ defmodule TaskTest do assert is_reference task.ref # Assert the link - {:links, links} = Process.info(self, :links) + {:links, links} = Process.info(self(), :links) assert task.pid in links receive do: (:ready -> :ok) @@ -58,7 +58,7 @@ defmodule TaskTest do task = Task.async(__MODULE__, :wait_and_send, [self(), :done]) assert task.__struct__ == Task - {:links, links} = Process.info(self, :links) + {:links, links} = Process.info(self(), :links) assert task.pid in links receive do: (:ready -> :ok) @@ -76,7 +76,7 @@ defmodule TaskTest do fun = fn -> wait_and_send(parent, :done) end {:ok, pid} = Task.start(fun) - {:links, links} = Process.info(self, :links) + {:links, links} = Process.info(self(), :links) refute pid in links receive do: (:ready -> :ok) @@ -91,7 +91,7 @@ defmodule TaskTest do test "start/3" do {:ok, pid} = Task.start(__MODULE__, :wait_and_send, [self(), :done]) - {:links, links} = Process.info(self, :links) + {:links, links} = Process.info(self(), :links) refute pid in links receive do: (:ready -> :ok) @@ -107,7 +107,7 @@ defmodule TaskTest do fun = fn -> wait_and_send(parent, :done) end {:ok, pid} = Task.start_link(fun) - {:links, links} = Process.info(self, :links) + {:links, links} = Process.info(self(), :links) assert pid in links receive do: (:ready -> :ok) @@ -122,7 +122,7 @@ defmodule TaskTest do test "start_link/3" do {:ok, pid} = Task.start_link(__MODULE__, :wait_and_send, [self(), :done]) - {:links, links} = Process.info(self, :links) + {:links, links} = Process.info(self(), :links) assert pid in links receive do: (:ready -> :ok) @@ -201,9 +201,9 @@ defmodule TaskTest do end test "yield/2 returns {:ok, result} when reply and :DOWN in message queue" do - task = %Task{ref: make_ref, owner: self()} + task = %Task{ref: make_ref(), owner: self()} send(self(), {task.ref, :result}) - send(self(), {:DOWN, task.ref, :process, self, :abnormal}) + send(self(), {:DOWN, task.ref, :process, self(), :abnormal}) assert Task.yield(task, 0) == {:ok, :result} refute_received {:DOWN, _, _, _, _} end @@ -232,9 +232,9 @@ defmodule TaskTest do end test "yield_many/2 returns {:ok, result} when reply and :DOWN in message queue" do - task = %Task{ref: make_ref, owner: self()} + task = %Task{ref: make_ref(), owner: self()} send(self(), {task.ref, :result}) - send(self(), {:DOWN, task.ref, :process, self, :abnormal}) + send(self(), {:DOWN, task.ref, :process, self(), :abnormal}) assert Task.yield_many([task], 0) == [{task, {:ok, :result}}] refute_received {:DOWN, _, _, _, _} end @@ -336,7 +336,7 @@ defmodule TaskTest do end test "shutdown/2 raises if task pid is nil" do - task = %Task{ref: make_ref, pid: nil} + task = %Task{ref: make_ref(), pid: nil} assert_raise ArgumentError, "task #{inspect task} does not have an associated task process", fn -> Task.shutdown(task) end end diff --git a/lib/elixir/test/elixir/test_helper.exs b/lib/elixir/test/elixir/test_helper.exs index dd4156662d8..d919fb4ec04 100644 --- a/lib/elixir/test/elixir/test_helper.exs +++ b/lib/elixir/test/elixir/test_helper.exs @@ -18,15 +18,15 @@ defmodule PathHelpers do end def fixture_path(extra) do - Path.join(fixture_path, extra) + Path.join(fixture_path(), extra) end def tmp_path(extra) do - Path.join(tmp_path, extra) + Path.join(tmp_path(), extra) end def elixir(args) do - runcmd(elixir_executable, args) + runcmd(elixir_executable(), args) end def elixir_executable do @@ -34,7 +34,7 @@ defmodule PathHelpers do end def elixirc(args) do - runcmd(elixirc_executable, args) + runcmd(elixirc_executable(), args) end def elixirc_executable do @@ -49,11 +49,11 @@ defmodule PathHelpers do end defp runcmd(executable, args) do - :os.cmd :binary.bin_to_list("#{executable} #{IO.chardata_to_string(args)}#{redirect_std_err_on_win}") + :os.cmd :binary.bin_to_list("#{executable} #{IO.chardata_to_string(args)}#{redirect_std_err_on_win()}") end defp executable_path(name) do - Path.expand("../../../../bin/#{name}#{executable_extension}", __DIR__) + Path.expand("../../../../bin/#{name}#{executable_extension()}", __DIR__) end if match? {:win32, _}, :os.type do diff --git a/lib/ex_unit/examples/one_of_each.exs b/lib/ex_unit/examples/one_of_each.exs index 789a0e4a7b8..2a85061e575 100644 --- a/lib/ex_unit/examples/one_of_each.exs +++ b/lib/ex_unit/examples/one_of_each.exs @@ -94,12 +94,12 @@ defmodule TestOneOfEach do end test "19. refute a message is received within a timeout" do - send self, {:hello, "Dave"} + send self(), {:hello, "Dave"} refute_receive {:hello, _}, 1000 end test "20. refute a message is ready to be received" do - send self, :hello_again + send self(), :hello_again refute_received :hello_again end diff --git a/lib/ex_unit/lib/ex_unit/assertions.ex b/lib/ex_unit/lib/ex_unit/assertions.ex index 3240117effc..ead1698d9ff 100644 --- a/lib/ex_unit/lib/ex_unit/assertions.ex +++ b/lib/ex_unit/lib/ex_unit/assertions.ex @@ -330,10 +330,10 @@ defmodule ExUnit.Assertions do ## Examples - send self, :hello + send self(), :hello assert_received :hello - send self, :bye + send self(), :bye assert_received :hello, "Oh No!" ** (ExUnit.AssertionError) Oh No! Process mailbox: @@ -341,7 +341,7 @@ defmodule ExUnit.Assertions do You can also match against specific patterns: - send self, {:hello, "world"} + send self(), {:hello, "world"} assert_received {:hello, _} """ @@ -631,10 +631,10 @@ defmodule ExUnit.Assertions do ## Examples - send self, :hello + send self(), :hello refute_received :bye - send self, :hello + send self(), :hello refute_received :hello, "Oh No!" ** (ExUnit.AssertionError) Oh No! Process mailbox: diff --git a/lib/ex_unit/lib/ex_unit/callbacks.ex b/lib/ex_unit/lib/ex_unit/callbacks.ex index f94301a0439..76fd73aeca2 100644 --- a/lib/ex_unit/lib/ex_unit/callbacks.ex +++ b/lib/ex_unit/lib/ex_unit/callbacks.ex @@ -207,8 +207,8 @@ defmodule ExUnit.Callbacks do guarantee the callback will be invoked only once. """ @spec on_exit(term, (() -> term)) :: :ok - def on_exit(ref \\ make_ref, callback) do - case ExUnit.OnExitHandler.add(self, ref, callback) do + def on_exit(ref \\ make_ref(), callback) do + case ExUnit.OnExitHandler.add(self(), ref, callback) do :ok -> :ok :error -> raise ArgumentError, "on_exit/1 callback can only be invoked from the test process" diff --git a/lib/ex_unit/lib/ex_unit/case.ex b/lib/ex_unit/lib/ex_unit/case.ex index 2bcaa2fadfe..85daed93434 100644 --- a/lib/ex_unit/lib/ex_unit/case.ex +++ b/lib/ex_unit/lib/ex_unit/case.ex @@ -276,7 +276,7 @@ defmodule ExUnit.Case do """ defmacro test(message) do - quote bind_quoted: binding do + quote bind_quoted: binding() do name = ExUnit.Case.register_test(__ENV__, :test, message, [:not_implemented]) def unquote(name)(_), do: flunk("Not yet implemented") end diff --git a/lib/ex_unit/lib/ex_unit/doc_test.ex b/lib/ex_unit/lib/ex_unit/doc_test.ex index 29bb56e3a21..e9367966224 100644 --- a/lib/ex_unit/lib/ex_unit/doc_test.ex +++ b/lib/ex_unit/lib/ex_unit/doc_test.ex @@ -192,7 +192,7 @@ defmodule ExUnit.DocTest do end end - tests = quote bind_quoted: binding do + tests = quote bind_quoted: binding() do file = "(for doctest at) " <> Path.relative_to_cwd(mod.__info__(:compile)[:source]) for {name, test} <- ExUnit.DocTest.__doctests__(mod, opts) do @tag :doctest diff --git a/lib/ex_unit/lib/ex_unit/runner.ex b/lib/ex_unit/lib/ex_unit/runner.ex index d71485b202f..edf81e855e4 100644 --- a/lib/ex_unit/lib/ex_unit/runner.ex +++ b/lib/ex_unit/lib/ex_unit/runner.ex @@ -133,7 +133,7 @@ defmodule ExUnit.Runner do # tests but we do send the notifications to formatter. Enum.each pending, &run_test(config, &1, []) EM.case_finished(config.manager, test_case) - send pid, {self, :case_finished, test_case} + send pid, {self(), :case_finished, test_case} end defp prepare_tests(config, tests) do @@ -151,20 +151,20 @@ defmodule ExUnit.Runner do end defp spawn_case(config, test_case, tests) do - parent = self + parent = self() {case_pid, case_ref} = spawn_monitor(fn -> - ExUnit.OnExitHandler.register(self) + ExUnit.OnExitHandler.register(self()) case exec_case_setup(test_case) do {:ok, test_case, context} -> Enum.each tests, &run_test(config, &1, context) - send parent, {self, :case_finished, test_case, []} + send parent, {self(), :case_finished, test_case, []} {:error, test_case} -> failed_tests = Enum.map tests, & %{&1 | state: {:invalid, test_case}} - send parent, {self, :case_finished, test_case, failed_tests} + send parent, {self(), :case_finished, test_case, failed_tests} end exit(:shutdown) @@ -240,7 +240,7 @@ defmodule ExUnit.Runner do {test_pid, test_ref} = spawn_monitor(fn -> - ExUnit.OnExitHandler.register(self) + ExUnit.OnExitHandler.register(self()) {us, test} = :timer.tc(fn -> @@ -252,7 +252,7 @@ defmodule ExUnit.Runner do end end) - send parent, {self, :test_finished, %{test | time: us}} + send parent, {self(), :test_finished, %{test | time: us}} exit(:shutdown) end) diff --git a/lib/ex_unit/test/ex_unit/assertions_test.exs b/lib/ex_unit/test/ex_unit/assertions_test.exs index 801912fa6e3..09ecb081272 100644 --- a/lib/ex_unit/test/ex_unit/assertions_test.exs +++ b/lib/ex_unit/test/ex_unit/assertions_test.exs @@ -153,20 +153,20 @@ defmodule ExUnit.AssertionsTest do end test "assert receive waits" do - parent = self + parent = self() spawn fn -> send parent, :hello end :hello = assert_receive :hello end test "assert received does not wait" do - send self, :hello + send self(), :hello :hello = assert_received :hello end @received :hello test "assert received with module attribute" do - send self, :hello + send self(), :hello :hello = assert_received @received end @@ -235,7 +235,7 @@ defmodule ExUnit.AssertionsTest do end test "assert received when different message" do - send self, {:message, :not_expected, :at_all} + send self(), {:message, :not_expected, :at_all} try do "This should never be tested" = assert_received :hello rescue @@ -247,7 +247,7 @@ defmodule ExUnit.AssertionsTest do end test "assert received when different message having more than 10 on mailbox" do - for i <- 1..11, do: send(self, {:message, i}) + for i <- 1..11, do: send(self(), {:message, i}) try do "This should never be tested" = assert_received x when x == :hello rescue @@ -261,7 +261,7 @@ defmodule ExUnit.AssertionsTest do end test "assert received leaks" do - send self, {:hello, :world} + send self(), {:hello, :world} assert_received {:hello, world} :world = world end @@ -275,7 +275,7 @@ defmodule ExUnit.AssertionsTest do end test "refute received when equal" do - send self, :hello + send self(), :hello try do "This should never be tested" = refute_received :hello rescue @@ -573,7 +573,7 @@ defmodule ExUnit.AssertionsTest do end test "flunk" do - "This should never be tested" = flunk + "This should never be tested" = flunk() rescue error in [ExUnit.AssertionError] -> "Flunked!" = error.message diff --git a/lib/ex_unit/test/ex_unit/callbacks_test.exs b/lib/ex_unit/test/ex_unit/callbacks_test.exs index 7d1c4948b07..f601aa0db8e 100644 --- a/lib/ex_unit/test/ex_unit/callbacks_test.exs +++ b/lib/ex_unit/test/ex_unit/callbacks_test.exs @@ -74,7 +74,7 @@ defmodule ExUnit.CallbacksTest do use ExUnit.Case setup _ do - :ok = error + :ok = error() end test "ok" do @@ -94,7 +94,7 @@ defmodule ExUnit.CallbacksTest do use ExUnit.Case setup_all _ do - :ok = error + :ok = error() end test "ok" do @@ -114,7 +114,7 @@ defmodule ExUnit.CallbacksTest do use ExUnit.Case test "ok" do - on_exit fn -> :ok = error end + on_exit fn -> :ok = error() end :ok end @@ -165,7 +165,7 @@ defmodule ExUnit.CallbacksTest do receive do: (:ready -> :ok) on_exit fn -> - send pid, {:on_exit, self} + send pid, {:on_exit, self()} assert_receive :done IO.puts "on_exit run" end @@ -229,7 +229,7 @@ defmodule ExUnit.CallbacksTest do end end - no_formatters! + no_formatters!() ExUnit.Server.cases_loaded() output = capture_io(fn -> ExUnit.run end) @@ -273,7 +273,7 @@ defmodule ExUnit.CallbacksTest do end end - no_formatters! + no_formatters!() ExUnit.Server.cases_loaded() output = capture_io(fn -> ExUnit.run end) diff --git a/lib/ex_unit/test/ex_unit/capture_io_test.exs b/lib/ex_unit/test/ex_unit/capture_io_test.exs index 7b4ed7b6ad4..5ab0697a1b2 100644 --- a/lib/ex_unit/test/ex_unit/capture_io_test.exs +++ b/lib/ex_unit/test/ex_unit/capture_io_test.exs @@ -18,7 +18,7 @@ defmodule ExUnit.CaptureIOTest do end def get_line(device \\ Process.group_leader) do - send device, {:io_request, self, device, {:get_until, :unicode, "", __MODULE__, :until_new_line, [?\n]}} + send device, {:io_request, self(), device, {:get_until, :unicode, "", __MODULE__, :until_new_line, [?\n]}} receive do {:io_reply, _, data} -> data end @@ -344,8 +344,8 @@ defmodule ExUnit.CaptureIOTest do end defp send_and_receive_io(req) do - send :erlang.group_leader, {:io_request, self, self, req} - s = self + send :erlang.group_leader, {:io_request, self(), self(), req} + s = self() receive do {:io_reply, ^s, res} -> res end diff --git a/lib/ex_unit/test/ex_unit/doc_test_test.exs b/lib/ex_unit/test/ex_unit/doc_test_test.exs index 12a6919b0b8..27d787fd60d 100644 --- a/lib/ex_unit/test/ex_unit/doc_test_test.exs +++ b/lib/ex_unit/test/ex_unit/doc_test_test.exs @@ -4,9 +4,9 @@ import ExUnit.TestHelpers defmodule ExUnit.DocTestTest.GoodModule do @doc """ - iex> test_fun + iex> test_fun() 1 - iex> test_fun + 1 + iex> test_fun() + 1 2 """ def test_fun, do: 1 @@ -74,17 +74,17 @@ end |> write_beam defmodule ExUnit.DocTestTest.SomewhatGoodModuleWithOnly do @doc """ - iex> test_fun1 + iex> test_fun1() 1 - iex> test_fun1 + 1 + iex> test_fun1() + 1 2 """ def test_fun1, do: 1 @doc """ - iex> test_fun2 + iex> test_fun2() 1 - iex> test_fun2 + 1 + iex> test_fun2() + 1 1 """ def test_fun2, do: 1 @@ -97,17 +97,17 @@ defmodule ExUnit.DocTestTest.SomewhatGoodModuleWithExcept do """ @doc """ - iex> test_fun1 + iex> test_fun1() 1 - iex> test_fun1 + 1 + iex> test_fun1() + 1 2 """ def test_fun1, do: 1 @doc """ - iex> test_fun2 + iex> test_fun2() 1 - iex> test_fun2 + 1 + iex> test_fun2() + 1 1 """ def test_fun2, do: 1 diff --git a/lib/ex_unit/test/ex_unit/formatter_test.exs b/lib/ex_unit/test/ex_unit/formatter_test.exs index 45d8b828880..7a8cff36a3d 100644 --- a/lib/ex_unit/test/ex_unit/formatter_test.exs +++ b/lib/ex_unit/test/ex_unit/formatter_test.exs @@ -72,11 +72,11 @@ defmodule ExUnit.FormatterTest do end test "formats test EXITs" do - failure = [{{:EXIT, self}, 1, []}] + failure = [{{:EXIT, self()}, 1, []}] assert format_test_failure(test(), failure, 1, 80, &formatter/2) == """ 1) world (Hello) test/ex_unit/formatter_test.exs:1 - ** (EXIT from #{inspect self}) 1 + ** (EXIT from #{inspect self()}) 1 """ end diff --git a/lib/iex/lib/iex.ex b/lib/iex/lib/iex.ex index 662faf5c7e7..395486c3640 100644 --- a/lib/iex/lib/iex.ex +++ b/lib/iex/lib/iex.ex @@ -414,7 +414,7 @@ defmodule IEx do """ defmacro pry(timeout \\ 5000) do quote do - IEx.pry(binding, __ENV__, unquote(timeout)) + IEx.pry(binding(), __ENV__, unquote(timeout)) end end @@ -428,7 +428,7 @@ defmodule IEx do """ def pry(binding, env, timeout) do opts = [binding: binding, dot_iex_path: "", env: env, prefix: "pry"] - meta = "#{inspect self} at #{Path.relative_to_cwd(env.file)}:#{env.line}" + meta = "#{inspect self()} at #{Path.relative_to_cwd(env.file)}:#{env.line}" desc = if File.regular?(env.file) do parse_file(env) @@ -496,9 +496,9 @@ defmodule IEx do glnode = node gl expand_fun = - if glnode != node do + if glnode != node() do _ = ensure_module_exists glnode, IEx.Remsh - IEx.Remsh.expand node + IEx.Remsh.expand node() else &IEx.Autocomplete.expand(&1) end @@ -518,7 +518,7 @@ defmodule IEx do end defp run_after_spawn do - _ = for fun <- Enum.reverse(after_spawn), do: fun.() + _ = for fun <- Enum.reverse(after_spawn()), do: fun.() :ok end end diff --git a/lib/iex/lib/iex/cli.ex b/lib/iex/lib/iex/cli.ex index aa3a99bc49c..c6bef37c2b5 100644 --- a/lib/iex/lib/iex/cli.ex +++ b/lib/iex/lib/iex/cli.ex @@ -50,8 +50,8 @@ defmodule IEx.CLI do a dumb terminal version is started instead. """ def start do - if tty_works? do - :user_drv.start([:"tty_sl -c -e", tty_args]) + if tty_works?() do + :user_drv.start([:"tty_sl -c -e", tty_args()]) else :application.set_env(:stdlib, :shell_prompt_func, {__MODULE__, :prompt}) @@ -92,7 +92,7 @@ defmodule IEx.CLI do abort "In order to use --remsh, you need to name the current node using --name or --sname. Aborting..." end else - {:erlang, :apply, [local_start_function, []]} + {:erlang, :apply, [local_start_function(), []]} end end @@ -101,7 +101,7 @@ defmodule IEx.CLI do end def remote_start(parent, ref) do - send parent, {:begin, ref, self} + send parent, {:begin, ref, self()} receive do: ({:done, ^ref} -> :ok) end @@ -110,7 +110,7 @@ defmodule IEx.CLI do end defp remote_start_mfa do - ref = make_ref + ref = make_ref() opts = options() parent = spawn_link fn -> diff --git a/lib/iex/lib/iex/config.ex b/lib/iex/lib/iex/config.ex index 05dfdcc8ee0..b0f3d7aa218 100644 --- a/lib/iex/lib/iex/config.ex +++ b/lib/iex/lib/iex/config.ex @@ -130,7 +130,7 @@ defmodule IEx.Config do cond do Keyword.has_key?(inspect_options, :width) -> inspect_options - colors_enabled? -> + colors_enabled?() -> [width: width()] ++ inspect_options true -> inspect_options diff --git a/lib/iex/lib/iex/evaluator.ex b/lib/iex/lib/iex/evaluator.ex index 2a622350e59..b8f07d2b515 100644 --- a/lib/iex/lib/iex/evaluator.ex +++ b/lib/iex/lib/iex/evaluator.ex @@ -12,12 +12,12 @@ defmodule IEx.Evaluator do """ def init(server, leader, opts) do old_leader = Process.group_leader - Process.group_leader(self, leader) + Process.group_leader(self(), leader) try do loop(server, IEx.History.init, loop_state(opts)) after - Process.group_leader(self, old_leader) + Process.group_leader(self(), old_leader) end end @@ -25,7 +25,7 @@ defmodule IEx.Evaluator do receive do {:eval, ^server, code, iex_state} -> {result, history, state} = eval(code, iex_state, history, state) - send server, {:evaled, self, result} + send server, {:evaled, self(), result} loop(server, history, state) {:peek_env, receiver} -> send receiver, {:peek_env, state.env} diff --git a/lib/iex/lib/iex/helpers.ex b/lib/iex/lib/iex/helpers.ex index f9827fe57d7..a8fb926c999 100644 --- a/lib/iex/lib/iex/helpers.ex +++ b/lib/iex/lib/iex/helpers.ex @@ -75,7 +75,7 @@ defmodule IEx.Helpers do debugging purposes. Do not depend on it in production code. """ def recompile do - if mix_started? do + if mix_started?() do config = Mix.Project.config reenable_tasks(config) Mix.Task.run("compile") @@ -157,7 +157,7 @@ defmodule IEx.Helpers do else IO.puts "Cannot clear the screen because ANSI escape codes are not enabled on this shell" end - dont_display_result + dont_display_result() end @doc """ @@ -165,7 +165,7 @@ defmodule IEx.Helpers do """ def h() do IEx.Introspection.h(IEx.Helpers) - dont_display_result + dont_display_result() end @doc """ @@ -330,7 +330,7 @@ defmodule IEx.Helpers do For instance, v(-1) returns the result of the last evaluated expression. """ def v(n \\ -1) do - IEx.History.nth(history, n) |> elem(2) + IEx.History.nth(history(), n) |> elem(2) end @doc """ @@ -404,7 +404,7 @@ defmodule IEx.Helpers do IO.puts IEx.color(:eval_info, " #{info}") end - dont_display_result + dont_display_result() end @doc """ @@ -438,7 +438,7 @@ defmodule IEx.Helpers do """ def pwd do IO.puts IEx.color(:eval_info, System.cwd!) - dont_display_result + dont_display_result() end @doc """ @@ -446,7 +446,7 @@ defmodule IEx.Helpers do """ def cd(directory) when is_binary(directory) do case File.cd(expand_home(directory)) do - :ok -> pwd + :ok -> pwd() {:error, :enoent} -> IO.puts IEx.color(:eval_error, "No directory #{directory}") end @@ -530,8 +530,8 @@ defmodule IEx.Helpers do """ def respawn do if whereis = IEx.Server.whereis do - send whereis, {:respawn, self} - dont_display_result + send whereis, {:respawn, self()} + dont_display_result() end end diff --git a/lib/iex/lib/iex/introspection.ex b/lib/iex/lib/iex/introspection.ex index 57d1048975c..09be4694b4a 100644 --- a/lib/iex/lib/iex/introspection.ex +++ b/lib/iex/lib/iex/introspection.ex @@ -28,12 +28,12 @@ defmodule IEx.Introspection do {:error, reason} -> puts_error("Could not load module #{inspect module}, got: #{reason}") end - dont_display_result + dont_display_result() end def h(_) do puts_error("Invalid arguments for h helper") - dont_display_result + dont_display_result() end @doc """ @@ -48,7 +48,7 @@ defmodule IEx.Introspection do unless printed?, do: nodocs(function) - dont_display_result + dont_display_result() end def h(module, function) when is_atom(module) and is_atom(function) do @@ -61,7 +61,7 @@ defmodule IEx.Introspection do nodocs("#{inspect module}.#{function}") end - dont_display_result + dont_display_result() end defp h_mod_fun(mod, fun) when is_atom(mod) do @@ -88,7 +88,7 @@ defmodule IEx.Introspection do unless printed?, do: nodocs("#{function}/#{arity}") - dont_display_result + dont_display_result() end def h(module, function, arity) when is_atom(module) and is_atom(function) and is_integer(arity) do @@ -101,7 +101,7 @@ defmodule IEx.Introspection do nodocs("#{inspect module}.#{function}/#{arity}") end - dont_display_result + dont_display_result() end defp h_mod_fun_arity(mod, fun, arity) when is_atom(mod) do @@ -194,7 +194,7 @@ defmodule IEx.Introspection do :not_found -> puts_error("No callbacks for #{inspect mod} were found") end - dont_display_result + dont_display_result() end @doc """ @@ -209,7 +209,7 @@ defmodule IEx.Introspection do :not_found -> nodocs("#{inspect mod}.#{fun}") end - dont_display_result + dont_display_result() end @doc """ @@ -224,7 +224,7 @@ defmodule IEx.Introspection do :not_found -> nodocs("#{inspect mod}.#{fun}/#{arity}") end - dont_display_result + dont_display_result() end defp print_callback_docs(mod, filter, printer) do @@ -281,7 +281,7 @@ defmodule IEx.Introspection do types -> Enum.each(types, &print_type/1) end - dont_display_result + dont_display_result() end @doc """ @@ -303,7 +303,7 @@ defmodule IEx.Introspection do end end - dont_display_result + dont_display_result() end @doc """ @@ -325,7 +325,7 @@ defmodule IEx.Introspection do end end - dont_display_result + dont_display_result() end defp print_type_doc(module, type) do @@ -352,7 +352,7 @@ defmodule IEx.Introspection do end end - dont_display_result + dont_display_result() end @doc """ @@ -373,7 +373,7 @@ defmodule IEx.Introspection do end end - dont_display_result + dont_display_result() end @doc """ @@ -394,7 +394,7 @@ defmodule IEx.Introspection do end end - dont_display_result + dont_display_result() end defp beam_specs(module) do diff --git a/lib/iex/lib/iex/server.ex b/lib/iex/lib/iex/server.ex index 72ab5789fac..dd924f041d5 100644 --- a/lib/iex/lib/iex/server.ex +++ b/lib/iex/lib/iex/server.ex @@ -71,12 +71,12 @@ defmodule IEx.Server do {:error, :no_iex} true -> ref = make_ref() - send server, {:take?, self, ref} + send server, {:take?, self(), ref} receive do ^ref -> - opts = [evaluator: self] ++ opts - send server, {:take, self, identifier, ref, opts} + opts = [evaluator: self()] ++ opts + send server, {:take, self(), identifier, ref, opts} receive do {^ref, nil} -> @@ -140,7 +140,7 @@ defmodule IEx.Server do defp run(opts) when is_list(opts) do IO.puts "Interactive Elixir (#{System.version}) - press Ctrl+C to exit (type h() ENTER for help)" - self_pid = self + self_pid = self() self_leader = Process.group_leader evaluator = opts[:evaluator] || spawn(fn -> IEx.Evaluator.init(self_pid, self_leader, opts) end) @@ -162,7 +162,7 @@ defmodule IEx.Server do Process.delete(:evaluator) Process.demonitor(evaluator_ref, [:flush]) if done? do - send(evaluator, {:done, self}) + send(evaluator, {:done, self()}) end :ok end @@ -179,7 +179,7 @@ defmodule IEx.Server do defp wait_input(state, evaluator, evaluator_ref, input) do receive do {:input, ^input, code} when is_binary(code) -> - send evaluator, {:eval, self, code, state} + send evaluator, {:eval, self(), code, state} wait_eval(evaluator, evaluator_ref) {:input, ^input, {:error, :interrupted}} -> io_error "** (EXIT) interrupted" @@ -275,13 +275,13 @@ defmodule IEx.Server do defp io_get(pid, prefix, counter) do prompt = prompt(prefix, counter) - send pid, {:input, self, IO.gets(:stdio, prompt)} + send pid, {:input, self(), IO.gets(:stdio, prompt)} end defp prompt(prefix, counter) do {mode, prefix} = if Node.alive? do - {:alive_prompt, prefix || remote_prefix} + {:alive_prompt, prefix || remote_prefix()} else {:default_prompt, prefix || "iex"} end @@ -289,7 +289,7 @@ defmodule IEx.Server do prompt = apply(IEx.Config, mode, []) |> String.replace("%counter", to_string(counter)) |> String.replace("%prefix", to_string(prefix)) - |> String.replace("%node", to_string(node)) + |> String.replace("%node", to_string(node())) prompt <> " " end @@ -299,6 +299,6 @@ defmodule IEx.Server do end defp remote_prefix do - if node == node(Process.group_leader), do: "iex", else: "rem" + if node() == node(Process.group_leader), do: "iex", else: "rem" end end diff --git a/lib/iex/test/iex/helpers_test.exs b/lib/iex/test/iex/helpers_test.exs index f261af9b447..4089d1cf9ed 100644 --- a/lib/iex/test/iex/helpers_test.exs +++ b/lib/iex/test/iex/helpers_test.exs @@ -7,17 +7,17 @@ defmodule IEx.HelpersTest do test "clear helper" do Application.put_env(:elixir, :ansi_enabled, true) - assert capture_iex("clear") == "\e[H\e[2J" + assert capture_iex("clear()") == "\e[H\e[2J" Application.put_env(:elixir, :ansi_enabled, false) - assert capture_iex("clear") =~ "Cannot clear the screen because ANSI escape codes are not enabled on this shell" + assert capture_iex("clear()") =~ "Cannot clear the screen because ANSI escape codes are not enabled on this shell" after Application.delete_env(:elixir, :ansi_enabled) end test "h helper" do assert "* IEx.Helpers\n\nWelcome to Interactive Elixir" <> _ - = capture_iex("h") + = capture_iex("h()") end test "h helper module" do @@ -204,18 +204,18 @@ defmodule IEx.HelpersTest do end test "flush helper" do - assert capture_io(fn -> send self(), :hello; flush end) == ":hello\n" + assert capture_io(fn -> send self(), :hello; flush() end) == ":hello\n" end test "pwd helper" do - File.cd! iex_path, fn -> - assert capture_io(fn -> pwd end) =~ ~r"lib[\\/]iex\n$" + File.cd! iex_path(), fn -> + assert capture_io(fn -> pwd() end) =~ ~r"lib[\\/]iex\n$" end end test "ls helper" do - File.cd! iex_path, fn -> - paths = capture_io(fn -> ls end) + File.cd! iex_path(), fn -> + paths = capture_io(fn -> ls() end) |> String.split |> Enum.map(&String.trim/1) @@ -229,8 +229,11 @@ defmodule IEx.HelpersTest do test "import_file helper" do with_file "dot-iex", "variable = :hello\nimport IO", fn -> - assert "** (CompileError) iex:1: undefined function variable/0" <> _ - = capture_iex("variable") + capture_io(:stderr, fn -> + assert "** (CompileError) iex:1: undefined function variable/0" <> _ = + capture_iex("variable") + end) + assert "** (CompileError) iex:1: undefined function puts/1" <> _ = capture_iex("puts \"hi\"") @@ -244,8 +247,11 @@ defmodule IEx.HelpersTest do dot_1 = "variable = :hello\nimport IO" with_file ["dot-iex", "dot-iex-1"], [dot, dot_1], fn -> - assert "** (CompileError) iex:1: undefined function parent/0" <> _ - = capture_iex("parent") + capture_io(:stderr, fn -> + assert "** (CompileError) iex:1: undefined function parent/0" <> _ = + capture_iex("parent") + end) + assert "** (CompileError) iex:1: undefined function puts/1" <> _ = capture_iex("puts \"hi\"") @@ -268,7 +274,7 @@ defmodule IEx.HelpersTest do end filename = "sample.ex" - with_file filename, test_module_code, fn -> + with_file filename, test_module_code(), fn -> assert c(filename) == [Sample] assert Sample.run == :run end @@ -278,7 +284,7 @@ defmodule IEx.HelpersTest do test "c helper with full path" do filename = "sample.ex" - with_file filename, test_module_code, fn -> + with_file filename, test_module_code(), fn -> assert c(Path.expand(filename)) == [Sample] assert Sample.run == :run end @@ -292,7 +298,7 @@ defmodule IEx.HelpersTest do end filename = "sample.ex" - with_file filename, test_module_code <> "\n" <> another_test_module, fn -> + with_file filename, test_module_code() <> "\n" <> another_test_module(), fn -> assert c(filename) |> Enum.sort == [Sample, Sample2] assert Sample.run == :run assert Sample2.hello == :world @@ -307,7 +313,7 @@ defmodule IEx.HelpersTest do end filenames = ["sample1.ex", "sample2.ex"] - with_file filenames, [test_module_code, another_test_module], fn -> + with_file filenames, [test_module_code(), another_test_module()], fn -> assert c(filenames) |> Enum.sort == [Sample, Sample2] assert Sample.run == :run assert Sample2.hello == :world @@ -322,7 +328,7 @@ defmodule IEx.HelpersTest do end filename = "sample.erl" - with_file filename, erlang_module_code, fn -> + with_file filename, erlang_module_code(), fn -> assert c(filename) == [:sample] assert :sample.hello == :world end @@ -337,7 +343,7 @@ defmodule IEx.HelpersTest do end filenames = ["sample.erl", "not_found.ex", "sample2.ex"] - with_file filenames, [erlang_module_code, "", another_test_module], fn -> + with_file filenames, [erlang_module_code(), "", another_test_module()], fn -> assert c(filenames) |> Enum.sort == [Sample2, :sample] assert :sample.hello == :world assert Sample2.hello == :world @@ -355,7 +361,7 @@ defmodule IEx.HelpersTest do assert l(:non_existent_module) == {:error, :nofile} filename = "sample.ex" - with_file filename, test_module_code, fn -> + with_file filename, test_module_code(), fn -> assert c(filename) == [Sample] assert Sample.run == :run @@ -374,10 +380,10 @@ defmodule IEx.HelpersTest do test "nl helper" do assert nl(:non_existent_module) == {:error, :nofile} - assert nl([node], Enum) == {:ok, [{:nonode@nohost, :loaded, Enum}]} + assert nl([node()], Enum) == {:ok, [{:nonode@nohost, :loaded, Enum}]} assert nl([:nosuchnode@badhost], Enum) == {:ok, [{:nosuchnode@badhost, :badrpc, :nodedown}]} capture_log fn -> - assert nl([node], :lists) == {:ok, [{:nonode@nohost, :error, :sticky_directory}]} + assert nl([node()], :lists) == {:ok, [{:nonode@nohost, :error, :sticky_directory}]} end end @@ -393,7 +399,7 @@ defmodule IEx.HelpersTest do end filename = "sample.ex" - with_file filename, test_module_code, fn -> + with_file filename, test_module_code(), fn -> assert capture_io(:stderr, fn -> assert c(filename) == [Sample] assert Sample.run == :run @@ -416,11 +422,11 @@ defmodule IEx.HelpersTest do end filename = "sample.erl" - with_file filename, erlang_module_code, fn -> + with_file filename, erlang_module_code(), fn -> assert c(filename) == [:sample] assert :sample.hello == :world - File.write!(filename, other_erlang_module_code) + File.write!(filename, other_erlang_module_code()) assert {:reloaded, :sample, [:sample]} = r(:sample) assert :sample.hello == :bye end @@ -516,7 +522,7 @@ defmodule IEx.HelpersTest do defp elixirc(args) do executable = Path.expand("../../../../bin/elixirc", __DIR__) - System.cmd("#{executable}#{executable_extension}", args, [stderr_to_stdout: true]) + System.cmd("#{executable}#{executable_extension()}", args, [stderr_to_stdout: true]) end defp iex_path do diff --git a/lib/iex/test/iex/info_test.exs b/lib/iex/test/iex/info_test.exs index 78aa6f552bc..724247134c6 100644 --- a/lib/iex/test/iex/info_test.exs +++ b/lib/iex/test/iex/info_test.exs @@ -104,7 +104,7 @@ defmodule IEx.InfoTest do info = Info.info(pid) assert info[:"Alive"] == true assert info[:"Name"] == "not registered" - assert info[:"Links"] == inspect(self) + assert info[:"Links"] == inspect(self()) assert info[:"Message queue length"] == 0 Process.register(pid, :iex_info_registered_pid) diff --git a/lib/iex/test/iex/interaction_test.exs b/lib/iex/test/iex/interaction_test.exs index 2efb9146cd4..666e6905824 100644 --- a/lib/iex/test/iex/interaction_test.exs +++ b/lib/iex/test/iex/interaction_test.exs @@ -79,7 +79,7 @@ defmodule IEx.InteractionTest do test "module definition" do input = """ defmodule Sample do - def foo, do: bar + def foo, do: bar() def bar, do: 13 end && Sample.foo """ @@ -120,7 +120,9 @@ defmodule IEx.InteractionTest do ## .iex file loading test "no .iex" do - assert "** (CompileError) iex:1: undefined function my_variable/0" <> _ = capture_iex("my_variable") + capture_io(:stderr, fn -> + assert "** (CompileError) iex:1: undefined function my_variable/0" <> _ = capture_iex("my_variable") + end) end test ".iex" do diff --git a/lib/iex/test/iex/server_test.exs b/lib/iex/test/iex/server_test.exs index ccb640771d5..0b396bac656 100644 --- a/lib/iex/test/iex/server_test.exs +++ b/lib/iex/test/iex/server_test.exs @@ -21,7 +21,7 @@ defmodule IEx.ServerTest do test "allows take over of the shell during boot" do assert capture_io("Y\na+b", fn -> - server = self + server = self() boot([], fn -> opts = [prefix: "dbg", binding: [a: 1, b: 2]] IEx.Server.take_over("iex:13", opts, 1000, server) diff --git a/lib/logger/lib/logger.ex b/lib/logger/lib/logger.ex index 4feddb9567a..4fa61f35aee 100644 --- a/lib/logger/lib/logger.ex +++ b/lib/logger/lib/logger.ex @@ -582,7 +582,7 @@ defmodule Logger do %{module: module, function: fun, file: file, line: line} = caller caller = - compile_time_application ++ + compile_time_application() ++ [module: module, function: form_fa(fun), file: file, line: line] quote do diff --git a/lib/mix/lib/mix.ex b/lib/mix/lib/mix.ex index 077fb96dd4b..b03d573db0a 100644 --- a/lib/mix/lib/mix.ex +++ b/lib/mix/lib/mix.ex @@ -68,7 +68,7 @@ defmodule Mix do def project do [app: :my_app, version: "1.0.0", - deps: deps] + deps: deps()] end defp deps do diff --git a/lib/mix/lib/mix/dep.ex b/lib/mix/lib/mix/dep.ex index a0013930976..bfa7f54a707 100644 --- a/lib/mix/lib/mix/dep.ex +++ b/lib/mix/lib/mix/dep.ex @@ -212,7 +212,7 @@ defmodule Mix.Dep do do: "the dependency is not locked (run \"mix deps.get\" to generate \"mix.lock\" file)" def format_status(%Mix.Dep{status: :compile}), - do: "the dependency build is outdated, please run \"#{mix_env_var}mix deps.compile\"" + do: "the dependency build is outdated, please run \"#{mix_env_var()}mix deps.compile\"" def format_status(%Mix.Dep{app: app, status: {:divergedreq, vsn, other}} = dep) do "the dependency #{app} #{vsn}\n" <> @@ -258,10 +258,10 @@ defmodule Mix.Dep do end def format_status(%Mix.Dep{status: {:elixirlock, _}}), - do: "the dependency was built with an out-of-date Elixir version, run \"#{mix_env_var}mix deps.compile\"" + do: "the dependency was built with an out-of-date Elixir version, run \"#{mix_env_var()}mix deps.compile\"" def format_status(%Mix.Dep{status: {:scmlock, _}}), - do: "the dependency was built with another SCM, run \"#{mix_env_var}mix deps.compile\"" + do: "the dependency was built with another SCM, run \"#{mix_env_var()}mix deps.compile\"" defp dep_status(%Mix.Dep{app: app, requirement: req, manager: manager, opts: opts, from: from}) do opts = Keyword.drop(opts, [:dest, :build, :lock, :manager]) diff --git a/lib/mix/lib/mix/dep/lock.ex b/lib/mix/lib/mix/dep/lock.ex index 37a6a00b02e..3ca467bb44a 100644 --- a/lib/mix/lib/mix/dep/lock.ex +++ b/lib/mix/lib/mix/dep/lock.ex @@ -32,10 +32,10 @@ defmodule Mix.Dep.Lock do """ @spec read() :: map def read() do - case File.read(lockfile) do + case File.read(lockfile()) do {:ok, info} -> - assert_no_merge_conflicts_in_lockfile(lockfile, info) - case Code.eval_string(info, [], file: lockfile) do + assert_no_merge_conflicts_in_lockfile(lockfile(), info) + case Code.eval_string(info, [], file: lockfile()) do {lock, _binding} when is_map(lock) -> lock {_, _binding} -> %{} end @@ -49,12 +49,12 @@ defmodule Mix.Dep.Lock do """ @spec write(map) :: :ok def write(map) do - unless map == read do + unless map == read() do lines = for {app, rev} <- Enum.sort(map), rev != nil do ~s("#{app}": #{inspect rev, limit: :infinity}) end - File.write! lockfile, "%{" <> Enum.join(lines, ",\n ") <> "}\n" + File.write! lockfile(), "%{" <> Enum.join(lines, ",\n ") <> "}\n" touch_manifest() end :ok diff --git a/lib/mix/lib/mix/dep/umbrella.ex b/lib/mix/lib/mix/dep/umbrella.ex index 0fb0053ea8f..85a719e78ef 100644 --- a/lib/mix/lib/mix/dep/umbrella.ex +++ b/lib/mix/lib/mix/dep/umbrella.ex @@ -24,7 +24,7 @@ defmodule Mix.Dep.Umbrella do Gets all umbrella dependencies in the loaded format. """ def loaded do - deps = unloaded + deps = unloaded() apps = Enum.map(deps, &(&1.app)) Enum.map(deps, fn umbrella_dep -> diff --git a/lib/mix/lib/mix/generator.ex b/lib/mix/lib/mix/generator.ex index 85446a972fe..c571c62b220 100644 --- a/lib/mix/lib/mix/generator.ex +++ b/lib/mix/lib/mix/generator.ex @@ -74,7 +74,7 @@ defmodule Mix.Generator do """ defmacro embed_template(name, contents) do - quote bind_quoted: binding do + quote bind_quoted: binding() do contents = case contents do [from_file: file] -> @@ -110,7 +110,7 @@ defmodule Mix.Generator do """ defmacro embed_text(name, contents) do - quote bind_quoted: binding do + quote bind_quoted: binding() do contents = case contents do [from_file: f] -> File.read!(f) diff --git a/lib/mix/lib/mix/project.ex b/lib/mix/lib/mix/project.ex index 2d86d3bd468..85693b294e4 100644 --- a/lib/mix/lib/mix/project.ex +++ b/lib/mix/lib/mix/project.ex @@ -56,7 +56,7 @@ defmodule Mix.Project do file = file || (atom && List.to_string(atom.__info__(:compile)[:source])) - config = ([app: app] ++ default_config) + config = ([app: app] ++ default_config()) |> Keyword.merge(get_project_config(atom)) case Mix.ProjectStack.push(atom, config, file) do @@ -113,7 +113,7 @@ defmodule Mix.Project do """ @spec get!() :: module | no_return def get! do - get || raise Mix.NoProjectError, [] + get() || raise Mix.NoProjectError, [] end @doc """ @@ -135,7 +135,7 @@ defmodule Mix.Project do def config do case Mix.ProjectStack.peek do %{config: config} -> config - _ -> default_config + _ -> default_config() end end diff --git a/lib/mix/lib/mix/shell/io.ex b/lib/mix/lib/mix/shell/io.ex index e23749ea98c..81f649424c6 100644 --- a/lib/mix/lib/mix/shell/io.ex +++ b/lib/mix/lib/mix/shell/io.ex @@ -33,7 +33,7 @@ defmodule Mix.Shell.IO do Writes a message to the shell followed by new line. """ def info(message) do - print_app + print_app() IO.puts IO.ANSI.format message end @@ -41,7 +41,7 @@ defmodule Mix.Shell.IO do Writes an error message to the shell followed by new line. """ def error(message) do - print_app + print_app() IO.puts :stderr, IO.ANSI.format(red(message)) end @@ -50,7 +50,7 @@ defmodule Mix.Shell.IO do input. Input will be consumed until enter is pressed. """ def prompt(message) do - print_app + print_app() IO.gets message <> " " end @@ -60,7 +60,7 @@ defmodule Mix.Shell.IO do regex `~r/^Y(es)?$/i`. """ def yes?(message) do - print_app + print_app() got_yes? IO.gets(message <> " [Yn] ") end diff --git a/lib/mix/lib/mix/shell/process.ex b/lib/mix/lib/mix/shell/process.ex index 6964e3704e8..74579da6ef8 100644 --- a/lib/mix/lib/mix/shell/process.ex +++ b/lib/mix/lib/mix/shell/process.ex @@ -61,7 +61,7 @@ defmodule Mix.Shell.Process do """ def print_app do if name = Mix.Shell.printable_app_name do - send self, {:mix_shell, :info, ["==> #{name}"]} + send self(), {:mix_shell, :info, ["==> #{name}"]} end end @@ -73,7 +73,7 @@ defmodule Mix.Shell.Process do print_app? = Keyword.get(opts, :print_app, true) Mix.Shell.cmd(command, opts, fn(data) -> if print_app?, do: print_app() - send self, {:mix_shell, :run, [data]} + send self(), {:mix_shell, :run, [data]} end) end @@ -81,16 +81,16 @@ defmodule Mix.Shell.Process do Forwards the message to the current process. """ def info(message) do - print_app - send self, {:mix_shell, :info, [format(message)]} + print_app() + send self(), {:mix_shell, :info, [format(message)]} end @doc """ Forwards the message to the current process. """ def error(message) do - print_app - send self, {:mix_shell, :error, [format(message)]} + print_app() + send self(), {:mix_shell, :error, [format(message)]} end defp format(message) do @@ -118,8 +118,8 @@ defmodule Mix.Shell.Process do """ def prompt(message) do - print_app - send self, {:mix_shell, :prompt, [message]} + print_app() + send self(), {:mix_shell, :prompt, [message]} receive do {:mix_shell_input, :prompt, response} -> response @@ -146,8 +146,8 @@ defmodule Mix.Shell.Process do """ def yes?(message) do - print_app - send self, {:mix_shell, :yes?, [message]} + print_app() + send self(), {:mix_shell, :yes?, [message]} receive do {:mix_shell_input, :yes?, response} -> response diff --git a/lib/mix/lib/mix/tasks/clean.ex b/lib/mix/lib/mix/tasks/clean.ex index f99df083fb1..8afac468370 100644 --- a/lib/mix/lib/mix/tasks/clean.ex +++ b/lib/mix/lib/mix/tasks/clean.ex @@ -20,7 +20,7 @@ defmodule Mix.Tasks.Clean do @spec run(OptionParser.argv) :: :ok def run(args) do Mix.Project.get! - loadpaths! + loadpaths!() {opts, _, _} = OptionParser.parse(args, switches: @switches) diff --git a/lib/mix/lib/mix/tasks/compile.elixir.ex b/lib/mix/lib/mix/tasks/compile.elixir.ex index e92bdbc7ce7..0e8d5e63d0c 100644 --- a/lib/mix/lib/mix/tasks/compile.elixir.ex +++ b/lib/mix/lib/mix/tasks/compile.elixir.ex @@ -64,7 +64,7 @@ defmodule Mix.Tasks.Compile.Elixir do @doc """ Returns Elixir manifests. """ - def manifests, do: [manifest] + def manifests, do: [manifest()] defp manifest, do: Path.join(Mix.Project.manifest_path, @manifest) @doc """ diff --git a/lib/mix/lib/mix/tasks/compile.erlang.ex b/lib/mix/lib/mix/tasks/compile.erlang.ex index f4b8febdf18..350761963a8 100644 --- a/lib/mix/lib/mix/tasks/compile.erlang.ex +++ b/lib/mix/lib/mix/tasks/compile.erlang.ex @@ -98,7 +98,7 @@ defmodule Mix.Tasks.Compile.Erlang do @doc """ Returns Erlang manifests. """ - def manifests, do: [manifest] + def manifests, do: [manifest()] defp manifest, do: Path.join(Mix.Project.manifest_path, @manifest) @doc """ diff --git a/lib/mix/lib/mix/tasks/compile.ex b/lib/mix/lib/mix/tasks/compile.ex index 321384746d1..7e9fceb07e8 100644 --- a/lib/mix/lib/mix/tasks/compile.ex +++ b/lib/mix/lib/mix/tasks/compile.ex @@ -49,7 +49,7 @@ defmodule Mix.Tasks.Compile do """ @spec run(OptionParser.argv) :: :ok | :noop def run(["--list"]) do - loadpaths! + loadpaths!() _ = Mix.Task.load_all shell = Mix.shell diff --git a/lib/mix/lib/mix/tasks/compile.leex.ex b/lib/mix/lib/mix/tasks/compile.leex.ex index 08d158f2848..3cff7948609 100644 --- a/lib/mix/lib/mix/tasks/compile.leex.ex +++ b/lib/mix/lib/mix/tasks/compile.leex.ex @@ -60,7 +60,7 @@ defmodule Mix.Tasks.Compile.Leex do @doc """ Returns Leex manifests. """ - def manifests, do: [manifest] + def manifests, do: [manifest()] defp manifest, do: Path.join(Mix.Project.manifest_path, @manifest) @doc """ diff --git a/lib/mix/lib/mix/tasks/compile.xref.ex b/lib/mix/lib/mix/tasks/compile.xref.ex index cea455c6e7a..c0ffbbb686f 100644 --- a/lib/mix/lib/mix/tasks/compile.xref.ex +++ b/lib/mix/lib/mix/tasks/compile.xref.ex @@ -57,7 +57,7 @@ defmodule Mix.Tasks.Compile.Xref do @doc """ Returns xref manifests. """ - def manifests, do: [manifest] + def manifests, do: [manifest()] defp manifest, do: Path.join(Mix.Project.manifest_path, @manifest) defp write_manifest do diff --git a/lib/mix/lib/mix/tasks/compile.yecc.ex b/lib/mix/lib/mix/tasks/compile.yecc.ex index 59669a5360d..545f1ab8545 100644 --- a/lib/mix/lib/mix/tasks/compile.yecc.ex +++ b/lib/mix/lib/mix/tasks/compile.yecc.ex @@ -60,7 +60,7 @@ defmodule Mix.Tasks.Compile.Yecc do @doc """ Returns Yecc manifests. """ - def manifests, do: [manifest] + def manifests, do: [manifest()] defp manifest, do: Path.join(Mix.Project.manifest_path, @manifest) @doc """ diff --git a/lib/mix/lib/mix/tasks/help.ex b/lib/mix/lib/mix/tasks/help.ex index a7531ea7a13..134406c3417 100644 --- a/lib/mix/lib/mix/tasks/help.ex +++ b/lib/mix/lib/mix/tasks/help.ex @@ -41,7 +41,7 @@ defmodule Mix.Tasks.Help do def run(argv) def run([]) do - loadpaths! + loadpaths!() modules = load_tasks() {docs, max} = build_task_doc_list(modules) @@ -52,7 +52,7 @@ defmodule Mix.Tasks.Help do end def run(["--names"]) do - loadpaths! + loadpaths!() tasks = Enum.map(load_tasks(), &Mix.Task.task_name/1) @@ -66,7 +66,7 @@ defmodule Mix.Tasks.Help do end def run(["--search", pattern]) do - loadpaths! + loadpaths!() modules = load_tasks() @@ -81,14 +81,14 @@ defmodule Mix.Tasks.Help do end def run([task]) do - loadpaths! + loadpaths!() module = Mix.Task.get!(task) doc = Mix.Task.moduledoc(module) || "There is no documentation for this task" opts = Application.get_env(:mix, :colors) if ansi_docs?(opts) do - opts = [width: width] ++ opts + opts = [width: width()] ++ opts IO.ANSI.Docs.print_heading("mix #{task}", opts) IO.ANSI.Docs.print(doc, opts) else diff --git a/lib/mix/lib/mix/tasks/new.ex b/lib/mix/lib/mix/tasks/new.ex index f263667bd30..abe62890d43 100644 --- a/lib/mix/lib/mix/tasks/new.ex +++ b/lib/mix/lib/mix/tasks/new.ex @@ -75,9 +75,9 @@ defmodule Mix.Tasks.New do version: get_version(System.version)] create_file "README.md", readme_template(assigns) - create_file ".gitignore", gitignore_text + create_file ".gitignore", gitignore_text() - if in_umbrella? do + if in_umbrella?() do create_file "mix.exs", mixfile_apps_template(assigns) else create_file "mix.exs", mixfile_template(assigns) @@ -121,7 +121,7 @@ defmodule Mix.Tasks.New do defp do_generate_umbrella(_app, mod, path, _opts) do assigns = [app: nil, mod: mod] - create_file ".gitignore", gitignore_text + create_file ".gitignore", gitignore_text() create_file "README.md", readme_template(assigns) create_file "mix.exs", mixfile_umbrella_template(assigns) @@ -251,7 +251,7 @@ defmodule Mix.Tasks.New do elixir: "~> <%= @version %>", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, - deps: deps] + deps: deps()] end # Configuration for the OTP application @@ -290,7 +290,7 @@ defmodule Mix.Tasks.New do elixir: "~> <%= @version %>", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, - deps: deps] + deps: deps()] end # Configuration for the OTP application @@ -327,7 +327,7 @@ defmodule Mix.Tasks.New do [apps_path: "apps", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, - deps: deps] + deps: deps()] end # Dependencies can be Hex packages: diff --git a/lib/mix/lib/mix/utils.ex b/lib/mix/lib/mix/utils.ex index 5bf797662cc..5af4e521002 100644 --- a/lib/mix/lib/mix/utils.ex +++ b/lib/mix/lib/mix/utils.ex @@ -26,7 +26,7 @@ defmodule Mix.Utils do """ def mix_paths do if path = System.get_env("MIX_PATH") do - String.split(path, path_separator) + String.split(path, path_separator()) else [] end @@ -442,7 +442,7 @@ defmodule Mix.Utils do end def proxy_config(url) do - {http_proxy, https_proxy} = proxy_env + {http_proxy, https_proxy} = proxy_env() proxy_auth(URI.parse(url), http_proxy, https_proxy) end diff --git a/lib/mix/test/fixtures/umbrella_dep/mix.exs b/lib/mix/test/fixtures/umbrella_dep/mix.exs index 79226a01f4f..dfaf25e0b3d 100644 --- a/lib/mix/test/fixtures/umbrella_dep/mix.exs +++ b/lib/mix/test/fixtures/umbrella_dep/mix.exs @@ -3,7 +3,7 @@ defmodule UmbrellaDep.Mixfile do def project do [app: :umbrella_dep, - deps: deps] + deps: deps()] end defp deps do diff --git a/lib/mix/test/mix/dep_test.exs b/lib/mix/test/mix/dep_test.exs index 6738781c23c..af17456f481 100644 --- a/lib/mix/test/mix/dep_test.exs +++ b/lib/mix/test/mix/dep_test.exs @@ -82,7 +82,7 @@ defmodule Mix.DepTest do test "raises when no SCM is specified" do with_deps [{:ok, "~> 0.1", not_really: :ok}], fn -> in_fixture "deps_status", fn -> - send self, {:mix_shell_input, :yes?, false} + send self(), {:mix_shell_input, :yes?, false} msg = "Could not find an SCM for dependency :ok from Mix.DepTest.ProcessDepsApp" assert_raise Mix.Error, msg, fn -> Mix.Dep.loaded([]) end end diff --git a/lib/mix/test/mix/generator_test.exs b/lib/mix/test/mix/generator_test.exs index b52d66e6a23..d429682d86a 100644 --- a/lib/mix/test/mix/generator_test.exs +++ b/lib/mix/test/mix/generator_test.exs @@ -10,7 +10,7 @@ defmodule Mix.GeneratorTest do embed_template :bar, "<%= @a + @b %>" test "embed text" do - assert foo_text == "foo" + assert foo_text() == "foo" end test "embed template" do @@ -18,7 +18,7 @@ defmodule Mix.GeneratorTest do end test "from file" do - assert self_text =~ "import Mix.Generator" + assert self_text() =~ "import Mix.Generator" end test "create file" do @@ -44,7 +44,7 @@ defmodule Mix.GeneratorTest do test "create with conflict returning true" do in_tmp "create_file", fn -> File.write! "foo", "HELLO" - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} create_file "foo", "WORLD" assert File.read!("foo") == "WORLD" @@ -56,7 +56,7 @@ defmodule Mix.GeneratorTest do test "create with conflict returning false" do in_tmp "create_file", fn -> File.write! "foo", "HELLO" - send self, {:mix_shell_input, :yes?, false} + send self(), {:mix_shell_input, :yes?, false} create_file "foo", "WORLD" assert File.read!("foo") == "HELLO" diff --git a/lib/mix/test/mix/shell_test.exs b/lib/mix/test/mix/shell_test.exs index 6226e887aba..4f055d9d044 100644 --- a/lib/mix/test/mix/shell_test.exs +++ b/lib/mix/test/mix/shell_test.exs @@ -24,17 +24,17 @@ defmodule Mix.ShellTest do assert_received {:mix_shell, :info, ["abc"]} assert_received {:mix_shell, :error, ["def"]} - send self, {:mix_shell_input, :prompt, "world"} + send self(), {:mix_shell_input, :prompt, "world"} assert Mix.shell.prompt("hello?") == "world" assert_received {:mix_shell, :prompt, ["hello?"]} - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} assert Mix.shell.yes?("hello?") assert_received {:mix_shell, :yes?, ["hello?"]} assert Mix.shell.cmd("echo first") == 0 - nl = os_newline + nl = os_newline() assert_received {:mix_shell, :run, ["first" <> ^nl]} end diff --git a/lib/mix/test/mix/tasks/archive_test.exs b/lib/mix/test/mix/tasks/archive_test.exs index de7842889be..795ef045124 100644 --- a/lib/mix/test/mix/tasks/archive_test.exs +++ b/lib/mix/test/mix/tasks/archive_test.exs @@ -40,7 +40,7 @@ defmodule Mix.Tasks.ArchiveTest do assert_received {:mix_shell, :info, ["Generated archive \"archive-0.1.0.ez\" with MIX_ENV=dev"]} assert File.regular? 'archive-0.1.0.ez' - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} Mix.Tasks.Archive.Install.run [] refute File.regular? tmp_path("userhome/.mix/archives/archive-0.1.0.ez") assert File.dir? tmp_path("userhome/.mix/archives/archive-0.1.0/archive-0.1.0/ebin") @@ -75,7 +75,7 @@ defmodule Mix.Tasks.ArchiveTest do # Install previous version Mix.Tasks.Archive.Build.run ["--no-elixir-version-check"] assert File.regular? "archive-0.1.0.ez" - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} Mix.Tasks.Archive.Install.run [] assert_received {:mix_shell, :error, [_]} @@ -86,13 +86,13 @@ defmodule Mix.Tasks.ArchiveTest do assert_received {:mix_shell, :info, ["Generated archive \"archive-0.2.0.ez\" with MIX_ENV=dev"]} # Install new version - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} Mix.Tasks.Archive.Install.run [] refute File.regular? tmp_path("userhome/.mix/archives/archive-0.2.0.ez") assert File.dir? tmp_path("userhome/.mix/archives/archive-0.2.0/archive-0.2.0/ebin") # Re-install current version should not change system - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} Mix.Tasks.Archive.Install.run [] refute File.regular? tmp_path("userhome/.mix/archives/archive-0.2.0.ez") assert File.dir? tmp_path("userhome/.mix/archives/archive-0.2.0/archive-0.2.0/ebin") @@ -110,12 +110,12 @@ defmodule Mix.Tasks.ArchiveTest do refute_received {:mix_shell, :error, [_]} # Check uninstall confirmation - send self, {:mix_shell_input, :yes?, false} + send self(), {:mix_shell_input, :yes?, false} Mix.Tasks.Archive.Uninstall.run ["archive-0.2.0"] assert File.dir? tmp_path("userhome/.mix/archives/archive-0.2.0/archive-0.2.0/ebin") # Remove it! - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} Mix.Tasks.Archive.Uninstall.run ["archive-0.2.0"] refute File.dir? tmp_path("userhome/.mix/archives/archive-0.2.0/archive-0.2.0/ebin") end @@ -130,16 +130,16 @@ defmodule Mix.Tasks.ArchiveTest do in_fixture "archive", fn() -> Mix.Tasks.Archive.Build.run ["--no-elixir-version-check"] assert File.regular? "archive-0.1.0.ez" - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} # Install with wrong checksum assert_raise Mix.Error, ~r"Data does not match the given SHA-512 checksum", fn -> - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} Mix.Tasks.Archive.Install.run ["--sha512", "wrong"] end # Install with correct checksum - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} Mix.Tasks.Archive.Install.run ["--sha512", sha512("archive-0.1.0.ez")] refute File.regular? tmp_path("userhome/.mix/archives/archive-0.1.0.ez") assert File.dir? tmp_path("userhome/.mix/archives/archive-0.1.0/archive-0.1.0/ebin") @@ -150,7 +150,7 @@ defmodule Mix.Tasks.ArchiveTest do # Install the archive in_fixture "archive", fn() -> Mix.Tasks.Archive.Build.run ["--no-elixir-version-check"] - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} Mix.Tasks.Archive.Install.run [] end diff --git a/lib/mix/test/mix/tasks/cmd_test.exs b/lib/mix/test/mix/tasks/cmd_test.exs index db4bf069213..a1b7a9211dc 100644 --- a/lib/mix/test/mix/tasks/cmd_test.exs +++ b/lib/mix/test/mix/tasks/cmd_test.exs @@ -7,7 +7,7 @@ defmodule Mix.Tasks.CmdTest do in_fixture "umbrella_dep/deps/umbrella", fn -> Mix.Project.in_project(:umbrella, ".", fn _ -> Mix.Task.run "cmd", ["echo", "hello"] - nl = os_newline + nl = os_newline() assert_received {:mix_shell, :info, ["==> bar"]} assert_received {:mix_shell, :run, ["hello" <> ^nl]} assert_received {:mix_shell, :info, ["==> foo"]} diff --git a/lib/mix/test/mix/tasks/compile.protocols_test.exs b/lib/mix/test/mix/tasks/compile.protocols_test.exs index efb6f3933c8..51e8b258fed 100644 --- a/lib/mix/test/mix/tasks/compile.protocols_test.exs +++ b/lib/mix/test/mix/tasks/compile.protocols_test.exs @@ -18,7 +18,7 @@ defmodule Mix.Tasks.Compile.ProtocolsTest do def foo(a, b) end """) - assert compile_elixir_and_protocols == :ok + assert compile_elixir_and_protocols() == :ok mark_as_old!("_build/dev/consolidated/Elixir.Compile.Protocol.beam") # Implement a local protocol @@ -27,17 +27,17 @@ defmodule Mix.Tasks.Compile.ProtocolsTest do def foo(a, b), do: a + b end """) - assert compile_elixir_and_protocols == :ok + assert compile_elixir_and_protocols() == :ok assert mark_as_old!("_build/dev/consolidated/Elixir.Compile.Protocol.beam") != @old # Delete a local implementation File.rm!("lib/impl.ex") - assert compile_elixir_and_protocols == :ok + assert compile_elixir_and_protocols() == :ok assert mark_as_old!("_build/dev/consolidated/Elixir.Compile.Protocol.beam") != @old # Delete a local protocol File.rm!("lib/protocol.ex") - assert compile_elixir_and_protocols == :noop + assert compile_elixir_and_protocols() == :noop refute File.regular?("_build/dev/consolidated/Elixir.Compile.Protocol.beam") end end @@ -51,7 +51,7 @@ defmodule Mix.Tasks.Compile.ProtocolsTest do assert Mix.Task.run("compile") mark_as_old!("_build/dev/consolidated/Elixir.String.Chars.beam") - assert compile_elixir_and_protocols == :noop + assert compile_elixir_and_protocols() == :noop assert mtime("_build/dev/consolidated/Elixir.String.Chars.beam") == @old # Implement a deps protocol @@ -63,12 +63,12 @@ defmodule Mix.Tasks.Compile.ProtocolsTest do end end """) - assert compile_elixir_and_protocols == :ok + assert compile_elixir_and_protocols() == :ok assert mark_as_old!("_build/dev/consolidated/Elixir.String.Chars.beam") != @old # Delete the local implementation File.rm!("lib/struct.ex") - assert compile_elixir_and_protocols == :ok + assert compile_elixir_and_protocols() == :ok assert mark_as_old!("_build/dev/consolidated/Elixir.String.Chars.beam") != @old end end diff --git a/lib/mix/test/mix/tasks/deps.git_test.exs b/lib/mix/test/mix/tasks/deps.git_test.exs index cc8bd38488c..546ee1771fc 100644 --- a/lib/mix/test/mix/tasks/deps.git_test.exs +++ b/lib/mix/test/mix/tasks/deps.git_test.exs @@ -205,7 +205,7 @@ defmodule Mix.Tasks.DepsGitTest do Mix.Project.push GitApp # Get git repo first revision - [last, first | _] = get_git_repo_revs + [last, first | _] = get_git_repo_revs() in_fixture "no_mixfile", fn -> Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), first, []}} @@ -231,7 +231,7 @@ defmodule Mix.Tasks.DepsGitTest do test "updates the repo when the lock updates" do Mix.Project.push GitApp - [last, first | _] = get_git_repo_revs + [last, first | _] = get_git_repo_revs() in_fixture "no_mixfile", fn -> Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), first, []}} @@ -267,7 +267,7 @@ defmodule Mix.Tasks.DepsGitTest do test "updates the repo and the lock when the mixfile updates" do Mix.Project.push GitApp - [last, first | _] = get_git_repo_revs + [last, first | _] = get_git_repo_revs() in_fixture "no_mixfile", fn -> # Move to the first version @@ -310,7 +310,7 @@ defmodule Mix.Tasks.DepsGitTest do test "does not load bad mixfiles on get" do Mix.Project.push GitApp - [last, _, bad | _] = get_git_repo_revs + [last, _, bad | _] = get_git_repo_revs() in_fixture "no_mixfile", fn -> Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), bad, []}} @@ -344,7 +344,7 @@ defmodule Mix.Tasks.DepsGitTest do test "does not load bad mixfiles on update" do Mix.Project.push GitApp - [last, _, bad | _] = get_git_repo_revs + [last, _, bad | _] = get_git_repo_revs() in_fixture "no_mixfile", fn -> Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), bad, []}} diff --git a/lib/mix/test/mix/tasks/escript_test.exs b/lib/mix/test/mix/tasks/escript_test.exs index a6be75467b3..28414211f45 100644 --- a/lib/mix/test/mix/tasks/escript_test.exs +++ b/lib/mix/test/mix/tasks/escript_test.exs @@ -151,7 +151,7 @@ defmodule Mix.Tasks.EscriptTest do assert_received {:mix_shell, :info, ["No escripts currently installed."]} # install our escript - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} Mix.Tasks.Escript.Install.run [] # check that it shows in the list @@ -160,12 +160,12 @@ defmodule Mix.Tasks.EscriptTest do refute_received {:mix_shell, :info, ["* escriptest.bat"]} # check uninstall confirmation - send self, {:mix_shell_input, :yes?, false} + send self(), {:mix_shell_input, :yes?, false} Mix.Tasks.Escript.Uninstall.run ["escriptest"] assert File.regular? tmp_path(".mix/escripts/escriptest") # uninstall the escript - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} Mix.Tasks.Escript.Uninstall.run ["escriptest"] refute File.regular? tmp_path(".mix/escripts/escriptest") refute File.regular? tmp_path(".mix/escripts/escriptest.bat") @@ -178,7 +178,7 @@ defmodule Mix.Tasks.EscriptTest do test "escript invalid install" do # Install our escript - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} assert_raise Mix.Error, "The given path does not point to an escript, installation aborted", fn -> Mix.Tasks.Escript.Install.run [__ENV__.file] diff --git a/lib/mix/test/mix/tasks/local.public_keys_test.exs b/lib/mix/test/mix/tasks/local.public_keys_test.exs index 82fc366b2a5..703f8ff4dad 100644 --- a/lib/mix/test/mix/tasks/local.public_keys_test.exs +++ b/lib/mix/test/mix/tasks/local.public_keys_test.exs @@ -32,12 +32,12 @@ defmodule Mix.Tasks.Local.PublicKeysTest do path = tmp_path("sample.pub") File.write!(path, @pub) - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} Mix.Tasks.Local.PublicKeys.run [path] assert_received {:mix_shell, :yes?, ["Are you sure you want to install public key" <> _]} assert_received {:mix_shell, :info, ["* creating " <> _]} - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} Mix.Tasks.Local.PublicKeys.run [path] assert_received {:mix_shell, :yes?, ["There is already a public key named sample.pub." <> _]} assert_received {:mix_shell, :info, ["* creating " <> _]} @@ -47,7 +47,7 @@ defmodule Mix.Tasks.Local.PublicKeysTest do assert_raise Mix.Error, ~r(Could not decode public key:), fn -> path = tmp_path("bad.pub") File.write!(path, "oops") - send self, {:mix_shell_input, :yes?, true} + send self(), {:mix_shell_input, :yes?, true} Mix.Tasks.Local.PublicKeys.run [path] end end diff --git a/lib/mix/test/mix/tasks/profile.fprof_test.exs b/lib/mix/test/mix/tasks/profile.fprof_test.exs index dac764fb9fd..0e3472f7496 100644 --- a/lib/mix/test/mix/tasks/profile.fprof_test.exs +++ b/lib/mix/test/mix/tasks/profile.fprof_test.exs @@ -48,8 +48,8 @@ defmodule Mix.Tasks.Profile.FprofTest do output = capture_io(fn -> Fprof.run(["-e", "spawn(fn -> :ok end); Enum.each(1..5, fn(_) -> MapSet.new end)", "--details"]) end) - assert output =~ ~r(#{:erlang.pid_to_list(self)} +\d+ +\d+\.\d{3}) - assert output =~ ~r(spawned by #{:erlang.pid_to_list(self)}) + assert output =~ ~r(#{:erlang.pid_to_list(self())} +\d+ +\d+\.\d{3}) + assert output =~ ~r(spawned by #{:erlang.pid_to_list(self())}) assert output =~ ~r(as :erlang.apply) assert output =~ ~r(initial calls:) end diff --git a/lib/mix/test/mix/tasks/run_test.exs b/lib/mix/test/mix/tasks/run_test.exs index a4946310eb9..bb4293b808a 100644 --- a/lib/mix/test/mix/tasks/run_test.exs +++ b/lib/mix/test/mix/tasks/run_test.exs @@ -27,10 +27,10 @@ defmodule Mix.Tasks.RunTest do git_repo = fixture_path("git_repo/lib/git_repo.ex") in_tmp context.test, fn -> - Mix.Tasks.Run.run ["-r", git_repo, "-e", "send self, {:hello, GitRepo.hello}"] + Mix.Tasks.Run.run ["-r", git_repo, "-e", "send self(), {:hello, GitRepo.hello}"] assert_received {:hello, "World"} - Mix.Tasks.Run.run ["-pr", git_repo, "-e", "send self, {:hello, GitRepo.hello}"] + Mix.Tasks.Run.run ["-pr", git_repo, "-e", "send self(), {:hello, GitRepo.hello}"] assert_received {:hello, "World"} end after @@ -64,7 +64,7 @@ defmodule Mix.Tasks.RunTest do in_tmp context.test, fn -> file = "argv.exs" - File.write! file, "send self, {:argv, System.argv}" + File.write! file, "send self(), {:argv, System.argv}" unload_file = fn -> Code.unload_files [Path.expand(file)] end @@ -77,13 +77,13 @@ defmodule Mix.Tasks.RunTest do assert_received {:argv, ["foo", "-e", "bar"]} unload_file.() - Mix.Tasks.Run.run ["-e", "send self, {:argv, System.argv}", file, "foo", "-x", "bar"] + Mix.Tasks.Run.run ["-e", "send self(), {:argv, System.argv}", file, "foo", "-x", "bar"] assert_received {:argv, [^file, "foo", "-x", "bar"]} unload_file.() Mix.Tasks.Run.run [ - "-e", "send self, :evaled", - "-e", "send self, {:argv, System.argv}", + "-e", "send self(), :evaled", + "-e", "send self(), {:argv, System.argv}", "--no-compile", file, "-x", "bar" ] assert_received :evaled diff --git a/lib/mix/test/mix/utils_test.exs b/lib/mix/test/mix/utils_test.exs index 2dcdb7b3b5d..5c5fdf1d121 100644 --- a/lib/mix/test/mix/utils_test.exs +++ b/lib/mix/test/mix/utils_test.exs @@ -28,7 +28,7 @@ defmodule Mix.UtilsTest do end test "extract files" do - files = Mix.Utils.extract_files [Path.join(fixture_path, "archive")], "*.ex" + files = Mix.Utils.extract_files [Path.join(fixture_path(), "archive")], "*.ex" assert length(files) == 1 assert Path.basename(hd(files)) == "local.sample.ex" end diff --git a/lib/mix/test/test_helper.exs b/lib/mix/test/test_helper.exs index b8a66cd83fd..b80efaff519 100644 --- a/lib/mix/test/test_helper.exs +++ b/lib/mix/test/test_helper.exs @@ -32,7 +32,7 @@ defmodule MixTest.Case do Mix.Shell.Process.flush Mix.ProjectStack.clear_cache Mix.ProjectStack.clear_stack - delete_tmp_paths + delete_tmp_paths() if apps do for app <- apps do @@ -51,7 +51,7 @@ defmodule MixTest.Case do end def fixture_path(extension) do - Path.join fixture_path, extension + Path.join fixture_path(), extension end def tmp_path do @@ -59,7 +59,7 @@ defmodule MixTest.Case do end def tmp_path(extension) do - Path.join tmp_path, to_string(extension) + Path.join tmp_path(), to_string(extension) end def purge(modules) do @@ -89,7 +89,7 @@ defmodule MixTest.Case do def in_fixture(which, tmp, function) do src = fixture_path(which) dest = tmp_path(tmp) - flag = String.to_charlist(tmp_path) + flag = String.to_charlist(tmp_path()) File.rm_rf!(dest) File.mkdir_p!(dest) @@ -130,8 +130,8 @@ defmodule MixTest.Case do end def mix(args, envs \\ []) when is_list(args) do - System.cmd(elixir_executable, - ["-r", mix_executable, "--" | args], + System.cmd(elixir_executable(), + ["-r", mix_executable(), "--" | args], stderr_to_stdout: true, env: envs) |> elem(0) end @@ -145,7 +145,7 @@ defmodule MixTest.Case do end defp delete_tmp_paths do - tmp = tmp_path |> String.to_charlist + tmp = tmp_path() |> String.to_charlist for path <- :code.get_path, :string.str(path, tmp) != 0, do: :code.del_path(path)