]> git.lizzy.rs Git - rust.git/blob - test-cargo-miri/tests/test.rs
1a8b3c72565d31b65ad42f7977bb788bca2b3167
[rust.git] / test-cargo-miri / tests / test.rs
1 use rand::{rngs::SmallRng, Rng, SeedableRng};
2
3 // Having more than 1 test does seem to make a difference
4 // (i.e., this calls ptr::swap which having just one test does not).
5 #[test]
6 fn simple1() {
7     assert_eq!(4, 4);
8 }
9
10 #[test]
11 fn simple2() {
12     assert_ne!(42, 24);
13 }
14
15 // A test that won't work on miri (tests disabling tests).
16 #[test]
17 #[cfg_attr(miri, ignore)]
18 fn does_not_work_on_miri() {
19     let x = 0u8;
20     assert!(&x as *const _ as usize % 4 < 4);
21 }
22
23 // We also use this to test some external crates, that we cannot depend on in the compiletest suite.
24
25 #[test]
26 fn entropy_rng() {
27     // Test `getrandom` directly (in multiple different versions).
28     let mut data = vec![0; 16];
29     getrandom_1::getrandom(&mut data).unwrap();
30     getrandom_2::getrandom(&mut data).unwrap();
31
32     // Try seeding with "real" entropy.
33     let mut rng = SmallRng::from_entropy();
34     let _val = rng.gen::<i32>();
35     let _val = rng.gen::<isize>();
36     let _val = rng.gen::<i128>();
37
38     // Also try per-thread RNG.
39     let mut rng = rand::thread_rng();
40     let _val = rng.gen::<i32>();
41     let _val = rng.gen::<isize>();
42     let _val = rng.gen::<i128>();
43 }
44
45 #[test]
46 fn cargo_env() {
47     assert_eq!(env!("CARGO_PKG_NAME"), "cargo-miri-test");
48     env!("CARGO_BIN_EXE_cargo-miri-test"); // Asserts that this exists.
49 }
50
51 #[test]
52 #[should_panic(expected = "Explicit panic")]
53 fn do_panic() // In large, friendly letters :)
54 {
55     panic!("Explicit panic from test!");
56 }
57
58 #[test]
59 #[allow(unconditional_panic)]
60 #[should_panic(expected = "the len is 0 but the index is 42")]
61 fn fail_index_check() {
62     [][42]
63 }
64
65 #[test]
66 fn page_size() {
67     let page_size = page_size::get();
68
69     // In particular, this checks that it is not 0.
70     assert!(
71         page_size.next_power_of_two() == page_size,
72         "page size not a power of two: {}",
73         page_size
74     );
75 }