From 2eaf041914ccfe098014b1dd361f99687653d678 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Wed, 3 Jul 2024 05:17:15 +0300 Subject: [PATCH] fix test --- crates/nsis-process/src/lib.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/crates/nsis-process/src/lib.rs b/crates/nsis-process/src/lib.rs index 89afb04..6293519 100644 --- a/crates/nsis-process/src/lib.rs +++ b/crates/nsis-process/src/lib.rs @@ -337,6 +337,7 @@ impl DerefMut for OwnedHandle { #[cfg(test)] mod tests { + use super::*; #[test] @@ -359,19 +360,27 @@ mod tests { } #[test] + #[cfg(feature = "test")] fn spawn_with_spaces() { + extern crate std; + use alloc::format; + use alloc::string::ToString; + let current = std::env::current_dir().unwrap(); let dir = current.join("dir space"); - std::fs::create_dir_all(dir).unwrap(); + std::fs::create_dir_all(&dir).unwrap(); + + let systemroot = std::env::var("SYSTEMROOT").unwrap_or_else(|_| "C:\\Windows".to_owned()); - let systemroot = std::env::var("SYSTEMROOT").unwrap_or("C:\\Windows"); + let cmd = format!("{systemroot}\\System32\\cmd.exe"); + let cmd_out = dir.join("cmdout.exe"); - let cmd = format!("{systemroot}\\System32\\cmd.exe"); - let cmd_out = dir.join("cmdout.exe"); + std::fs::copy(cmd, &cmd_out).unwrap(); - std::fs::copy(cmd, cmd_out).unwrap(); + assert!(unsafe { run_as_user(cmd_out.display().to_string().as_str(), "/c timeout 3") }); - unsafe { run_as_user(cmd_out.display().to_string().as_str(), "/c timeout 3") }; + std::thread::sleep(std::time::Duration::from_secs(5)); + std::fs::remove_file(cmd_out).unwrap(); } }