Skip to content

Commit 6ceb716

Browse files
authored
Merge pull request #701 from RalfJung/rand
test rand a bit more
2 parents deb0ff4 + f72f53c commit 6ceb716

File tree

4 files changed

+75
-122
lines changed

4 files changed

+75
-122
lines changed

test-cargo-miri/Cargo.lock

Lines changed: 65 additions & 116 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-cargo-miri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ edition = "2018"
88
byteorder = "1.0"
99

1010
[dev-dependencies]
11-
rand = "0.6.5"
11+
rand = { version = "0.7.0-pre.0", features = ["small_rng"] }

test-cargo-miri/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ mod test {
1919
fn rng() {
2020
let mut rng = rand::rngs::StdRng::seed_from_u64(0xcafebeef);
2121
let x: u32 = rng.gen();
22-
let y: u32 = rng.gen();
23-
assert_ne!(x, y);
22+
let y: usize = rng.gen();
23+
let z: u128 = rng.gen();
24+
assert_ne!(x as usize, y);
25+
assert_ne!(y as u128, z);
2426
}
2527
}

test-cargo-miri/tests/test.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rand::{FromEntropy, Rng, rngs::SmallRng};
1+
use rand::{SeedableRng, Rng, rngs::SmallRng};
22

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

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

1818
// Also try per-thread RNG.
1919
let mut rng = rand::thread_rng();
2020
let _val = rng.gen::<i32>();
21+
let _val = rng.gen::<isize>();
22+
let _val = rng.gen::<i128>();
2123
}
2224

2325
// A test that won't work on miri

0 commit comments

Comments
 (0)