diff --git a/.github/workflows/ub-detection.yml b/.github/workflows/ub-detection.yml index ca4b8b6..cda1168 100644 --- a/.github/workflows/ub-detection.yml +++ b/.github/workflows/ub-detection.yml @@ -19,4 +19,6 @@ jobs: - run: | rustup +nightly component add miri cargo +nightly miri setup - MIRIFLAGS="-Zmiri-strict-provenance" cargo +nightly miri test --lib + PROPTEST_DISABLE_FAILURE_PERSISTENCE=true \ + MIRIFLAGS="-Zmiri-env-forward=PROPTEST_DISABLE_FAILURE_PERSISTENCE -Zmiri-strict-provenance" \ + cargo +nightly miri test --lib diff --git a/Cargo.toml b/Cargo.toml index 88aeeda..49d9fde 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ license = "Apache-2.0" # TODO(template) update license if needed publish = false [workspace.dependencies] +proptest = "1" [workspace.lints.rust] missing_docs = "deny" diff --git a/template_crate/Cargo.toml b/template_crate/Cargo.toml index aa411db..e0b327d 100644 --- a/template_crate/Cargo.toml +++ b/template_crate/Cargo.toml @@ -14,6 +14,9 @@ license.workspace = true # code break after upgrades thiserror = { version = "1.0", default-features = false } +[dev-dependencies] +proptest = { workspace = true } + # TODO(template) # don't forget to put this at every crate # to inherit workspace's lints diff --git a/template_crate/src/lib.rs b/template_crate/src/lib.rs index ba9e493..f3b62de 100644 --- a/template_crate/src/lib.rs +++ b/template_crate/src/lib.rs @@ -46,6 +46,7 @@ pub fn sub_small_integers(a: u8, b: u8) -> Result { #[cfg(test)] mod tests { use super::*; + use proptest::proptest; #[test] fn addition_of_bounded() { @@ -67,4 +68,14 @@ mod tests { add_small_integers(UPPER_BOUND - 1, UPPER_BOUND - 1) ); } + + proptest! { + #[test] + fn addition_proptest(a in 0_u8..20, b in 0_u8..20) { + assert_eq!( + a.checked_add(b), + add_small_integers(a, b).ok() + ); + } + } }