use proptest::test_runner::{Config as ProptestConfig, FileFailurePersistence};
#[derive(Debug, Clone, Copy)]
pub enum Profile {
Quick,
Default,
Thorough,
Ci,
}
impl Profile {
pub fn from_env() -> Self {
match std::env::var("PROPTEST_PROFILE")
.unwrap_or_default()
.to_ascii_lowercase()
.as_str()
{
"quick" => Self::Quick,
"thorough" => Self::Thorough,
"ci" => Self::Ci,
_ => Self::Default,
}
}
pub fn cases(self) -> u32 {
match self {
Self::Quick => 32,
Self::Default => 256,
Self::Thorough => 2048,
Self::Ci => 512,
}
}
pub fn max_shrink_iters(self) -> u32 {
match self {
Self::Quick => 128,
Self::Default => 512,
Self::Thorough => 2048,
Self::Ci => 512,
}
}
}
pub fn config() -> ProptestConfig {
let profile = Profile::from_env();
let cases = std::env::var("PROPTEST_CASES")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or_else(|| profile.cases());
let persistence: Option<Box<dyn proptest::test_runner::FailurePersistence>> = match profile {
Profile::Ci => None, _ => Some(Box::new(FileFailurePersistence::WithSource(
"proptest-regressions",
))),
};
ProptestConfig {
cases,
max_shrink_iters: profile.max_shrink_iters(),
failure_persistence: persistence,
..ProptestConfig::default()
}
}