summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@dashbit.co>2021-12-07 08:18:19 +0100
committerJosé Valim <jose.valim@dashbit.co>2021-12-07 08:18:19 +0100
commitaf0fd816062d7f3d519e47c183c3476829186d88 (patch)
tree996e75c28ee6b7223e9f7a31f780935d909e2b88
parent853fd9b6b80c26146c64ee021c3120ff1a01ba6c (diff)
downloadelixir-af0fd816062d7f3d519e47c183c3476829186d88.tar.gz
Make sure --version flag halts elixir and iex, closes #11453
-rwxr-xr-xbin/elixir2
-rw-r--r--bin/elixir.bat2
-rwxr-xr-xbin/elixirc2
-rw-r--r--bin/elixirc.bat2
-rw-r--r--lib/elixir/lib/kernel/cli.ex11
-rw-r--r--lib/elixir/test/elixir/kernel/cli_test.exs6
-rw-r--r--lib/elixir/test/elixir/test_helper.exs8
7 files changed, 25 insertions, 8 deletions
diff --git a/bin/elixir b/bin/elixir
index cb55b5ac4..01ff08175 100755
--- a/bin/elixir
+++ b/bin/elixir
@@ -16,7 +16,7 @@ Usage: $(basename "$0") [options] [.exs file] [data]
-pr "FILE" Requires the given files/patterns in parallel (*)
-pa "PATH" Prepends the given path to Erlang code path (*)
-pz "PATH" Appends the given path to Erlang code path (*)
- -v, --version Prints Erlang/OTP and Elixir versions
+ -v, --version Prints Erlang/OTP and Elixir versions (standalone)
--app APP Starts the given app and its dependencies (*)
--erl "SWITCHES" Switches to be passed down to Erlang (*)
diff --git a/bin/elixir.bat b/bin/elixir.bat
index 3118b0c7f..071425b32 100644
--- a/bin/elixir.bat
+++ b/bin/elixir.bat
@@ -23,7 +23,7 @@ echo -S SCRIPT Finds and executes the given script in $PATH
echo -pr "FILE" Requires the given files/patterns in parallel (*)
echo -pa "PATH" Prepends the given path to Erlang code path (*)
echo -pz "PATH" Appends the given path to Erlang code path (*)
-echo -v, --version Prints Erlang/OTP and Elixir versions
+echo -v, --version Prints Erlang/OTP and Elixir versions (standalone)
echo.
echo --app APP Starts the given app and its dependencies (*)
echo --erl "SWITCHES" Switches to be passed down to Erlang (*)
diff --git a/bin/elixirc b/bin/elixirc
index 23bb5a644..650e4758b 100755
--- a/bin/elixirc
+++ b/bin/elixirc
@@ -7,7 +7,7 @@ Usage: $(basename "$0") [elixir switches] [compiler switches] [.ex files]
-h, --help Prints this message and exits
-o The directory to output compiled files
- -v, --version Prints Elixir version and exits
+ -v, --version Prints Elixir version and exits (standalone)
--ignore-module-conflict Does not emit warnings if a module was previously defined
--no-debug-info Does not attach debug info to compiled modules
diff --git a/bin/elixirc.bat b/bin/elixirc.bat
index a559d1349..e046f6af2 100644
--- a/bin/elixirc.bat
+++ b/bin/elixirc.bat
@@ -16,7 +16,7 @@ echo Usage: %~nx0 [elixir switches] [compiler switches] [.ex files]
echo.
echo -h, --help Prints this message and exits
echo -o The directory to output compiled files
-echo -v, --version Prints Elixir version and exits
+echo -v, --version Prints Elixir version and exits (standalone)
echo.
echo --ignore-module-conflict Does not emit warnings if a module was previously defined
echo --no-debug-info Does not attach debug info to compiled modules
diff --git a/lib/elixir/lib/kernel/cli.ex b/lib/elixir/lib/kernel/cli.ex
index 5f3a04ae9..a61522771 100644
--- a/lib/elixir/lib/kernel/cli.ex
+++ b/lib/elixir/lib/kernel/cli.ex
@@ -218,12 +218,16 @@ defmodule Kernel.CLI do
# Parse shared options
- defp parse_shared([opt | _], _config) when opt in @standalone_opts do
+ defp warn_standalone(opt) do
IO.puts(:stderr, "#{opt} : Standalone options can't be combined with other options")
+ end
+
+ defp parse_shared([opt | _], _config) when opt in @standalone_opts do
+ warn_standalone(opt)
System.halt(1)
end
- defp parse_shared([opt | t], config) when opt in ["-v", "--version"] do
+ defp parse_shared([opt | t], _config) when opt in ["-v", "--version"] do
if function_exported?(IEx, :started?, 0) and IEx.started?() do
IO.puts("IEx " <> System.build_info()[:build])
else
@@ -231,7 +235,8 @@ defmodule Kernel.CLI do
IO.puts("Elixir " <> System.build_info()[:build])
end
- parse_shared(t, config)
+ t != [] && warn_standalone(opt)
+ System.halt(1)
end
defp parse_shared(["-pa", h | t], config) do
diff --git a/lib/elixir/test/elixir/kernel/cli_test.exs b/lib/elixir/test/elixir/kernel/cli_test.exs
index 11001403a..43b59a2fa 100644
--- a/lib/elixir/test/elixir/kernel/cli_test.exs
+++ b/lib/elixir/test/elixir/kernel/cli_test.exs
@@ -71,10 +71,14 @@ defmodule Kernel.CLITest do
assert output =~ "Erlang/OTP #{System.otp_release()}"
assert output =~ "Elixir #{System.version()}"
+ output = iex('--version')
+ assert output =~ "Erlang/OTP #{System.otp_release()}"
+ assert output =~ "IEx #{System.version()}"
+
output = elixir('--version -e "IO.puts(:test_output)"')
assert output =~ "Erlang/OTP #{System.otp_release()}"
assert output =~ "Elixir #{System.version()}"
- assert output =~ "test_output"
+ assert output =~ "Standalone options can't be combined with other options"
end
test "--short-version smoke test" do
diff --git a/lib/elixir/test/elixir/test_helper.exs b/lib/elixir/test/elixir/test_helper.exs
index a20b7371d..0425019ee 100644
--- a/lib/elixir/test/elixir/test_helper.exs
+++ b/lib/elixir/test/elixir/test_helper.exs
@@ -39,6 +39,14 @@ defmodule PathHelpers do
executable_path("elixirc")
end
+ def iex(args) do
+ run_cmd(iex_executable(), args)
+ end
+
+ def iex_executable do
+ executable_path("iex")
+ end
+
def write_beam({:module, name, bin, _} = res) do
File.mkdir_p!(unquote(path))
beam_path = Path.join(unquote(path), Atom.to_string(name) <> ".beam")