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

du: simplify file creation in tests

This commit is contained in:
Daniel Hofstetter 2023-12-26 15:15:02 +01:00
parent 30eb77ac79
commit 37c83ec480

View file

@ -6,7 +6,6 @@
// spell-checker:ignore (paths) sublink subwords azerty azeaze xcwww azeaz amaz azea qzerty tazerty tsublink testfile1 testfile2 filelist testdir testfile // spell-checker:ignore (paths) sublink subwords azerty azeaze xcwww azeaz amaz azea qzerty tazerty tsublink testfile1 testfile2 filelist testdir testfile
#[cfg(not(windows))] #[cfg(not(windows))]
use regex::Regex; use regex::Regex;
use std::io::Write;
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(any(target_os = "linux", target_os = "android"))]
use crate::common::util::expected_result; use crate::common::util::expected_result;
@ -347,12 +346,10 @@ fn test_du_dereference_args() {
let ts = TestScenario::new(util_name!()); let ts = TestScenario::new(util_name!());
let at = &ts.fixtures; let at = &ts.fixtures;
at.mkdir_all("subdir"); at.mkdir("dir");
let mut file1 = at.make_file("subdir/file-ignore1"); at.write("dir/file-ignore1", "azeaze");
file1.write_all(b"azeaze").unwrap(); at.write("dir/file-ignore2", "amaz?ng");
let mut file2 = at.make_file("subdir/file-ignore1"); at.symlink_dir("dir", "sublink");
file2.write_all(b"amaz?ng").unwrap();
at.symlink_dir("subdir", "sublink");
for arg in ["-D", "-H", "--dereference-args"] { for arg in ["-D", "-H", "--dereference-args"] {
let result = ts.ucmd().arg(arg).arg("-s").arg("sublink").succeeds(); let result = ts.ucmd().arg(arg).arg("-s").arg("sublink").succeeds();
@ -848,10 +845,8 @@ fn test_du_exclude_mix() {
let ts = TestScenario::new(util_name!()); let ts = TestScenario::new(util_name!());
let at = &ts.fixtures; let at = &ts.fixtures;
let mut file1 = at.make_file("file-ignore1"); at.write("file-ignore1", "azeaze");
file1.write_all(b"azeaze").unwrap(); at.write("file-ignore2", "amaz?ng");
let mut file2 = at.make_file("file-ignore2");
file2.write_all(b"amaz?ng").unwrap();
at.mkdir_all("azerty/xcwww/azeaze"); at.mkdir_all("azerty/xcwww/azeaze");
at.mkdir_all("azerty/xcwww/qzerty"); at.mkdir_all("azerty/xcwww/qzerty");
@ -983,8 +978,7 @@ fn test_du_symlink_multiple_fail() {
let at = &ts.fixtures; let at = &ts.fixtures;
at.symlink_file("non-existing.txt", "target.txt"); at.symlink_file("non-existing.txt", "target.txt");
let mut file1 = at.make_file("file1"); at.write("file1", "azeaze");
file1.write_all(b"azeaze").unwrap();
let result = ts.ucmd().arg("-L").arg("target.txt").arg("file1").fails(); let result = ts.ucmd().arg("-L").arg("target.txt").arg("file1").fails();
assert_eq!(result.code(), 1); assert_eq!(result.code(), 1);
@ -998,17 +992,13 @@ fn test_du_files0_from() {
let ts = TestScenario::new(util_name!()); let ts = TestScenario::new(util_name!());
let at = &ts.fixtures; let at = &ts.fixtures;
let mut file1 = at.make_file("testfile1"); at.write("testfile1", "content1");
file1.write_all(b"content1").unwrap(); at.write("testfile2", "content2");
let mut file2 = at.make_file("testfile2");
file2.write_all(b"content2").unwrap();
at.mkdir("testdir"); at.mkdir("testdir");
let mut file3 = at.make_file("testdir/testfile3"); at.write("testdir/testfile3", "content3");
file3.write_all(b"content3").unwrap();
let mut file_list = at.make_file("filelist"); at.write("filelist", "testfile1\0testfile2\0testdir\0");
write!(file_list, "testfile1\0testfile2\0testdir\0").unwrap();
ts.ucmd() ts.ucmd()
.arg("--files0-from=filelist") .arg("--files0-from=filelist")
@ -1023,10 +1013,8 @@ fn test_du_files0_from_stdin() {
let ts = TestScenario::new(util_name!()); let ts = TestScenario::new(util_name!());
let at = &ts.fixtures; let at = &ts.fixtures;
let mut file1 = at.make_file("testfile1"); at.write("testfile1", "content1");
file1.write_all(b"content1").unwrap(); at.write("testfile2", "content2");
let mut file2 = at.make_file("testfile2");
file2.write_all(b"content2").unwrap();
let input = "testfile1\0testfile2\0"; let input = "testfile1\0testfile2\0";