From efc396377ff95b0c464fe4bf793dc3da59abd36e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 17 Jul 2024 19:29:39 +0900 Subject: [PATCH] test(allocator): Merge test (#9267) --- .../tests/{apis.rs => alloction.rs} | 30 ++++++++++++++++++- crates/swc_allocator/tests/escape.rs | 29 ------------------ 2 files changed, 29 insertions(+), 30 deletions(-) rename crates/swc_allocator/tests/{apis.rs => alloction.rs} (56%) delete mode 100644 crates/swc_allocator/tests/escape.rs diff --git a/crates/swc_allocator/tests/apis.rs b/crates/swc_allocator/tests/alloction.rs similarity index 56% rename from crates/swc_allocator/tests/apis.rs rename to crates/swc_allocator/tests/alloction.rs index bf35cea53d35..99934ea4a6c7 100644 --- a/crates/swc_allocator/tests/apis.rs +++ b/crates/swc_allocator/tests/alloction.rs @@ -1,5 +1,5 @@ use criterion::black_box; -use swc_allocator::Allocator; +use swc_allocator::{boxed::Box, Allocator, FastAlloc}; #[test] fn direct_alloc_std() { @@ -33,3 +33,31 @@ fn direct_alloc_in_scope() { vec.push(item); } } + +#[test] +fn escape() { + let allocator = Allocator::default(); + + let obj = { + let _guard = unsafe { allocator.guard() }; + Box::new(1234) + }; + + assert_eq!(*obj, 1234); + // It should not segfault, because the allocator is still alive. + drop(obj); +} + +#[test] +fn global_allocator_escape() { + let allocator = Allocator::default(); + let obj = { + let _guard = unsafe { allocator.guard() }; + Box::new_in(1234, FastAlloc::global()) + }; + + assert_eq!(*obj, 1234); + drop(allocator); + // Object created with global allocator should outlive the allocator. + drop(obj); +} diff --git a/crates/swc_allocator/tests/escape.rs b/crates/swc_allocator/tests/escape.rs deleted file mode 100644 index f12ab5520b0e..000000000000 --- a/crates/swc_allocator/tests/escape.rs +++ /dev/null @@ -1,29 +0,0 @@ -use swc_allocator::{boxed::Box, Allocator, FastAlloc}; - -#[test] -fn escape() { - let allocator = Allocator::default(); - - let obj = { - let _guard = unsafe { allocator.guard() }; - Box::new(1234) - }; - - assert_eq!(*obj, 1234); - // It should not segfault, because the allocator is still alive. - drop(obj); -} - -#[test] -fn global_allocator() { - let allocator = Allocator::default(); - let obj = { - let _guard = unsafe { allocator.guard() }; - Box::new_in(1234, FastAlloc::global()) - }; - - assert_eq!(*obj, 1234); - drop(allocator); - // Object created with global allocator should outlive the allocator. - drop(obj); -}