Make sure --version flag halts elixir and iex, closes #11453

This commit is contained in:
José Valim
2021-12-07 08:24:01 +01:00
parent a0b77bd884
commit 2efc1e5cac
7 changed files with 25 additions and 8 deletions
+8 -3
View File
@@ -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
+5 -1
View File
@@ -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
+8
View File
@@ -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")