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

du: implement files0-from (#5721)

* du: implement files0-from

Should make tests/du/files0-from-dir pass

* du: prepare tests/du/files0-from.pl

* fix the build on Windows

* add testfile to the ignore list

* remove useless comment

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

* mkdir is enough

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

* address review comments

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
Sylvestre Ledru 2023-12-26 14:40:31 +01:00 committed by GitHub
parent 4acc96fee3
commit 30eb77ac79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 150 additions and 9 deletions

View file

@ -3,10 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore (paths) sublink subwords azerty azeaze xcwww azeaz amaz azea qzerty tazerty tsublink
// spell-checker:ignore (paths) sublink subwords azerty azeaze xcwww azeaz amaz azea qzerty tazerty tsublink testfile1 testfile2 filelist testdir testfile
#[cfg(not(windows))]
use regex::Regex;
#[cfg(not(windows))]
use std::io::Write;
#[cfg(any(target_os = "linux", target_os = "android"))]
@ -991,3 +990,74 @@ fn test_du_symlink_multiple_fail() {
assert_eq!(result.code(), 1);
result.stdout_contains("4\tfile1\n");
}
#[test]
// Disable on Windows because of different path separators and handling of null characters
#[cfg(not(target_os = "windows"))]
fn test_du_files0_from() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
let mut file1 = at.make_file("testfile1");
file1.write_all(b"content1").unwrap();
let mut file2 = at.make_file("testfile2");
file2.write_all(b"content2").unwrap();
at.mkdir("testdir");
let mut file3 = at.make_file("testdir/testfile3");
file3.write_all(b"content3").unwrap();
let mut file_list = at.make_file("filelist");
write!(file_list, "testfile1\0testfile2\0testdir\0").unwrap();
ts.ucmd()
.arg("--files0-from=filelist")
.succeeds()
.stdout_contains("testfile1")
.stdout_contains("testfile2")
.stdout_contains("testdir");
}
#[test]
fn test_du_files0_from_stdin() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
let mut file1 = at.make_file("testfile1");
file1.write_all(b"content1").unwrap();
let mut file2 = at.make_file("testfile2");
file2.write_all(b"content2").unwrap();
let input = "testfile1\0testfile2\0";
ts.ucmd()
.arg("--files0-from=-")
.pipe_in(input)
.succeeds()
.stdout_contains("testfile1")
.stdout_contains("testfile2");
}
#[test]
fn test_du_files0_from_dir() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.mkdir("dir");
let result = ts.ucmd().arg("--files0-from=dir").fails();
assert_eq!(result.stderr_str(), "du: dir: read error: Is a directory\n");
}
#[test]
fn test_du_files0_from_combined() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.mkdir("dir");
let result = ts.ucmd().arg("--files0-from=-").arg("foo").fails();
let stderr = result.stderr_str();
assert!(stderr.contains("file operands cannot be combined with --files0-from"));
}