Skip to content

Commit 0790fd8

Browse files
committed
Fix tests on windows
Fixes #685
1 parent ec3b568 commit 0790fd8

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

apps/language_server/lib/language_server/providers/hover.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,19 @@ defmodule ElixirLS.LanguageServer.Providers.Hover do
165165
defp third_dep?(_source, nil), do: false
166166

167167
defp third_dep?(source, project_dir) do
168-
prefix = project_dir <> "/deps"
168+
prefix = deps_path(project_dir)
169169
String.starts_with?(source, prefix)
170170
end
171171

172172
defp third_dep_name(source, project_dir) do
173-
prefix = project_dir <> "/deps/"
173+
prefix = deps_path(project_dir) <> "/"
174174
String.replace_prefix(source, prefix, "") |> String.split("/") |> hd()
175175
end
176176

177+
defp deps_path(project_dir) do
178+
project_dir |> Path.expand() |> Path.join("deps")
179+
end
180+
177181
defp builtin?(source) do
178182
@builtin_flag |> Enum.any?(fn y -> String.contains?(source, y) end)
179183
end

apps/language_server/lib/language_server/server.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,13 +916,16 @@ defmodule ElixirLS.LanguageServer.Server do
916916

917917
test_pattern = get_in(state.settings, ["testPattern", app_name]) || "*_test.exs"
918918

919+
file_path = Path.expand(file_path)
920+
919921
Mix.Utils.extract_files(test_paths, test_pattern)
920922
|> Enum.any?(fn path -> String.ends_with?(file_path, path) end)
921923
end
922924

923925
defp is_test_file?(file_path) do
924926
test_paths = Mix.Project.config()[:test_paths] || ["test"]
925927
test_pattern = Mix.Project.config()[:test_pattern] || "*_test.exs"
928+
file_path = Path.expand(file_path)
926929

927930
Mix.Utils.extract_files(test_paths, test_pattern)
928931
|> Enum.map(&Path.absname/1)

apps/language_server/test/providers/formatting_test.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,10 @@ defmodule ElixirLS.LanguageServer.Providers.FormattingTest do
486486
assert_formatted("test/file.exs", project_dir)
487487
refute_formatted("test/file.ex", project_dir)
488488

489-
assert_formatted("symlink/file.exs", project_dir)
490-
refute_formatted("symlink/file.ex", project_dir)
489+
unless is_windows() do
490+
assert_formatted("symlink/file.exs", project_dir)
491+
refute_formatted("symlink/file.ex", project_dir)
492+
end
491493

492494
File.mkdir!("#{project_dir}/test/foo")
493495
refute_formatted("test/foo/file.ex", project_dir)

apps/language_server/test/server_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ defmodule ElixirLS.LanguageServer.ServerTest do
730730
Server.receive_packet(server, did_open(uri, "elixir", 1, code))
731731
Server.receive_packet(server, completion_req(1, uri, 2, 25))
732732

733-
resp = assert_receive(%{"id" => 1}, 5000)
733+
resp = assert_receive(%{"id" => 1}, 10000)
734734

735735
assert response(1, %{
736736
"isIncomplete" => true,
@@ -1280,7 +1280,7 @@ defmodule ElixirLS.LanguageServer.ServerTest do
12801280
file_uri = SourceFile.Path.to_uri(file_path)
12811281
file_absolute_path = SourceFile.Path.from_uri(file_uri)
12821282
text = File.read!(file_path)
1283-
project_dir = SourceFile.Path.from_uri("#{root_uri()}/apps/app1")
1283+
project_dir = SourceFile.Path.absolute_from_uri("#{root_uri()}/apps/app1")
12841284

12851285
initialize(server, %{"enableTestLenses" => true})
12861286

@@ -1365,7 +1365,7 @@ defmodule ElixirLS.LanguageServer.ServerTest do
13651365
file_uri = SourceFile.Path.to_uri(file_path)
13661366
file_absolute_path = SourceFile.Path.from_uri(file_uri)
13671367
text = File.read!(file_path)
1368-
project_dir = SourceFile.Path.from_uri(root_uri())
1368+
project_dir = SourceFile.Path.absolute_from_uri(root_uri())
13691369

13701370
initialize(server, %{"enableTestLenses" => true})
13711371

@@ -1427,7 +1427,7 @@ defmodule ElixirLS.LanguageServer.ServerTest do
14271427
file_uri = SourceFile.Path.to_uri(file_path)
14281428
file_absolute_path = SourceFile.Path.from_uri(file_uri)
14291429
text = File.read!(file_path)
1430-
project_dir = SourceFile.Path.from_uri("#{root_uri()}/apps/app1")
1430+
project_dir = SourceFile.Path.absolute_from_uri("#{root_uri()}/apps/app1")
14311431

14321432
initialize(server, %{
14331433
"enableTestLenses" => true,

apps/language_server/test/source_file/invalid_project_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule ElixirLS.LanguageServer.SourceFile.InvalidProjectTest do
77

88
def appropriate_formatter_function_name(_) do
99
formatter_function =
10-
if function_exported?(Mix.Tasks.Format, :formatter_for_file, 1) do
10+
if Version.match?(System.version(), ">= 1.13.0") do
1111
:formatter_for_file
1212
else
1313
:formatter_opts_for_file
@@ -16,7 +16,7 @@ defmodule ElixirLS.LanguageServer.SourceFile.InvalidProjectTest do
1616
{:ok, formatter_name: formatter_function}
1717
end
1818

19-
describe "formatter_for " do
19+
describe "formatter_for" do
2020
setup [:appropriate_formatter_function_name]
2121

2222
test "should handle syntax errors", ctx do

apps/language_server/test/source_file/path_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ defmodule ElixirLS.LanguageServer.SourceFile.PathTest do
130130
describe "to_uri/1" do
131131
# tests based on cases from https://github.com/microsoft/vscode-uri/blob/master/src/test/uri.test.ts
132132
test "unix path" do
133-
with_os(:linux, fn ->
133+
unless is_windows() do
134134
assert "file:///nodes%2B%23.ex" == to_uri("/nodes+#.ex")
135135
assert "file:///coding/c%23/project1" == to_uri("/coding/c#/project1")
136136

@@ -139,7 +139,7 @@ defmodule ElixirLS.LanguageServer.SourceFile.PathTest do
139139

140140
assert "file:///foo/%25A0.txt" == to_uri("/foo/%A0.txt")
141141
assert "file:///foo/%252e.txt" == to_uri("/foo/%2e.txt")
142-
end)
142+
end
143143
end
144144

145145
test "windows path" do

0 commit comments

Comments
 (0)