From dc5c9b91588474244c3a4564bb80205c7db509f3 Mon Sep 17 00:00:00 2001 From: "Paul J. Davis" Date: Mon, 18 Mar 2024 08:03:03 -0500 Subject: [PATCH] Fixup Dependencies While reading through changes the new dependencies for tempdir and lazy_static caught my eye. The first bit was that these should be marked as `dev-dependencies` so that we're not forcing them onto users of `tiledb-rs` that don't need them. I've also removed the lazy_static dependency for a couple reasons. First, tests sharing global state should be a last resort which caught my eye first. But then I also realized, there's actually a subtle test we can add here per test. If core ever creates a non-writable file that breaks directory removal, we wouldn't know which test it was using lazy_static (as the error would happen at process exit). Creating a TempDir per test means we'll automatically know which test caused the issue (if it ever even happens). --- Cargo.toml | 5 +++-- src/array/mod.rs | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7d12bff8..1ac87aff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -lazy_static = "1.4.0" -tempdir = "0.3.7" tiledb-sys = {version = "0.1.0", path = "tiledb-sys" } + +[dev-dependencies] +tempdir = "0.3.7" diff --git a/src/array/mod.rs b/src/array/mod.rs index f648310f..8667c34e 100644 --- a/src/array/mod.rs +++ b/src/array/mod.rs @@ -149,22 +149,17 @@ impl Drop for Array<'_> { #[cfg(test)] mod tests { - extern crate lazy_static; - extern crate tempdir; + use std::io; + use tempdir::TempDir; use crate::array::*; use crate::context::Context; use crate::Datatype; - use lazy_static::lazy_static; - - lazy_static! { - static ref DIR: tempdir::TempDir = - tempdir::TempDir::new("tiledb-rs.array").unwrap(); - } #[test] - fn test_array_create() { - let arr_path = DIR.path().join("test_array_create"); + fn test_array_create() -> io::Result<()> { + let tmp_dir = TempDir::new("test_rs_bdelit")?; + let arr_dir = tmp_dir.path().join("create_test"); let c: Context = Context::new().unwrap(); @@ -196,6 +191,11 @@ mod tests { // domain not set // TODO - assert!(Array::create(&c, arr_path.to_str().unwrap(), s).is_ok()); + assert!(Array::create(&c, arr_dir.to_str().unwrap(), s).is_ok()); + + // Make sure we can remove the array we created. + tmp_dir.close()?; + + Ok(()) } }