1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

du: Fix incorrect block size assumption.

du and other tools like stat assume a 512 byte block. ls is the only
tool to use 1024.

Add Simple set of tests
This commit is contained in:
bootandy 2018-03-20 12:10:05 -04:00
parent fa867e93ea
commit e253406026
7 changed files with 84 additions and 4 deletions

BIN
tests/fixtures/du/subdir/subwords.txt vendored Normal file

Binary file not shown.

View file

@ -0,0 +1 @@
hello

1
tests/fixtures/du/words.txt vendored Normal file
View file

@ -0,0 +1 @@
hello

62
tests/test_du.rs Normal file
View file

@ -0,0 +1,62 @@
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";
#[test]
fn test_du_basics() {
let (_at, mut ucmd) = at_and_ucmd!();
let result = ucmd.run();
assert!(result.success);
assert_eq!(result.stderr, "");
assert_eq!(result.stdout, "24\t./subdir\n32\t./\n");
}
#[test]
fn test_du_basics_subdir() {
let (_at, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(SUB_DIR).run();
assert!(result.success);
assert_eq!(result.stderr, "");
assert_eq!(result.stdout, "24\tsubdir\n");
}
#[test]
fn test_du_basics_bad_name() {
let (_at, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("bad_name").run();
assert_eq!(result.stdout, "");
assert_eq!(result.stderr, "du: bad_name: No such file or directory\n");
}
#[test]
fn test_du_soft_link() {
let ts = TestScenario::new("du");
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();
assert!(result.success);
assert_eq!(result.stderr, "");
assert_eq!(result.stdout, "32\tsubdir\n");
}
// todo:
// du on file with no permissions
// du on soft link
// du on hard link
// du on multi dir with '-d'
//
/*
* let mut permissions = at.make_file(TEST_HELLO_WORLD_DEST)
* .metadata()
* .unwrap()
* .permissions();
* permissions.set_readonly(true);
*/

View file

@ -52,6 +52,7 @@ generic! {
"cut", test_cut;
"dircolors", test_dircolors;
"dirname", test_dirname;
"du", test_du;
"echo", test_echo;
"env", test_env;
"expr", test_expr;