Skip to content

Commit 43d3412

Browse files
committed
Add unstable --branch flag
1 parent 0f7a7de commit 43d3412

11 files changed

Lines changed: 62 additions & 11 deletions

File tree

.github/workflows/ci.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ jobs:
7676
- run: cargo test --workspace --all-features
7777
# TODO: move this test to tests/test.rs
7878
- run: cargo install --path . --debug
79-
- run: |
79+
- name: Test cargo llvm-cov nextest
80+
run: |
8081
set -eEuxo pipefail
8182
cargo llvm-cov nextest --text --fail-under-lines 50
8283
cargo llvm-cov nextest --text --fail-under-lines 50 --profile default --cargo-profile dev
@@ -103,20 +104,32 @@ jobs:
103104
cargo llvm-cov nextest --archive-file a.tar.zst --text --fail-under-lines 70
104105
cargo llvm-cov report --nextest-archive-file a.tar.zst --fail-under-lines 70
105106
working-directory: tests/fixtures/crates/bin_crate
106-
- run: |
107+
- name: Test nightly-specific options, old Cargo compatibility, trybuild compatibility
108+
run: |
107109
set -eEuxo pipefail
110+
111+
# Test nightly-specific options
108112
git clone https://github.com/taiki-e/easytime.git
109-
cd easytime
113+
pushd easytime >/dev/null
110114
git checkout 7ecb6e6
111115
cargo llvm-cov test --doctests --text --fail-under-lines 30
116+
popd >/dev/null
117+
pushd tests/fixtures/crates/cargo_config >/dev/null
118+
# TODO: --fail-under-branches?
119+
cargo llvm-cov test --branch --text --fail-under-lines 80
120+
popd >/dev/null
121+
112122
# Test minimum runnable Cargo version.
113123
rustup toolchain add 1.60 --no-self-update
124+
pushd easytime >/dev/null
114125
cargo +1.60 llvm-cov test --text --fail-under-lines 30
115-
cd ..
126+
popd >/dev/null
127+
116128
# Test trybuild compatibility.
117129
git clone --depth 1 https://github.com/taiki-e/easy-ext.git
118-
cd easy-ext
130+
pushd easy-ext >/dev/null
119131
cargo llvm-cov --text --test compiletest --fail-under-lines 70
132+
popd >/dev/null
120133
if: startsWith(matrix.rust, 'nightly')
121134
- run: cargo hack build --workspace --no-private --feature-powerset --no-dev-deps
122135
- run: cargo minimal-versions build --workspace --no-private --detach-path-deps=skip-exact --all-features

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
1010

1111
## [Unreleased]
1212

13+
- Add unstable `--branch` flag to include branch coverage. ([#356](https://github.com/taiki-e/cargo-llvm-cov/pull/356))
14+
1315
## [0.6.7] - 2024-03-10
1416

1517
- Add `--nextest-archive-file` option to `cargo llvm-cov report` to support calling it for the result of `cargo llvm-cov nextest --archive-file`. ([#355](https://github.com/taiki-e/cargo-llvm-cov/pull/355))

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Cargo subcommand to easily use LLVM source-based code coverage.
88

99
This is a wrapper around rustc [`-C instrument-coverage`][instrument-coverage] and provides:
1010

11-
- Generate very precise coverage data. (line coverage and region coverage)
11+
- Generate very precise coverage data. (line, region, and branch coverage. branch coverage is currently optional and requires nightly, see [#8] for more)
1212
- Support `cargo test`, `cargo run`, and [`cargo nextest`][nextest] with command-line interface compatible with cargo.
1313
- Support for proc-macro, including coverage of UI tests.
1414
- Support for doc tests. (this is currently optional and requires nightly, see [#2] for more)
@@ -181,6 +181,9 @@ OPTIONS:
181181

182182
This flag can only be used together with --json, --lcov, or --cobertura.
183183

184+
--branch
185+
Include branch coverage. (unstable)
186+
184187
--doctests
185188
Including doc tests (unstable)
186189

@@ -685,7 +688,7 @@ pacman -S cargo-llvm-cov
685688

686689
## Known limitations
687690

688-
- Branch coverage is not supported yet. See [#8] and [rust-lang/rust#79649] for more.
691+
- Support for branch coverage is unstable. See [#8] and [rust-lang/rust#79649] for more.
689692
- Support for doc tests is unstable and has known issues. See [#2] and [rust-lang/rust#79417] for more.
690693

691694
See also [the code-coverage-related issues reported in rust-lang/rust](https://github.com/rust-lang/rust/labels/A-code-coverage).

docs/cargo-llvm-cov-run.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ OPTIONS:
135135

136136
This flag can only be used together with --json, --lcov, or --cobertura.
137137

138+
--branch
139+
Include branch coverage. (unstable)
140+
138141
--ignore-run-fail
139142
Run all tests regardless of failure and generate report
140143

docs/cargo-llvm-cov-test.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ OPTIONS:
140140

141141
This flag can only be used together with --json, --lcov, or --cobertura.
142142

143+
--branch
144+
Include branch coverage. (unstable)
145+
143146
--doctests
144147
Including doc tests (unstable)
145148

docs/cargo-llvm-cov.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ OPTIONS:
135135

136136
This flag can only be used together with --json, --lcov, or --cobertura.
137137

138+
--branch
139+
Include branch coverage. (unstable)
140+
138141
--doctests
139142
Including doc tests (unstable)
140143

src/cargo.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl Workspace {
4040
options: &ManifestOptions,
4141
target: Option<&str>,
4242
doctests: bool,
43+
branch: bool,
4344
show_env: bool,
4445
) -> Result<Self> {
4546
// Metadata and config
@@ -58,6 +59,9 @@ impl Workspace {
5859
if doctests && !rustc_version.nightly {
5960
bail!("--doctests flag requires nightly toolchain; consider using `cargo +nightly llvm-cov`")
6061
}
62+
if branch && !rustc_version.nightly {
63+
bail!("--branch flag requires nightly toolchain; consider using `cargo +nightly llvm-cov`")
64+
}
6165
let stable_coverage =
6266
rustc.clone().args(["-C", "help"]).read()?.contains("instrument-coverage");
6367
if !stable_coverage && !rustc_version.nightly {

src/clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::{
2121
};
2222

2323
pub(crate) fn run(args: &mut Args) -> Result<()> {
24-
let ws = Workspace::new(&args.manifest, None, false, false)?;
24+
let ws = Workspace::new(&args.manifest, None, false, false, false)?;
2525
cli::merge_config_to_args(&ws, &mut None, &mut args.verbose, &mut args.color);
2626
term::set_coloring(&mut args.color);
2727

src/cli.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ pub(crate) struct LlvmCovOptions {
355355
pub(crate) dep_coverage: Option<String>,
356356
/// Skip functions in coverage report.
357357
pub(crate) skip_functions: bool,
358+
/// Include branch coverage. (unstable)
359+
pub(crate) branch: bool,
358360
}
359361

360362
impl LlvmCovOptions {
@@ -508,6 +510,7 @@ impl Args {
508510
let mut include_build_script = false;
509511
let mut dep_coverage = None;
510512
let mut skip_functions = false;
513+
let mut branch = false;
511514

512515
// build options
513516
let mut release = false;
@@ -666,6 +669,7 @@ impl Args {
666669
Long("open") => parse_flag!(open),
667670
Long("summary-only") => parse_flag!(summary_only),
668671
Long("skip-functions") => parse_flag!(skip_functions),
672+
Long("branch") => parse_flag!(branch),
669673
Long("output-path") => parse_opt!(output_path),
670674
Long("output-dir") => parse_opt!(output_dir),
671675
Long("failure-mode") => parse_opt!(failure_mode),
@@ -1185,6 +1189,7 @@ impl Args {
11851189
include_build_script,
11861190
dep_coverage,
11871191
skip_functions,
1192+
branch,
11881193
},
11891194
show_env: ShowEnvOptions { export_prefix },
11901195
doctests,

src/context.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ pub(crate) struct Context {
4646
impl Context {
4747
pub(crate) fn new(mut args: Args) -> Result<Self> {
4848
let show_env = args.subcommand == Subcommand::ShowEnv;
49-
let ws = Workspace::new(&args.manifest, args.target.as_deref(), args.doctests, show_env)?;
49+
let ws = Workspace::new(
50+
&args.manifest,
51+
args.target.as_deref(),
52+
args.doctests,
53+
args.cov.branch,
54+
show_env,
55+
)?;
5056
cli::merge_config_to_args(&ws, &mut args.target, &mut args.verbose, &mut args.color);
5157
term::set_coloring(&mut args.color);
5258
term::verbose::set(args.verbose != 0);
@@ -65,6 +71,9 @@ impl Context {
6571
if args.cov.dep_coverage.is_some() {
6672
warn!("--dep-coverage option is unstable");
6773
}
74+
if args.cov.branch {
75+
warn!("--branch option is unstable");
76+
}
6877
if args.doc {
6978
warn!("--doc option is unstable");
7079
} else if args.doctests {

0 commit comments

Comments
 (0)