From 3891da5ff02c54dfd178ffffb4578435d2ae9326 Mon Sep 17 00:00:00 2001 From: Gregory Conrad Date: Thu, 25 May 2023 12:13:55 -0700 Subject: [PATCH] test: fix some test failures due to tempfile --- src/db.rs | 14 ++++++-------- src/lib.rs | 9 +++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/db.rs b/src/db.rs index 3cc54cb0..e0aab8c9 100644 --- a/src/db.rs +++ b/src/db.rs @@ -710,13 +710,11 @@ impl std::fmt::Debug for Database { #[cfg(test)] mod test { - use tempfile::NamedTempFile; - use crate::{Database, Durability, Error, ReadableTable, TableDefinition}; #[test] fn small_pages() { - let tmpfile: NamedTempFile = NamedTempFile::new().unwrap(); + let tmpfile = crate::create_tempfile(); let db = Database::builder() .set_page_size(512) @@ -733,7 +731,7 @@ mod test { #[test] fn small_pages2() { - let tmpfile: NamedTempFile = NamedTempFile::new().unwrap(); + let tmpfile = crate::create_tempfile(); let db = Database::builder() .set_page_size(512) @@ -827,7 +825,7 @@ mod test { #[test] fn small_pages3() { - let tmpfile: NamedTempFile = NamedTempFile::new().unwrap(); + let tmpfile = crate::create_tempfile(); let db = Database::builder() .set_page_size(1024) @@ -860,7 +858,7 @@ mod test { #[test] fn small_pages4() { - let tmpfile: NamedTempFile = NamedTempFile::new().unwrap(); + let tmpfile = crate::create_tempfile(); let db = Database::builder() .set_cache_size(1024 * 1024) @@ -897,7 +895,7 @@ mod test { #[test] fn crash_regression1() { - let tmpfile: NamedTempFile = NamedTempFile::new().unwrap(); + let tmpfile = crate::create_tempfile(); let db = Database::builder() .set_cache_size(1024 * 1024) @@ -920,7 +918,7 @@ mod test { #[test] fn dynamic_shrink() { - let tmpfile: NamedTempFile = NamedTempFile::new().unwrap(); + let tmpfile = crate::create_tempfile(); let table_definition: TableDefinition = TableDefinition::new("x"); let big_value = vec![0u8; 1024]; diff --git a/src/lib.rs b/src/lib.rs index 824842d9..157dc705 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,3 +43,12 @@ mod transactions; mod tree_store; mod tuple_types; mod types; + +#[cfg(test)] +fn create_tempfile() -> tempfile::NamedTempFile { + if cfg!(target_os = "wasi") { + tempfile::NamedTempFile::new_in("").unwrap() + } else { + tempfile::NamedTempFile::new().unwrap() + } +}