Skip to content

Commit

Permalink
Add support for proptests
Browse files Browse the repository at this point in the history
  • Loading branch information
akubera committed Jul 13, 2023
1 parent 65f9f8f commit 6515af3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ builds/
*venv*/
.python-version
*.ipynb

proptest-regressions
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
19 changes: 19 additions & 0 deletions scripts/bigdecimal-property-tests
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ impl One for BigDecimal {
}
}


impl Add<BigDecimal> for BigDecimal {
type Output = BigDecimal;

Expand Down Expand Up @@ -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"); }
Empty file added src/lib.tests.property-tests.rs
Empty file.

0 comments on commit 6515af3

Please sign in to comment.