diff --git a/.gitignore b/.gitignore index 62216a9..8af57e8 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ builds/ *venv*/ .python-version *.ipynb + +proptest-regressions diff --git a/Cargo.toml b/Cargo.toml index bb51afb..302c713 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,9 @@ siphasher = { version = "0.3.10", default-features = false } # BENCH: oorandom = { version = "11.1.3" } # BENCH: lazy_static = { version = "1" } +# Only required for property testing - incompatible with older versions of rust +# PROPERTY-TESTS: proptest = "1" + [features] default = ["std"] string-only = [] diff --git a/scripts/bigdecimal-property-tests b/scripts/bigdecimal-property-tests new file mode 100755 index 0000000..bce2e79 --- /dev/null +++ b/scripts/bigdecimal-property-tests @@ -0,0 +1,19 @@ +#!/bin/sh +# +# Run commands with property-tests enabled for bigdecimal crate +# +# Tests are defined in src/lib.tests.property-test.rs +# + +# enable property-test dependencies in Cargo +sed -i.bak -e 's|# PROPERTY-TESTS: ||' Cargo.toml + +# include the property-test file in lib.rs +sed -i.bak -e 's|// ::PROPERTY-TESTS:: ||' src/lib.rs + +# Run commands +"$@" + +# Restore Cargo.toml with backup +mv Cargo.toml.bak Cargo.toml +mv src/lib.rs.bak src/lib.rs diff --git a/src/lib.rs b/src/lib.rs index 5370f9a..a77801b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1116,6 +1116,7 @@ impl One for BigDecimal { } } + impl Add for BigDecimal { type Output = BigDecimal; @@ -3254,3 +3255,9 @@ mod test_with_scale_round { include!("lib.tests.with_scale_round.rs"); } + +// enable these tests with scripts/bigdecimal-property-tests +// ::PROPERTY-TESTS:: #[cfg(test)] #[macro_use] extern crate proptest; +// ::PROPERTY-TESTS:: #[cfg(test)] mod property_tests { +// ::PROPERTY-TESTS:: use super::*; use paste::paste; +// ::PROPERTY-TESTS:: include!("lib.tests.property-tests.rs"); } diff --git a/src/lib.tests.property-tests.rs b/src/lib.tests.property-tests.rs new file mode 100644 index 0000000..e69de29