remove_from_coverage 2.0.0 copy "remove_from_coverage: ^2.0.0" to clipboard
remove_from_coverage: ^2.0.0 copied to clipboard

A command-line tool to customize the contents of a coverage lcov.info file.

example/README.md

Example Project #

Given here is an example project that can use remove_from_coverage to fix its coverage data in coverage/lcov.info.

Project Explanation #

In lib, name.dart contains a Name class that stores a first, middle, and last name. Since we want Name to be an immutable value class, it makes use of the excellent built_value package to automatically generate a toString method, == operator, and builder.

built_value does its code generation in another file, name.g.dart, using Dart's part mechanic to link it to name.dart.

We can trigger the code generation with the following command:

pub run build_runner build

In test, name_test.dart covers the functionality we desire from this package.

The Problem #

Our test in name_test.dart is sufficient for our testing of name.dart, but code coverage packages would also evaluate the coverage of name.g.dart. There might be cases where we'd want to test everything in that generated file, but if we don't, that generated file might have very few lines covered.

Suppose we use the test_cov package to generate coverage statistics:

dart run test_cov

We're told that the code coverage is only 56.9% and the output lcov.info file is saved to the coverage directory.

The Solution #

We can use remove_from_coverage to strip out undesired data from the lcov.info file, so that any reports generated from it will properly reflect the coverage.

If pub global scripts are on your path, you can use the following:

remove_from_coverage -f coverage/lcov.info -r '.g.dart$'

Otherwise, you can use the following:

dart global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '.g.dart$'

Now, lcov.info shows only the files we desire, so any reports/percentages generates from it will now be correct.

In general, note that generated files should not be added to source control as I've done here. I added name.g.dart and .test_coverage.dart so the example can be browsed online.

Similarly, the entire coverage directory is not often necessary to add to source control.

33
likes
140
pub points
79%
popularity

Publisher

unverified uploader

A command-line tool to customize the contents of a coverage lcov.info file.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

args

More

Packages that depend on remove_from_coverage