rust/test-cargo-miri/tests/test.rs

50 lines
1.1 KiB
Rust
Raw Normal View History

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).
#[test]
2019-06-29 06:33:47 -05:00
fn simple1() {
assert_eq!(4, 4);
}
2019-06-29 06:33:47 -05:00
#[test]
fn simple2() {
assert_ne!(42, 24);
}
// A test that won't work on miri (tests disabling tests)
#[cfg(not(miri))]
#[test]
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.
#[test]
2019-04-16 13:12:55 -05:00
fn entropy_rng() {
2019-06-29 06:33:47 -05:00
// Try seeding with "real" entropy.
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>();
// 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>();
}
2018-12-19 04:11:01 -06:00
#[test]
2019-06-29 06:33:47 -05:00
fn num_cpus() {
assert_eq!(num_cpus::get(), 1);
2018-12-19 04:11:01 -06:00
}
2019-11-17 10:09:16 -06:00
#[test]
#[should_panic]
fn do_panic() { // In large, friendly letters :)
panic!("Explicit panic from test!");
}