1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #2280 from jhscheer/symlink_tests

Improve symlink/hardlink handling in tests
This commit is contained in:
Sylvestre Ledru 2021-05-27 09:41:48 +02:00 committed by GitHub
commit 41539df91d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 8 deletions

View file

@ -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();

View file

@ -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();

View file

@ -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<S: AsRef<OsStr>>(&self, bin: S) -> UCommand {
UCommand::new_from_tmp(bin, self.tmpd.clone(), false)
}