Skip to content

Commit

Permalink
tests: fix race condition when running sh commands
Browse files Browse the repository at this point in the history
  • Loading branch information
rindeal authored Jun 20, 2024
1 parent 2468fcc commit 3540cea
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions tests/test_exact_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,38 +245,28 @@ fn apparent_size_output() -> Vec<String> {
#[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")
.arg("-c")
.arg("mkdir -p /tmp/unreadable_folder && chmod 000 /tmp/unreadable_folder")
.output()
.unwrap();
let output = Command::new("sh")
.arg("-c")
.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();
}

0 comments on commit 3540cea

Please sign in to comment.