mirror of
https://github.com/bspeice/qadapt
synced 2024-11-24 23:08:11 -05:00
Fix up the tests
This commit is contained in:
parent
db120dbe45
commit
2c3cd714a1
@ -89,6 +89,7 @@ pub struct QADAPT;
|
|||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// use qadapt::enter_protected;
|
/// use qadapt::enter_protected;
|
||||||
|
/// use qadapt::exit_protected;
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// // Force an allocation by using a Box
|
/// // Force an allocation by using a Box
|
||||||
@ -129,6 +130,7 @@ pub fn enter_protected() {
|
|||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// use qadapt::enter_protected;
|
/// use qadapt::enter_protected;
|
||||||
|
/// use qadapt::exit_protected;
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// // Force an allocation by using a Box
|
/// // Force an allocation by using a Box
|
||||||
|
@ -10,20 +10,32 @@ fn math() {
|
|||||||
assert_eq!(x, 4);
|
assert_eq!(x, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Because the `exit_protected` guard is never run, the compiler
|
||||||
|
// warns us of unreachable code
|
||||||
|
#[allow(unreachable_code)]
|
||||||
fn early_return() -> usize {
|
fn early_return() -> usize {
|
||||||
assert_no_alloc!(return 8)
|
assert_no_alloc!(return 8)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_box() -> Box<usize> {
|
|
||||||
Box::new(early_return())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn early_return_boxing() {
|
fn early_return_boxing() {
|
||||||
|
// The release-mode compiler is able to optimize through the Box
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
// The release-mode compiler is able to optimize through the Box
|
Box::new(early_return());
|
||||||
into_box();
|
} else {
|
||||||
|
panic!("Intentional")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn list_push() {
|
||||||
|
let mut x = Vec::with_capacity(1);
|
||||||
|
x.push(1);
|
||||||
|
|
||||||
|
if cfg!(debug_assertions) {
|
||||||
|
assert_no_alloc!(x.push(12))
|
||||||
} else {
|
} else {
|
||||||
panic!("Intentional")
|
panic!("Intentional")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user