2021-06-03 22:49:06 +00:00
|
|
|
// * This file is part of the uutils coreutils package.
|
|
|
|
// *
|
|
|
|
// * For the full copyright and license information, please view the LICENSE
|
|
|
|
// * file that was distributed with this source code.
|
|
|
|
|
2022-04-11 20:50:01 +00:00
|
|
|
// spell-checker:ignore (paths) sublink subwords azerty azeaze xcwww azeaz amaz azea qzerty tazerty
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
use regex::Regex;
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
use std::io::Write;
|
2021-05-30 05:10:54 +00:00
|
|
|
|
2023-03-20 15:26:31 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
|
|
|
use crate::common::util::expected_result;
|
|
|
|
use crate::common::util::TestScenario;
|
2018-03-20 16:10:05 +00:00
|
|
|
|
2018-03-22 16:05:33 +00:00
|
|
|
const SUB_DIR: &str = "subdir/deeper";
|
2021-06-10 15:01:28 +00:00
|
|
|
const SUB_DEEPER_DIR: &str = "subdir/deeper/deeper_dir";
|
2018-03-22 16:05:33 +00:00
|
|
|
const SUB_DIR_LINKS: &str = "subdir/links";
|
2021-06-10 15:01:28 +00:00
|
|
|
const SUB_DIR_LINKS_DEEPER_SYM_DIR: &str = "subdir/links/deeper_dir";
|
2018-03-22 16:05:33 +00:00
|
|
|
const SUB_FILE: &str = "subdir/links/subwords.txt";
|
|
|
|
const SUB_LINK: &str = "subdir/links/sublink.txt";
|
2018-03-20 16:10:05 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_du_basics() {
|
2021-04-17 09:22:49 +00:00
|
|
|
new_ucmd!().succeeds().no_stderr();
|
2018-03-21 14:14:18 +00:00
|
|
|
}
|
2021-03-18 01:32:34 +00:00
|
|
|
#[cfg(target_vendor = "apple")]
|
2021-04-19 08:45:51 +00:00
|
|
|
fn _du_basics(s: &str) {
|
2018-03-20 21:55:31 +00:00
|
|
|
let answer = "32\t./subdir
|
|
|
|
8\t./subdir/deeper
|
|
|
|
24\t./subdir/links
|
2021-06-10 15:01:28 +00:00
|
|
|
40\t.
|
2018-03-20 21:55:31 +00:00
|
|
|
";
|
2018-03-21 14:14:18 +00:00
|
|
|
assert_eq!(s, answer);
|
|
|
|
}
|
2021-03-18 01:32:34 +00:00
|
|
|
#[cfg(not(target_vendor = "apple"))]
|
2021-04-05 20:03:43 +00:00
|
|
|
fn _du_basics(s: &str) {
|
2018-03-21 14:14:18 +00:00
|
|
|
let answer = "28\t./subdir
|
|
|
|
8\t./subdir/deeper
|
|
|
|
16\t./subdir/links
|
2021-06-10 15:01:28 +00:00
|
|
|
36\t.
|
2018-03-21 14:14:18 +00:00
|
|
|
";
|
|
|
|
assert_eq!(s, answer);
|
2018-03-20 16:10:05 +00:00
|
|
|
}
|
|
|
|
|
2022-09-10 16:38:14 +00:00
|
|
|
#[test]
|
|
|
|
fn test_invalid_arg() {
|
|
|
|
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
|
|
|
}
|
|
|
|
|
2018-03-20 16:10:05 +00:00
|
|
|
#[test]
|
|
|
|
fn test_du_basics_subdir() {
|
2021-07-07 20:09:01 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
2021-04-19 08:45:51 +00:00
|
|
|
|
2021-07-07 20:09:01 +00:00
|
|
|
let result = ts.ucmd().arg(SUB_DIR).succeeds();
|
2018-03-20 16:10:05 +00:00
|
|
|
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
2021-04-19 08:45:51 +00:00
|
|
|
{
|
2021-07-07 20:09:01 +00:00
|
|
|
let result_reference = unwrap_or_return!(expected_result(&ts, &[SUB_DIR]));
|
2021-04-19 08:45:51 +00:00
|
|
|
if result_reference.succeeded() {
|
|
|
|
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-04-05 20:03:43 +00:00
|
|
|
_du_basics_subdir(result.stdout_str());
|
2018-03-21 14:14:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 01:32:34 +00:00
|
|
|
#[cfg(target_vendor = "apple")]
|
2021-04-05 20:03:43 +00:00
|
|
|
fn _du_basics_subdir(s: &str) {
|
2021-06-10 15:01:28 +00:00
|
|
|
assert_eq!(s, "4\tsubdir/deeper/deeper_dir\n8\tsubdir/deeper\n");
|
2018-03-21 14:14:18 +00:00
|
|
|
}
|
2021-04-01 21:16:47 +00:00
|
|
|
#[cfg(target_os = "windows")]
|
2021-04-05 20:03:43 +00:00
|
|
|
fn _du_basics_subdir(s: &str) {
|
2021-06-10 15:01:28 +00:00
|
|
|
assert_eq!(s, "0\tsubdir/deeper\\deeper_dir\n0\tsubdir/deeper\n");
|
2021-04-01 21:16:47 +00:00
|
|
|
}
|
2021-05-05 18:05:03 +00:00
|
|
|
#[cfg(target_os = "freebsd")]
|
|
|
|
fn _du_basics_subdir(s: &str) {
|
2021-06-10 15:01:28 +00:00
|
|
|
assert_eq!(s, "8\tsubdir/deeper/deeper_dir\n16\tsubdir/deeper\n");
|
2021-05-05 18:05:03 +00:00
|
|
|
}
|
2021-05-08 11:13:52 +00:00
|
|
|
#[cfg(all(
|
|
|
|
not(target_vendor = "apple"),
|
|
|
|
not(target_os = "windows"),
|
|
|
|
not(target_os = "freebsd")
|
|
|
|
))]
|
2021-04-05 20:03:43 +00:00
|
|
|
fn _du_basics_subdir(s: &str) {
|
2019-12-25 06:42:11 +00:00
|
|
|
// MS-WSL linux has altered expected output
|
2023-03-19 04:59:08 +00:00
|
|
|
if uucore::os::is_wsl_1() {
|
2019-12-25 06:42:11 +00:00
|
|
|
assert_eq!(s, "0\tsubdir/deeper\n");
|
2023-03-19 04:59:08 +00:00
|
|
|
} else {
|
|
|
|
assert_eq!(s, "8\tsubdir/deeper\n");
|
2019-12-25 06:42:11 +00:00
|
|
|
}
|
2018-03-20 16:10:05 +00:00
|
|
|
}
|
|
|
|
|
2021-05-31 13:22:37 +00:00
|
|
|
#[test]
|
|
|
|
fn test_du_invalid_size() {
|
2021-06-12 14:00:48 +00:00
|
|
|
let args = &["block-size", "threshold"];
|
2021-07-07 20:09:01 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
2021-06-12 14:00:48 +00:00
|
|
|
for s in args {
|
2021-07-07 20:09:01 +00:00
|
|
|
ts.ucmd()
|
2023-01-27 09:29:45 +00:00
|
|
|
.arg(format!("--{s}=1fb4t"))
|
2021-06-12 14:00:48 +00:00
|
|
|
.arg("/tmp")
|
|
|
|
.fails()
|
|
|
|
.code_is(1)
|
2023-01-27 09:29:45 +00:00
|
|
|
.stderr_only(format!("du: invalid suffix in --{s} argument '1fb4t'\n"));
|
2022-05-16 14:39:20 +00:00
|
|
|
ts.ucmd()
|
2023-01-27 09:29:45 +00:00
|
|
|
.arg(format!("--{s}=x"))
|
2022-05-16 14:39:20 +00:00
|
|
|
.arg("/tmp")
|
|
|
|
.fails()
|
|
|
|
.code_is(1)
|
2023-01-27 09:29:45 +00:00
|
|
|
.stderr_only(format!("du: invalid --{s} argument 'x'\n"));
|
2021-06-12 14:00:48 +00:00
|
|
|
#[cfg(not(target_pointer_width = "128"))]
|
2021-07-07 20:09:01 +00:00
|
|
|
ts.ucmd()
|
2023-01-27 09:29:45 +00:00
|
|
|
.arg(format!("--{s}=1Y"))
|
2021-06-12 14:00:48 +00:00
|
|
|
.arg("/tmp")
|
|
|
|
.fails()
|
|
|
|
.code_is(1)
|
2023-01-27 09:29:45 +00:00
|
|
|
.stderr_only(format!("du: --{s} argument '1Y' too large\n"));
|
2021-06-12 14:00:48 +00:00
|
|
|
}
|
2021-05-31 13:22:37 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 16:10:05 +00:00
|
|
|
#[test]
|
|
|
|
fn test_du_basics_bad_name() {
|
2021-04-19 08:45:51 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("bad_name")
|
|
|
|
.succeeds() // TODO: replace with ".fails()" once `du` is fixed
|
2021-05-25 23:45:53 +00:00
|
|
|
.stderr_only("du: bad_name: No such file or directory\n");
|
2018-03-20 16:10:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_du_soft_link() {
|
2021-07-07 20:09:01 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = &ts.fixtures;
|
2018-03-20 16:10:05 +00:00
|
|
|
|
2021-04-19 08:45:51 +00:00
|
|
|
at.symlink_file(SUB_FILE, SUB_LINK);
|
2018-03-20 16:10:05 +00:00
|
|
|
|
2021-07-07 20:09:01 +00:00
|
|
|
let result = ts.ucmd().arg(SUB_DIR_LINKS).succeeds();
|
2018-03-20 16:10:05 +00:00
|
|
|
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
2021-04-19 08:45:51 +00:00
|
|
|
{
|
2021-07-07 20:09:01 +00:00
|
|
|
let result_reference = unwrap_or_return!(expected_result(&ts, &[SUB_DIR_LINKS]));
|
2021-04-19 08:45:51 +00:00
|
|
|
if result_reference.succeeded() {
|
|
|
|
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-04-05 20:03:43 +00:00
|
|
|
_du_soft_link(result.stdout_str());
|
2018-03-21 14:14:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 01:32:34 +00:00
|
|
|
#[cfg(target_vendor = "apple")]
|
2021-04-05 20:03:43 +00:00
|
|
|
fn _du_soft_link(s: &str) {
|
2020-01-01 23:06:56 +00:00
|
|
|
// 'macos' host variants may have `du` output variation for soft links
|
|
|
|
assert!((s == "12\tsubdir/links\n") || (s == "16\tsubdir/links\n"));
|
2018-03-21 14:14:18 +00:00
|
|
|
}
|
2021-04-01 21:16:47 +00:00
|
|
|
#[cfg(target_os = "windows")]
|
2021-04-05 20:03:43 +00:00
|
|
|
fn _du_soft_link(s: &str) {
|
2021-04-01 21:16:47 +00:00
|
|
|
assert_eq!(s, "8\tsubdir/links\n");
|
|
|
|
}
|
2021-05-05 18:05:03 +00:00
|
|
|
#[cfg(target_os = "freebsd")]
|
|
|
|
fn _du_soft_link(s: &str) {
|
|
|
|
assert_eq!(s, "16\tsubdir/links\n");
|
|
|
|
}
|
2021-05-08 11:13:52 +00:00
|
|
|
#[cfg(all(
|
|
|
|
not(target_vendor = "apple"),
|
|
|
|
not(target_os = "windows"),
|
|
|
|
not(target_os = "freebsd")
|
|
|
|
))]
|
2021-04-05 20:03:43 +00:00
|
|
|
fn _du_soft_link(s: &str) {
|
2019-12-25 06:42:11 +00:00
|
|
|
// MS-WSL linux has altered expected output
|
2023-03-19 04:59:08 +00:00
|
|
|
if uucore::os::is_wsl_1() {
|
2019-12-25 06:42:11 +00:00
|
|
|
assert_eq!(s, "8\tsubdir/links\n");
|
2023-03-19 04:59:08 +00:00
|
|
|
} else {
|
|
|
|
assert_eq!(s, "16\tsubdir/links\n");
|
2019-12-25 06:42:11 +00:00
|
|
|
}
|
2018-03-20 16:10:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(not(target_os = "android"))]
|
2018-03-20 20:40:27 +00:00
|
|
|
#[test]
|
|
|
|
fn test_du_hard_link() {
|
2021-07-07 20:09:01 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = &ts.fixtures;
|
2018-03-20 20:40:27 +00:00
|
|
|
|
2021-05-26 10:55:53 +00:00
|
|
|
at.hard_link(SUB_FILE, SUB_LINK);
|
2018-03-20 20:40:27 +00:00
|
|
|
|
2021-07-07 20:09:01 +00:00
|
|
|
let result = ts.ucmd().arg(SUB_DIR_LINKS).succeeds();
|
2018-03-20 20:40:27 +00:00
|
|
|
|
2021-04-19 08:45:51 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
{
|
2021-07-07 20:09:01 +00:00
|
|
|
let result_reference = unwrap_or_return!(expected_result(&ts, &[SUB_DIR_LINKS]));
|
2021-04-19 08:45:51 +00:00
|
|
|
if result_reference.succeeded() {
|
|
|
|
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-03-22 16:05:33 +00:00
|
|
|
// We do not double count hard links as the inodes are identical
|
2021-04-05 20:03:43 +00:00
|
|
|
_du_hard_link(result.stdout_str());
|
2018-03-21 14:14:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 01:32:34 +00:00
|
|
|
#[cfg(target_vendor = "apple")]
|
2021-04-05 20:03:43 +00:00
|
|
|
fn _du_hard_link(s: &str) {
|
2022-01-30 20:25:09 +00:00
|
|
|
assert_eq!(s, "12\tsubdir/links\n");
|
2018-03-21 14:14:18 +00:00
|
|
|
}
|
2021-04-01 21:16:47 +00:00
|
|
|
#[cfg(target_os = "windows")]
|
2021-04-05 20:03:43 +00:00
|
|
|
fn _du_hard_link(s: &str) {
|
2022-01-30 20:25:09 +00:00
|
|
|
assert_eq!(s, "8\tsubdir/links\n");
|
2021-04-01 21:16:47 +00:00
|
|
|
}
|
2021-05-05 18:05:03 +00:00
|
|
|
#[cfg(target_os = "freebsd")]
|
|
|
|
fn _du_hard_link(s: &str) {
|
2022-01-30 20:25:09 +00:00
|
|
|
assert_eq!(s, "16\tsubdir/links\n");
|
2021-05-05 18:05:03 +00:00
|
|
|
}
|
2021-05-08 11:13:52 +00:00
|
|
|
#[cfg(all(
|
|
|
|
not(target_vendor = "apple"),
|
|
|
|
not(target_os = "windows"),
|
|
|
|
not(target_os = "freebsd")
|
|
|
|
))]
|
2021-04-05 20:03:43 +00:00
|
|
|
fn _du_hard_link(s: &str) {
|
2019-12-25 06:42:11 +00:00
|
|
|
// MS-WSL linux has altered expected output
|
2023-03-19 04:59:08 +00:00
|
|
|
if uucore::os::is_wsl_1() {
|
2019-12-25 06:42:11 +00:00
|
|
|
assert_eq!(s, "8\tsubdir/links\n");
|
2023-03-19 04:59:08 +00:00
|
|
|
} else {
|
|
|
|
assert_eq!(s, "16\tsubdir/links\n");
|
2019-12-25 06:42:11 +00:00
|
|
|
}
|
2018-03-20 20:40:27 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 21:55:31 +00:00
|
|
|
#[test]
|
|
|
|
fn test_du_d_flag() {
|
2021-07-07 20:09:01 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
2021-04-19 08:45:51 +00:00
|
|
|
|
2021-07-07 20:09:01 +00:00
|
|
|
let result = ts.ucmd().arg("-d1").succeeds();
|
2018-03-20 21:55:31 +00:00
|
|
|
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
2021-04-19 08:45:51 +00:00
|
|
|
{
|
2021-07-07 20:09:01 +00:00
|
|
|
let result_reference = unwrap_or_return!(expected_result(&ts, &["-d1"]));
|
2021-04-19 08:45:51 +00:00
|
|
|
if result_reference.succeeded() {
|
2021-06-10 15:01:28 +00:00
|
|
|
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
2021-04-19 08:45:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-04-05 20:03:43 +00:00
|
|
|
_du_d_flag(result.stdout_str());
|
2018-03-21 14:14:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 01:32:34 +00:00
|
|
|
#[cfg(target_vendor = "apple")]
|
2021-04-05 20:03:43 +00:00
|
|
|
fn _du_d_flag(s: &str) {
|
2021-06-10 15:01:28 +00:00
|
|
|
assert_eq!(s, "20\t./subdir\n24\t.\n");
|
2018-03-21 14:14:18 +00:00
|
|
|
}
|
2021-04-01 21:16:47 +00:00
|
|
|
#[cfg(target_os = "windows")]
|
2021-04-05 20:03:43 +00:00
|
|
|
fn _du_d_flag(s: &str) {
|
2021-06-10 15:01:28 +00:00
|
|
|
assert_eq!(s, "8\t.\\subdir\n8\t.\n");
|
2021-04-01 21:16:47 +00:00
|
|
|
}
|
2021-05-05 18:05:03 +00:00
|
|
|
#[cfg(target_os = "freebsd")]
|
|
|
|
fn _du_d_flag(s: &str) {
|
2021-06-10 15:01:28 +00:00
|
|
|
assert_eq!(s, "36\t./subdir\n44\t.\n");
|
2021-05-05 18:05:03 +00:00
|
|
|
}
|
2021-05-08 11:13:52 +00:00
|
|
|
#[cfg(all(
|
|
|
|
not(target_vendor = "apple"),
|
|
|
|
not(target_os = "windows"),
|
|
|
|
not(target_os = "freebsd")
|
|
|
|
))]
|
2021-04-05 20:03:43 +00:00
|
|
|
fn _du_d_flag(s: &str) {
|
2019-12-25 06:42:11 +00:00
|
|
|
// MS-WSL linux has altered expected output
|
2023-03-19 04:59:08 +00:00
|
|
|
if uucore::os::is_wsl_1() {
|
2021-06-10 15:01:28 +00:00
|
|
|
assert_eq!(s, "8\t./subdir\n8\t.\n");
|
2023-03-19 04:59:08 +00:00
|
|
|
} else {
|
|
|
|
assert_eq!(s, "28\t./subdir\n36\t.\n");
|
2021-06-10 15:01:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_du_dereference() {
|
2021-07-07 20:09:01 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = &ts.fixtures;
|
2021-06-10 15:01:28 +00:00
|
|
|
|
|
|
|
at.symlink_dir(SUB_DEEPER_DIR, SUB_DIR_LINKS_DEEPER_SYM_DIR);
|
|
|
|
|
2021-07-07 20:09:01 +00:00
|
|
|
let result = ts.ucmd().arg("-L").arg(SUB_DIR_LINKS).succeeds();
|
2021-06-10 15:01:28 +00:00
|
|
|
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
2021-06-10 15:01:28 +00:00
|
|
|
{
|
2021-07-07 20:09:01 +00:00
|
|
|
let result_reference = unwrap_or_return!(expected_result(&ts, &["-L", SUB_DIR_LINKS]));
|
|
|
|
|
2021-06-10 15:01:28 +00:00
|
|
|
if result_reference.succeeded() {
|
|
|
|
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_du_dereference(result.stdout_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_vendor = "apple")]
|
|
|
|
fn _du_dereference(s: &str) {
|
|
|
|
assert_eq!(s, "4\tsubdir/links/deeper_dir\n16\tsubdir/links\n");
|
|
|
|
}
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
fn _du_dereference(s: &str) {
|
|
|
|
assert_eq!(s, "0\tsubdir/links\\deeper_dir\n8\tsubdir/links\n");
|
|
|
|
}
|
|
|
|
#[cfg(target_os = "freebsd")]
|
|
|
|
fn _du_dereference(s: &str) {
|
|
|
|
assert_eq!(s, "8\tsubdir/links/deeper_dir\n24\tsubdir/links\n");
|
|
|
|
}
|
|
|
|
#[cfg(all(
|
|
|
|
not(target_vendor = "apple"),
|
|
|
|
not(target_os = "windows"),
|
|
|
|
not(target_os = "freebsd")
|
|
|
|
))]
|
|
|
|
fn _du_dereference(s: &str) {
|
|
|
|
// MS-WSL linux has altered expected output
|
2023-03-19 04:59:08 +00:00
|
|
|
if uucore::os::is_wsl_1() {
|
2021-06-10 15:01:28 +00:00
|
|
|
assert_eq!(s, "0\tsubdir/links/deeper_dir\n8\tsubdir/links\n");
|
2023-03-19 04:59:08 +00:00
|
|
|
} else {
|
|
|
|
assert_eq!(s, "8\tsubdir/links/deeper_dir\n24\tsubdir/links\n");
|
2019-12-25 06:42:11 +00:00
|
|
|
}
|
2018-03-20 21:55:31 +00:00
|
|
|
}
|
2021-04-01 23:42:43 +00:00
|
|
|
|
2021-06-19 16:02:39 +00:00
|
|
|
#[test]
|
|
|
|
fn test_du_inodes_basic() {
|
2021-07-07 20:09:01 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let result = ts.ucmd().arg("--inodes").succeeds();
|
2021-06-19 16:02:39 +00:00
|
|
|
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
2021-06-19 16:02:39 +00:00
|
|
|
{
|
2021-07-07 20:09:01 +00:00
|
|
|
let result_reference = unwrap_or_return!(expected_result(&ts, &["--inodes"]));
|
2021-06-19 16:02:39 +00:00
|
|
|
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
|
|
|
}
|
|
|
|
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
2021-06-19 16:02:39 +00:00
|
|
|
_du_inodes_basic(result.stdout_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
fn _du_inodes_basic(s: &str) {
|
|
|
|
assert_eq!(
|
|
|
|
s,
|
|
|
|
"2\t.\\subdir\\deeper\\deeper_dir
|
|
|
|
4\t.\\subdir\\deeper
|
|
|
|
3\t.\\subdir\\links
|
|
|
|
8\t.\\subdir
|
|
|
|
11\t.
|
|
|
|
"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "windows"))]
|
|
|
|
fn _du_inodes_basic(s: &str) {
|
|
|
|
assert_eq!(
|
|
|
|
s,
|
|
|
|
"2\t./subdir/deeper/deeper_dir
|
|
|
|
4\t./subdir/deeper
|
|
|
|
3\t./subdir/links
|
|
|
|
8\t./subdir
|
|
|
|
11\t.
|
|
|
|
"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_du_inodes() {
|
2021-07-07 20:09:01 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
2021-06-19 16:02:39 +00:00
|
|
|
|
2021-07-07 20:09:01 +00:00
|
|
|
ts.ucmd()
|
2021-06-19 16:02:39 +00:00
|
|
|
.arg("--summarize")
|
|
|
|
.arg("--inodes")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only("11\t.\n");
|
|
|
|
|
2021-07-07 20:09:01 +00:00
|
|
|
let result = ts.ucmd().arg("--separate-dirs").arg("--inodes").succeeds();
|
2021-06-19 16:02:39 +00:00
|
|
|
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
result.stdout_contains("3\t.\\subdir\\links\n");
|
|
|
|
#[cfg(not(target_os = "windows"))]
|
|
|
|
result.stdout_contains("3\t./subdir/links\n");
|
|
|
|
result.stdout_contains("3\t.\n");
|
|
|
|
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
2021-06-19 16:02:39 +00:00
|
|
|
{
|
2021-07-07 20:09:01 +00:00
|
|
|
let result_reference =
|
|
|
|
unwrap_or_return!(expected_result(&ts, &["--separate-dirs", "--inodes"]));
|
2021-06-19 16:02:39 +00:00
|
|
|
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-01 23:42:43 +00:00
|
|
|
#[test]
|
|
|
|
fn test_du_h_flag_empty_file() {
|
2021-04-19 08:45:51 +00:00
|
|
|
new_ucmd!()
|
2021-04-05 20:03:43 +00:00
|
|
|
.arg("-h")
|
|
|
|
.arg("empty.txt")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only("0\tempty.txt\n");
|
2021-04-01 23:42:43 +00:00
|
|
|
}
|
2021-04-07 06:41:04 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "touch")]
|
|
|
|
#[test]
|
|
|
|
fn test_du_time() {
|
2021-07-07 20:09:01 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
2021-04-07 06:41:04 +00:00
|
|
|
|
2023-02-28 10:06:42 +00:00
|
|
|
// du --time formats the timestamp according to the local timezone. We set the TZ
|
|
|
|
// environment variable to UTC in the commands below to ensure consistent outputs
|
|
|
|
// and test results regardless of the timezone of the machine this test runs in.
|
|
|
|
|
2021-07-07 20:09:01 +00:00
|
|
|
ts.ccmd("touch")
|
2023-02-28 10:06:42 +00:00
|
|
|
.env("TZ", "UTC")
|
2021-04-17 09:22:49 +00:00
|
|
|
.arg("-a")
|
|
|
|
.arg("-t")
|
|
|
|
.arg("201505150000")
|
|
|
|
.arg("date_test")
|
2021-04-19 08:45:51 +00:00
|
|
|
.succeeds();
|
2021-04-07 06:41:04 +00:00
|
|
|
|
2021-07-07 20:09:01 +00:00
|
|
|
ts.ccmd("touch")
|
2023-02-28 10:06:42 +00:00
|
|
|
.env("TZ", "UTC")
|
2021-05-26 05:27:15 +00:00
|
|
|
.arg("-m")
|
|
|
|
.arg("-t")
|
|
|
|
.arg("201606160000")
|
2021-04-19 08:45:51 +00:00
|
|
|
.arg("date_test")
|
2021-05-26 05:27:15 +00:00
|
|
|
.succeeds();
|
|
|
|
|
2023-02-28 10:06:42 +00:00
|
|
|
let result = ts
|
|
|
|
.ucmd()
|
|
|
|
.env("TZ", "UTC")
|
|
|
|
.arg("--time")
|
|
|
|
.arg("date_test")
|
|
|
|
.succeeds();
|
2021-05-26 05:27:15 +00:00
|
|
|
result.stdout_only("0\t2016-06-16 00:00\tdate_test\n");
|
|
|
|
|
2023-02-28 10:06:42 +00:00
|
|
|
let result = ts
|
|
|
|
.ucmd()
|
|
|
|
.env("TZ", "UTC")
|
|
|
|
.arg("--time=atime")
|
|
|
|
.arg("date_test")
|
|
|
|
.succeeds();
|
2021-05-26 05:27:15 +00:00
|
|
|
result.stdout_only("0\t2015-05-15 00:00\tdate_test\n");
|
|
|
|
|
2023-02-28 10:06:42 +00:00
|
|
|
let result = ts
|
|
|
|
.ucmd()
|
|
|
|
.env("TZ", "UTC")
|
|
|
|
.arg("--time=ctime")
|
|
|
|
.arg("date_test")
|
|
|
|
.succeeds();
|
2021-05-26 05:27:15 +00:00
|
|
|
result.stdout_only("0\t2016-06-16 00:00\tdate_test\n");
|
|
|
|
|
2021-07-18 23:55:11 +00:00
|
|
|
if birth_supported() {
|
2021-05-26 05:27:15 +00:00
|
|
|
use regex::Regex;
|
|
|
|
|
|
|
|
let re_birth =
|
|
|
|
Regex::new(r"0\t[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}\tdate_test").unwrap();
|
2021-07-07 20:09:01 +00:00
|
|
|
let result = ts.ucmd().arg("--time=birth").arg("date_test").succeeds();
|
2021-05-26 05:27:15 +00:00
|
|
|
result.stdout_matches(&re_birth);
|
|
|
|
}
|
2021-04-07 06:41:04 +00:00
|
|
|
}
|
2021-04-17 08:26:52 +00:00
|
|
|
|
2021-07-18 23:55:11 +00:00
|
|
|
#[cfg(feature = "touch")]
|
|
|
|
fn birth_supported() -> bool {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let m = match std::fs::metadata(ts.fixtures.subdir) {
|
|
|
|
Ok(m) => m,
|
|
|
|
Err(e) => panic!("{}", e),
|
|
|
|
};
|
|
|
|
m.created().is_ok()
|
|
|
|
}
|
|
|
|
|
2021-04-17 08:26:52 +00:00
|
|
|
#[cfg(not(target_os = "windows"))]
|
|
|
|
#[cfg(feature = "chmod")]
|
|
|
|
#[test]
|
|
|
|
fn test_du_no_permission() {
|
2021-07-07 20:09:01 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = &ts.fixtures;
|
2021-04-07 06:41:04 +00:00
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
at.mkdir_all(SUB_DIR_LINKS);
|
2021-04-07 06:41:04 +00:00
|
|
|
|
2021-07-07 20:09:01 +00:00
|
|
|
ts.ccmd("chmod").arg("-r").arg(SUB_DIR_LINKS).succeeds();
|
2021-04-07 06:41:04 +00:00
|
|
|
|
2022-04-09 21:46:01 +00:00
|
|
|
let result = ts.ucmd().arg(SUB_DIR_LINKS).fails();
|
2022-05-03 15:22:05 +00:00
|
|
|
result.stderr_contains("du: cannot read directory 'subdir/links': Permission denied");
|
2021-04-07 06:41:04 +00:00
|
|
|
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
2021-04-22 20:37:44 +00:00
|
|
|
{
|
2021-07-07 20:09:01 +00:00
|
|
|
let result_reference = unwrap_or_return!(expected_result(&ts, &[SUB_DIR_LINKS]));
|
2021-04-22 20:37:44 +00:00
|
|
|
if result_reference
|
|
|
|
.stderr_str()
|
|
|
|
.contains("du: cannot read directory 'subdir/links': Permission denied")
|
|
|
|
{
|
|
|
|
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 08:45:51 +00:00
|
|
|
_du_no_permission(result.stdout_str());
|
2021-04-17 08:26:52 +00:00
|
|
|
}
|
|
|
|
|
2022-04-09 21:46:01 +00:00
|
|
|
#[cfg(not(target_os = "windows"))]
|
|
|
|
#[cfg(feature = "chmod")]
|
|
|
|
#[test]
|
|
|
|
fn test_du_no_exec_permission() {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = &ts.fixtures;
|
|
|
|
|
|
|
|
at.mkdir_all("d/no-x/y");
|
|
|
|
|
|
|
|
ts.ccmd("chmod").arg("u=rw").arg("d/no-x").succeeds();
|
|
|
|
|
|
|
|
let result = ts.ucmd().arg("d/no-x").fails();
|
|
|
|
result.stderr_contains("du: cannot access 'd/no-x/y': Permission denied");
|
|
|
|
}
|
|
|
|
|
2021-04-17 08:26:52 +00:00
|
|
|
#[cfg(target_vendor = "apple")]
|
2021-04-19 08:45:51 +00:00
|
|
|
fn _du_no_permission(s: &str) {
|
2021-04-17 08:26:52 +00:00
|
|
|
assert_eq!(s, "0\tsubdir/links\n");
|
|
|
|
}
|
|
|
|
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))]
|
2021-04-19 08:45:51 +00:00
|
|
|
fn _du_no_permission(s: &str) {
|
2021-04-17 08:26:52 +00:00
|
|
|
assert_eq!(s, "4\tsubdir/links\n");
|
2021-04-01 23:42:43 +00:00
|
|
|
}
|
2021-06-06 13:34:40 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_du_one_file_system() {
|
2021-07-07 20:09:01 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
2021-06-06 13:34:40 +00:00
|
|
|
|
2021-07-07 20:09:01 +00:00
|
|
|
let result = ts.ucmd().arg("-x").arg(SUB_DIR).succeeds();
|
2021-06-06 13:34:40 +00:00
|
|
|
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
2021-06-06 13:34:40 +00:00
|
|
|
{
|
2021-07-07 20:09:01 +00:00
|
|
|
let result_reference = unwrap_or_return!(expected_result(&ts, &["-x", SUB_DIR]));
|
2021-06-06 13:34:40 +00:00
|
|
|
if result_reference.succeeded() {
|
|
|
|
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_du_basics_subdir(result.stdout_str());
|
|
|
|
}
|
2021-06-12 14:00:48 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_du_threshold() {
|
2021-07-07 20:09:01 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
2021-06-12 14:00:48 +00:00
|
|
|
|
|
|
|
let threshold = if cfg!(windows) { "7K" } else { "10K" };
|
|
|
|
|
2021-07-07 20:09:01 +00:00
|
|
|
ts.ucmd()
|
2023-01-27 09:29:45 +00:00
|
|
|
.arg(format!("--threshold={threshold}"))
|
2021-06-12 14:00:48 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_contains("links")
|
2021-06-10 15:01:28 +00:00
|
|
|
.stdout_does_not_contain("deeper_dir");
|
2021-06-12 14:00:48 +00:00
|
|
|
|
2021-07-07 20:09:01 +00:00
|
|
|
ts.ucmd()
|
2023-01-27 09:29:45 +00:00
|
|
|
.arg(format!("--threshold=-{threshold}"))
|
2021-06-12 14:00:48 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_does_not_contain("links")
|
2021-06-10 15:01:28 +00:00
|
|
|
.stdout_contains("deeper_dir");
|
2021-06-12 14:00:48 +00:00
|
|
|
}
|
2021-06-26 00:34:04 +00:00
|
|
|
|
2023-03-26 13:08:56 +00:00
|
|
|
#[test]
|
|
|
|
fn test_du_invalid_threshold() {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
|
|
|
|
let threshold = "-0";
|
|
|
|
|
2023-03-26 21:38:31 +00:00
|
|
|
ts.ucmd().arg(format!("--threshold={threshold}")).fails();
|
2023-03-26 13:08:56 +00:00
|
|
|
}
|
|
|
|
|
2021-06-26 00:34:04 +00:00
|
|
|
#[test]
|
|
|
|
fn test_du_apparent_size() {
|
2021-07-07 20:09:01 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let result = ts.ucmd().arg("--apparent-size").succeeds();
|
2021-06-26 00:34:04 +00:00
|
|
|
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
2021-06-26 00:34:04 +00:00
|
|
|
{
|
2021-07-07 20:09:01 +00:00
|
|
|
let result_reference = unwrap_or_return!(expected_result(&ts, &["--apparent-size"]));
|
2021-06-26 00:34:04 +00:00
|
|
|
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
|
|
|
}
|
|
|
|
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
2021-06-26 00:34:04 +00:00
|
|
|
_du_apparent_size(result.stdout_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
fn _du_apparent_size(s: &str) {
|
|
|
|
assert_eq!(
|
|
|
|
s,
|
|
|
|
"1\t.\\subdir\\deeper\\deeper_dir
|
|
|
|
1\t.\\subdir\\deeper
|
|
|
|
6\t.\\subdir\\links
|
|
|
|
6\t.\\subdir
|
|
|
|
6\t.
|
|
|
|
"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#[cfg(target_vendor = "apple")]
|
|
|
|
fn _du_apparent_size(s: &str) {
|
|
|
|
assert_eq!(
|
|
|
|
s,
|
|
|
|
"1\t./subdir/deeper/deeper_dir
|
|
|
|
1\t./subdir/deeper
|
|
|
|
6\t./subdir/links
|
|
|
|
6\t./subdir
|
|
|
|
6\t.
|
|
|
|
"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#[cfg(target_os = "freebsd")]
|
|
|
|
fn _du_apparent_size(s: &str) {
|
|
|
|
assert_eq!(
|
|
|
|
s,
|
|
|
|
"1\t./subdir/deeper/deeper_dir
|
|
|
|
2\t./subdir/deeper
|
|
|
|
6\t./subdir/links
|
|
|
|
8\t./subdir
|
|
|
|
8\t.
|
|
|
|
"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#[cfg(all(
|
|
|
|
not(target_vendor = "apple"),
|
|
|
|
not(target_os = "windows"),
|
|
|
|
not(target_os = "freebsd")
|
|
|
|
))]
|
|
|
|
fn _du_apparent_size(s: &str) {
|
|
|
|
assert_eq!(
|
|
|
|
s,
|
|
|
|
"5\t./subdir/deeper/deeper_dir
|
|
|
|
9\t./subdir/deeper
|
|
|
|
10\t./subdir/links
|
|
|
|
22\t./subdir
|
|
|
|
26\t.
|
|
|
|
"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_du_bytes() {
|
2021-07-07 20:09:01 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let result = ts.ucmd().arg("--bytes").succeeds();
|
2021-06-26 00:34:04 +00:00
|
|
|
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
2021-06-26 00:34:04 +00:00
|
|
|
{
|
2021-07-07 20:09:01 +00:00
|
|
|
let result_reference = unwrap_or_return!(expected_result(&ts, &["--bytes"]));
|
2021-06-26 00:34:04 +00:00
|
|
|
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
result.stdout_contains("5145\t.\\subdir\n");
|
|
|
|
#[cfg(target_vendor = "apple")]
|
|
|
|
result.stdout_contains("5625\t./subdir\n");
|
|
|
|
#[cfg(target_os = "freebsd")]
|
|
|
|
result.stdout_contains("7193\t./subdir\n");
|
|
|
|
#[cfg(all(
|
|
|
|
not(target_vendor = "apple"),
|
|
|
|
not(target_os = "windows"),
|
2021-07-06 17:45:06 +00:00
|
|
|
not(target_os = "freebsd"),
|
2022-02-09 18:08:28 +00:00
|
|
|
not(target_os = "linux"),
|
|
|
|
not(target_os = "android"),
|
2021-06-26 00:34:04 +00:00
|
|
|
))]
|
|
|
|
result.stdout_contains("21529\t./subdir\n");
|
|
|
|
}
|
2022-04-11 20:50:01 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_du_exclude() {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = &ts.fixtures;
|
|
|
|
|
|
|
|
at.symlink_dir(SUB_DEEPER_DIR, SUB_DIR_LINKS_DEEPER_SYM_DIR);
|
|
|
|
at.mkdir_all(SUB_DIR_LINKS);
|
|
|
|
|
|
|
|
ts.ucmd()
|
|
|
|
.arg("--exclude=subdir")
|
|
|
|
.arg(SUB_DEEPER_DIR)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_contains("subdir/deeper/deeper_dir");
|
|
|
|
ts.ucmd()
|
|
|
|
.arg("--exclude=subdir")
|
|
|
|
.arg("subdir")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("");
|
|
|
|
ts.ucmd()
|
|
|
|
.arg("--exclude=subdir")
|
|
|
|
.arg("--verbose")
|
|
|
|
.arg("subdir")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_contains("'subdir' ignored");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
// Disable on Windows because we are looking for /
|
|
|
|
// And the tests would be more complex if we have to support \ too
|
|
|
|
#[cfg(not(target_os = "windows"))]
|
|
|
|
fn test_du_exclude_2() {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = &ts.fixtures;
|
|
|
|
|
|
|
|
at.mkdir_all("azerty/xcwww/azeaze");
|
|
|
|
|
|
|
|
let result = ts.ucmd().arg("azerty").succeeds();
|
|
|
|
|
|
|
|
let path_regexp = r"(.*)azerty/xcwww/azeaze(.*)azerty/xcwww(.*)azerty";
|
|
|
|
let re = Regex::new(path_regexp).unwrap();
|
|
|
|
assert!(re.is_match(result.stdout_str().replace('\n', "").trim()));
|
|
|
|
|
|
|
|
// Exact match
|
|
|
|
ts.ucmd()
|
|
|
|
.arg("--exclude=azeaze")
|
|
|
|
.arg("azerty")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_does_not_contain("azerty/xcwww/azeaze");
|
|
|
|
// Partial match and NOT a glob
|
|
|
|
ts.ucmd()
|
|
|
|
.arg("--exclude=azeaz")
|
|
|
|
.arg("azerty")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_contains("azerty/xcwww/azeaze");
|
|
|
|
// Partial match and a various glob
|
|
|
|
ts.ucmd()
|
|
|
|
.arg("--exclude=azea?")
|
|
|
|
.arg("azerty")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_contains("azerty/xcwww/azeaze");
|
|
|
|
ts.ucmd()
|
|
|
|
.arg("--exclude=azea{z,b}")
|
|
|
|
.arg("azerty")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_contains("azerty/xcwww/azeaze");
|
|
|
|
ts.ucmd()
|
|
|
|
.arg("--exclude=azea*")
|
|
|
|
.arg("azerty")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_does_not_contain("azerty/xcwww/azeaze");
|
|
|
|
ts.ucmd()
|
|
|
|
.arg("--exclude=azeaz?")
|
|
|
|
.arg("azerty")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_does_not_contain("azerty/xcwww/azeaze");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
// Disable on Windows because we are looking for /
|
|
|
|
// And the tests would be more complex if we have to support \ too
|
|
|
|
#[cfg(not(target_os = "windows"))]
|
|
|
|
fn test_du_exclude_mix() {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = &ts.fixtures;
|
|
|
|
|
|
|
|
let mut file1 = at.make_file("file-ignore1");
|
|
|
|
file1.write_all(b"azeaze").unwrap();
|
|
|
|
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/qzerty");
|
|
|
|
at.mkdir_all("azerty/xcwww/amazing");
|
|
|
|
|
|
|
|
ts.ucmd()
|
|
|
|
.arg("azerty")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_contains("azerty/xcwww/azeaze");
|
|
|
|
ts.ucmd()
|
|
|
|
.arg("--exclude=azeaze")
|
|
|
|
.arg("azerty")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_does_not_contain("azerty/xcwww/azeaze");
|
|
|
|
|
|
|
|
// Just exclude one file name
|
|
|
|
let result = ts.ucmd().arg("--exclude=qzerty").arg("azerty").succeeds();
|
|
|
|
assert!(!result.stdout_str().contains("qzerty"));
|
|
|
|
assert!(result.stdout_str().contains("azerty"));
|
|
|
|
assert!(result.stdout_str().contains("xcwww"));
|
|
|
|
|
|
|
|
// Exclude from file
|
|
|
|
let result = ts
|
|
|
|
.ucmd()
|
|
|
|
.arg("--exclude-from=file-ignore1")
|
|
|
|
.arg("azerty")
|
|
|
|
.succeeds();
|
|
|
|
assert!(!result.stdout_str().contains("azeaze"));
|
|
|
|
assert!(result.stdout_str().contains("qzerty"));
|
|
|
|
assert!(result.stdout_str().contains("xcwww"));
|
|
|
|
|
|
|
|
// Mix two files and string
|
|
|
|
let result = ts
|
|
|
|
.ucmd()
|
|
|
|
.arg("--exclude=qzerty")
|
|
|
|
.arg("--exclude-from=file-ignore1")
|
|
|
|
.arg("--exclude-from=file-ignore2")
|
|
|
|
.arg("azerty")
|
|
|
|
.succeeds();
|
|
|
|
assert!(!result.stdout_str().contains("amazing"));
|
|
|
|
assert!(!result.stdout_str().contains("qzerty"));
|
|
|
|
assert!(!result.stdout_str().contains("azeaze"));
|
|
|
|
assert!(result.stdout_str().contains("xcwww"));
|
|
|
|
}
|
|
|
|
|
2022-07-29 04:24:00 +00:00
|
|
|
#[test]
|
|
|
|
// Disable on Windows because we are looking for /
|
|
|
|
// And the tests would be more complex if we have to support \ too
|
|
|
|
#[cfg(not(target_os = "windows"))]
|
|
|
|
fn test_du_complex_exclude_patterns() {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = &ts.fixtures;
|
|
|
|
|
|
|
|
at.mkdir_all("azerty/xcwww/azeaze");
|
|
|
|
at.mkdir_all("azerty/xcwww/qzerty");
|
|
|
|
at.mkdir_all("azerty/xcwww/amazing");
|
|
|
|
|
|
|
|
// Negation in glob should work with both ^ and !
|
|
|
|
let result = ts
|
|
|
|
.ucmd()
|
|
|
|
.arg("--exclude=azerty/*/[^q]*")
|
|
|
|
.arg("azerty")
|
|
|
|
.succeeds();
|
|
|
|
assert!(!result.stdout_str().contains("amazing"));
|
|
|
|
assert!(result.stdout_str().contains("qzerty"));
|
|
|
|
assert!(!result.stdout_str().contains("azeaze"));
|
|
|
|
assert!(result.stdout_str().contains("xcwww"));
|
|
|
|
|
|
|
|
let result = ts
|
|
|
|
.ucmd()
|
|
|
|
.arg("--exclude=azerty/*/[!q]*")
|
|
|
|
.arg("azerty")
|
|
|
|
.succeeds();
|
|
|
|
assert!(!result.stdout_str().contains("amazing"));
|
|
|
|
assert!(result.stdout_str().contains("qzerty"));
|
|
|
|
assert!(!result.stdout_str().contains("azeaze"));
|
|
|
|
assert!(result.stdout_str().contains("xcwww"));
|
|
|
|
}
|
|
|
|
|
2022-04-11 20:50:01 +00:00
|
|
|
#[test]
|
|
|
|
fn test_du_exclude_several_components() {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = &ts.fixtures;
|
|
|
|
|
|
|
|
at.mkdir_all("a/b/c");
|
|
|
|
at.mkdir_all("a/x/y");
|
|
|
|
at.mkdir_all("a/u/y");
|
|
|
|
|
|
|
|
// Exact match
|
|
|
|
let result = ts
|
|
|
|
.ucmd()
|
|
|
|
.arg("--exclude=a/u")
|
|
|
|
.arg("--exclude=a/b")
|
|
|
|
.arg("a")
|
|
|
|
.succeeds();
|
|
|
|
assert!(!result.stdout_str().contains("a/u"));
|
|
|
|
assert!(!result.stdout_str().contains("a/b"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_du_exclude_invalid_syntax() {
|
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = &ts.fixtures;
|
|
|
|
|
|
|
|
at.mkdir_all("azerty/xcwww/azeaze");
|
|
|
|
|
|
|
|
ts.ucmd()
|
|
|
|
.arg("--exclude=a[ze")
|
|
|
|
.arg("azerty")
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("du: Invalid exclude syntax");
|
|
|
|
}
|