From f6975a78ca7085dc9d2a4083f7cbf27716cd2c7c Mon Sep 17 00:00:00 2001 From: 0xMimir Date: Mon, 11 Sep 2023 10:26:08 +0200 Subject: [PATCH 1/3] - Added `--fail-immediately` flag to abort execution the moment the first test failure occurs --- CHANGELOG.md | 6 ++++++ src/args.rs | 3 +++ src/config/mod.rs | 4 ++++ src/lib.rs | 5 +++++ 4 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 309a5d2e60..b6faaf0e62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/args.rs b/src/args.rs index 9c4860795b..c957ae6fd4 100644 --- a/src/args.rs +++ b/src/args.rs @@ -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, + /// 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, diff --git a/src/config/mod.rs b/src/config/mod.rs index 7bcf6a195e..58ae26fcff 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -186,6 +186,8 @@ pub struct Config { objects: Vec, /// Joined to target/tarpaulin to store profraws profraw_folder: PathBuf, + /// Option to fail immediately after single test fails + pub fail_immediately: bool, } fn default_test_timeout() -> Duration { @@ -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, } } } @@ -340,6 +343,7 @@ impl From 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]) diff --git a/src/lib.rs b/src/lib.rs index cf6106ccc0..cb8fd13adc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -300,6 +300,11 @@ pub fn launch_tarpaulin( return_code |= res.1; } } + + + if config.fail_immediately && return_code != 0{ + return Err(RunError::TestFailed); + } } result.dedup(); } From 843bc4de8bb56a2acbff8516a4c67ebe967af3c0 Mon Sep 17 00:00:00 2001 From: 0xMimir Date: Mon, 11 Sep 2023 10:27:11 +0200 Subject: [PATCH 2/3] Update mod.rs Typo fix --- src/config/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 58ae26fcff..94d4605c40 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -186,7 +186,7 @@ pub struct Config { objects: Vec, /// Joined to target/tarpaulin to store profraws profraw_folder: PathBuf, - /// Option to fail immediately after single test fails + /// Option to fail immediately after a single test fails pub fail_immediately: bool, } From 45c1e31c59dd15d925903d49b49ad68a42c6ba2e Mon Sep 17 00:00:00 2001 From: Mimir Date: Mon, 11 Sep 2023 21:42:45 +0200 Subject: [PATCH 3/3] cargo fmt --- src/config/mod.rs | 2 +- src/lib.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 94d4605c40..8ccda56744 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -343,7 +343,7 @@ impl From 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 + fail_immediately: args.fail_immediately, }; if args.ignore_config { Self(vec![args_config]) diff --git a/src/lib.rs b/src/lib.rs index cb8fd13adc..6c4a609239 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -301,8 +301,7 @@ pub fn launch_tarpaulin( } } - - if config.fail_immediately && return_code != 0{ + if config.fail_immediately && return_code != 0 { return Err(RunError::TestFailed); } }