From 4b82e1b015901812ea172fea257fb763e054b5d9 Mon Sep 17 00:00:00 2001 From: rindeal Date: Thu, 20 Jun 2024 05:51:03 +0000 Subject: [PATCH] tests: fix race condition when running sh commands --- tests/test_exact_output.rs | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/tests/test_exact_output.rs b/tests/test_exact_output.rs index cb58b5ad..f2e88489 100644 --- a/tests/test_exact_output.rs +++ b/tests/test_exact_output.rs @@ -245,38 +245,28 @@ fn apparent_size_output() -> Vec { #[cfg_attr(target_os = "windows", ignore)] #[test] pub fn test_permission_normal() { - Command::new("sh") + let output = Command::new("sh") .arg("-c") - .arg("mkdir -p /tmp/unreadable_folder && chmod 000 /tmp/unreadable_folder") + .arg("t=\"$(mktemp -d)\" && chmod 000 \"$t\" && printf %s \"$t\"") .output() .unwrap(); - let command_args = vec!["/tmp/unreadable_folder"]; + let tmpdir = String::from_utf8(output.stdout).unwrap(); + let command_args = vec![&tmpdir]; let permission_msg = r#"Did not have permissions for all"#.trim().to_string(); exact_output_test(command_args, vec![], vec![permission_msg]); - - Command::new("sh") - .arg("-c") - .arg("chmod 555 /tmp/unreadable_folder") - .output() - .unwrap(); } #[cfg_attr(target_os = "windows", ignore)] #[test] pub fn test_permission_flag() { - Command::new("sh") + let output = Command::new("sh") .arg("-c") - .arg("mkdir -p /tmp/unreadable_folder && chmod 000 /tmp/unreadable_folder") + .arg("t=\"$(mktemp -d)\" && chmod 000 \"$t\" && printf %s \"$t\"") .output() .unwrap(); + let tmpdir = String::from_utf8(output.stdout).unwrap(); // add the flag to CLI - let command_args = vec!["--print-errors", "/tmp/unreadable_folder"]; + let command_args = vec!["--print-errors", &tmpdir]; let permission_msg = r#"Did not have permissions for directories"#.trim().to_string(); exact_output_test(command_args, vec![], vec![permission_msg]); - - Command::new("sh") - .arg("-c") - .arg("chmod 555 /tmp/unreadable_folder") - .output() - .unwrap(); }