]> git.lizzy.rs Git - rust.git/blob - test-cargo-miri/tests/test.rs
implement SecRandomCopyBytes for macOS RNG
[rust.git] / test-cargo-miri / tests / test.rs
1 #![allow(unused_imports)] // FIXME for macOS
2
3 extern crate rand;
4
5 use rand::{SeedableRng, FromEntropy, Rng, rngs::SmallRng};
6
7 #[test]
8 fn simple() {
9     assert_eq!(4, 4);
10 }
11
12 // Having more than 1 test does seem to make a difference
13 // (i.e., this calls ptr::swap which having just one test does not).
14 #[test]
15 fn fixed_rng() {
16     let mut rng = rand::rngs::StdRng::seed_from_u64(0xdeadcafe);
17     let x: u32 = rng.gen();
18     let y: u32 = rng.gen();
19     assert_ne!(x, y);
20 }
21
22 #[test]
23 fn entropy_rng() {
24     // Use this opportunity to test querying the RNG (needs an external crate, hence tested here and not in the compiletest suite)
25     let mut rng = SmallRng::from_entropy();
26     let _val = rng.gen::<i32>();
27
28     // Also try per-thread RNG.
29     let mut rng = rand::thread_rng();
30     let _val = rng.gen::<i32>();
31 }
32
33 // A test that won't work on miri
34 #[cfg(not(miri))]
35 #[test]
36 fn does_not_work_on_miri() {
37     let x = 0u8;
38     assert!(&x as *const _ as usize % 4 < 4);
39 }