mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 09:48:03 +00:00
du: add test for -d flag
This commit is contained in:
parent
b6c7771087
commit
ea504bf0ec
5 changed files with 26 additions and 23 deletions
1
tests/fixtures/du/subdir/links/subwords2.txt
vendored
Normal file
1
tests/fixtures/du/subdir/links/subwords2.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
hello
|
2
tests/fixtures/du/words.txt
vendored
2
tests/fixtures/du/words.txt
vendored
|
@ -1 +1 @@
|
|||
hello
|
||||
hi
|
||||
|
|
|
@ -1,18 +1,22 @@
|
|||
use common::util::*;
|
||||
use std::fs::set_permissions;
|
||||
|
||||
static SUB_DIR: &str = "subdir";
|
||||
static SUB_FILE: &str = "subdir/subwords.txt";
|
||||
static SUB_LINK: &str = "subdir/sublink.txt";
|
||||
static SUB_DIR: &str = "subdir/deeper";
|
||||
static SUB_DIR_LINKS: &str = "subdir/links";
|
||||
static SUB_FILE: &str = "subdir/links/subwords.txt";
|
||||
static SUB_LINK: &str = "subdir/links/sublink.txt";
|
||||
|
||||
#[test]
|
||||
fn test_du_basics() {
|
||||
let (_at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let answer = "32\t./subdir
|
||||
8\t./subdir/deeper
|
||||
24\t./subdir/links
|
||||
40\t./
|
||||
";
|
||||
let result = ucmd.run();
|
||||
assert!(result.success);
|
||||
assert_eq!(result.stderr, "");
|
||||
assert_eq!(result.stdout, "24\t./subdir\n32\t./\n");
|
||||
assert_eq!(result.stdout, answer);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -22,7 +26,7 @@ fn test_du_basics_subdir() {
|
|||
let result = ucmd.arg(SUB_DIR).run();
|
||||
assert!(result.success);
|
||||
assert_eq!(result.stderr, "");
|
||||
assert_eq!(result.stdout, "24\tsubdir\n");
|
||||
assert_eq!(result.stdout, "8\tsubdir/deeper\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -41,10 +45,10 @@ fn test_du_soft_link() {
|
|||
let link = ts.cmd("ln").arg("-s").arg(SUB_FILE).arg(SUB_LINK).run();
|
||||
assert!(link.success);
|
||||
|
||||
let result = ts.ucmd().arg(SUB_DIR).run();
|
||||
let result = ts.ucmd().arg(SUB_DIR_LINKS).run();
|
||||
assert!(result.success);
|
||||
assert_eq!(result.stderr, "");
|
||||
assert_eq!(result.stdout, "32\tsubdir\n");
|
||||
assert_eq!(result.stdout, "32\tsubdir/links\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -54,21 +58,19 @@ fn test_du_hard_link() {
|
|||
let link = ts.cmd("ln").arg(SUB_FILE).arg(SUB_LINK).run();
|
||||
assert!(link.success);
|
||||
|
||||
let result = ts.ucmd().arg(SUB_DIR).run();
|
||||
let result = ts.ucmd().arg(SUB_DIR_LINKS).run();
|
||||
assert!(result.success);
|
||||
assert_eq!(result.stderr, "");
|
||||
// We do not double count hard links as the inodes are identicle
|
||||
assert_eq!(result.stdout, "24\tsubdir\n");
|
||||
assert_eq!(result.stdout, "24\tsubdir/links\n");
|
||||
}
|
||||
|
||||
// todo:
|
||||
// du on file with no permissions
|
||||
// du on multi dir with '-d'
|
||||
//
|
||||
/*
|
||||
* let mut permissions = at.make_file(TEST_HELLO_WORLD_DEST)
|
||||
* .metadata()
|
||||
* .unwrap()
|
||||
* .permissions();
|
||||
* permissions.set_readonly(true);
|
||||
*/
|
||||
#[test]
|
||||
fn test_du_d_flag() {
|
||||
let ts = TestScenario::new("du");
|
||||
|
||||
let result = ts.ucmd().arg("-d").arg("1").run();
|
||||
assert!(result.success);
|
||||
assert_eq!(result.stderr, "");
|
||||
assert_eq!(result.stdout, "32\t./subdir\n40\t./\n");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue