Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to fail immediately after single test fails #1374

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
From 2019 onwards, all notable changes to tarpaulin will be documented in this
file.

## [Unreleased]
### Added
- Added `--fail-immediately` flag to abort execution the moment the first test failure occurs

### Changed

## [Unreleased]
### Changed
- Upgraded from clap v2 to v4. This has a few changes, notably any arguments which can be specified more
Expand Down
3 changes: 3 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ pub struct ConfigArgs {
/// CI server being used, if unspecified tarpaulin may automatically infer for coveralls uploads
#[arg(long, value_name = "SERVICE")]
pub ciserver: Option<Ci>,
/// Option to fail immediately after a single test fails
#[arg(long)]
pub fail_immediately: bool,
/// Arguments to be passed to the test executables can be used to filter or skip certain tests
#[arg(last = true)]
pub args: Vec<String>,
Expand Down
4 changes: 4 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ pub struct Config {
objects: Vec<PathBuf>,
/// Joined to target/tarpaulin to store profraws
profraw_folder: PathBuf,
/// Option to fail immediately after a single test fails
pub fail_immediately: bool,
}

fn default_test_timeout() -> Duration {
Expand Down Expand Up @@ -255,6 +257,7 @@ impl Default for Config {
post_test_delay: Some(Duration::from_secs(1)),
objects: vec![],
profraw_folder: PathBuf::from("profraws"),
fail_immediately: false,
}
}
}
Expand Down Expand Up @@ -340,6 +343,7 @@ impl From<ConfigArgs> for ConfigWrapper {
post_test_delay: args.post_test_delay.map(Duration::from_secs),
objects: canonicalize_paths(args.objects),
profraw_folder: PathBuf::from("profraws"),
fail_immediately: args.fail_immediately,
};
if args.ignore_config {
Self(vec![args_config])
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ pub fn launch_tarpaulin(
return_code |= res.1;
}
}

if config.fail_immediately && return_code != 0 {
return Err(RunError::TestFailed);
}
}
result.dedup();
}
Expand Down