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 common::util::*;
|
||||||
use std::fs::set_permissions;
|
|
||||||
|
|
||||||
static SUB_DIR: &str = "subdir";
|
static SUB_DIR: &str = "subdir/deeper";
|
||||||
static SUB_FILE: &str = "subdir/subwords.txt";
|
static SUB_DIR_LINKS: &str = "subdir/links";
|
||||||
static SUB_LINK: &str = "subdir/sublink.txt";
|
static SUB_FILE: &str = "subdir/links/subwords.txt";
|
||||||
|
static SUB_LINK: &str = "subdir/links/sublink.txt";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_du_basics() {
|
fn test_du_basics() {
|
||||||
let (_at, mut ucmd) = at_and_ucmd!();
|
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();
|
let result = ucmd.run();
|
||||||
assert!(result.success);
|
assert!(result.success);
|
||||||
assert_eq!(result.stderr, "");
|
assert_eq!(result.stderr, "");
|
||||||
assert_eq!(result.stdout, "24\t./subdir\n32\t./\n");
|
assert_eq!(result.stdout, answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -22,7 +26,7 @@ fn test_du_basics_subdir() {
|
||||||
let result = ucmd.arg(SUB_DIR).run();
|
let result = ucmd.arg(SUB_DIR).run();
|
||||||
assert!(result.success);
|
assert!(result.success);
|
||||||
assert_eq!(result.stderr, "");
|
assert_eq!(result.stderr, "");
|
||||||
assert_eq!(result.stdout, "24\tsubdir\n");
|
assert_eq!(result.stdout, "8\tsubdir/deeper\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -41,10 +45,10 @@ fn test_du_soft_link() {
|
||||||
let link = ts.cmd("ln").arg("-s").arg(SUB_FILE).arg(SUB_LINK).run();
|
let link = ts.cmd("ln").arg("-s").arg(SUB_FILE).arg(SUB_LINK).run();
|
||||||
assert!(link.success);
|
assert!(link.success);
|
||||||
|
|
||||||
let result = ts.ucmd().arg(SUB_DIR).run();
|
let result = ts.ucmd().arg(SUB_DIR_LINKS).run();
|
||||||
assert!(result.success);
|
assert!(result.success);
|
||||||
assert_eq!(result.stderr, "");
|
assert_eq!(result.stderr, "");
|
||||||
assert_eq!(result.stdout, "32\tsubdir\n");
|
assert_eq!(result.stdout, "32\tsubdir/links\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -54,21 +58,19 @@ fn test_du_hard_link() {
|
||||||
let link = ts.cmd("ln").arg(SUB_FILE).arg(SUB_LINK).run();
|
let link = ts.cmd("ln").arg(SUB_FILE).arg(SUB_LINK).run();
|
||||||
assert!(link.success);
|
assert!(link.success);
|
||||||
|
|
||||||
let result = ts.ucmd().arg(SUB_DIR).run();
|
let result = ts.ucmd().arg(SUB_DIR_LINKS).run();
|
||||||
assert!(result.success);
|
assert!(result.success);
|
||||||
assert_eq!(result.stderr, "");
|
assert_eq!(result.stderr, "");
|
||||||
// We do not double count hard links as the inodes are identicle
|
// 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:
|
#[test]
|
||||||
// du on file with no permissions
|
fn test_du_d_flag() {
|
||||||
// du on multi dir with '-d'
|
let ts = TestScenario::new("du");
|
||||||
//
|
|
||||||
/*
|
let result = ts.ucmd().arg("-d").arg("1").run();
|
||||||
* let mut permissions = at.make_file(TEST_HELLO_WORLD_DEST)
|
assert!(result.success);
|
||||||
* .metadata()
|
assert_eq!(result.stderr, "");
|
||||||
* .unwrap()
|
assert_eq!(result.stdout, "32\t./subdir\n40\t./\n");
|
||||||
* .permissions();
|
}
|
||||||
* permissions.set_readonly(true);
|
|
||||||
*/
|
|
||||||
|
|
Loading…
Reference in a new issue