Skip to content

Commit b53ac91

Browse files
committed
Fixed unit tests
When patches are unapplied, getting the beam file returned an empty path charlist, which dialyzer assumed was a real file name due to a weak assumption, which caused unit tests to fail. This was remedied by checking for a non-empty charlist, which allows tests to succeed. Also made patch a test only dependency for .formatter.exs, as this was causing formatters to fail.
1 parent 840caeb commit b53ac91

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

apps/language_server/.formatter.exs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ impossible_to_format = [
33
"test/fixtures/project_with_tests/test/error_test.exs"
44
]
55

6+
deps =
7+
if Mix.env() == :test do
8+
[:patch]
9+
else
10+
[]
11+
end
12+
613
proto_dsl = [
714
defalias: 1,
815
defenum: 1,
@@ -14,7 +21,7 @@ proto_dsl = [
1421
]
1522

1623
[
17-
import_deps: [:patch],
24+
import_deps: deps,
1825
export: [
1926
locals_without_parens: proto_dsl
2027
],

apps/language_server/lib/language_server/dialyzer/utils.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ defmodule ElixirLS.LanguageServer.Dialyzer.Utils do
44
@spec dialyzable?(module()) :: boolean()
55
def dialyzable?(module) do
66
file = get_beam_file(module)
7+
78
is_list(file) and match?({:ok, _}, :dialyzer_utils.get_core_from_beam(file))
89
end
910

1011
@spec get_beam_file(module()) :: charlist() | :preloaded | :non_existing | :cover_compiled
1112
def get_beam_file(module) do
1213
case :code.which(module) do
13-
file when is_list(file) ->
14+
[_ | _] = file ->
1415
file
1516

1617
other ->

apps/language_server/test/experimental/project_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ defmodule ElixirLS.Experimental.ProjectTest do
137137

138138
def with_patched_system_put_env(_) do
139139
patch(System, :put_env, :ok)
140+
on_exit(fn -> restore(System) end)
140141
:ok
141142
end
142143

apps/language_server/test/experimental/server/configuration_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ defmodule ElixirLS.Experimental.Server.ConfigurationTest do
149149

150150
def with_patched_system_put_env(_) do
151151
patch(System, :put_env, :ok)
152+
153+
on_exit(fn ->
154+
restore(System)
155+
end)
156+
152157
:ok
153158
end
154159

0 commit comments

Comments
 (0)