-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve incompatible version errors on boot
This commit makes a few improvements to the errors shown when Lexical boots with incompatible Elixir/Erlang versions: * Consistent formatting for all errors * Prevent an exception that would occur if using an incompatible major version (e.g. Elixir 1.12) * If both Elixir and Erlang are incompatible, show both errors * Show full range of compatible versions instead of just the range for the current major version
- Loading branch information
1 parent
ef0a427
commit 1a2e4f1
Showing
3 changed files
with
124 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
defmodule Lexical.Server.BootTest do | ||
alias Lexical.Server.Boot | ||
alias Lexical.VM.Versions | ||
|
||
use ExUnit.Case | ||
use Patch | ||
|
||
describe "detect_errors/0" do | ||
test "returns empty list when all checks succeed" do | ||
patch_runtime_versions("1.14.5", "25.0") | ||
patch_compiled_versions("1.14.5", "25.0") | ||
|
||
assert [] = Boot.detect_errors() | ||
end | ||
|
||
test "includes error when compiled erlang is too new" do | ||
patch_runtime_versions("1.14.5", "25.0") | ||
patch_compiled_versions("1.14.5", "26.1") | ||
|
||
assert [error] = Boot.detect_errors() | ||
assert error =~ "FATAL: Lexical version check failed" | ||
assert error =~ "Compiled with: 26.1" | ||
assert error =~ "Started with: 25.0" | ||
end | ||
|
||
test "includes error when runtime elixir is incompatible" do | ||
patch_runtime_versions("1.12.0", "24.3.4") | ||
patch_compiled_versions("1.13.4", "24.3.4") | ||
|
||
assert [error] = Boot.detect_errors() | ||
assert error =~ "FATAL: Lexical is not compatible with Elixir 1.12.0" | ||
end | ||
|
||
test "includes error when runtime erlang is incompatible" do | ||
patch_runtime_versions("1.13.4", "23.0") | ||
patch_compiled_versions("1.13.4", "23.0") | ||
|
||
assert [error] = Boot.detect_errors() | ||
assert error =~ "FATAL: Lexical is not compatible with Erlang/OTP 23.0.0" | ||
end | ||
|
||
test "includes multiple errors when runtime elixir and erlang are incompatible" do | ||
patch_runtime_versions("1.15.2", "26.0.0") | ||
patch_compiled_versions("1.15.6", "26.1") | ||
|
||
assert [elixir_error, erlang_error] = Boot.detect_errors() | ||
assert elixir_error =~ "FATAL: Lexical is not compatible with Elixir 1.15.2" | ||
assert erlang_error =~ "FATAL: Lexical is not compatible with Erlang/OTP 26.0.0" | ||
end | ||
end | ||
|
||
defp patch_runtime_versions(elixir, erlang) do | ||
patch(Versions, :elixir_version, elixir) | ||
patch(Versions, :erlang_version, erlang) | ||
end | ||
|
||
defp patch_compiled_versions(elixir, erlang) do | ||
patch(Versions, :code_find_file, fn file -> {:ok, file} end) | ||
|
||
patch(Versions, :read_file, fn file -> | ||
if String.ends_with?(file, ".elixir") do | ||
{:ok, elixir} | ||
else | ||
{:ok, erlang} | ||
end | ||
end) | ||
end | ||
end |