diff --git a/CHANGELOG.md b/CHANGELOG.md index ce5fb6b5..7c560ae7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com ## [Unreleased] - cargo-llvm-cov no longer changes the current directory when running cargo. ([#161](https://github.com/taiki-e/cargo-llvm-cov/pull/161)) +- Exclude build script from report by default. ([#163](https://github.com/taiki-e/cargo-llvm-cov/pull/163)) + You can use `--include-build-script` flag to include build script in report. ## [0.3.3] - 2022-05-06 diff --git a/README.md b/README.md index ead93040..63f652d7 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,9 @@ OPTIONS: --show-missing-lines Show lines with no coverage + --include-build-script + Include build script in coverage report + --doctests Including doc tests (unstable) diff --git a/src/cli.rs b/src/cli.rs index 2a9a8c35..604ec3f5 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -319,6 +319,9 @@ pub(crate) struct LlvmCovOptions { /// Show lines with no coverage. #[clap(long)] pub(crate) show_missing_lines: bool, + /// Include build script in coverage report. + #[clap(long)] + pub(crate) include_build_script: bool, } impl LlvmCovOptions { diff --git a/src/main.rs b/src/main.rs index d2b69ff1..7d1201ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -448,8 +448,12 @@ fn object_files(cx: &Context) -> Result> { if stem == "build-script-build" || stem.starts_with("build_script_build-") { let p = p.parent().unwrap(); if p.parent().unwrap().file_name().unwrap() == "build" { - let dir = p.file_name().unwrap().to_string_lossy(); - if !cx.build_script_re.is_match(&dir) { + if cx.cov.include_build_script { + let dir = p.file_name().unwrap().to_string_lossy(); + if !cx.build_script_re.is_match(&dir) { + return false; + } + } else { return false; } } diff --git a/tests/long-help.txt b/tests/long-help.txt index 42b4e140..206f79e2 100644 --- a/tests/long-help.txt +++ b/tests/long-help.txt @@ -88,6 +88,9 @@ OPTIONS: --show-missing-lines Show lines with no coverage + --include-build-script + Include build script in coverage report + --doctests Including doc tests (unstable) diff --git a/tests/short-help.txt b/tests/short-help.txt index d3a3e80f..76495e8c 100644 --- a/tests/short-help.txt +++ b/tests/short-help.txt @@ -56,6 +56,9 @@ OPTIONS: --show-missing-lines Show lines with no coverage + --include-build-script + Include build script in coverage report + --doctests Including doc tests (unstable)