Skip to content

Commit

Permalink
Merge pull request #701 from RalfJung/rand
Browse files Browse the repository at this point in the history
test rand a bit more
  • Loading branch information
RalfJung committed Jun 12, 2019
2 parents deb0ff4 + f72f53c commit 6ceb716
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 122 deletions.
181 changes: 65 additions & 116 deletions test-cargo-miri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test-cargo-miri/Cargo.toml
Expand Up @@ -8,4 +8,4 @@ edition = "2018"
byteorder = "1.0"

[dev-dependencies]
rand = "0.6.5"
rand = { version = "0.7.0-pre.0", features = ["small_rng"] }
6 changes: 4 additions & 2 deletions test-cargo-miri/src/main.rs
Expand Up @@ -19,7 +19,9 @@ mod test {
fn rng() {
let mut rng = rand::rngs::StdRng::seed_from_u64(0xcafebeef);
let x: u32 = rng.gen();
let y: u32 = rng.gen();
assert_ne!(x, y);
let y: usize = rng.gen();
let z: u128 = rng.gen();
assert_ne!(x as usize, y);
assert_ne!(y as u128, z);
}
}
8 changes: 5 additions & 3 deletions test-cargo-miri/tests/test.rs
@@ -1,4 +1,4 @@
use rand::{FromEntropy, Rng, rngs::SmallRng};
use rand::{SeedableRng, Rng, rngs::SmallRng};

// Having more than 1 test does seem to make a difference
// (i.e., this calls ptr::swap which having just one test does not).
Expand All @@ -7,17 +7,19 @@ fn simple() {
assert_eq!(4, 4);
}

// Having more than 1 test does seem to make a difference
// (i.e., this calls ptr::swap which having just one test does not).
#[test]
fn entropy_rng() {
// Use this opportunity to test querying the RNG (needs an external crate, hence tested here and not in the compiletest suite)
let mut rng = SmallRng::from_entropy();
let _val = rng.gen::<i32>();
let _val = rng.gen::<isize>();
let _val = rng.gen::<i128>();

// Also try per-thread RNG.
let mut rng = rand::thread_rng();
let _val = rng.gen::<i32>();
let _val = rng.gen::<isize>();
let _val = rng.gen::<i128>();
}

// A test that won't work on miri
Expand Down

0 comments on commit 6ceb716

Please sign in to comment.