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

66 lines
1.5 KiB
Rust
Raw Normal View History

2022-05-21 09:10:08 -05:00
use rand::{rngs::SmallRng, Rng, SeedableRng};
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).
2019-06-29 06:33:47 -05:00
#[test]
#[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);
}
2022-07-14 05:03:08 -05:00
// Make sure integration tests can access dev-dependencies
#[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>();
}
#[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]
2022-05-21 09:10:08 -05:00
#[should_panic(expected = "Explicit panic")]
2022-05-21 17:59:49 -05:00
fn do_panic() // In large, friendly letters :)
{
2019-11-17 10:09:16 -06:00
panic!("Explicit panic from test!");
}
#[test]
2020-02-21 04:03:52 -06:00
#[allow(unconditional_panic)]
2022-05-21 09:10:08 -05:00
#[should_panic(expected = "the len is 0 but the index is 42")]
fn fail_index_check() {
[][42]
}
2022-05-21 09:10:08 -05:00
#[test]
fn page_size() {
let page_size = page_size::get();
2022-05-22 00:59:18 -05:00
// In particular, this checks that it is not 0.
assert!(page_size.is_power_of_two(), "page size not a power of two: {}", page_size);
2022-05-21 09:10:08 -05:00
}