]> git.lizzy.rs Git - rust.git/blob - test-cargo-miri/tests/test.rs
69a31c42a75c1b8f69b797ae57d2fa77bae14395
[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     #[cfg(not(target_os="macos"))] // FIXME entropy does not work on macOS
25     // (Not disabling the entire test as that would change the output.)
26     {
27         // Use this opportunity to test querying the RNG (needs an external crate, hence tested here and not in the compiletest suite)
28         let mut rng = SmallRng::from_entropy();
29         let _val = rng.gen::<i32>();
30
31         // Also try per-thread RNG.
32         let mut rng = rand::thread_rng();
33         let _val = rng.gen::<i32>();
34     }
35 }
36
37 // A test that won't work on miri
38 #[cfg(not(miri))]
39 #[test]
40 fn does_not_work_on_miri() {
41     let x = 0u8;
42     assert!(&x as *const _ as usize % 4 < 4);
43 }