From 72a5bb73c1056dcb34fad4af138258603bb36d18 Mon Sep 17 00:00:00 2001 From: Piotr Czarnecki Date: Fri, 14 Aug 2015 14:20:09 +0200 Subject: [PATCH] Move tests around --- src/libarena/lib.rs | 130 ++++++++++++++++++++++---------------------- 1 file changed, 64 insertions(+), 66 deletions(-) diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 8c42fcfb81f..fe88d51470d 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -362,38 +362,6 @@ pub fn clear(&mut self) { } } -#[test] -fn test_arena_destructors() { - let arena = Arena::new(); - for i in 0..10 { - // Arena allocate something with drop glue to make sure it - // doesn't leak. - arena.alloc(|| Rc::new(i)); - // Allocate something with funny size and alignment, to keep - // things interesting. - arena.alloc(|| [0u8, 1u8, 2u8]); - } -} - -#[test] -#[should_panic] -fn test_arena_destructors_fail() { - let arena = Arena::new(); - // Put some stuff in the arena. - for i in 0..10 { - // Arena allocate something with drop glue to make sure it - // doesn't leak. - arena.alloc(|| Rc::new(i)); - // Allocate something with funny size and alignment, to keep - // things interesting. - arena.alloc(|| [0u8, 1, 2]); - } - // Now, panic while allocating - arena.alloc::, _>(|| { - panic!(); - }); -} - /// A faster arena that can hold objects of only one type. pub struct TypedArena { /// A pointer to the next object to be allocated. @@ -693,40 +661,6 @@ pub fn test_noncopy() { } } - #[bench] - pub fn bench_noncopy(b: &mut Bencher) { - let arena = TypedArena::new(); - b.iter(|| { - arena.alloc(Noncopy { - string: "hello world".to_string(), - array: vec![1, 2, 3, 4, 5], - }) - }) - } - - #[bench] - pub fn bench_noncopy_nonarena(b: &mut Bencher) { - b.iter(|| { - let _: Box<_> = Box::new(Noncopy { - string: "hello world".to_string(), - array: vec![1, 2, 3, 4, 5], - }); - }) - } - - #[bench] - pub fn bench_noncopy_old_arena(b: &mut Bencher) { - let arena = Arena::new(); - b.iter(|| { - arena.alloc(|| { - Noncopy { - string: "hello world".to_string(), - array: vec![1, 2, 3, 4, 5], - } - }) - }) - } - #[test] pub fn test_typed_arena_zero_sized() { let arena = TypedArena::new(); @@ -798,4 +732,68 @@ pub fn test_arena_alloc_bytes() { } } } + + #[test] + fn test_arena_destructors() { + let arena = Arena::new(); + for i in 0..10 { + // Arena allocate something with drop glue to make sure it + // doesn't leak. + arena.alloc(|| Rc::new(i)); + // Allocate something with funny size and alignment, to keep + // things interesting. + arena.alloc(|| [0u8, 1u8, 2u8]); + } + } + + #[test] + #[should_panic] + fn test_arena_destructors_fail() { + let arena = Arena::new(); + // Put some stuff in the arena. + for i in 0..10 { + // Arena allocate something with drop glue to make sure it + // doesn't leak. + arena.alloc(|| { Rc::new(i) }); + // Allocate something with funny size and alignment, to keep + // things interesting. + arena.alloc(|| { [0u8, 1, 2] }); + } + // Now, panic while allocating + arena.alloc::, _>(|| { + panic!(); + }); + } + + #[bench] + pub fn bench_noncopy(b: &mut Bencher) { + let arena = TypedArena::new(); + b.iter(|| { + arena.alloc(Noncopy { + string: "hello world".to_string(), + array: vec!( 1, 2, 3, 4, 5 ), + }) + }) + } + + #[bench] + pub fn bench_noncopy_nonarena(b: &mut Bencher) { + b.iter(|| { + let _: Box<_> = Box::new(Noncopy { + string: "hello world".to_string(), + array: vec!( 1, 2, 3, 4, 5 ), + }); + }) + } + + #[bench] + pub fn bench_noncopy_old_arena(b: &mut Bencher) { + let arena = Arena::new(); + b.iter(|| { + arena.alloc(|| Noncopy { + string: "hello world".to_string(), + array: vec!( 1, 2, 3, 4, 5 ), + }) + }) + } } -- 2.44.0