Skip to content

Commit 7d744eb

Browse files
gjJosé Valim
authored andcommitted
Ensure that mix --cover displays correct coverage in an umbrella app (#8176)
`:cover.start/0` initializes the internal database where coverage data on all compiled modules is stored. Prior to this change, the database wasn't cleared out between sub-apps in an umbrella app. When `:cover.analyse/2` is called, it runs against the entire contents of the internal database. In an umbrella app, the coverage report for App1 would show App1, the report for App2 would show App1 and App2, App3 would have App1, App2, and App3, and so on. Closes #8086
1 parent 3e6c698 commit 7d744eb

File tree

11 files changed

+83
-0
lines changed

11 files changed

+83
-0
lines changed

lib/mix/lib/mix/tasks/test.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule Mix.Tasks.Test do
66

77
def start(compile_path, opts) do
88
Mix.shell().info("Cover compiling modules ...")
9+
_ = :cover.stop()
910
_ = :cover.start()
1011

1112
case :cover.compile_beam_directory(compile_path |> to_charlist) do
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
defmodule Bar do
2+
def hello do
3+
:world
4+
end
5+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defmodule Bar.MixProject do
2+
use Mix.Project
3+
4+
def project do
5+
[
6+
app: :bar,
7+
version: "0.1.0",
8+
# Choose something besides *_test.exs so that these test files don't
9+
# get accidentally swept up into the actual Mix test suite.
10+
test_pattern: "*_tests.exs"
11+
]
12+
end
13+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule BarTest do
2+
use ExUnit.Case
3+
4+
test "greets the world" do
5+
assert Foo.hello() == :world
6+
end
7+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ExUnit.start()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
defmodule Foo do
2+
def hello do
3+
:world
4+
end
5+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defmodule Foo.MixProject do
2+
use Mix.Project
3+
4+
def project do
5+
[
6+
app: :foo,
7+
version: "0.1.0",
8+
# Choose something besides *_test.exs so that these test files don't
9+
# get accidentally swept up into the actual Mix test suite.
10+
test_pattern: "*_tests.exs"
11+
]
12+
end
13+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule FooTest do
2+
use ExUnit.Case
3+
4+
test "greets the world" do
5+
assert Foo.hello() == :world
6+
end
7+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ExUnit.start()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule UmbrellaCover.MixProject do
2+
use Mix.Project
3+
4+
def project do
5+
[
6+
apps_path: "apps"
7+
]
8+
end
9+
end

0 commit comments

Comments
 (0)