Skip to content

Commit ead9d5a

Browse files
Import .coverdata after test run and improve documentation (#309)
* Import `.coverdata` after test run and improve docs * Update README table of contents * Update README based on review suggestion Co-authored-by: Alberto Sartori <[email protected]> --------- Co-authored-by: Alberto Sartori <[email protected]>
1 parent 36ac3ba commit ead9d5a

File tree

3 files changed

+62
-14
lines changed

3 files changed

+62
-14
lines changed

README.md

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,17 @@ end
9191
- [[mix coveralls.cobertura] Show coverage as Cobertura report](#mix-coverallscobertura-show-coverage-as-cobertura-report)
9292
- [[mix coveralls.lcov] Show coverage as lcov report (Experimental)](#mix-coverallslcov-show-coverage-as-lcov-report-experimental)
9393
- [coveralls.json](#coverallsjson)
94-
- [Stop Words](#stop-words)
95-
- [Exclude Files](#exclude-files)
96-
- [Terminal Report Output](#terminal-report-output)
97-
- [Coverage Options](#coverage-options)
94+
- [Stop Words](#stop-words)
95+
- [Exclude Files](#exclude-files)
96+
- [Terminal Report Output](#terminal-report-output)
97+
- [Coverage Options](#coverage-options)
98+
- [Other Considerations](#other-considerations)
9899
- [Ignore Lines](#ignore-lines)
100+
- [Silence OTP Cover Warnings](#silence-otp-cover-warnings)
101+
- [Merging Coverage Results](#merging-coverage-results)
99102
- [Notes](#notes)
100103
- [Todo](#todo)
101-
- [License](#license)
104+
- [License](#license)
102105

103106
### [mix coveralls] Show coverage
104107
Run the `MIX_ENV=test mix coveralls` command to show coverage information on localhost.
@@ -146,7 +149,8 @@ Usage: mix coveralls <Options>
146149
and your git repo resides in "app", then the root path should be: "/home/runs/app/" (from
147150
coveralls.io)
148151
--flagname Job flag name which will be shown in the Coveralls UI
149-
--import_cover Directory from where '.coverdata' files should be imported and their results added to the report
152+
--import-cover Directory from where '.coverdata' files should be imported and their results added to the report.
153+
Coverdata is imported after tests are run.
150154

151155
Usage: mix coveralls.detail [--filter file-name-pattern]
152156
Used to display coverage with detail
@@ -463,6 +467,8 @@ Example configuration file:
463467
}
464468
```
465469
470+
## Other Considerations
471+
466472
### Ignore Lines
467473
468474
Use comments `coveralls-ignore-start` and `coveralls-ignore-stop` to ignore certain lines from code coverage calculation.
@@ -503,6 +509,46 @@ imported_info(_Text,_Module,_Imported) ->
503509
ok.
504510
```
505511
512+
### Merging Coverage Results
513+
514+
ExCoveralls can include `.coverdata` files in the result of the current test run through the `--import-cover` flag. This can be used to include coverage data from partitioned tests or integration tests that may run in a subprocess, for instance.
515+
516+
Coverage data is generated when running `mix test --cover`, optionally with the `--export-coverage` flag to specify an output name.
517+
518+
```shell
519+
$ mix test --only integration --cover --export-coverage integration-coverage
520+
Excluding tags: [:test]
521+
Including tags: [:integration]
522+
... test run omitted ...
523+
# Coverage data written to cover/integration-coverage.coverdata
524+
525+
# Report coverage, do not run integration tests
526+
$ mix coveralls --exclude integration
527+
Excluding tags: [:integration]
528+
... test run omitted ...
529+
530+
----------------
531+
COV FILE LINES RELEVANT MISSED
532+
...
533+
[TOTAL] 80.2% # <-- This result does not include coverage from integration tests
534+
----------------
535+
536+
# Report coverage, do not run integration tests, but include previously written coverdata
537+
$ mix coveralls --exclude integration --import-cover cover
538+
Excluding tags: [:integration]
539+
... test run omitted ...
540+
541+
----------------
542+
COV FILE LINES RELEVANT MISSED
543+
...
544+
[TOTAL] 95.3% # <-- This result now includes coverage from integration tests
545+
----------------
546+
```
547+
548+
Coverage data is imported after tests are run.
549+
550+
See the `mix test` [Coverage documentation](https://hexdocs.pm/mix/Mix.Tasks.Test.html#module-coverage) for more information on `.coverdata`.
551+
506552
### Notes
507553
- If mock library is used, it will show some warnings during execution.
508554
- https://github.com/eproxus/meck/pull/17
@@ -514,6 +560,6 @@ imported_info(_Text,_Module,_Imported) ->
514560
- It might not work well on projects which handle multiple project (Mix.Project) files.
515561
- Needs improvement on file-path handling.
516562
517-
## License
563+
# License
518564
519565
This source code is licensed under the MIT license. Copyright (c) 2013-present, parroty.

lib/excoveralls.ex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ defmodule ExCoveralls do
4141
def start(compile_path, opts) do
4242
Cover.compile(compile_path)
4343

44-
options = ConfServer.get()
45-
if options[:import_cover] do
46-
Cover.import(options[:import_cover])
47-
end
48-
4944
fn() ->
50-
execute(ConfServer.get, compile_path, opts)
45+
options = ConfServer.get()
46+
47+
if options[:import_cover] do
48+
Cover.import(options[:import_cover])
49+
end
50+
51+
execute(options, compile_path, opts)
5152
end
5253
end
5354

lib/excoveralls/task/util.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Usage: mix coveralls <Options>
2727
and your git repo resides in "app", then the root path should be: "/home/runs/app/" (from
2828
coveralls.io)
2929
--flagname Job flag name which will be shown in the Coveralls UI
30-
--import_cover Directory from where '.coverdata' files should be imported and their results added to the report
30+
--import-cover Directory from where '.coverdata' files should be imported and their results added to the report.
31+
Coverdata is imported after tests are run.
3132
3233
Usage: mix coveralls.detail [--filter file-name-pattern]
3334
Used to display coverage with detail

0 commit comments

Comments
 (0)