@@ -83,6 +83,7 @@ defmodule Mix.Tasks.Compile.ErlangTest do
8383 test "continues even if one file fails to compile" do
8484 in_fixture ( "compile_erlang" , fn ->
8585 file = Path . absname ( "src/zzz.erl" )
86+ source = deterministic_source ( file )
8687
8788 File . write! ( file , """
8889 -module(zzz).
@@ -94,8 +95,8 @@ defmodule Mix.Tasks.Compile.ErlangTest do
9495
9596 assert % Mix.Task.Compiler.Diagnostic {
9697 compiler_name: "erl_parse" ,
97- file: ^ file ,
98- source: ^ file ,
98+ file: ^ source ,
99+ source: ^ source ,
99100 message: "syntax error before: zzz" ,
100101 position: position ( 2 , 5 ) ,
101102 severity: :error
@@ -110,6 +111,7 @@ defmodule Mix.Tasks.Compile.ErlangTest do
110111 test "saves warnings between builds" do
111112 in_fixture ( "compile_erlang" , fn ->
112113 file = Path . absname ( "src/has_warning.erl" )
114+ source = deterministic_source ( file )
113115
114116 File . write! ( file , """
115117 -module(has_warning).
@@ -120,8 +122,8 @@ defmodule Mix.Tasks.Compile.ErlangTest do
120122 assert { :ok , [ diagnostic ] } = Mix.Tasks.Compile.Erlang . run ( [ ] )
121123
122124 assert % Mix.Task.Compiler.Diagnostic {
123- file: ^ file ,
124- source: ^ file ,
125+ file: ^ source ,
126+ source: ^ source ,
125127 compiler_name: "erl_lint" ,
126128 message: "function my_fn/0 is unused" ,
127129 position: position ( 2 , 1 ) ,
@@ -161,11 +163,11 @@ defmodule Mix.Tasks.Compile.ErlangTest do
161163
162164 assert capture_io ( fn ->
163165 assert { :noop , _ } = Mix.Tasks.Compile.Erlang . run ( [ ] )
164- end ) =~ ~r" src/ has_warning.erl:2:(1:)? warning: function my_fn/0 is unused\n "
166+ end ) =~ ~r" has_warning.erl:2:(1:)? warning: function my_fn/0 is unused\n "
165167
166168 assert capture_io ( fn ->
167169 assert { :noop , _ } = Mix.Tasks.Compile.Erlang . run ( [ ] )
168- end ) =~ ~r" src/ has_warning.erl:2:(1:)? warning: function my_fn/0 is unused\n "
170+ end ) =~ ~r" has_warning.erl:2:(1:)? warning: function my_fn/0 is unused\n "
169171
170172 # Should not print old warnings after fixing
171173 File . write! ( file , """
@@ -183,6 +185,39 @@ defmodule Mix.Tasks.Compile.ErlangTest do
183185 end )
184186 end
185187
188+ test "returns syntax error from an Erlang file when --return-errors is set" do
189+ in_fixture ( "no_mixfile" , fn ->
190+ import ExUnit.CaptureIO
191+
192+ file = Path . absname ( "src/a.erl" )
193+ source = deterministic_source ( file )
194+
195+ File . mkdir! ( "src" )
196+
197+ File . write! ( file , """
198+ -module(b).
199+ def b(), do: b
200+ """ )
201+
202+ capture_io ( fn ->
203+ assert { :error , [ diagnostic ] } =
204+ Mix.Tasks.Compile.Erlang . run ( [ "--force" , "--return-errors" ] )
205+
206+ assert % Mix.Task.Compiler.Diagnostic {
207+ compiler_name: "erl_parse" ,
208+ file: ^ source ,
209+ source: ^ source ,
210+ message: "syntax error before: b" ,
211+ position: position ( 2 , 5 ) ,
212+ severity: :error
213+ } = diagnostic
214+ end )
215+
216+ refute File . regular? ( "ebin/Elixir.A.beam" )
217+ refute File . regular? ( "ebin/Elixir.B.beam" )
218+ end )
219+ end
220+
186221 @ tag erlc_options: [ { :warnings_as_errors , true } ]
187222 test "adds :debug_info to erlc_options by default" do
188223 in_fixture ( "compile_erlang" , fn ->
@@ -196,4 +231,10 @@ defmodule Mix.Tasks.Compile.ErlangTest do
196231 assert debug_info != :none
197232 end )
198233 end
234+
235+ if :deterministic in :compile . env_compiler_options ( ) do
236+ defp deterministic_source ( file ) , do: Path . basename ( file )
237+ else
238+ defp deterministic_source ( file ) , do: file
239+ end
199240end
0 commit comments