du: add test for -d flag

This commit is contained in:
bootandy 2018-03-20 17:55:31 -04:00
parent b6c7771087
commit ea504bf0ec
5 changed files with 26 additions and 23 deletions

View file

@ -0,0 +1 @@
hello

View file

@ -1 +1 @@
hello
hi

View file

@ -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");
}