Skip to content

Commit 2efc1e5

Browse files
committed
Make sure --version flag halts elixir and iex, closes #11453
1 parent a0b77bd commit 2efc1e5

File tree

7 files changed

+25
-8
lines changed

7 files changed

+25
-8
lines changed

bin/elixir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Usage: $(basename "$0") [options] [.exs file] [data]
1616
-pr "FILE" Requires the given files/patterns in parallel (*)
1717
-pa "PATH" Prepends the given path to Erlang code path (*)
1818
-pz "PATH" Appends the given path to Erlang code path (*)
19-
-v, --version Prints Erlang/OTP and Elixir versions
19+
-v, --version Prints Erlang/OTP and Elixir versions (standalone)
2020
2121
--app APP Starts the given app and its dependencies (*)
2222
--erl "SWITCHES" Switches to be passed down to Erlang (*)

bin/elixir.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ echo -S SCRIPT Finds and executes the given script in $PATH
2323
echo -pr "FILE" Requires the given files/patterns in parallel (*)
2424
echo -pa "PATH" Prepends the given path to Erlang code path (*)
2525
echo -pz "PATH" Appends the given path to Erlang code path (*)
26-
echo -v, --version Prints Erlang/OTP and Elixir versions
26+
echo -v, --version Prints Erlang/OTP and Elixir versions (standalone)
2727
echo.
2828
echo --app APP Starts the given app and its dependencies (*)
2929
echo --erl "SWITCHES" Switches to be passed down to Erlang (*)

bin/elixirc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Usage: $(basename "$0") [elixir switches] [compiler switches] [.ex files]
77
88
-h, --help Prints this message and exits
99
-o The directory to output compiled files
10-
-v, --version Prints Elixir version and exits
10+
-v, --version Prints Elixir version and exits (standalone)
1111
1212
--ignore-module-conflict Does not emit warnings if a module was previously defined
1313
--no-debug-info Does not attach debug info to compiled modules

bin/elixirc.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ echo Usage: %~nx0 [elixir switches] [compiler switches] [.ex files]
1616
echo.
1717
echo -h, --help Prints this message and exits
1818
echo -o The directory to output compiled files
19-
echo -v, --version Prints Elixir version and exits
19+
echo -v, --version Prints Elixir version and exits (standalone)
2020
echo.
2121
echo --ignore-module-conflict Does not emit warnings if a module was previously defined
2222
echo --no-debug-info Does not attach debug info to compiled modules

lib/elixir/lib/kernel/cli.ex

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,25 @@ defmodule Kernel.CLI do
218218

219219
# Parse shared options
220220

221-
defp parse_shared([opt | _], _config) when opt in @standalone_opts do
221+
defp warn_standalone(opt) do
222222
IO.puts(:stderr, "#{opt} : Standalone options can't be combined with other options")
223+
end
224+
225+
defp parse_shared([opt | _], _config) when opt in @standalone_opts do
226+
warn_standalone(opt)
223227
System.halt(1)
224228
end
225229

226-
defp parse_shared([opt | t], config) when opt in ["-v", "--version"] do
230+
defp parse_shared([opt | t], _config) when opt in ["-v", "--version"] do
227231
if function_exported?(IEx, :started?, 0) and IEx.started?() do
228232
IO.puts("IEx " <> System.build_info()[:build])
229233
else
230234
IO.puts(:erlang.system_info(:system_version))
231235
IO.puts("Elixir " <> System.build_info()[:build])
232236
end
233237

234-
parse_shared(t, config)
238+
t != [] && warn_standalone(opt)
239+
System.halt(1)
235240
end
236241

237242
defp parse_shared(["-pa", h | t], config) do

lib/elixir/test/elixir/kernel/cli_test.exs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@ defmodule Kernel.CLITest do
7171
assert output =~ "Erlang/OTP #{System.otp_release()}"
7272
assert output =~ "Elixir #{System.version()}"
7373

74+
output = iex('--version')
75+
assert output =~ "Erlang/OTP #{System.otp_release()}"
76+
assert output =~ "IEx #{System.version()}"
77+
7478
output = elixir('--version -e "IO.puts(:test_output)"')
7579
assert output =~ "Erlang/OTP #{System.otp_release()}"
7680
assert output =~ "Elixir #{System.version()}"
77-
assert output =~ "test_output"
81+
assert output =~ "Standalone options can't be combined with other options"
7882
end
7983

8084
test "--short-version smoke test" do

lib/elixir/test/elixir/test_helper.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ defmodule PathHelpers do
3939
executable_path("elixirc")
4040
end
4141

42+
def iex(args) do
43+
run_cmd(iex_executable(), args)
44+
end
45+
46+
def iex_executable do
47+
executable_path("iex")
48+
end
49+
4250
def write_beam({:module, name, bin, _} = res) do
4351
File.mkdir_p!(unquote(path))
4452
beam_path = Path.join(unquote(path), Atom.to_string(name) <> ".beam")

0 commit comments

Comments
 (0)