From afb1b9efb4ff31fb934d459555f22cb82d94b483 Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Wed, 26 May 2021 12:53:11 +0200 Subject: [PATCH 1/3] tests/util: add AtPath::hard_link --- tests/common/util.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index 611baadd4..6f9f779ef 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -7,7 +7,7 @@ use std::env; #[cfg(not(windows))] use std::ffi::CString; use std::ffi::OsStr; -use std::fs::{self, File, OpenOptions}; +use std::fs::{self, hard_link, File, OpenOptions}; use std::io::{Read, Result, Write}; #[cfg(unix)] use std::os::unix::fs::{symlink as symlink_dir, symlink as symlink_file}; @@ -524,6 +524,14 @@ impl AtPath { } } + pub fn hard_link(&self, src: &str, dst: &str) { + log_info( + "hard_link", + &format!("{},{}", self.plus_as_string(src), self.plus_as_string(dst)), + ); + hard_link(&self.plus(src), &self.plus(dst)).unwrap(); + } + pub fn symlink_file(&self, src: &str, dst: &str) { log_info( "symlink", @@ -680,6 +688,10 @@ impl TestScenario { cmd } + /// Returns builder for invoking any system command. Paths given are treated + /// relative to the environment's unique temporary test directory. + /// Differs from the builder returned by `cmd` in that `cmd_keepenv` does not call + /// `Command::env_clear` (Clears the entire environment map for the child process.) pub fn cmd_keepenv>(&self, bin: S) -> UCommand { UCommand::new_from_tmp(bin, self.tmpd.clone(), false) } From 6a70d89e8ca43c979a3b8053ecc43122d8d23bf5 Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Wed, 26 May 2021 12:55:53 +0200 Subject: [PATCH 2/3] tests/du: replace call to 'ln' with call to 'AtPath::hard_link' --- tests/by-util/test_du.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/by-util/test_du.rs b/tests/by-util/test_du.rs index c72bd02a6..04dbf9f37 100644 --- a/tests/by-util/test_du.rs +++ b/tests/by-util/test_du.rs @@ -129,11 +129,9 @@ fn _du_soft_link(s: &str) { #[test] fn test_du_hard_link() { let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; - let result_ln = scene.cmd("ln").arg(SUB_FILE).arg(SUB_LINK).run(); - if !result_ln.succeeded() { - scene.ccmd("ln").arg(SUB_FILE).arg(SUB_LINK).succeeds(); - } + at.hard_link(SUB_FILE, SUB_LINK); let result = scene.ucmd().arg(SUB_DIR_LINKS).succeeds(); From efd5921bdaade152a9a1d07d813f685980d13900 Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Wed, 26 May 2021 13:07:04 +0200 Subject: [PATCH 3/3] tests/test: replace call to 'ln -s' with call to 'AtPath::symlink_file' --- tests/by-util/test_test.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/by-util/test_test.rs b/tests/by-util/test_test.rs index 0dfc0c620..3a55f772a 100644 --- a/tests/by-util/test_test.rs +++ b/tests/by-util/test_test.rs @@ -437,10 +437,9 @@ fn test_not_is_not_empty() { #[cfg(not(windows))] fn test_symlink_is_symlink() { let scenario = TestScenario::new(util_name!()); - let mut ln = scenario.cmd("ln"); + let at = &scenario.fixtures; - // creating symlinks requires admin on Windows - ln.args(&["-s", "regular_file", "symlink"]).succeeds(); + at.symlink_file("regular_file", "symlink"); // FIXME: implement on Windows scenario.ucmd().args(&["-h", "symlink"]).succeeds();