Skip to content

Commit 74d6183

Browse files
committed
Add docs on native coverage
1 parent 9b80ab5 commit 74d6183

2 files changed

Lines changed: 26 additions & 20 deletions

File tree

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ defmodule Mix.Tasks.Test.Coverage do
1717
1818
Elixir uses Erlang's [`:cover`](`:cover`) for its default test coverage.
1919
Erlang coverage is done by tracking *executable lines of code*.
20-
This implies blank lines, code comments,
20+
This implies blank lines, code comments, literals (such as atoms),
2121
function signatures, and patterns are not necessarily executable and
22-
therefore won't be tracked in coverage reports. Code in macros are
23-
also often executed at compilation time, and therefore may not be covered.
24-
Similarly, Elixir AST literals, such as atoms, are not executable either.
22+
therefore won't be tracked in coverage reports. Code in macros defined in
23+
your project are also often executed at compilation time, and therefore
24+
may not be covered.
2525
2626
Let's see an example:
2727
@@ -75,6 +75,16 @@ defmodule Mix.Tasks.Test.Coverage do
7575
coverage techniques. It is up to you and your team to specify how much
7676
emphasis you want to place on it.
7777
78+
## Native coverage
79+
80+
Erlang/OTP 27+ supports "native coverage", which relies on the JIT compiler
81+
to compute coverage, leading to better performance when running a test suite
82+
with coverage enabled.
83+
84+
You can enable it by setting:
85+
86+
ERL_COMPILER_OPTIONS=line_coverage mix test.coverage
87+
7888
## Exporting coverage
7989
8090
This task can be used when you need to group the coverage

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -359,24 +359,20 @@ defmodule Mix.Tasks.Test do
359359
360360
### Limitations
361361
362-
Coverage in Elixir has the following limitations:
363-
364-
* Literals, such as atoms, strings, and numbers, are not traced by coverage.
365-
For example, if a function simply returns `:ok`, the atom `:ok` itself is
366-
never taken into account by coverage;
367-
368-
* Macros, such as the ones defined by `defmacro/2` and `defguard/2`, and code
369-
invoked only by macros are never considered as covered, unless they are also
370-
invoked during the tests themselves. That's because macros are invoked at
371-
compilation time, before the test coverage instrumentation begins;
362+
Elixir uses Erlang's [`:cover`](`:cover`) for its default test coverage.
363+
Erlang coverage is done by tracking *executable lines of code*. See
364+
`mix test.coverage` for details.
372365
373366
### Configuration
374367
375-
The `:test_coverage` configures the coverage tool and accepts the following options:
376-
377-
* `:output` - the output directory for cover results. Defaults to `"cover"`.
368+
The `:test_coverage` configures the coverage tool and the default tool
369+
accepts the following options:
378370
379371
* `:tool` - a module specifying the coverage tool to use.
372+
Defaults to `Mix.Tasks.Test.Coverage`.
373+
374+
* `:output` - the output directory for cover results.
375+
Defaults to `"cover"`.
380376
381377
* `:summary` - at the end of each coverage run, a summary of each
382378
module is printed, with results in red or green depending on whether
@@ -399,9 +395,9 @@ defmodule Mix.Tasks.Test do
399395
* `:local_only` - by default coverage only tracks local calls,
400396
set this option to false if you plan to run coverage across nodes.
401397
402-
By default, a wrapper around OTP's `cover` is used as the default coverage
403-
tool. You can learn more about how it works in the docs for
404-
`mix test.coverage`. Your tool of choice can be given as follows:
398+
By default, a wrapper around OTP's `cover` is used as the coverage tool.
399+
You can learn more about how it works in the docs for `mix test.coverage`.
400+
Your tool of choice can be given as follows:
405401
406402
def project() do
407403
[

0 commit comments

Comments
 (0)