// 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.
// spell-checker:ignore (paths) atim sublink subwords azerty azeaze xcwww azeaz amaz azea qzerty tazerty tsublink testfile1 testfile2 filelist fpath testdir testfile
#[cfg(not(windows))]
use regex::Regex;
#[cfg(any(target_os = "linux", target_os = "android"))]
use crate::common::util::expected_result;
use crate::common::util::TestScenario;
const SUB_DIR: &str = "subdir/deeper";
const SUB_DEEPER_DIR: &str = "subdir/deeper/deeper_dir";
const SUB_DIR_LINKS: &str = "subdir/links";
const SUB_DIR_LINKS_DEEPER_SYM_DIR: &str = "subdir/links/deeper_dir";
const SUB_FILE: &str = "subdir/links/subwords.txt";
const SUB_LINK: &str = "subdir/links/sublink.txt";
#[test]
fn test_du_basics() {
let ts = TestScenario::new(util_name!());
let result = ts.ucmd().succeeds();
#[cfg(any(target_os = "linux", target_os = "android"))]
{
let result_reference = unwrap_or_return!(expected_result(&ts, &[]));
if result_reference.succeeded() {
assert_eq!(result.stdout_str(), result_reference.stdout_str());
return;
}
}
_du_basics(result.stdout_str());
}
#[cfg(target_vendor = "apple")]
fn _du_basics(s: &str) {
let answer = concat!(
"4\t./subdir/deeper/deeper_dir\n",
"8\t./subdir/deeper\n",
"12\t./subdir/links\n",
"20\t./subdir\n",
"24\t.\n"
);
assert_eq!(s, answer);
}
#[cfg(target_os = "windows")]
fn _du_basics(s: &str) {
let answer = concat!(
"0\t.\\subdir\\deeper\\deeper_dir\n",
"0\t.\\subdir\\deeper\n",
"8\t.\\subdir\\links\n",
"8\t.\\subdir\n",
"8\t.\n"
);
assert_eq!(s, answer);
}
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows"),))]
fn _du_basics(s: &str) {
let answer = concat!(
"8\t./subdir/deeper/deeper_dir\n",
"16\t./subdir/deeper\n",
"16\t./subdir/links\n",
"36\t./subdir\n",
"44\t.\n"
);
assert_eq!(s, answer);
}
#[test]
fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
}
#[test]
fn test_du_basics_subdir() {
let ts = TestScenario::new(util_name!());
let result = ts.ucmd().arg(SUB_DIR).succeeds();
#[cfg(any(target_os = "linux", target_os = "android"))]
{
let result_reference = unwrap_or_return!(expected_result(&ts, &[SUB_DIR]));
if result_reference.succeeded() {
assert_eq!(result.stdout_str(), result_reference.stdout_str());
return;
}
}
_du_basics_subdir(result.stdout_str());
}
#[cfg(target_vendor = "apple")]
fn _du_basics_subdir(s: &