coreutils/tests/test_rmdir.rs
Nathan Ross 569cd162d3 tests: refactor conventional TestScenario usage
Updates to individual integration tests

  - use proposed conventional approach to beginning tests

  - use new convenience functions for using fixtures

  - use new names for TestScenario

Updates to integration test modules

  - add proposed conventional module-level functions

Updates to test/common/util.rs

  - rename TestSet, and its methods, for semantic clarity

  - create convenience functions for use of fixtures

  - delete convenience functions obsoleted by new conventions
2016-08-01 13:42:00 -04:00

122 lines
3.2 KiB
Rust

extern crate libc;
use common::util::*;
static UTIL_NAME: &'static str = "rmdir";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
#[test]
fn test_rmdir_empty_directory_no_parents() {
let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rmdir_empty_no_parents";
at.mkdir(dir);
assert!(at.dir_exists(dir));
let result = ucmd.arg(dir).run();
assert_empty_stderr!(result);
assert!(result.success);
assert!(!at.dir_exists(dir));
}
#[test]
fn test_rmdir_empty_directory_with_parents() {
let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rmdir_empty/with/parents";
at.mkdir_all(dir);
assert!(at.dir_exists(dir));
let result = ucmd.arg("-p").arg(dir).run();
assert_empty_stderr!(result);
assert!(result.success);
assert!(!at.dir_exists(dir));
}
#[test]
fn test_rmdir_nonempty_directory_no_parents() {
let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rmdir_nonempty_no_parents";
let file = "test_rmdir_nonempty_no_parents/foo";
at.mkdir(dir);
assert!(at.dir_exists(dir));
at.touch(file);
assert!(at.file_exists(file));
let result = ucmd.arg(dir).run();
assert_eq!(result.stderr,
"rmdir: error: failed to remove 'test_rmdir_nonempty_no_parents': Directory not \
empty\n");
assert!(!result.success);
assert!(at.dir_exists(dir));
}
#[test]
fn test_rmdir_nonempty_directory_with_parents() {
let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rmdir_nonempty/with/parents";
let file = "test_rmdir_nonempty/with/parents/foo";
at.mkdir_all(dir);
assert!(at.dir_exists(dir));
at.touch(file);
assert!(at.file_exists(file));
let result = ucmd.arg("-p").arg(dir).run();
assert_eq!(result.stderr,
"rmdir: error: failed to remove 'test_rmdir_nonempty/with/parents': Directory not \
empty\nrmdir: error: failed to remove 'test_rmdir_nonempty/with': Directory not \
empty\nrmdir: error: failed to remove 'test_rmdir_nonempty': Directory not \
empty\n");
assert!(!result.success);
assert!(at.dir_exists(dir));
}
#[test]
fn test_rmdir_ignore_nonempty_directory_no_parents() {
let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rmdir_ignore_nonempty_no_parents";
let file = "test_rmdir_ignore_nonempty_no_parents/foo";
at.mkdir(dir);
assert!(at.dir_exists(dir));
at.touch(file);
assert!(at.file_exists(file));
let result = ucmd.arg("--ignore-fail-on-non-empty").arg(dir).run();
assert_empty_stderr!(result);
assert!(result.success);
assert!(at.dir_exists(dir));
}
#[test]
fn test_rmdir_ignore_nonempty_directory_with_parents() {
let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rmdir_ignore_nonempty/with/parents";
let file = "test_rmdir_ignore_nonempty/with/parents/foo";
at.mkdir_all(dir);
assert!(at.dir_exists(dir));
at.touch(file);
assert!(at.file_exists(file));
let result = ucmd.arg("--ignore-fail-on-non-empty").arg("-p").arg(dir).run();
assert_empty_stderr!(result);
assert!(result.success);
assert!(at.dir_exists(dir));
}