-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(max-fail): introduce --max-fail runner option
- Loading branch information
Aidan De Angelis
committed
Dec 3, 2024
1 parent
f0d557a
commit 7eb4c44
Showing
7 changed files
with
126 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::errors::MaxFailParseError; | ||
use std::{fmt, str::FromStr}; | ||
|
||
/// Type for the max-fail flag | ||
#[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
pub enum MaxFail { | ||
/// Allow a specific number of tests to fail before exiting. | ||
Count(usize), | ||
|
||
/// Run all tests. Equivalent to --no-fast-fail. | ||
All, | ||
} | ||
|
||
impl FromStr for MaxFail { | ||
type Err = MaxFailParseError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
if s.to_lowercase() == "all" { | ||
return Ok(Self::All); | ||
} | ||
|
||
match s.parse::<isize>() { | ||
Err(e) => Err(MaxFailParseError::new(format!("Error: {e} parsing {s}"))), | ||
Ok(j) if j <= 0 => Err(MaxFailParseError::new("max-fail may not be <= 0")), | ||
Ok(j) => Ok(MaxFail::Count(j as usize)), | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for MaxFail { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::All => write!(f, "all"), | ||
Self::Count(n) => write!(f, "{n}"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters