Skip to content

Commit df8784d

Browse files
committed
More fixes
1 parent ab02c33 commit df8784d

File tree

9 files changed

+72
-50
lines changed

9 files changed

+72
-50
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ permissions:
1818

1919
jobs:
2020
test_linux:
21-
name: Ubuntu 24.04, Erlang/OTP ${{ matrix.otp_version }}
21+
name: Ubuntu 24.04, Erlang/OTP ${{ matrix.otp_version }}${{ matrix.deterministic && ' (deterministic)' || '' }}
2222
strategy:
2323
fail-fast: false
2424
matrix:
2525
include:
26+
- otp_version: "27.1"
27+
deterministic: true
2628
- otp_version: "27.1"
2729
otp_latest: true
2830
- otp_version: "27.0"
@@ -34,11 +36,8 @@ jobs:
3436
- otp_version: maint
3537
development: true
3638
runs-on: ubuntu-24.04
37-
# The following env vars are only respected from Erlang/OTP 27.1,
38-
# and therefore are gated behind otp_latest.
3939
env:
40-
ERLC_OPTS: ${{ matrix.otp_latest && 'warnings_as_errors' || '' }}
41-
ERL_COMPILER_OPTIONS: ${{ matrix.otp_latest && 'deterministic' || '' }}
40+
ERL_COMPILER_OPTIONS: ${{ matrix.deterministic && 'warnings_as_errors deterministic' || '' }}
4241
steps:
4342
- uses: actions/checkout@v4
4443
with:
@@ -75,7 +74,7 @@ jobs:
7574
# Recompile System without .git
7675
cd lib/elixir && ../../bin/elixirc -o ebin lib/system.ex && cd -
7776
taskset 1 make check_reproducible
78-
if: ${{ matrix.otp_latest }}
77+
if: ${{ matrix.deterministic }}
7978

8079
test_windows:
8180
name: Windows Server 2019, Erlang/OTP ${{ matrix.otp_version }}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ MAN_PREFIX ?= $(SHARE_PREFIX)/man
55
CANONICAL := main/
66
ELIXIRC := bin/elixirc --ignore-module-conflict $(ELIXIRC_OPTS)
77
ERLC := erlc -I lib/elixir/include
8-
ERL_MAKE := if [ -n "$(ERLC_OPTS)" ]; then ERL_COMPILER_OPTIONS=$(ERLC_OPTS) erl -make; else erl -make; fi
8+
ERL_MAKE := erl -make
99
ERL := erl -I lib/elixir/include -noshell -pa lib/elixir/ebin
1010
GENERATE_APP := $(CURDIR)/lib/elixir/scripts/generate_app.escript
1111
VERSION := $(strip $(shell cat VERSION))

lib/mix/lib/mix/compilers/erlang.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,8 @@ defmodule Mix.Compilers.Erlang do
295295

296296
defp to_diagnostics(warnings_or_errors, severity) do
297297
for {file, issues} <- warnings_or_errors,
298+
file = if(?/ in file, do: Path.absname(file), else: List.to_string(file)),
298299
{location, module, data} <- issues do
299-
file = Path.absname(file)
300-
301300
%Mix.Task.Compiler.Diagnostic{
302301
file: file,
303302
source: file,

lib/mix/lib/mix/project.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,12 @@ defmodule Mix.Project do
163163
# Only the top of the stack can be accessed.
164164
@doc false
165165
def push(module, file \\ nil, app \\ nil) when is_atom(module) do
166-
file = file || (module && List.to_string(module.__info__(:compile)[:source]))
166+
file =
167+
cond do
168+
file != nil -> file
169+
source = module && module.module_info(:compile)[:source] -> List.to_string(source)
170+
true -> "nofile"
171+
end
167172

168173
case Mix.ProjectStack.push(module, push_config(module, app), file) do
169174
:ok ->

lib/mix/test/mix/cli_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ defmodule Mix.CLITest do
240240
System.delete_env("MIX_EXS")
241241
end
242242

243+
@tag :cover
243244
@tag tmp_dir: "new_with_tests"
244245
test "new with tests and cover", %{tmp_dir: tmp_dir} do
245246
File.cd!(tmp_dir, fn ->

lib/mix/test/mix/tasks/compile.erlang_test.exs

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
199240
end

lib/mix/test/mix/tasks/compile_test.exs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -224,38 +224,6 @@ defmodule Mix.Tasks.CompileTest do
224224
end)
225225
end
226226

227-
test "returns syntax error from an Erlang file when --return-errors is set" do
228-
in_fixture("no_mixfile", fn ->
229-
import ExUnit.CaptureIO
230-
231-
file = Path.absname("src/a.erl")
232-
File.mkdir!("src")
233-
234-
File.write!(file, """
235-
-module(b).
236-
def b(), do: b
237-
""")
238-
239-
assert File.regular?(file)
240-
241-
capture_io(fn ->
242-
assert {:error, [diagnostic]} = Mix.Task.run("compile", ["--force", "--return-errors"])
243-
244-
assert %Mix.Task.Compiler.Diagnostic{
245-
compiler_name: "erl_parse",
246-
file: ^file,
247-
source: ^file,
248-
message: "syntax error before: b",
249-
position: position(2, 5),
250-
severity: :error
251-
} = diagnostic
252-
end)
253-
254-
refute File.regular?("ebin/Elixir.A.beam")
255-
refute File.regular?("ebin/Elixir.B.beam")
256-
end)
257-
end
258-
259227
test "skip protocol consolidation when --no-protocol-consolidation" do
260228
in_fixture("no_mixfile", fn ->
261229
File.rm("_build/dev/lib/sample/.mix/compile.protocols")

lib/mix/test/mix/tasks/test_test.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ defmodule Mix.Tasks.TestTest do
134134
end
135135

136136
describe "--cover" do
137+
@describetag :cover
137138
test "reports the coverage of each app's modules in an umbrella" do
138139
in_fixture("umbrella_test", fn ->
139140
# This fixture by default results in coverage above the default threshold
@@ -341,7 +342,8 @@ defmodule Mix.Tasks.TestTest do
341342
end
342343

343344
describe "--partitions" do
344-
test "splits tests into partitions" do
345+
@tag :cover
346+
test "splits tests into partitions (with coverage)" do
345347
in_fixture("test_stale", fn ->
346348
assert mix(["test", "--partitions", "3", "--cover"], [{"MIX_TEST_PARTITION", "1"}]) =~
347349
"1 test, 0 failures"

lib/mix/test/test_helper.exs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,16 @@ git_exclude =
3737
{line_exclude, line_include} =
3838
if line = System.get_env("LINE"), do: {[:test], [line: line]}, else: {[], []}
3939

40+
cover_exclude =
41+
if :deterministic in :compile.env_compiler_options() do
42+
[:cover]
43+
else
44+
[]
45+
end
46+
4047
ExUnit.start(
4148
trace: !!System.get_env("TRACE"),
42-
exclude: epmd_exclude ++ os_exclude ++ git_exclude ++ line_exclude,
49+
exclude: epmd_exclude ++ os_exclude ++ git_exclude ++ line_exclude ++ cover_exclude,
4350
include: line_include
4451
)
4552

0 commit comments

Comments
 (0)