2019-06-12 11:30:05 -05:00
|
|
|
use rand::{SeedableRng, Rng, rngs::SmallRng};
|
2019-02-07 06:00:42 -06:00
|
|
|
|
2019-05-15 07:45:15 -05:00
|
|
|
// Having more than 1 test does seem to make a difference
|
|
|
|
// (i.e., this calls ptr::swap which having just one test does not).
|
2017-01-24 10:55:42 -06:00
|
|
|
#[test]
|
2019-06-29 06:33:47 -05:00
|
|
|
fn simple1() {
|
2017-01-24 10:55:42 -06:00
|
|
|
assert_eq!(4, 4);
|
|
|
|
}
|
2018-11-27 08:06:51 -06:00
|
|
|
|
2019-06-29 06:33:47 -05:00
|
|
|
#[test]
|
|
|
|
fn simple2() {
|
|
|
|
assert_ne!(42, 24);
|
|
|
|
}
|
|
|
|
|
2019-11-30 03:31:53 -06:00
|
|
|
// A test that won't work on miri (tests disabling tests).
|
2019-06-29 06:33:47 -05:00
|
|
|
#[test]
|
2019-12-07 04:55:19 -06:00
|
|
|
#[cfg_attr(miri, ignore)]
|
2019-06-29 06:33:47 -05:00
|
|
|
fn does_not_work_on_miri() {
|
|
|
|
let x = 0u8;
|
|
|
|
assert!(&x as *const _ as usize % 4 < 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We also use this to test some external crates, that we cannot depend on in the compiletest suite.
|
|
|
|
|
2019-04-16 12:12:56 -05:00
|
|
|
#[test]
|
2019-04-16 13:12:55 -05:00
|
|
|
fn entropy_rng() {
|
2021-04-04 08:35:19 -05:00
|
|
|
// Test `getrandom` directly (in multiple different versions).
|
2021-04-04 04:09:40 -05:00
|
|
|
let mut data = vec![0; 16];
|
2021-04-04 08:35:19 -05:00
|
|
|
getrandom_1::getrandom(&mut data).unwrap();
|
|
|
|
getrandom_2::getrandom(&mut data).unwrap();
|
2021-04-04 04:09:40 -05:00
|
|
|
|
2019-06-29 06:33:47 -05:00
|
|
|
// Try seeding with "real" entropy.
|
2019-04-21 14:37:06 -05:00
|
|
|
let mut rng = SmallRng::from_entropy();
|
|
|
|
let _val = rng.gen::<i32>();
|
2019-06-12 11:19:50 -05:00
|
|
|
let _val = rng.gen::<isize>();
|
|
|
|
let _val = rng.gen::<i128>();
|
2019-04-16 12:49:36 -05:00
|
|
|
|
2019-04-21 14:37:06 -05:00
|
|
|
// Also try per-thread RNG.
|
|
|
|
let mut rng = rand::thread_rng();
|
|
|
|
let _val = rng.gen::<i32>();
|
2019-06-12 11:19:50 -05:00
|
|
|
let _val = rng.gen::<isize>();
|
|
|
|
let _val = rng.gen::<i128>();
|
2019-04-16 12:12:56 -05:00
|
|
|
}
|
|
|
|
|
2020-09-09 01:51:41 -05:00
|
|
|
#[test]
|
|
|
|
fn cargo_env() {
|
|
|
|
assert_eq!(env!("CARGO_PKG_NAME"), "cargo-miri-test");
|
|
|
|
env!("CARGO_BIN_EXE_cargo-miri-test"); // Asserts that this exists.
|
|
|
|
}
|
|
|
|
|
2019-11-17 10:09:16 -06:00
|
|
|
#[test]
|
2020-09-17 08:39:52 -05:00
|
|
|
#[should_panic(expected="Explicit panic")]
|
2019-11-17 10:09:16 -06:00
|
|
|
fn do_panic() { // In large, friendly letters :)
|
|
|
|
panic!("Explicit panic from test!");
|
|
|
|
}
|
2019-11-30 03:37:14 -06:00
|
|
|
|
|
|
|
#[test]
|
2020-02-21 04:03:52 -06:00
|
|
|
#[allow(unconditional_panic)]
|
2020-09-17 08:39:52 -05:00
|
|
|
#[should_panic(expected="the len is 0 but the index is 42")]
|
2019-11-30 03:37:14 -06:00
|
|
|
fn fail_index_check() {
|
|
|
|
[][42]
|
|
|
|
}
|