aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJill <kokakiwi@deuxfleurs.fr>2022-02-04 17:53:46 +0100
committerJill <kokakiwi@deuxfleurs.fr>2022-02-10 17:55:50 +0100
commitcd13ea461b5e6011ddda28c4923260315d67482a (patch)
tree1f091599575e3c94a5360a1649a6ea1091961b4d
parent5d19f3d2d73426749e6f7b69eea1dbf24fdedc6a (diff)
downloadgarage-cd13ea461b5e6011ddda28c4923260315d67482a.tar.gz
garage-cd13ea461b5e6011ddda28c4923260315d67482a.zip
garage(tests): Add some unsafe-usage doc and tweaks
-rw-r--r--src/garage/tests/common/garage.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/garage/tests/common/garage.rs b/src/garage/tests/common/garage.rs
index d9dbcc7c..b887856a 100644
--- a/src/garage/tests/common/garage.rs
+++ b/src/garage/tests/common/garage.rs
@@ -1,4 +1,3 @@
-use std::env::var_os;
use std::mem::MaybeUninit;
use std::path::{Path, PathBuf};
use std::process;
@@ -186,6 +185,8 @@ static INSTANCE_INIT: Once = Once::new();
#[static_init::destructor]
extern "C" fn terminate_instance() {
if INSTANCE_INIT.is_completed() {
+ // This block is sound as it depends on `INSTANCE_INIT` being completed, meaning `INSTANCE`
+ // is actually initialized.
unsafe {
INSTANCE.assume_init_mut().terminate();
}
@@ -200,15 +201,17 @@ pub fn instance() -> &'static Instance {
INSTANCE.write(instance);
});
+ // This block is sound as it depends on `INSTANCE_INIT` being completed by calling `call_once` (blocking),
+ // meaning `INSTANCE` is actually initialized.
unsafe { INSTANCE.assume_init_ref() }
}
pub fn command(config_path: &Path) -> process::Command {
+ use std::env;
+
let mut command = process::Command::new(
- var_os("GARAGE_TEST_INTEGRATION_EXE")
- .as_ref()
- .and_then(|e| e.to_str())
- .unwrap_or(env!("CARGO_BIN_EXE_garage")),
+ env::var("GARAGE_TEST_INTEGRATION_EXE")
+ .unwrap_or_else(|_| env!("CARGO_BIN_EXE_garage").to_owned()),
);
command.arg("-c").arg(config_path);