2019-06-12 18:30:05 +02:00
|
|
|
use rand::{SeedableRng, Rng, rngs::SmallRng};
|
2019-02-07 13:00:42 +01:00
|
|
|
|
2019-05-15 14:45:15 +02: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 17:55:42 +01:00
|
|
|
#[test]
|
2019-06-29 13:33:47 +02:00
|
|
|
fn simple1() {
|
2017-01-24 17:55:42 +01:00
|
|
|
assert_eq!(4, 4);
|
|
|
|
}
|
2018-11-27 15:06:51 +01:00
|
|
|
|
2019-06-29 13:33:47 +02:00
|
|
|
#[test]
|
|
|
|
fn simple2() {
|
|
|
|
assert_ne!(42, 24);
|
|
|
|
}
|
|
|
|
|
2019-11-30 10:31:53 +01:00
|
|
|
// A test that won't work on miri (tests disabling tests).
|
2019-06-29 13:33:47 +02:00
|
|
|
#[test]
|
2019-12-07 11:55:19 +01:00
|
|
|
#[cfg_attr(miri, ignore)]
|
2019-06-29 13:33:47 +02: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 19:12:56 +02:00
|
|
|
#[test]
|
2019-04-16 20:12:55 +02:00
|
|
|
fn entropy_rng() {
|
2019-06-29 13:33:47 +02:00
|
|
|
// Try seeding with "real" entropy.
|
2019-04-21 21:37:06 +02:00
|
|
|
let mut rng = SmallRng::from_entropy();
|
|
|
|
let _val = rng.gen::<i32>();
|
2019-06-12 18:19:50 +02:00
|
|
|
let _val = rng.gen::<isize>();
|
|
|
|
let _val = rng.gen::<i128>();
|
2019-04-16 19:49:36 +02:00
|
|
|
|
2019-04-21 21:37:06 +02:00
|
|
|
// Also try per-thread RNG.
|
|
|
|
let mut rng = rand::thread_rng();
|
|
|
|
let _val = rng.gen::<i32>();
|
2019-06-12 18:19:50 +02:00
|
|
|
let _val = rng.gen::<isize>();
|
|
|
|
let _val = rng.gen::<i128>();
|
2019-04-16 19:12:56 +02:00
|
|
|
}
|
|
|
|
|
2018-12-19 11:11:01 +01:00
|
|
|
#[test]
|
2019-06-29 13:33:47 +02:00
|
|
|
fn num_cpus() {
|
|
|
|
assert_eq!(num_cpus::get(), 1);
|
2018-12-19 11:11:01 +01:00
|
|
|
}
|
2019-11-17 11:09:16 -05:00
|
|
|
|
2019-11-19 15:55:12 -05:00
|
|
|
|
2019-11-30 10:37:14 +01:00
|
|
|
// FIXME: Remove this `cfg` once we fix https://github.com/rust-lang/miri/issues/1059.
|
2019-11-19 15:55:12 -05:00
|
|
|
// We cfg-gate the `should_panic` attribute and the `panic!` itself, so that the test
|
2020-03-22 08:51:15 +01:00
|
|
|
// stdout does not depend on the target.
|
2019-11-17 11:09:16 -05:00
|
|
|
#[test]
|
2019-11-30 10:31:53 +01:00
|
|
|
#[cfg_attr(not(windows), should_panic(expected="Explicit panic"))]
|
2019-11-17 11:09:16 -05:00
|
|
|
fn do_panic() { // In large, friendly letters :)
|
2019-11-19 15:55:12 -05:00
|
|
|
#[cfg(not(windows))]
|
2019-11-17 11:09:16 -05:00
|
|
|
panic!("Explicit panic from test!");
|
|
|
|
}
|
2019-11-30 10:37:14 +01:00
|
|
|
|
|
|
|
// FIXME: see above
|
|
|
|
#[test]
|
2020-02-21 11:03:52 +01:00
|
|
|
#[allow(unconditional_panic)]
|
2019-11-30 10:37:14 +01:00
|
|
|
#[cfg_attr(not(windows), should_panic(expected="the len is 0 but the index is 42"))]
|
|
|
|
fn fail_index_check() {
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
[][42]
|
|
|
|
}
|