Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test rand a bit more #701

Merged
merged 2 commits into from Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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