From 2c3cd714a17d8ed478b7047db2e2a9fc0b07d17b Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sat, 8 Dec 2018 16:08:36 -0500 Subject: [PATCH] Fix up the tests --- src/lib.rs | 2 ++ tests/assert_macro.rs | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7aaaa9a..8d3e7b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,6 +89,7 @@ pub struct QADAPT; /// /// ```rust,no_run /// use qadapt::enter_protected; +/// use qadapt::exit_protected; /// /// fn main() { /// // Force an allocation by using a Box @@ -129,6 +130,7 @@ pub fn enter_protected() { /// /// ```rust,no_run /// use qadapt::enter_protected; +/// use qadapt::exit_protected; /// /// fn main() { /// // Force an allocation by using a Box diff --git a/tests/assert_macro.rs b/tests/assert_macro.rs index 03f98ec..8befd29 100644 --- a/tests/assert_macro.rs +++ b/tests/assert_macro.rs @@ -10,21 +10,33 @@ fn math() { 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 { assert_no_alloc!(return 8) } -fn into_box() -> Box { - Box::new(early_return()) -} - #[test] #[should_panic] fn early_return_boxing() { + // The release-mode compiler is able to optimize through the Box if cfg!(debug_assertions) { - // The release-mode compiler is able to optimize through the Box - into_box(); + Box::new(early_return()); } 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 { + panic!("Intentional") + } +} \ No newline at end of file