Skip to content

Commit b55fece

Browse files
authored
Fixed unit tests that were broken before 1.13 (#749)
The unit tests on builds prior to 1.13 were failing because I was patching the wrong function. Prior to 1.13, formatter_for_file didn't exist, but the unit tests would patch that but the `function_exported?` check in `source_file.ex` would skip that branch and succeed, which would cause the tests to fail. The change is simple, check to see if `formatter_for_file` exists, and if it doesn't, patch the `formatter_opts_for_file` function
1 parent 45149aa commit b55fece

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

apps/language_server/test/source_file/invalid_project_test.exs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,22 @@ defmodule ElixirLS.LanguageServer.SourceFile.InvalidProjectTest do
55
alias ElixirLS.LanguageServer.SourceFile
66
import ExUnit.CaptureLog
77

8+
def appropriate_formatter_function_name(_) do
9+
formatter_function =
10+
if function_exported?(Mix.Tasks.Format, :formatter_for_file, 1) do
11+
:formatter_for_file
12+
else
13+
:formatter_opts_for_file
14+
end
15+
16+
{:ok, formatter_name: formatter_function}
17+
end
18+
819
describe "formatter_for " do
9-
test "should handle syntax errors" do
10-
patch(Mix.Tasks.Format, :formatter_for_file, fn _ ->
20+
setup [:appropriate_formatter_function_name]
21+
22+
test "should handle syntax errors", ctx do
23+
patch(Mix.Tasks.Format, ctx.formatter_name, fn _ ->
1124
raise %SyntaxError{file: ".formatter.exs", line: 1}
1225
end)
1326

@@ -19,8 +32,8 @@ defmodule ElixirLS.LanguageServer.SourceFile.InvalidProjectTest do
1932
assert String.contains?(output, "Unable to get formatter options")
2033
end
2134

22-
test "should handle compile errors" do
23-
patch(Mix.Tasks.Format, :formatter_for_file, fn _ ->
35+
test "should handle compile errors", ctx do
36+
patch(Mix.Tasks.Format, ctx.formatter_name, fn _ ->
2437
raise %SyntaxError{file: ".formatter.exs", line: 1}
2538
end)
2639

0 commit comments

Comments
 (0)