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

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
This commit is contained in:
Nathan Ross 2016-07-29 17:26:32 -04:00
parent d7a053305c
commit 569cd162d3
57 changed files with 918 additions and 800 deletions

View file

@ -25,10 +25,14 @@ static TESTS_DIR: &'static str = "tests";
static FIXTURES_DIR: &'static str = "fixtures"; static FIXTURES_DIR: &'static str = "fixtures";
static ALREADY_RUN: &'static str = " you have already run this UCommand, if you want to run \ static ALREADY_RUN: &'static str = " you have already run this UCommand, if you want to run \
another command in the same test, use TestSet::new instead of \ another command in the same test, use TestScenario::new instead of \
testing();"; testing();";
static MULTIPLE_STDIN_MEANINGLESS: &'static str = "Ucommand is designed around a typical use case of: provide args and input stream -> spawn process -> block until completion -> return output streams. For verifying that a particular section of the input stream is what causes a particular behavior, use the Command type directly."; static MULTIPLE_STDIN_MEANINGLESS: &'static str = "Ucommand is designed around a typical use case of: provide args and input stream -> spawn process -> block until completion -> return output streams. For verifying that a particular section of the input stream is what causes a particular behavior, use the Command type directly.";
fn read_scenario_fixture<S: AsRef<OsStr>>(tmpd: &Option<Rc<TempDir>>, file_rel_path: S) -> String {
let tmpdir_path = tmpd.as_ref().unwrap().as_ref().path();
AtPath::new(tmpdir_path).read(file_rel_path.as_ref().to_str().unwrap())
}
pub fn repeat_str(s: &str, n: u32) -> String { pub fn repeat_str(s: &str, n: u32) -> String {
let mut repeated = String::new(); let mut repeated = String::new();
@ -41,6 +45,8 @@ pub fn repeat_str(s: &str, n: u32) -> String {
/// A command result is the outputs of a command (streams and status code) /// A command result is the outputs of a command (streams and status code)
/// within a struct which has convenience assertion functions about those outputs /// within a struct which has convenience assertion functions about those outputs
pub struct CmdResult { pub struct CmdResult {
//tmpd is used for convenience functions for asserts against fixtures
tmpd: Option<Rc<TempDir>>,
pub success: bool, pub success: bool,
pub stdout: String, pub stdout: String,
pub stderr: String, pub stderr: String,
@ -88,6 +94,12 @@ impl CmdResult {
Box::new(self) Box::new(self)
} }
/// like stdout_is(...), but expects the contents of the file at the provided relative path
pub fn stdout_is_fixture<T: AsRef<OsStr>>(&self, file_rel_path: T) -> Box<&CmdResult> {
let contents = read_scenario_fixture(&self.tmpd, file_rel_path);
self.stdout_is(contents)
}
/// asserts that the command resulted in stderr stream output that equals the /// asserts that the command resulted in stderr stream output that equals the
/// passed in value, when both are trimmed of trailing whitespace /// passed in value, when both are trimmed of trailing whitespace
/// stderr_only is a better choice unless stdout may or will be non-empty /// stderr_only is a better choice unless stdout may or will be non-empty
@ -96,6 +108,12 @@ impl CmdResult {
Box::new(self) Box::new(self)
} }
/// like stderr_is(...), but expects the contents of the file at the provided relative path
pub fn stderr_is_fixture<T: AsRef<OsStr>>(&self, file_rel_path: T) -> Box<&CmdResult> {
let contents = read_scenario_fixture(&self.tmpd, file_rel_path);
self.stderr_is(contents)
}
/// asserts that /// asserts that
/// 1. the command resulted in stdout stream output that equals the /// 1. the command resulted in stdout stream output that equals the
/// passed in value, when both are trimmed of trailing whitespace /// passed in value, when both are trimmed of trailing whitespace
@ -104,6 +122,12 @@ impl CmdResult {
self.stdout_is(msg).no_stderr() self.stdout_is(msg).no_stderr()
} }
/// like stdout_only(...), but expects the contents of the file at the provided relative path
pub fn stdout_only_fixture<T: AsRef<OsStr>>(&self, file_rel_path: T) -> Box<&CmdResult> {
let contents = read_scenario_fixture(&self.tmpd, file_rel_path);
self.stdout_only(contents)
}
/// asserts that /// asserts that
/// 1. the command resulted in stderr stream output that equals the /// 1. the command resulted in stderr stream output that equals the
/// passed in value, when both are trimmed of trailing whitespace /// passed in value, when both are trimmed of trailing whitespace
@ -112,6 +136,12 @@ impl CmdResult {
self.stderr_is(msg).no_stdout() self.stderr_is(msg).no_stdout()
} }
/// like stderr_only(...), but expects the contents of the file at the provided relative path
pub fn stderr_only_fixture<T: AsRef<OsStr>>(&self, file_rel_path: T) -> Box<&CmdResult> {
let contents = read_scenario_fixture(&self.tmpd, file_rel_path);
self.stderr_only(contents)
}
pub fn fails_silently(&self) -> Box<&CmdResult> { pub fn fails_silently(&self) -> Box<&CmdResult> {
assert!(!self.success); assert!(!self.success);
assert_eq!(0, self.stderr.len()); assert_eq!(0, self.stderr.len());
@ -321,17 +351,17 @@ impl AtPath {
/// 1. centralizes logic for locating the uutils binary and calling the utility /// 1. centralizes logic for locating the uutils binary and calling the utility
/// 2. provides a temporary directory for the test case /// 2. provides a temporary directory for the test case
/// 3. copies over fixtures for the utility to the temporary directory /// 3. copies over fixtures for the utility to the temporary directory
pub struct TestSet { pub struct TestScenario {
bin_path: PathBuf, bin_path: PathBuf,
util_name: String, util_name: String,
pub fixtures: AtPath, pub fixtures: AtPath,
tmpd: Rc<TempDir>, tmpd: Rc<TempDir>,
} }
impl TestSet { impl TestScenario {
pub fn new(util_name: &str) -> TestSet { pub fn new(util_name: &str) -> TestScenario {
let tmpd = Rc::new(TempDir::new("uutils").unwrap()); let tmpd = Rc::new(TempDir::new("uutils").unwrap());
let ts = TestSet { let ts = TestScenario {
bin_path: { bin_path: {
// Instead of hardcoding the path relative to the current // Instead of hardcoding the path relative to the current
// directory, use Cargo's OUT_DIR to find path to executable. // directory, use Cargo's OUT_DIR to find path to executable.
@ -356,7 +386,7 @@ impl TestSet {
ts ts
} }
pub fn util_cmd(&self) -> UCommand { pub fn ucmd(&self) -> UCommand {
let mut cmd = self.cmd(&self.bin_path); let mut cmd = self.cmd(&self.bin_path);
cmd.arg(&self.util_name); cmd.arg(&self.util_name);
cmd cmd
@ -368,7 +398,7 @@ impl TestSet {
// different names are used rather than an argument // different names are used rather than an argument
// because the need to keep the environment is exceedingly rare. // because the need to keep the environment is exceedingly rare.
pub fn util_cmd_keepenv(&self) -> UCommand { pub fn ucmd_keepenv(&self) -> UCommand {
let mut cmd = self.cmd_keepenv(&self.bin_path); let mut cmd = self.cmd_keepenv(&self.bin_path);
cmd.arg(&self.util_name); cmd.arg(&self.util_name);
cmd cmd
@ -440,6 +470,12 @@ impl UCommand {
Box::new(self) Box::new(self)
} }
/// like arg(...), but uses the contents of the file at the provided relative path as the argument
pub fn arg_fixture<S: AsRef<OsStr>>(&mut self, file_rel_path: S) -> Box<&mut UCommand> {
let contents = read_scenario_fixture(&self.tmpd, file_rel_path);
self.arg(contents)
}
pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> Box<&mut UCommand> { pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> Box<&mut UCommand> {
if self.has_run { if self.has_run {
panic!(MULTIPLE_STDIN_MEANINGLESS); panic!(MULTIPLE_STDIN_MEANINGLESS);
@ -462,6 +498,12 @@ impl UCommand {
Box::new(self) Box::new(self)
} }
/// like pipe_in(...), but uses the contents of the file at the provided relative path as the piped in data
pub fn pipe_in_fixture<S: AsRef<OsStr>>(&mut self, file_rel_path: S) -> Box<&mut UCommand> {
let contents = read_scenario_fixture(&self.tmpd, file_rel_path);
self.pipe_in(contents)
}
pub fn env<K, V>(&mut self, key: K, val: V) -> Box<&mut UCommand> where K: AsRef<OsStr>, V: AsRef<OsStr> { pub fn env<K, V>(&mut self, key: K, val: V) -> Box<&mut UCommand> where K: AsRef<OsStr>, V: AsRef<OsStr> {
if self.has_run { if self.has_run {
panic!(ALREADY_RUN); panic!(ALREADY_RUN);
@ -505,6 +547,7 @@ impl UCommand {
let prog = self.run_no_wait().wait_with_output().unwrap(); let prog = self.run_no_wait().wait_with_output().unwrap();
CmdResult { CmdResult {
tmpd: self.tmpd.clone(),
success: prog.status.success(), success: prog.status.success(),
stdout: from_utf8(&prog.stdout).unwrap().to_string(), stdout: from_utf8(&prog.stdout).unwrap().to_string(),
stderr: from_utf8(&prog.stderr).unwrap().to_string(), stderr: from_utf8(&prog.stderr).unwrap().to_string(),
@ -543,17 +586,3 @@ pub fn read_size(child: &mut Child, size: usize) -> String {
child.stdout.as_mut().unwrap().read(output.as_mut_slice()).unwrap(); child.stdout.as_mut().unwrap().read(output.as_mut_slice()).unwrap();
String::from_utf8(output).unwrap() String::from_utf8(output).unwrap()
} }
/// returns a testSet and a ucommand initialized to the utility binary
/// operating in the fixtures directory with a cleared environment
pub fn testset_and_ucommand(utilname: &str) -> (TestSet, UCommand) {
let ts = TestSet::new(utilname);
let ucmd = ts.util_cmd();
(ts, ucmd)
}
pub fn testing(utilname: &str) -> (AtPath, UCommand) {
let ts = TestSet::new(utilname);
let ucmd = ts.util_cmd();
(ts.fixtures, ucmd)
}

View file

@ -1,12 +1,15 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "base64"; static UTIL_NAME: &'static str = "base64";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_encode() { fn test_encode() {
let (_, mut ucmd) = testing(UTIL_NAME);
let input = "hello, world!"; let input = "hello, world!";
ucmd.pipe_in(input) new_ucmd()
.pipe_in(input)
.succeeds() .succeeds()
.stdout_only("aGVsbG8sIHdvcmxkIQ==\n"); .stdout_only("aGVsbG8sIHdvcmxkIQ==\n");
} }
@ -14,9 +17,9 @@ fn test_encode() {
#[test] #[test]
fn test_decode() { fn test_decode() {
for decode_param in vec!["-d", "--decode"] { for decode_param in vec!["-d", "--decode"] {
let (_, mut ucmd) = testing(UTIL_NAME);
let input = "aGVsbG8sIHdvcmxkIQ=="; let input = "aGVsbG8sIHdvcmxkIQ==";
ucmd.arg(decode_param) new_ucmd()
.arg(decode_param)
.pipe_in(input) .pipe_in(input)
.succeeds() .succeeds()
.stdout_only("hello, world!"); .stdout_only("hello, world!");
@ -25,9 +28,9 @@ fn test_decode() {
#[test] #[test]
fn test_garbage() { fn test_garbage() {
let (_, mut ucmd) = testing(UTIL_NAME);
let input = "aGVsbG8sIHdvcmxkIQ==\0"; let input = "aGVsbG8sIHdvcmxkIQ==\0";
ucmd.arg("-d") new_ucmd()
.arg("-d")
.pipe_in(input) .pipe_in(input)
.fails() .fails()
.stderr_only("base64: error: invalid character (Invalid character '0' at position 20)\n"); .stderr_only("base64: error: invalid character (Invalid character '0' at position 20)\n");
@ -36,9 +39,10 @@ fn test_garbage() {
#[test] #[test]
fn test_ignore_garbage() { fn test_ignore_garbage() {
for ignore_garbage_param in vec!["-i", "--ignore-garbage"] { for ignore_garbage_param in vec!["-i", "--ignore-garbage"] {
let (_, mut ucmd) = testing(UTIL_NAME);
let input = "aGVsbG8sIHdvcmxkIQ==\0"; let input = "aGVsbG8sIHdvcmxkIQ==\0";
ucmd.arg("-d").arg(ignore_garbage_param) new_ucmd()
.arg("-d")
.arg(ignore_garbage_param)
.pipe_in(input) .pipe_in(input)
.succeeds() .succeeds()
.stdout_only("hello, world!"); .stdout_only("hello, world!");
@ -48,9 +52,10 @@ fn test_ignore_garbage() {
#[test] #[test]
fn test_wrap() { fn test_wrap() {
for wrap_param in vec!["-w", "--wrap"] { for wrap_param in vec!["-w", "--wrap"] {
let (_, mut ucmd) = testing(UTIL_NAME);
let input = "The quick brown fox jumps over the lazy dog."; let input = "The quick brown fox jumps over the lazy dog.";
ucmd.arg(wrap_param).arg("20") new_ucmd()
.arg(wrap_param)
.arg("20")
.pipe_in(input) .pipe_in(input)
.succeeds() .succeeds()
.stdout_only("VGhlIHF1aWNrIGJyb3du\nIGZveCBqdW1wcyBvdmVy\nIHRoZSBsYXp5IGRvZy4=\n"); .stdout_only("VGhlIHF1aWNrIGJyb3du\nIGZveCBqdW1wcyBvdmVy\nIHRoZSBsYXp5IGRvZy4=\n");
@ -60,8 +65,8 @@ fn test_wrap() {
#[test] #[test]
fn test_wrap_no_arg() { fn test_wrap_no_arg() {
for wrap_param in vec!["-w", "--wrap"] { for wrap_param in vec!["-w", "--wrap"] {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg(wrap_param) .arg(wrap_param)
.fails() .fails()
.stderr_only( .stderr_only(
format!("base64: error: Argument to option '{}' missing.", format!("base64: error: Argument to option '{}' missing.",
@ -72,8 +77,8 @@ fn test_wrap_no_arg() {
#[test] #[test]
fn test_wrap_bad_arg() { fn test_wrap_bad_arg() {
for wrap_param in vec!["-w", "--wrap"] { for wrap_param in vec!["-w", "--wrap"] {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg(wrap_param).arg("b") .arg(wrap_param).arg("b")
.fails() .fails()
.stderr_only("base64: error: Argument to option 'wrap' improperly formatted: invalid digit found in string"); .stderr_only("base64: error: Argument to option 'wrap' improperly formatted: invalid digit found in string");
} }

View file

@ -1,10 +1,13 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "basename"; static UTIL_NAME: &'static str = "basename";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
fn expect_successful_stdout(input: Vec<&str>, expected: &str) { fn expect_successful_stdout(input: Vec<&str>, expected: &str) {
let (_, mut ucmd) = testing(UTIL_NAME); let results = new_ucmd()
let results = ucmd.args(&input).run(); .args(&input).run();
assert_empty_stderr!(results); assert_empty_stderr!(results);
assert!(results.success); assert!(results.success);
assert_eq!(expected, results.stdout.trim_right()); assert_eq!(expected, results.stdout.trim_right());
@ -35,8 +38,8 @@ fn test_dont_remove_suffix() {
} }
fn expect_error(input: Vec<&str>, expected_stdout: &str) { fn expect_error(input: Vec<&str>, expected_stdout: &str) {
let (_, mut ucmd) = testing(UTIL_NAME); let results = new_ucmd()
let results = ucmd.args(&input).run(); .args(&input).run();
assert!(!results.success); assert!(!results.success);
assert!(results.stderr.len() > 0); assert!(results.stderr.len() > 0);
assert_eq!(expected_stdout, results.stdout.trim_right()); assert_eq!(expected_stdout, results.stdout.trim_right());

View file

@ -1,11 +1,14 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "cat"; static UTIL_NAME: &'static str = "cat";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_output_multi_files_print_all_chars() { fn test_output_multi_files_print_all_chars() {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.args(&["alpha.txt", "256.txt", "-A", "-n"]) .args(&["alpha.txt", "256.txt", "-A", "-n"])
.succeeds() .succeeds()
.stdout_only(" 1\tabcde$\n 2\tfghij$\n 3\tklmno$\n 4\tpqrst$\n \ .stdout_only(" 1\tabcde$\n 2\tfghij$\n 3\tklmno$\n 4\tpqrst$\n \
5\tuvwxyz$\n 6\t^@^A^B^C^D^E^F^G^H^I$\n \ 5\tuvwxyz$\n 6\t^@^A^B^C^D^E^F^G^H^I$\n \
@ -23,8 +26,8 @@ fn test_output_multi_files_print_all_chars() {
#[test] #[test]
fn test_stdin_show_nonprinting() { fn test_stdin_show_nonprinting() {
for same_param in vec!["-v", "--show-nonprinting"] { for same_param in vec!["-v", "--show-nonprinting"] {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.args(&vec![same_param]) .args(&vec![same_param])
.pipe_in("\t\0\n") .pipe_in("\t\0\n")
.succeeds() .succeeds()
.stdout_only("\t^@"); .stdout_only("\t^@");
@ -34,8 +37,8 @@ fn test_stdin_show_nonprinting() {
#[test] #[test]
fn test_stdin_show_tabs() { fn test_stdin_show_tabs() {
for same_param in vec!["-T", "--show-tabs"] { for same_param in vec!["-T", "--show-tabs"] {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.args(&[same_param]) .args(&[same_param])
.pipe_in("\t\0\n") .pipe_in("\t\0\n")
.succeeds() .succeeds()
.stdout_only("^I\0"); .stdout_only("^I\0");
@ -46,8 +49,8 @@ fn test_stdin_show_tabs() {
#[test] #[test]
fn test_stdin_show_ends() { fn test_stdin_show_ends() {
for same_param in vec!["-E", "--show-ends"] { for same_param in vec!["-E", "--show-ends"] {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.args(&[same_param,"-"]) .args(&[same_param,"-"])
.pipe_in("\t\0\n") .pipe_in("\t\0\n")
.succeeds() .succeeds()
.stdout_only("\t\0$"); .stdout_only("\t\0$");
@ -57,8 +60,8 @@ fn test_stdin_show_ends() {
#[test] #[test]
fn test_stdin_show_all() { fn test_stdin_show_all() {
for same_param in vec!["-A", "--show-all"] { for same_param in vec!["-A", "--show-all"] {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.args(&[same_param]) .args(&[same_param])
.pipe_in("\t\0\n") .pipe_in("\t\0\n")
.succeeds() .succeeds()
.stdout_only("^I^@$"); .stdout_only("^I^@$");
@ -67,8 +70,8 @@ fn test_stdin_show_all() {
#[test] #[test]
fn test_stdin_nonprinting_and_endofline() { fn test_stdin_nonprinting_and_endofline() {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.args(&["-e"]) .args(&["-e"])
.pipe_in("\t\0\n") .pipe_in("\t\0\n")
.succeeds() .succeeds()
.stdout_only("\t^@$\n"); .stdout_only("\t^@$\n");
@ -76,8 +79,8 @@ fn test_stdin_nonprinting_and_endofline() {
#[test] #[test]
fn test_stdin_nonprinting_and_tabs() { fn test_stdin_nonprinting_and_tabs() {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.args(&["-t"]) .args(&["-t"])
.pipe_in("\t\0\n") .pipe_in("\t\0\n")
.succeeds() .succeeds()
.stdout_only("^I^@\n"); .stdout_only("^I^@\n");
@ -86,8 +89,8 @@ fn test_stdin_nonprinting_and_tabs() {
#[test] #[test]
fn test_stdin_squeeze_blank() { fn test_stdin_squeeze_blank() {
for same_param in vec!["-s", "--squeeze-blank"] { for same_param in vec!["-s", "--squeeze-blank"] {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg(same_param) .arg(same_param)
.pipe_in("\n\na\n\n\n\n\nb\n\n\n") .pipe_in("\n\na\n\n\n\n\nb\n\n\n")
.succeeds() .succeeds()
.stdout_only("\na\n\nb\n\n"); .stdout_only("\na\n\nb\n\n");
@ -97,8 +100,8 @@ fn test_stdin_squeeze_blank() {
#[test] #[test]
fn test_stdin_number_non_blank() { fn test_stdin_number_non_blank() {
for same_param in vec!["-b", "--number-nonblank"] { for same_param in vec!["-b", "--number-nonblank"] {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg(same_param) .arg(same_param)
.arg("-") .arg("-")
.pipe_in("\na\nb\n\n\nc") .pipe_in("\na\nb\n\n\nc")
.succeeds() .succeeds()
@ -109,8 +112,8 @@ fn test_stdin_number_non_blank() {
#[test] #[test]
fn test_non_blank_overrides_number() { fn test_non_blank_overrides_number() {
for same_param in vec!["-b", "--number-nonblank"] { for same_param in vec!["-b", "--number-nonblank"] {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.args(&[same_param, "-"]) .args(&[same_param, "-"])
.pipe_in("\na\nb\n\n\nc") .pipe_in("\na\nb\n\n\nc")
.succeeds() .succeeds()
.stdout_only("\n 1\ta\n 2\tb\n\n\n 3\tc"); .stdout_only("\n 1\ta\n 2\tb\n\n\n 3\tc");
@ -120,8 +123,8 @@ fn test_non_blank_overrides_number() {
#[test] #[test]
fn test_squeeze_blank_before_numbering() { fn test_squeeze_blank_before_numbering() {
for same_param in vec!["-s", "--squeeze-blank"] { for same_param in vec!["-s", "--squeeze-blank"] {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.args(&[same_param, "-n", "-"]) .args(&[same_param, "-n", "-"])
.pipe_in("a\n\n\nb") .pipe_in("a\n\n\nb")
.succeeds() .succeeds()
.stdout_only(" 1\ta\n 2\t\n 3\tb"); .stdout_only(" 1\ta\n 2\t\n 3\tb");

View file

@ -6,6 +6,12 @@ extern crate libc;
use self::libc::umask; use self::libc::umask;
static UTIL_NAME: &'static str = "chmod"; static UTIL_NAME: &'static str = "chmod";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
static TEST_FILE: &'static str = "file"; static TEST_FILE: &'static str = "file";
static REFERENCE_FILE: &'static str = "reference"; static REFERENCE_FILE: &'static str = "reference";
static REFERENCE_PERMS: u32 = 0o247; static REFERENCE_PERMS: u32 = 0o247;
@ -47,7 +53,7 @@ fn run_single_test(test: &TestCase, at: AtPath, mut ucmd: UCommand) {
fn run_tests(tests: Vec<TestCase>) { fn run_tests(tests: Vec<TestCase>) {
for test in tests { for test in tests {
let (at, ucmd) = testing(UTIL_NAME); let (at, ucmd) = at_and_ucmd();
run_single_test(&test, at, ucmd); run_single_test(&test, at, ucmd);
} }
} }
@ -129,7 +135,7 @@ fn test_chmod_reference_file() {
TestCase{args: vec!{"--reference", REFERENCE_FILE, TEST_FILE}, before: 0o070, after: 0o247}, TestCase{args: vec!{"--reference", REFERENCE_FILE, TEST_FILE}, before: 0o070, after: 0o247},
TestCase{args: vec!{"a-w", "--reference", REFERENCE_FILE, TEST_FILE}, before: 0o070, after: 0o247}, TestCase{args: vec!{"a-w", "--reference", REFERENCE_FILE, TEST_FILE}, before: 0o070, after: 0o247},
}; };
let (at, ucmd) = testing(UTIL_NAME); let (at, ucmd) = at_and_ucmd();
mkfile(&at.plus_as_string(REFERENCE_FILE), REFERENCE_PERMS); mkfile(&at.plus_as_string(REFERENCE_FILE), REFERENCE_PERMS);
run_single_test(&tests[0], at, ucmd); run_single_test(&tests[0], at, ucmd);
} }

View file

@ -4,6 +4,9 @@ extern crate uu_chown;
pub use self::uu_chown::*; pub use self::uu_chown::*;
static UTIL_NAME: &'static str = "chown"; static UTIL_NAME: &'static str = "chown";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[cfg(test)] #[cfg(test)]
mod test_passwd { mod test_passwd {
@ -46,7 +49,7 @@ mod test_passwd {
#[test] #[test]
fn test_invalid_option() { fn test_invalid_option() {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-w").arg("-q").arg("/"); .arg("-w").arg("-q").arg("/")
ucmd.fails(); .fails();
} }

View file

@ -1,36 +1,27 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "cksum"; static UTIL_NAME: &'static str = "cksum";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_single_file() { fn test_single_file() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().arg("lorem_ipsum.txt")
let result = ucmd.arg("lorem_ipsum.txt").run(); .succeeds().stdout_is_fixture("single_file.expected");
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, at.read("single_file.expected"));
} }
#[test] #[test]
fn test_multiple_files() { fn test_multiple_files() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.arg("lorem_ipsum.txt") .arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt") .arg("alice_in_wonderland.txt")
.run(); .succeeds().stdout_is_fixture("multiple_files.expected");
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, at.read("multiple_files.expected"));
} }
#[test] #[test]
fn test_stdin() { fn test_stdin() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let input = at.read("lorem_ipsum.txt"); .pipe_in_fixture("lorem_ipsum.txt")
let result = ucmd.run_piped_stdin(input); .succeeds().stdout_is_fixture("stdin.expected");
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, at.read("stdin.expected"));
} }

View file

@ -1,12 +1,20 @@
use common::util::testing; use common::util::*;
use std::ffi::OsStr; use std::ffi::OsStr;
static UTIL_NAME: &'static str = "comm"; static UTIL_NAME: &'static str = "comm";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
fn comm<A: AsRef<OsStr>, B: AsRef<str>>(args: &[A], fn comm<A: AsRef<OsStr>, B: AsRef<str>>(args: &[A],
file_stdout_relpath_opt: Option<B>, file_stdout_relpath_opt: Option<B>,
error_message_opt: Option<B>) { error_message_opt: Option<B>) {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let result = ucmd.args(args) let result = ucmd.args(args)
.run(); .run();
assert!(result.success == error_message_opt.is_none()); assert!(result.success == error_message_opt.is_none());
@ -146,8 +154,8 @@ fn unintuitive_default_behavior_1() {
#[ignore] //bug? should help be stdout if not called via -h|--help? #[ignore] //bug? should help be stdout if not called via -h|--help?
#[test] #[test]
fn no_arguments() { fn no_arguments() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.run(); .run();
assert!(!result.success); assert!(!result.success);
assert!(result.stdout.len() == 0); assert!(result.stdout.len() == 0);
assert!(result.stderr.len() > 0); assert!(result.stderr.len() > 0);
@ -156,8 +164,8 @@ fn no_arguments() {
#[ignore] //bug? should help be stdout if not called via -h|--help? #[ignore] //bug? should help be stdout if not called via -h|--help?
#[test] #[test]
fn one_argument() { fn one_argument() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.arg("a").run(); .arg("a").run();
assert!(!result.success); assert!(!result.success);
assert!(result.stdout.len() == 0); assert!(result.stdout.len() == 0);
assert!(result.stderr.len() > 0); assert!(result.stderr.len() > 0);

View file

@ -1,5 +1,10 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "cp"; static UTIL_NAME: &'static str = "cp";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
static TEST_HELLO_WORLD_SOURCE: &'static str = "hello_world.txt"; static TEST_HELLO_WORLD_SOURCE: &'static str = "hello_world.txt";
static TEST_HELLO_WORLD_DEST: &'static str = "copy_of_hello_world.txt"; static TEST_HELLO_WORLD_DEST: &'static str = "copy_of_hello_world.txt";
@ -9,7 +14,7 @@ static TEST_COPY_FROM_FOLDER_FILE: &'static str = "hello_dir_with_file/hello_wor
#[test] #[test]
fn test_cp_cp() { fn test_cp_cp() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
// Invoke our binary to make the copy. // Invoke our binary to make the copy.
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_HELLO_WORLD_DEST) .arg(TEST_HELLO_WORLD_DEST)
@ -25,11 +30,10 @@ fn test_cp_cp() {
#[test] #[test]
fn test_cp_with_dirs_t() { fn test_cp_with_dirs_t() {
let ts = TestSet::new(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let at = &ts.fixtures;
//using -t option //using -t option
let result_to_dir_t = ts.util_cmd() let result_to_dir_t = ucmd
.arg("-t") .arg("-t")
.arg(TEST_COPY_TO_FOLDER) .arg(TEST_COPY_TO_FOLDER)
.arg(TEST_HELLO_WORLD_SOURCE) .arg(TEST_HELLO_WORLD_SOURCE)
@ -40,18 +44,18 @@ fn test_cp_with_dirs_t() {
#[test] #[test]
fn test_cp_with_dirs() { fn test_cp_with_dirs() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let at = &ts.fixtures; let at = &scene.fixtures;
//using -t option //using -t option
let result_to_dir = ts.util_cmd() let result_to_dir = scene.ucmd()
.arg(TEST_HELLO_WORLD_SOURCE) .arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_COPY_TO_FOLDER) .arg(TEST_COPY_TO_FOLDER)
.run(); .run();
assert!(result_to_dir.success); assert!(result_to_dir.success);
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n"); assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
let result_from_dir = ts.util_cmd() let result_from_dir = scene.ucmd()
.arg(TEST_COPY_FROM_FOLDER_FILE) .arg(TEST_COPY_FROM_FOLDER_FILE)
.arg(TEST_HELLO_WORLD_DEST) .arg(TEST_HELLO_WORLD_DEST)
.run(); .run();

View file

@ -1,57 +1,46 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "cut"; static UTIL_NAME: &'static str = "cut";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
static INPUT: &'static str = "lists.txt"; static INPUT: &'static str = "lists.txt";
#[test] #[test]
fn test_prefix() { fn test_prefix() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().args(&["-c", "-10", INPUT]).run().stdout_is_fixture("lists_prefix.expected");
let result = ucmd.args(&["-c", "-10", INPUT]).run();
assert_eq!(result.stdout, at.read("lists_prefix.expected"));
} }
#[test] #[test]
fn test_char_range() { fn test_char_range() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().args(&["-c", "4-10", INPUT]).run().stdout_is_fixture("lists_char_range.expected");
let result = ucmd.args(&["-c", "4-10", INPUT]).run();
assert_eq!(result.stdout, at.read("lists_char_range.expected"));
} }
#[test] #[test]
fn test_column_to_end_of_line() { fn test_column_to_end_of_line() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().args(&["-d", ":", "-f", "5-", INPUT]).run().stdout_is_fixture("lists_column_to_end_of_line.expected");
let result = ucmd.args(&["-d", ":", "-f", "5-", INPUT]).run();
assert_eq!(result.stdout,
at.read("lists_column_to_end_of_line.expected"));
} }
#[test] #[test]
fn test_specific_field() { fn test_specific_field() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().args(&["-d", " ", "-f", "3", INPUT]).run().stdout_is_fixture("lists_specific_field.expected");
let result = ucmd.args(&["-d", " ", "-f", "3", INPUT]).run();
assert_eq!(result.stdout, at.read("lists_specific_field.expected"));
} }
#[test] #[test]
fn test_multiple_fields() { fn test_multiple_fields() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().args(&["-d", ":", "-f", "1,3", INPUT]).run().stdout_is_fixture("lists_multiple_fields.expected");
let result = ucmd.args(&["-d", ":", "-f", "1,3", INPUT]).run();
assert_eq!(result.stdout, at.read("lists_multiple_fields.expected"));
} }
#[test] #[test]
fn test_tail() { fn test_tail() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().args(&["-d", ":", "--complement", "-f", "1", INPUT]).run().stdout_is_fixture("lists_tail.expected");
let result = ucmd.args(&["-d", ":", "--complement", "-f", "1", INPUT]).run();
assert_eq!(result.stdout, at.read("lists_tail.expected"));
} }
#[test] #[test]
fn test_change_delimiter() { fn test_change_delimiter() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-d", ":", "--complement", "--output-delimiter=#", "-f", "1", INPUT]) .args(&["-d", ":", "--complement", "--output-delimiter=#", "-f", "1", INPUT])
.run(); .run().stdout_is_fixture("lists_change_delimiter.expected");
assert_eq!(result.stdout, at.read("lists_change_delimiter.expected"));
} }

View file

@ -4,6 +4,9 @@ use self::uu_dircolors::{StrUtils, guess_syntax, OutputFmt};
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "dircolors"; static UTIL_NAME: &'static str = "dircolors";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_shell_syntax() { fn test_shell_syntax() {
@ -57,55 +60,46 @@ fn test_keywords() {
#[test] #[test]
fn test_internal_db() { fn test_internal_db() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-p"); .arg("-p")
let out = ucmd.run().stdout; .run()
let filename = "internal.expected"; .stdout_is_fixture("internal.expected");
assert_eq!(out, at.read(filename));
} }
#[test] #[test]
fn test_bash_default() { fn test_bash_default() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().env("TERM", "screen").arg("-b").run().stdout_is_fixture("bash_def.expected");
ucmd.arg("-b");
let out = ucmd.env("TERM", "screen").run().stdout;
let filename = "bash_def.expected";
assert_eq!(out, at.read(filename));
} }
#[test] #[test]
fn test_csh_default() { fn test_csh_default() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().env("TERM", "screen").arg("-c").run().stdout_is_fixture("csh_def.expected");
ucmd.arg("-c");
let out = ucmd.env("TERM", "screen").run().stdout;
let filename = "csh_def.expected";
assert_eq!(out, at.read(filename));
} }
#[test] #[test]
fn test_no_env() { fn test_no_env() {
// no SHELL and TERM // no SHELL and TERM
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.fails(); .fails();
} }
#[test] #[test]
fn test_exclusive_option() { fn test_exclusive_option() {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-cp"); .arg("-cp")
ucmd.fails(); .fails();
} }
fn test_helper(file_name: &str, term: &str) { fn test_helper(file_name: &str, term: &str) {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-c").env("TERM", term); .env("TERM", term)
let out = ucmd.arg(format!("{}.txt", file_name)).run().stdout; .arg("-c")
let filename = format!("{}.csh.expected", file_name); .arg(format!("{}.txt", file_name))
assert_eq!(out, at.read(&filename)); .run().stdout_is_fixture(format!("{}.csh.expected", file_name));
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-b").env("TERM", term); .env("TERM", term)
let out = ucmd.arg(format!("{}.txt", file_name)).run().stdout; .arg("-b")
let filename = format!("{}.sh.expected", file_name); .arg(format!("{}.txt", file_name))
assert_eq!(out, at.read(&filename)); .run().stdout_is_fixture(format!("{}.sh.expected", file_name));
} }

View file

@ -1,48 +1,46 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "dirname"; static UTIL_NAME: &'static str = "dirname";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_path_with_trailing_slashes() { fn test_path_with_trailing_slashes() {
let (_, mut ucmd) = testing(UTIL_NAME);
let dir = "/root/alpha/beta/gamma/delta/epsilon/omega//"; let dir = "/root/alpha/beta/gamma/delta/epsilon/omega//";
let out = ucmd.arg(dir).run().stdout; let out = new_ucmd().arg(dir).run().stdout;
assert_eq!(out.trim_right(), "/root/alpha/beta/gamma/delta/epsilon"); assert_eq!(out.trim_right(), "/root/alpha/beta/gamma/delta/epsilon");
} }
#[test] #[test]
fn test_path_without_trailing_slashes() { fn test_path_without_trailing_slashes() {
let (_, mut ucmd) = testing(UTIL_NAME);
let dir = "/root/alpha/beta/gamma/delta/epsilon/omega"; let dir = "/root/alpha/beta/gamma/delta/epsilon/omega";
let out = ucmd.arg(dir).run().stdout; let out = new_ucmd().arg(dir).run().stdout;
assert_eq!(out.trim_right(), "/root/alpha/beta/gamma/delta/epsilon"); assert_eq!(out.trim_right(), "/root/alpha/beta/gamma/delta/epsilon");
} }
#[test] #[test]
fn test_root() { fn test_root() {
let (_, mut ucmd) = testing(UTIL_NAME);
let dir = "/"; let dir = "/";
let out = ucmd.arg(dir).run().stdout; let out = new_ucmd().arg(dir).run().stdout;
assert_eq!(out.trim_right(), "/"); assert_eq!(out.trim_right(), "/");
} }
#[test] #[test]
fn test_pwd() { fn test_pwd() {
let (_, mut ucmd) = testing(UTIL_NAME);
let dir = "."; let dir = ".";
let out = ucmd.arg(dir).run().stdout; let out = new_ucmd().arg(dir).run().stdout;
assert_eq!(out.trim_right(), "."); assert_eq!(out.trim_right(), ".");
} }
#[test] #[test]
fn test_empty() { fn test_empty() {
let (_, mut ucmd) = testing(UTIL_NAME);
let dir = ""; let dir = "";
let out = ucmd.arg(dir).run().stdout; let out = new_ucmd().arg(dir).run().stdout;
assert_eq!(out.trim_right(), "."); assert_eq!(out.trim_right(), ".");
} }

View file

@ -1,36 +1,39 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "echo"; static UTIL_NAME: &'static str = "echo";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_default() { fn test_default() {
let (_, mut ucmd) = testing(UTIL_NAME); assert_eq!(new_ucmd()
assert_eq!(ucmd.run().stdout, "\n"); .run().stdout, "\n");
} }
#[test] #[test]
fn test_no_trailing_newline() { fn test_no_trailing_newline() {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-n") .arg("-n")
.arg("hello_world"); .arg("hello_world")
.run()
assert_eq!(ucmd.run().stdout, "hello_world"); .stdout_is("hello_world");
} }
#[test] #[test]
fn test_enable_escapes() { fn test_enable_escapes() {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-e") .arg("-e")
.arg("\\\\\\t\\r"); .arg("\\\\\\t\\r")
.run()
assert_eq!(ucmd.run().stdout, "\\\t\r\n"); .stdout_is("\\\t\r\n");
} }
#[test] #[test]
fn test_disable_escapes() { fn test_disable_escapes() {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-E") .arg("-E")
.arg("\\b\\c\\e"); .arg("\\b\\c\\e")
.run()
assert_eq!(ucmd.run().stdout, "\\b\\c\\e\n"); .stdout_is("\\b\\c\\e\n");
} }

View file

@ -1,19 +1,22 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "env"; static UTIL_NAME: &'static str = "env";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_single_name_value_pair() { fn test_single_name_value_pair() {
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.arg("FOO=bar").run().stdout; .arg("FOO=bar").run().stdout;
assert!(out.lines().any(|line| line == "FOO=bar")); assert!(out.lines().any(|line| line == "FOO=bar"));
} }
#[test] #[test]
fn test_multiple_name_value_pairs() { fn test_multiple_name_value_pairs() {
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.arg("FOO=bar") .arg("FOO=bar")
.arg("ABC=xyz") .arg("ABC=xyz")
.run() .run()
.stdout; .stdout;
@ -24,16 +27,16 @@ fn test_multiple_name_value_pairs() {
#[test] #[test]
fn test_ignore_environment() { fn test_ignore_environment() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let out = ts.util_cmd() let out = scene.ucmd()
.arg("-i") .arg("-i")
.run() .run()
.stdout; .stdout;
assert_eq!(out, ""); assert_eq!(out, "");
let out = ts.util_cmd() let out = scene.ucmd()
.arg("-") .arg("-")
.run() .run()
.stdout; .stdout;
@ -43,8 +46,8 @@ fn test_ignore_environment() {
#[test] #[test]
fn test_null_delimiter() { fn test_null_delimiter() {
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.arg("-i") .arg("-i")
.arg("--null") .arg("--null")
.arg("FOO=bar") .arg("FOO=bar")
.arg("ABC=xyz") .arg("ABC=xyz")
@ -63,8 +66,8 @@ fn test_null_delimiter() {
fn test_unset_variable() { fn test_unset_variable() {
// This test depends on the HOME variable being pre-defined by the // This test depends on the HOME variable being pre-defined by the
// default shell // default shell
let out = TestSet::new(UTIL_NAME) let out = TestScenario::new(UTIL_NAME)
.util_cmd_keepenv() .ucmd_keepenv()
.arg("-u") .arg("-u")
.arg("HOME") .arg("HOME")
.run() .run()

View file

@ -1,51 +1,54 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "expr"; static UTIL_NAME: &'static str = "expr";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_simple_arithmetic() { fn test_simple_arithmetic() {
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.args(&["1", "+", "1"]).run().stdout; .args(&["1", "+", "1"]).run().stdout;
assert_eq!(out, "2\n"); assert_eq!(out, "2\n");
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.args(&["1", "-", "1"]).run().stdout; .args(&["1", "-", "1"]).run().stdout;
assert_eq!(out, "0\n"); assert_eq!(out, "0\n");
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.args(&["3", "*", "2"]).run().stdout; .args(&["3", "*", "2"]).run().stdout;
assert_eq!(out, "6\n"); assert_eq!(out, "6\n");
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.args(&["4", "/", "2"]).run().stdout; .args(&["4", "/", "2"]).run().stdout;
assert_eq!(out, "2\n"); assert_eq!(out, "2\n");
} }
#[test] #[test]
fn test_parenthesis() { fn test_parenthesis() {
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.args(&["(", "1", "+", "1", ")", "*", "2"]).run().stdout; .args(&["(", "1", "+", "1", ")", "*", "2"]).run().stdout;
assert_eq!(out, "4\n"); assert_eq!(out, "4\n");
} }
#[test] #[test]
fn test_or() { fn test_or() {
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.args(&["0", "|", "foo"]).run().stdout; .args(&["0", "|", "foo"]).run().stdout;
assert_eq!(out, "foo\n"); assert_eq!(out, "foo\n");
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.args(&["foo", "|", "bar"]).run().stdout; .args(&["foo", "|", "bar"]).run().stdout;
assert_eq!(out, "foo\n"); assert_eq!(out, "foo\n");
} }
#[test] #[test]
fn test_and() { fn test_and() {
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.args(&["foo", "&", "1"]).run().stdout; .args(&["foo", "&", "1"]).run().stdout;
assert_eq!(out, "foo\n"); assert_eq!(out, "foo\n");
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.args(&["", "&", "1"]).run().stdout; .args(&["", "&", "1"]).run().stdout;
assert_eq!(out, "0\n"); assert_eq!(out, "0\n");
} }

View file

@ -18,6 +18,9 @@ const LOG_PRIMES: f64 = 14.0; // ceil(log2(NUM_PRIMES))
const NUM_TESTS: usize = 100; const NUM_TESTS: usize = 100;
static UTIL_NAME: &'static str = "factor"; static UTIL_NAME: &'static str = "factor";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_random() { fn test_random() {
@ -157,9 +160,8 @@ fn test_big_primes() {
} }
fn run(instring: &[u8], outstring: &[u8]) { fn run(instring: &[u8], outstring: &[u8]) {
let (_, mut ucmd) = testing(UTIL_NAME);
// now run factor // now run factor
let out = ucmd.run_piped_stdin(instring).stdout; let out = new_ucmd().run_piped_stdin(instring).stdout;
assert_eq!(out, String::from_utf8(outstring.to_owned()).unwrap()); assert_eq!(out, String::from_utf8(outstring.to_owned()).unwrap());
} }

View file

@ -1,10 +1,13 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "false"; static UTIL_NAME: &'static str = "false";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_exit_code() { fn test_exit_code() {
let (_, mut ucmd) = testing(UTIL_NAME); let exit_status = new_ucmd()
let exit_status = ucmd.run().success; .run().success;
assert_eq!(exit_status, false); assert_eq!(exit_status, false);
} }

View file

@ -1,38 +1,35 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "fold"; static UTIL_NAME: &'static str = "fold";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_default_80_column_wrap() { fn test_default_80_column_wrap() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let out = ucmd.arg("lorem_ipsum.txt") .arg("lorem_ipsum.txt")
.run() .run()
.stdout; .stdout_is_fixture("lorem_ipsum_80_column.expected");
assert_eq!(out, at.read("lorem_ipsum_80_column.expected"));
} }
#[test] #[test]
fn test_40_column_hard_cutoff() { fn test_40_column_hard_cutoff() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let out = ucmd.arg("-w")
.arg("40")
.arg("lorem_ipsum.txt")
.run()
.stdout;
assert_eq!(out, at.read("lorem_ipsum_40_column_hard.expected"));
}
#[test]
fn test_40_column_word_boundary() {
let (at, mut ucmd) = testing(UTIL_NAME);
let out = ucmd.arg("-s")
.arg("-w") .arg("-w")
.arg("40") .arg("40")
.arg("lorem_ipsum.txt") .arg("lorem_ipsum.txt")
.run() .run()
.stdout; .stdout_is_fixture("lorem_ipsum_40_column_hard.expected");
}
assert_eq!(out, at.read("lorem_ipsum_40_column_word.expected"));
#[test]
fn test_40_column_word_boundary() {
new_ucmd()
.arg("-s")
.arg("-w")
.arg("40")
.arg("lorem_ipsum.txt")
.run()
.stdout_is_fixture("lorem_ipsum_40_column_word.expected");
} }

View file

@ -8,14 +8,19 @@ macro_rules! test_digest {
($($t:ident)*) => ($( ($($t:ident)*) => ($(
mod $t { mod $t {
use common::util::*; use::common::util::*;
static UTIL_NAME: &'static str = "hashsum"; static UTIL_NAME: &'static str = "hashsum";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
static DIGEST_ARG: &'static str = concat!("--", stringify!($t)); static DIGEST_ARG: &'static str = concat!("--", stringify!($t));
static EXPECTED_FILE: &'static str = concat!(stringify!($t), ".expected"); static EXPECTED_FILE: &'static str = concat!(stringify!($t), ".expected");
#[test] #[test]
fn test_single_file() { fn test_single_file() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let result = ucmd.arg(DIGEST_ARG).arg("input.txt").run(); let result = ucmd.arg(DIGEST_ARG).arg("input.txt").run();
assert_empty_stderr!(result); assert_empty_stderr!(result);
@ -25,7 +30,7 @@ macro_rules! test_digest {
#[test] #[test]
fn test_stdin() { fn test_stdin() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let input = at.read("input.txt"); let input = at.read("input.txt");
let result = ucmd.arg(DIGEST_ARG).run_piped_stdin(input); let result = ucmd.arg(DIGEST_ARG).run_piped_stdin(input);

View file

@ -1,71 +1,74 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "head"; static UTIL_NAME: &'static str = "head";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
static INPUT: &'static str = "lorem_ipsum.txt"; static INPUT: &'static str = "lorem_ipsum.txt";
#[test] #[test]
fn test_stdin_default() { fn test_stdin_default() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.run_piped_stdin(at.read(INPUT)); .pipe_in_fixture(INPUT)
assert_eq!(result.stdout, at.read("lorem_ipsum_default.expected")); .run().stdout_is_fixture("lorem_ipsum_default.expected");
} }
#[test] #[test]
fn test_stdin_1_line_obsolete() { fn test_stdin_1_line_obsolete() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-1"]) .args(&["-1"])
.run_piped_stdin(at.read(INPUT)); .pipe_in_fixture(INPUT)
assert_eq!(result.stdout, at.read("lorem_ipsum_1_line.expected")); .run().stdout_is_fixture("lorem_ipsum_1_line.expected");
} }
#[test] #[test]
fn test_stdin_1_line() { fn test_stdin_1_line() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-n", "1"]) .args(&["-n", "1"])
.run_piped_stdin(at.read(INPUT)); .pipe_in_fixture(INPUT)
assert_eq!(result.stdout, at.read("lorem_ipsum_1_line.expected")); .run().stdout_is_fixture("lorem_ipsum_1_line.expected");
} }
#[test] #[test]
fn test_stdin_5_chars() { fn test_stdin_5_chars() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-c", "5"]) .args(&["-c", "5"])
.run_piped_stdin(at.read(INPUT)); .pipe_in_fixture(INPUT)
assert_eq!(result.stdout, at.read("lorem_ipsum_5_chars.expected")); .run().stdout_is_fixture("lorem_ipsum_5_chars.expected");
} }
#[test] #[test]
fn test_single_default() { fn test_single_default() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.arg(INPUT).run(); .arg(INPUT)
assert_eq!(result.stdout, at.read("lorem_ipsum_default.expected")); .run().stdout_is_fixture("lorem_ipsum_default.expected");
} }
#[test] #[test]
fn test_single_1_line_obsolete() { fn test_single_1_line_obsolete() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-1", INPUT]).run(); .args(&["-1", INPUT])
assert_eq!(result.stdout, at.read("lorem_ipsum_1_line.expected")); .run().stdout_is_fixture("lorem_ipsum_1_line.expected");
} }
#[test] #[test]
fn test_single_1_line() { fn test_single_1_line() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-n", "1", INPUT]).run(); .args(&["-n", "1", INPUT])
assert_eq!(result.stdout, at.read("lorem_ipsum_1_line.expected")); .run().stdout_is_fixture("lorem_ipsum_1_line.expected");
} }
#[test] #[test]
fn test_single_5_chars() { fn test_single_5_chars() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-c", "5", INPUT]).run(); .args(&["-c", "5", INPUT])
assert_eq!(result.stdout, at.read("lorem_ipsum_5_chars.expected")); .run().stdout_is_fixture("lorem_ipsum_5_chars.expected");
} }
#[test] #[test]
fn test_verbose() { fn test_verbose() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-v", INPUT]).run(); .args(&["-v", INPUT])
assert_eq!(result.stdout, at.read("lorem_ipsum_verbose.expected")); .run().stdout_is_fixture("lorem_ipsum_verbose.expected");
} }

View file

@ -9,10 +9,15 @@ use common::util::*;
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
static UTIL_NAME: &'static str = "install"; static UTIL_NAME: &'static str = "install";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
#[test] #[test]
fn test_install_help() { fn test_install_help() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let result = ucmd.arg("--help").run(); let result = ucmd.arg("--help").run();
@ -24,7 +29,7 @@ fn test_install_help() {
#[test] #[test]
fn test_install_basic() { fn test_install_basic() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_install_target_dir_dir_a"; let dir = "test_install_target_dir_dir_a";
let file1 = "test_install_target_dir_file_a1"; let file1 = "test_install_target_dir_file_a1";
let file2 = "test_install_target_dir_file_a2"; let file2 = "test_install_target_dir_file_a2";
@ -45,7 +50,7 @@ fn test_install_basic() {
#[test] #[test]
fn test_install_unimplemented_arg() { fn test_install_unimplemented_arg() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_install_target_dir_dir_b"; let dir = "test_install_target_dir_dir_b";
let file = "test_install_target_dir_file_b"; let file = "test_install_target_dir_file_b";
let context_arg = "--context"; let context_arg = "--context";
@ -62,7 +67,7 @@ fn test_install_unimplemented_arg() {
#[test] #[test]
fn test_install_component_directories() { fn test_install_component_directories() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let component1 = "test_install_target_dir_component_c1"; let component1 = "test_install_target_dir_component_c1";
let component2 = "test_install_target_dir_component_c2"; let component2 = "test_install_target_dir_component_c2";
let component3 = "test_install_target_dir_component_c3"; let component3 = "test_install_target_dir_component_c3";
@ -80,7 +85,7 @@ fn test_install_component_directories() {
#[test] #[test]
fn test_install_component_directories_failing() { fn test_install_component_directories_failing() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let component = "test_install_target_dir_component_d1"; let component = "test_install_target_dir_component_d1";
let directories_arg = "-d"; let directories_arg = "-d";
@ -93,7 +98,7 @@ fn test_install_component_directories_failing() {
#[test] #[test]
fn test_install_mode_numeric() { fn test_install_mode_numeric() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_install_target_dir_dir_e"; let dir = "test_install_target_dir_dir_e";
let file = "test_install_target_dir_file_e"; let file = "test_install_target_dir_file_e";
let mode_arg = "--mode=333"; let mode_arg = "--mode=333";
@ -114,7 +119,7 @@ fn test_install_mode_numeric() {
#[test] #[test]
fn test_install_mode_symbolic() { fn test_install_mode_symbolic() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_install_target_dir_dir_f"; let dir = "test_install_target_dir_dir_f";
let file = "test_install_target_dir_file_f"; let file = "test_install_target_dir_file_f";
let mode_arg = "--mode=o+wx"; let mode_arg = "--mode=o+wx";
@ -135,7 +140,7 @@ fn test_install_mode_symbolic() {
#[test] #[test]
fn test_install_mode_failing() { fn test_install_mode_failing() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_install_target_dir_dir_g"; let dir = "test_install_target_dir_dir_g";
let file = "test_install_target_dir_file_g"; let file = "test_install_target_dir_file_g";
let mode_arg = "--mode=999"; let mode_arg = "--mode=999";
@ -154,7 +159,7 @@ fn test_install_mode_failing() {
#[test] #[test]
fn test_install_mode_directories() { fn test_install_mode_directories() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let component = "test_install_target_dir_component_h"; let component = "test_install_target_dir_component_h";
let directories_arg = "-d"; let directories_arg = "-d";
let mode_arg = "--mode=333"; let mode_arg = "--mode=333";

View file

@ -3,10 +3,15 @@ extern crate libc;
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "link"; static UTIL_NAME: &'static str = "link";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
#[test] #[test]
fn test_link_existing_file() { fn test_link_existing_file() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_link_existing_file"; let file = "test_link_existing_file";
let link = "test_link_existing_file_link"; let link = "test_link_existing_file_link";
@ -25,7 +30,7 @@ fn test_link_existing_file() {
#[test] #[test]
fn test_link_no_circular() { fn test_link_no_circular() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let link = "test_link_no_circular"; let link = "test_link_no_circular";
let result = ucmd.args(&[link, link]).run(); let result = ucmd.args(&[link, link]).run();
@ -37,7 +42,7 @@ fn test_link_no_circular() {
#[test] #[test]
fn test_link_nonexistent_file() { fn test_link_nonexistent_file() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_link_nonexistent_file"; let file = "test_link_nonexistent_file";
let link = "test_link_nonexistent_file_link"; let link = "test_link_nonexistent_file_link";

View file

@ -1,10 +1,15 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "ln"; static UTIL_NAME: &'static str = "ln";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
#[test] #[test]
fn test_symlink_existing_file() { fn test_symlink_existing_file() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_symlink_existing_file"; let file = "test_symlink_existing_file";
let link = "test_symlink_existing_file_link"; let link = "test_symlink_existing_file_link";
@ -20,7 +25,7 @@ fn test_symlink_existing_file() {
#[test] #[test]
fn test_symlink_dangling_file() { fn test_symlink_dangling_file() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_symlink_dangling_file"; let file = "test_symlink_dangling_file";
let link = "test_symlink_dangling_file_link"; let link = "test_symlink_dangling_file_link";
@ -34,7 +39,7 @@ fn test_symlink_dangling_file() {
#[test] #[test]
fn test_symlink_existing_directory() { fn test_symlink_existing_directory() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_symlink_existing_dir"; let dir = "test_symlink_existing_dir";
let link = "test_symlink_existing_dir_link"; let link = "test_symlink_existing_dir_link";
@ -50,7 +55,7 @@ fn test_symlink_existing_directory() {
#[test] #[test]
fn test_symlink_dangling_directory() { fn test_symlink_dangling_directory() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_symlink_dangling_dir"; let dir = "test_symlink_dangling_dir";
let link = "test_symlink_dangling_dir_link"; let link = "test_symlink_dangling_dir_link";
@ -64,7 +69,7 @@ fn test_symlink_dangling_directory() {
#[test] #[test]
fn test_symlink_circular() { fn test_symlink_circular() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let link = "test_symlink_circular"; let link = "test_symlink_circular";
let result = ucmd.args(&["-s", link]).run(); let result = ucmd.args(&["-s", link]).run();
@ -76,7 +81,7 @@ fn test_symlink_circular() {
#[test] #[test]
fn test_symlink_dont_overwrite() { fn test_symlink_dont_overwrite() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_symlink_dont_overwrite"; let file = "test_symlink_dont_overwrite";
let link = "test_symlink_dont_overwrite_link"; let link = "test_symlink_dont_overwrite_link";
@ -92,7 +97,7 @@ fn test_symlink_dont_overwrite() {
#[test] #[test]
fn test_symlink_overwrite_force() { fn test_symlink_overwrite_force() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file_a = "test_symlink_overwrite_force_a"; let file_a = "test_symlink_overwrite_force_a";
let file_b = "test_symlink_overwrite_force_b"; let file_b = "test_symlink_overwrite_force_b";
let link = "test_symlink_overwrite_force_link"; let link = "test_symlink_overwrite_force_link";
@ -111,15 +116,15 @@ fn test_symlink_overwrite_force() {
#[test] #[test]
fn test_symlink_interactive() { fn test_symlink_interactive() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let at = &ts.fixtures; let at = &scene.fixtures;
let file = "test_symlink_interactive_file"; let file = "test_symlink_interactive_file";
let link = "test_symlink_interactive_file_link"; let link = "test_symlink_interactive_file_link";
at.touch(file); at.touch(file);
at.touch(link); at.touch(link);
let result1 = ts.util_cmd() let result1 = scene.ucmd()
.args(&["-i", "-s", file, link]) .args(&["-i", "-s", file, link])
.run_piped_stdin("n"); .run_piped_stdin("n");
@ -129,7 +134,7 @@ fn test_symlink_interactive() {
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(!at.is_symlink(link)); assert!(!at.is_symlink(link));
let result2 = ts.util_cmd() let result2 = scene.ucmd()
.args(&["-i", "-s", file, link]) .args(&["-i", "-s", file, link])
.run_piped_stdin("Yesh"); .run_piped_stdin("Yesh");
@ -143,7 +148,7 @@ fn test_symlink_interactive() {
#[test] #[test]
fn test_symlink_simple_backup() { fn test_symlink_simple_backup() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_symlink_simple_backup"; let file = "test_symlink_simple_backup";
let link = "test_symlink_simple_backup_link"; let link = "test_symlink_simple_backup_link";
@ -169,7 +174,7 @@ fn test_symlink_simple_backup() {
#[test] #[test]
fn test_symlink_custom_backup_suffix() { fn test_symlink_custom_backup_suffix() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_symlink_custom_backup_suffix"; let file = "test_symlink_custom_backup_suffix";
let link = "test_symlink_custom_backup_suffix_link"; let link = "test_symlink_custom_backup_suffix_link";
let suffix = "super-suffix-of-the-century"; let suffix = "super-suffix-of-the-century";
@ -197,7 +202,7 @@ fn test_symlink_custom_backup_suffix() {
#[test] #[test]
fn test_symlink_backup_numbering() { fn test_symlink_backup_numbering() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_symlink_backup_numbering"; let file = "test_symlink_backup_numbering";
let link = "test_symlink_backup_numbering_link"; let link = "test_symlink_backup_numbering_link";
@ -223,7 +228,7 @@ fn test_symlink_backup_numbering() {
#[test] #[test]
fn test_symlink_existing_backup() { fn test_symlink_existing_backup() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_symlink_existing_backup"; let file = "test_symlink_existing_backup";
let link = "test_symlink_existing_backup_link"; let link = "test_symlink_existing_backup_link";
let link_backup = "test_symlink_existing_backup_link.~1~"; let link_backup = "test_symlink_existing_backup_link.~1~";
@ -257,7 +262,7 @@ fn test_symlink_existing_backup() {
#[test] #[test]
fn test_symlink_target_dir() { fn test_symlink_target_dir() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_ln_target_dir_dir"; let dir = "test_ln_target_dir_dir";
let file_a = "test_ln_target_dir_file_a"; let file_a = "test_ln_target_dir_file_a";
let file_b = "test_ln_target_dir_file_b"; let file_b = "test_ln_target_dir_file_b";
@ -282,7 +287,7 @@ fn test_symlink_target_dir() {
#[test] #[test]
fn test_symlink_overwrite_dir() { fn test_symlink_overwrite_dir() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let path_a = "test_symlink_overwrite_dir_a"; let path_a = "test_symlink_overwrite_dir_a";
let path_b = "test_symlink_overwrite_dir_b"; let path_b = "test_symlink_overwrite_dir_b";
@ -301,7 +306,7 @@ fn test_symlink_overwrite_dir() {
#[test] #[test]
fn test_symlink_overwrite_nonempty_dir() { fn test_symlink_overwrite_nonempty_dir() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let path_a = "test_symlink_overwrite_nonempty_dir_a"; let path_a = "test_symlink_overwrite_nonempty_dir_a";
let path_b = "test_symlink_overwrite_nonempty_dir_b"; let path_b = "test_symlink_overwrite_nonempty_dir_b";
let dummy = "test_symlink_overwrite_nonempty_dir_b/file"; let dummy = "test_symlink_overwrite_nonempty_dir_b/file";
@ -328,7 +333,7 @@ fn test_symlink_overwrite_nonempty_dir() {
#[test] #[test]
fn test_symlink_errors() { fn test_symlink_errors() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_symlink_errors_dir"; let dir = "test_symlink_errors_dir";
let file_a = "test_symlink_errors_file_a"; let file_a = "test_symlink_errors_file_a";
let file_b = "test_symlink_errors_file_b"; let file_b = "test_symlink_errors_file_b";
@ -348,21 +353,21 @@ fn test_symlink_errors() {
#[test] #[test]
fn test_symlink_verbose() { fn test_symlink_verbose() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let at = &ts.fixtures; let at = &scene.fixtures;
let file_a = "test_symlink_verbose_file_a"; let file_a = "test_symlink_verbose_file_a";
let file_b = "test_symlink_verbose_file_b"; let file_b = "test_symlink_verbose_file_b";
at.touch(file_a); at.touch(file_a);
let result = ts.util_cmd().args(&["-v", file_a, file_b]).run(); let result = scene.ucmd().args(&["-v", file_a, file_b]).run();
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert_eq!(result.stdout, format!("'{}' -> '{}'\n", file_b, file_a)); assert_eq!(result.stdout, format!("'{}' -> '{}'\n", file_b, file_a));
assert!(result.success); assert!(result.success);
at.touch(file_b); at.touch(file_b);
let result = ts.util_cmd().args(&["-v", "-b", file_a, file_b]).run(); let result = scene.ucmd().args(&["-v", "-b", file_a, file_b]).run();
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert_eq!(result.stdout, assert_eq!(result.stdout,
format!("'{}' -> '{}' (backup: '{}~')\n", file_b, file_a, file_b)); format!("'{}' -> '{}' (backup: '{}~')\n", file_b, file_a, file_b));

View file

@ -1,12 +1,14 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "ls"; static UTIL_NAME: &'static str = "ls";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_ls_ls() { fn test_ls_ls() {
let (_, mut ucmd) = testing(UTIL_NAME);
let result = ucmd.run(); let result = new_ucmd().run();
let exit_success = result.success; let exit_success = result.success;
assert_eq!(exit_success, true); assert_eq!(exit_success, true);

View file

@ -1,6 +1,9 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "mkdir"; static UTIL_NAME: &'static str = "mkdir";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
static TEST_DIR1: &'static str = "mkdir_test1"; static TEST_DIR1: &'static str = "mkdir_test1";
static TEST_DIR2: &'static str = "mkdir_test2"; static TEST_DIR2: &'static str = "mkdir_test2";
@ -10,24 +13,24 @@ static TEST_DIR5: &'static str = "mkdir_test5/mkdir_test5_1";
#[test] #[test]
fn test_mkdir_mkdir() { fn test_mkdir_mkdir() {
let (_, mut ucmd) = testing(UTIL_NAME); let exit_success = new_ucmd()
let exit_success = ucmd.arg(TEST_DIR1).run().success; .arg(TEST_DIR1).run().success;
assert_eq!(exit_success, true); assert_eq!(exit_success, true);
} }
#[test] #[test]
fn test_mkdir_dup_dir() { fn test_mkdir_dup_dir() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let exit_success = ts.util_cmd().arg(TEST_DIR2).run().success; let exit_success = scene.ucmd().arg(TEST_DIR2).run().success;
let exit_success2 = ts.util_cmd().arg(TEST_DIR2).run().success; let exit_success2 = scene.ucmd().arg(TEST_DIR2).run().success;
assert!(exit_success); assert!(exit_success);
assert!(!exit_success2); assert!(!exit_success2);
} }
#[test] #[test]
fn test_mkdir_mode() { fn test_mkdir_mode() {
let (_, mut ucmd) = testing(UTIL_NAME); let exit_success = new_ucmd()
let exit_success = ucmd.arg("-m") .arg("-m")
.arg("755") .arg("755")
.arg(TEST_DIR3) .arg(TEST_DIR3)
.run() .run()
@ -37,14 +40,14 @@ fn test_mkdir_mode() {
#[test] #[test]
fn test_mkdir_parent() { fn test_mkdir_parent() {
let (_, mut ucmd) = testing(UTIL_NAME); let exit_success = new_ucmd()
let exit_success = ucmd.arg("-p").arg(TEST_DIR4).run().success; .arg("-p").arg(TEST_DIR4).run().success;
assert!(exit_success); assert!(exit_success);
} }
#[test] #[test]
fn test_mkdir_no_parent() { fn test_mkdir_no_parent() {
let (_, mut ucmd) = testing(UTIL_NAME); let exit_success = new_ucmd()
let exit_success = ucmd.arg(TEST_DIR5).run().success; .arg(TEST_DIR5).run().success;
assert!(!exit_success); assert!(!exit_success);
} }

View file

@ -19,18 +19,18 @@ const TMPDIR: &'static str = "TMPDIR";
#[test] #[test]
fn test_mktemp_mktemp() { fn test_mktemp_mktemp() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let pathname = ts.fixtures.as_string(); let pathname = scene.fixtures.as_string();
let exit_success1 = ts.util_cmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE1).run().success; let exit_success1 = scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE1).run().success;
let exit_success2 = ts.util_cmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE2).run().success; let exit_success2 = scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE2).run().success;
let exit_success3 = ts.util_cmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE3).run().success; let exit_success3 = scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE3).run().success;
let exit_success4 = ts.util_cmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE4).run().success; let exit_success4 = scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE4).run().success;
let exit_success5 = ts.util_cmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE5).run().success; let exit_success5 = scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE5).run().success;
let exit_success6 = ts.util_cmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE6).run().success; let exit_success6 = scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE6).run().success;
let exit_success7 = ts.util_cmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE7).run().success; let exit_success7 = scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE7).run().success;
let exit_success8 = ts.util_cmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE8).run().success; let exit_success8 = scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE8).run().success;
assert!(exit_success1); assert!(exit_success1);
@ -45,18 +45,18 @@ fn test_mktemp_mktemp() {
#[test] #[test]
fn test_mktemp_make_temp_dir() { fn test_mktemp_make_temp_dir() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let pathname = ts.fixtures.as_string(); let pathname = scene.fixtures.as_string();
let exit_success1 = ts.util_cmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE1).run().success; let exit_success1 = scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE1).run().success;
let exit_success2 = ts.util_cmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE2).run().success; let exit_success2 = scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE2).run().success;
let exit_success3 = ts.util_cmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE3).run().success; let exit_success3 = scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE3).run().success;
let exit_success4 = ts.util_cmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE4).run().success; let exit_success4 = scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE4).run().success;
let exit_success5 = ts.util_cmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE5).run().success; let exit_success5 = scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE5).run().success;
let exit_success6 = ts.util_cmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE6).run().success; let exit_success6 = scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE6).run().success;
let exit_success7 = ts.util_cmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE7).run().success; let exit_success7 = scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE7).run().success;
let exit_success8 = ts.util_cmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE8).run().success; let exit_success8 = scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE8).run().success;
assert!(exit_success1); assert!(exit_success1);
assert!(!exit_success2); assert!(!exit_success2);
@ -70,18 +70,18 @@ fn test_mktemp_make_temp_dir() {
#[test] #[test]
fn test_mktemp_dry_run() { fn test_mktemp_dry_run() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let pathname = ts.fixtures.as_string(); let pathname = scene.fixtures.as_string();
let exit_success1 = ts.util_cmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE1).run().success; let exit_success1 = scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE1).run().success;
let exit_success2 = ts.util_cmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE2).run().success; let exit_success2 = scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE2).run().success;
let exit_success3 = ts.util_cmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE3).run().success; let exit_success3 = scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE3).run().success;
let exit_success4 = ts.util_cmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE4).run().success; let exit_success4 = scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE4).run().success;
let exit_success5 = ts.util_cmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE5).run().success; let exit_success5 = scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE5).run().success;
let exit_success6 = ts.util_cmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE6).run().success; let exit_success6 = scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE6).run().success;
let exit_success7 = ts.util_cmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE7).run().success; let exit_success7 = scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE7).run().success;
let exit_success8 = ts.util_cmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE8).run().success; let exit_success8 = scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE8).run().success;
assert!(exit_success1); assert!(exit_success1);
@ -96,10 +96,10 @@ fn test_mktemp_dry_run() {
#[test] #[test]
fn test_mktemp_quiet() { fn test_mktemp_quiet() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let result1 = ts.util_cmd().arg("-p").arg("/definitely/not/exist/I/promise").arg("-q").run(); let result1 = scene.ucmd().arg("-p").arg("/definitely/not/exist/I/promise").arg("-q").run();
let result2 = ts.util_cmd().arg("-d").arg("-p").arg("/definitely/not/exist/I/promise").arg("-q").run(); let result2 = scene.ucmd().arg("-d").arg("-p").arg("/definitely/not/exist/I/promise").arg("-q").run();
assert!(result1.stderr.is_empty() && result1.stdout.is_empty() && !result1.success); assert!(result1.stderr.is_empty() && result1.stdout.is_empty() && !result1.success);
assert!(result2.stderr.is_empty() && result2.stdout.is_empty() && !result2.success); assert!(result2.stderr.is_empty() && result2.stdout.is_empty() && !result2.success);
@ -107,18 +107,18 @@ fn test_mktemp_quiet() {
#[test] #[test]
fn test_mktemp_suffix() { fn test_mktemp_suffix() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let pathname = ts.fixtures.as_string(); let pathname = scene.fixtures.as_string();
let exit_success1 = ts.util_cmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE1).run().success; let exit_success1 = scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE1).run().success;
let exit_success2 = ts.util_cmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE2).run().success; let exit_success2 = scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE2).run().success;
let exit_success3 = ts.util_cmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE3).run().success; let exit_success3 = scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE3).run().success;
let exit_success4 = ts.util_cmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE4).run().success; let exit_success4 = scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE4).run().success;
let exit_success5 = ts.util_cmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE5).run().success; let exit_success5 = scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE5).run().success;
let exit_success6 = ts.util_cmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE6).run().success; let exit_success6 = scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE6).run().success;
let exit_success7 = ts.util_cmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE7).run().success; let exit_success7 = scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE7).run().success;
let exit_success8 = ts.util_cmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE8).run().success; let exit_success8 = scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE8).run().success;
assert!(exit_success1); assert!(exit_success1);
@ -133,19 +133,19 @@ fn test_mktemp_suffix() {
#[test] #[test]
fn test_mktemp_tmpdir() { fn test_mktemp_tmpdir() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let path = TempDir::new_in(ts.fixtures.as_string(), UTIL_NAME).unwrap(); let path = TempDir::new_in(scene.fixtures.as_string(), UTIL_NAME).unwrap();
let pathname = path.path().as_os_str(); let pathname = path.path().as_os_str();
let exit_success1 = ts.util_cmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE1).run().success; let exit_success1 = scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE1).run().success;
let exit_success2 = ts.util_cmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE2).run().success; let exit_success2 = scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE2).run().success;
let exit_success3 = ts.util_cmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE3).run().success; let exit_success3 = scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE3).run().success;
let exit_success4 = ts.util_cmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE4).run().success; let exit_success4 = scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE4).run().success;
let exit_success5 = ts.util_cmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE5).run().success; let exit_success5 = scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE5).run().success;
let exit_success6 = ts.util_cmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE6).run().success; let exit_success6 = scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE6).run().success;
let exit_success7 = ts.util_cmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE7).run().success; let exit_success7 = scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE7).run().success;
let exit_success8 = ts.util_cmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE8).run().success; let exit_success8 = scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE8).run().success;
assert!(exit_success1); assert!(exit_success1);

View file

@ -8,10 +8,15 @@ use self::filetime::*;
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "mv"; static UTIL_NAME: &'static str = "mv";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
#[test] #[test]
fn test_mv_rename_dir() { fn test_mv_rename_dir() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir1 = "test_mv_rename_dir"; let dir1 = "test_mv_rename_dir";
let dir2 = "test_mv_rename_dir2"; let dir2 = "test_mv_rename_dir2";
@ -26,7 +31,7 @@ fn test_mv_rename_dir() {
#[test] #[test]
fn test_mv_rename_file() { fn test_mv_rename_file() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file1 = "test_mv_rename_file"; let file1 = "test_mv_rename_file";
let file2 = "test_mv_rename_file2"; let file2 = "test_mv_rename_file2";
@ -41,7 +46,7 @@ fn test_mv_rename_file() {
#[test] #[test]
fn test_mv_move_file_into_dir() { fn test_mv_move_file_into_dir() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_mv_move_file_into_dir_dir"; let dir = "test_mv_move_file_into_dir_dir";
let file = "test_mv_move_file_into_dir_file"; let file = "test_mv_move_file_into_dir_file";
@ -57,8 +62,8 @@ fn test_mv_move_file_into_dir() {
#[test] #[test]
fn test_mv_strip_slashes() { fn test_mv_strip_slashes() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let at = &ts.fixtures; let at = &scene.fixtures;
let dir = "test_mv_strip_slashes_dir"; let dir = "test_mv_strip_slashes_dir";
let file = "test_mv_strip_slashes_file"; let file = "test_mv_strip_slashes_file";
let mut source = file.to_owned(); let mut source = file.to_owned();
@ -67,12 +72,12 @@ fn test_mv_strip_slashes() {
at.mkdir(dir); at.mkdir(dir);
at.touch(file); at.touch(file);
let result = ts.util_cmd().arg(&source).arg(dir).run(); let result = scene.ucmd().arg(&source).arg(dir).run();
assert!(!result.success); assert!(!result.success);
assert!(!at.file_exists(&format!("{}/{}", dir, file))); assert!(!at.file_exists(&format!("{}/{}", dir, file)));
let result = ts.util_cmd().arg("--strip-trailing-slashes").arg(source).arg(dir).run(); let result = scene.ucmd().arg("--strip-trailing-slashes").arg(source).arg(dir).run();
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -81,7 +86,7 @@ fn test_mv_strip_slashes() {
#[test] #[test]
fn test_mv_multiple_files() { fn test_mv_multiple_files() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let target_dir = "test_mv_multiple_files_dir"; let target_dir = "test_mv_multiple_files_dir";
let file_a = "test_mv_multiple_file_a"; let file_a = "test_mv_multiple_file_a";
let file_b = "test_mv_multiple_file_b"; let file_b = "test_mv_multiple_file_b";
@ -100,7 +105,7 @@ fn test_mv_multiple_files() {
#[test] #[test]
fn test_mv_multiple_folders() { fn test_mv_multiple_folders() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let target_dir = "test_mv_multiple_dirs_dir"; let target_dir = "test_mv_multiple_dirs_dir";
let dir_a = "test_mv_multiple_dir_a"; let dir_a = "test_mv_multiple_dir_a";
let dir_b = "test_mv_multiple_dir_b"; let dir_b = "test_mv_multiple_dir_b";
@ -119,8 +124,8 @@ fn test_mv_multiple_folders() {
#[test] #[test]
fn test_mv_interactive() { fn test_mv_interactive() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let at = &ts.fixtures; let at = &scene.fixtures;
let file_a = "test_mv_interactive_file_a"; let file_a = "test_mv_interactive_file_a";
let file_b = "test_mv_interactive_file_b"; let file_b = "test_mv_interactive_file_b";
@ -128,7 +133,7 @@ fn test_mv_interactive() {
at.touch(file_b); at.touch(file_b);
let result1 = ts.util_cmd().arg("-i").arg(file_a).arg(file_b).run_piped_stdin("n"); let result1 = scene.ucmd().arg("-i").arg(file_a).arg(file_b).run_piped_stdin("n");
assert_empty_stderr!(result1); assert_empty_stderr!(result1);
assert!(result1.success); assert!(result1.success);
@ -137,7 +142,7 @@ fn test_mv_interactive() {
assert!(at.file_exists(file_b)); assert!(at.file_exists(file_b));
let result2 = ts.util_cmd().arg("-i").arg(file_a).arg(file_b).run_piped_stdin("Yesh"); let result2 = scene.ucmd().arg("-i").arg(file_a).arg(file_b).run_piped_stdin("Yesh");
assert_empty_stderr!(result2); assert_empty_stderr!(result2);
assert!(result2.success); assert!(result2.success);
@ -148,7 +153,7 @@ fn test_mv_interactive() {
#[test] #[test]
fn test_mv_no_clobber() { fn test_mv_no_clobber() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file_a = "test_mv_no_clobber_file_a"; let file_a = "test_mv_no_clobber_file_a";
let file_b = "test_mv_no_clobber_file_b"; let file_b = "test_mv_no_clobber_file_b";
@ -165,7 +170,7 @@ fn test_mv_no_clobber() {
#[test] #[test]
fn test_mv_replace_file() { fn test_mv_replace_file() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file_a = "test_mv_replace_file_a"; let file_a = "test_mv_replace_file_a";
let file_b = "test_mv_replace_file_b"; let file_b = "test_mv_replace_file_b";
@ -182,7 +187,7 @@ fn test_mv_replace_file() {
#[test] #[test]
fn test_mv_force_replace_file() { fn test_mv_force_replace_file() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file_a = "test_mv_force_replace_file_a"; let file_a = "test_mv_force_replace_file_a";
let file_b = "test_mv_force_replace_file_b"; let file_b = "test_mv_force_replace_file_b";
@ -199,7 +204,7 @@ fn test_mv_force_replace_file() {
#[test] #[test]
fn test_mv_simple_backup() { fn test_mv_simple_backup() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file_a = "test_mv_simple_backup_file_a"; let file_a = "test_mv_simple_backup_file_a";
let file_b = "test_mv_simple_backup_file_b"; let file_b = "test_mv_simple_backup_file_b";
@ -217,7 +222,7 @@ fn test_mv_simple_backup() {
#[test] #[test]
fn test_mv_custom_backup_suffix() { fn test_mv_custom_backup_suffix() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file_a = "test_mv_custom_backup_suffix_file_a"; let file_a = "test_mv_custom_backup_suffix_file_a";
let file_b = "test_mv_custom_backup_suffix_file_b"; let file_b = "test_mv_custom_backup_suffix_file_b";
let suffix = "super-suffix-of-the-century"; let suffix = "super-suffix-of-the-century";
@ -240,7 +245,7 @@ fn test_mv_custom_backup_suffix() {
#[test] #[test]
fn test_mv_backup_numbering() { fn test_mv_backup_numbering() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file_a = "test_mv_backup_numbering_file_a"; let file_a = "test_mv_backup_numbering_file_a";
let file_b = "test_mv_backup_numbering_file_b"; let file_b = "test_mv_backup_numbering_file_b";
@ -258,7 +263,7 @@ fn test_mv_backup_numbering() {
#[test] #[test]
fn test_mv_existing_backup() { fn test_mv_existing_backup() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file_a = "test_mv_existing_backup_file_a"; let file_a = "test_mv_existing_backup_file_a";
let file_b = "test_mv_existing_backup_file_b"; let file_b = "test_mv_existing_backup_file_b";
let file_b_backup = "test_mv_existing_backup_file_b.~1~"; let file_b_backup = "test_mv_existing_backup_file_b.~1~";
@ -280,8 +285,8 @@ fn test_mv_existing_backup() {
#[test] #[test]
fn test_mv_update_option() { fn test_mv_update_option() {
let test_set = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let at = &test_set.fixtures; let at = &scene.fixtures;
let file_a = "test_mv_update_option_file_a"; let file_a = "test_mv_update_option_file_a";
let file_b = "test_mv_update_option_file_b"; let file_b = "test_mv_update_option_file_b";
@ -293,7 +298,7 @@ fn test_mv_update_option() {
filetime::set_file_times(at.plus_as_string(file_a), now, now).unwrap(); filetime::set_file_times(at.plus_as_string(file_a), now, now).unwrap();
filetime::set_file_times(at.plus_as_string(file_b), now, later).unwrap(); filetime::set_file_times(at.plus_as_string(file_b), now, later).unwrap();
let result1 = test_set.util_cmd().arg("--update").arg(file_a).arg(file_b).run(); let result1 = scene.ucmd().arg("--update").arg(file_a).arg(file_b).run();
assert_empty_stderr!(result1); assert_empty_stderr!(result1);
assert!(result1.success); assert!(result1.success);
@ -301,7 +306,7 @@ fn test_mv_update_option() {
assert!(at.file_exists(file_a)); assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b)); assert!(at.file_exists(file_b));
let result2 = test_set.util_cmd().arg("--update").arg(file_b).arg(file_a).run(); let result2 = scene.ucmd().arg("--update").arg(file_b).arg(file_a).run();
assert_empty_stderr!(result2); assert_empty_stderr!(result2);
assert!(result2.success); assert!(result2.success);
@ -312,7 +317,7 @@ fn test_mv_update_option() {
#[test] #[test]
fn test_mv_target_dir() { fn test_mv_target_dir() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_mv_target_dir_dir"; let dir = "test_mv_target_dir_dir";
let file_a = "test_mv_target_dir_file_a"; let file_a = "test_mv_target_dir_file_a";
let file_b = "test_mv_target_dir_file_b"; let file_b = "test_mv_target_dir_file_b";
@ -333,7 +338,7 @@ fn test_mv_target_dir() {
#[test] #[test]
fn test_mv_overwrite_dir() { fn test_mv_overwrite_dir() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir_a = "test_mv_overwrite_dir_a"; let dir_a = "test_mv_overwrite_dir_a";
let dir_b = "test_mv_overwrite_dir_b"; let dir_b = "test_mv_overwrite_dir_b";
@ -350,7 +355,7 @@ fn test_mv_overwrite_dir() {
#[test] #[test]
fn test_mv_overwrite_nonempty_dir() { fn test_mv_overwrite_nonempty_dir() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir_a = "test_mv_overwrite_nonempty_dir_a"; let dir_a = "test_mv_overwrite_nonempty_dir_a";
let dir_b = "test_mv_overwrite_nonempty_dir_b"; let dir_b = "test_mv_overwrite_nonempty_dir_b";
let dummy = "test_mv_overwrite_nonempty_dir_b/file"; let dummy = "test_mv_overwrite_nonempty_dir_b/file";
@ -376,7 +381,7 @@ fn test_mv_overwrite_nonempty_dir() {
#[test] #[test]
fn test_mv_backup_dir() { fn test_mv_backup_dir() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir_a = "test_mv_backup_dir_dir_a"; let dir_a = "test_mv_backup_dir_dir_a";
let dir_b = "test_mv_backup_dir_dir_b"; let dir_b = "test_mv_backup_dir_dir_b";
@ -399,8 +404,8 @@ fn test_mv_backup_dir() {
#[test] #[test]
fn test_mv_errors() { fn test_mv_errors() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let at = &ts.fixtures; let at = &scene.fixtures;
let dir = "test_mv_errors_dir"; let dir = "test_mv_errors_dir";
let file_a = "test_mv_errors_file_a"; let file_a = "test_mv_errors_file_a";
let file_b = "test_mv_errors_file_b"; let file_b = "test_mv_errors_file_b";
@ -410,7 +415,7 @@ fn test_mv_errors() {
// $ mv -T -t a b // $ mv -T -t a b
// mv: cannot combine --target-directory (-t) and --no-target-directory (-T) // mv: cannot combine --target-directory (-t) and --no-target-directory (-T)
let result = ts.util_cmd().arg("-T").arg("-t").arg(dir).arg(file_a).arg(file_b).run(); let result = scene.ucmd().arg("-T").arg("-t").arg(dir).arg(file_a).arg(file_b).run();
assert_eq!(result.stderr, assert_eq!(result.stderr,
"mv: error: cannot combine --target-directory (-t) and --no-target-directory \ "mv: error: cannot combine --target-directory (-t) and --no-target-directory \
(-T)\n"); (-T)\n");
@ -420,7 +425,7 @@ fn test_mv_errors() {
// $ at.touch file && at.mkdir dir // $ at.touch file && at.mkdir dir
// $ mv -T file dir // $ mv -T file dir
// err == mv: cannot overwrite directory dir with non-directory // err == mv: cannot overwrite directory dir with non-directory
let result = ts.util_cmd().arg("-T").arg(file_a).arg(dir).run(); let result = scene.ucmd().arg("-T").arg(file_a).arg(dir).run();
assert_eq!(result.stderr, assert_eq!(result.stderr,
format!("mv: error: cannot overwrite directory {} with non-directory\n", format!("mv: error: cannot overwrite directory {} with non-directory\n",
dir)); dir));
@ -429,15 +434,15 @@ fn test_mv_errors() {
// $ at.mkdir dir && at.touch file // $ at.mkdir dir && at.touch file
// $ mv dir file // $ mv dir file
// err == mv: cannot overwrite non-directory file with directory dir // err == mv: cannot overwrite non-directory file with directory dir
let result = ts.util_cmd().arg(dir).arg(file_a).run(); let result = scene.ucmd().arg(dir).arg(file_a).run();
assert!(result.stderr.len() > 0); assert!(result.stderr.len() > 0);
assert!(!result.success); assert!(!result.success);
} }
#[test] #[test]
fn test_mv_verbose() { fn test_mv_verbose() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let at = &ts.fixtures; let at = &scene.fixtures;
let dir = "test_mv_verbose_dir"; let dir = "test_mv_verbose_dir";
let file_a = "test_mv_verbose_file_a"; let file_a = "test_mv_verbose_file_a";
let file_b = "test_mv_verbose_file_b"; let file_b = "test_mv_verbose_file_b";
@ -445,7 +450,7 @@ fn test_mv_verbose() {
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
let result = ts.util_cmd().arg("-v").arg(file_a).arg(file_b).run(); let result = scene.ucmd().arg("-v").arg(file_a).arg(file_b).run();
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert_eq!(result.stdout, assert_eq!(result.stdout,
format!("{} -> {}\n", file_a, file_b)); format!("{} -> {}\n", file_a, file_b));
@ -453,7 +458,7 @@ fn test_mv_verbose() {
at.touch(file_a); at.touch(file_a);
let result = ts.util_cmd().arg("-vb").arg(file_a).arg(file_b).run(); let result = scene.ucmd().arg("-vb").arg(file_a).arg(file_b).run();
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert_eq!(result.stdout, assert_eq!(result.stdout,
format!("{} -> {} (backup: {}~)\n", format!("{} -> {} (backup: {}~)\n",

View file

@ -1,25 +1,28 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "nl"; static UTIL_NAME: &'static str = "nl";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_stdin_nonewline() { fn test_stdin_nonewline() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.run_piped_stdin("No Newline".as_bytes()); .run_piped_stdin("No Newline".as_bytes());
assert_eq!(result.stdout, " 1\tNo Newline\n"); assert_eq!(result.stdout, " 1\tNo Newline\n");
} }
#[test] #[test]
fn test_stdin_newline() { fn test_stdin_newline() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-s", "-", "-w", "1"]) .args(&["-s", "-", "-w", "1"])
.run_piped_stdin("Line One\nLine Two\n".as_bytes()); .run_piped_stdin("Line One\nLine Two\n".as_bytes());
assert_eq!(result.stdout, "1-Line One\n2-Line Two\n"); assert_eq!(result.stdout, "1-Line One\n2-Line Two\n");
} }
#[test] #[test]
fn test_padding_without_overflow() { fn test_padding_without_overflow() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-i", "1000", "-s", "x", "-n", "rz", "simple.txt"]).run(); .args(&["-i", "1000", "-s", "x", "-n", "rz", "simple.txt"]).run();
assert_eq!(result.stdout, assert_eq!(result.stdout,
"000001xL1\n001001xL2\n002001xL3\n003001xL4\n004001xL5\n005001xL6\n006001xL7\n0070\ "000001xL1\n001001xL2\n002001xL3\n003001xL4\n004001xL5\n005001xL6\n006001xL7\n0070\
01xL8\n008001xL9\n009001xL10\n010001xL11\n011001xL12\n012001xL13\n013001xL14\n014\ 01xL8\n008001xL9\n009001xL10\n010001xL11\n011001xL12\n012001xL13\n013001xL14\n014\
@ -28,8 +31,8 @@ fn test_padding_without_overflow() {
#[test] #[test]
fn test_padding_with_overflow() { fn test_padding_with_overflow() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-i", "1000", "-s", "x", "-n", "rz", "-w", "4", "simple.txt"]).run(); .args(&["-i", "1000", "-s", "x", "-n", "rz", "-w", "4", "simple.txt"]).run();
assert_eq!(result.stdout, assert_eq!(result.stdout,
"0001xL1\n1001xL2\n2001xL3\n3001xL4\n4001xL5\n5001xL6\n6001xL7\n7001xL8\n8001xL9\n\ "0001xL1\n1001xL2\n2001xL3\n3001xL4\n4001xL5\n5001xL6\n6001xL7\n7001xL8\n8001xL9\n\
9001xL10\n10001xL11\n11001xL12\n12001xL13\n13001xL14\n14001xL15\n"); 9001xL10\n10001xL11\n11001xL12\n12001xL13\n13001xL14\n14001xL15\n");
@ -47,8 +50,8 @@ fn test_sections_and_styles() {
|Followed by 4x empty\n\n\n\n\n9 |Nonempty\n10 |Nonempty\n11 \ |Followed by 4x empty\n\n\n\n\n9 |Nonempty\n10 |Nonempty\n11 \
|Nonempty.\n")] |Nonempty.\n")]
.iter() { .iter() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-s", "|", "-n", "ln", "-w", "3", "-b", "a", "-l", "5", fixture]) .args(&["-s", "|", "-n", "ln", "-w", "3", "-b", "a", "-l", "5", fixture])
.run(); .run();
assert_eq!(result.stdout, output); assert_eq!(result.stdout, output);
} }

View file

@ -6,6 +6,9 @@ use std::fs::File;
use std::fs::remove_file; use std::fs::remove_file;
static UTIL_NAME: &'static str = "od"; static UTIL_NAME: &'static str = "od";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
// octal dump of 'abcdefghijklmnopqrstuvwxyz\n' // octal dump of 'abcdefghijklmnopqrstuvwxyz\n'
static ALPHA_OUT: &'static str = "0000000 061141 062143 063145 064147 065151 066153 067155 070157\n0000020 071161 072163 073165 074167 075171 000012 \n0000033\n"; static ALPHA_OUT: &'static str = "0000000 061141 062143 063145 064147 065151 066153 067155 070157\n0000020 071161 072163 073165 074167 075171 000012 \n0000033\n";
@ -16,7 +19,6 @@ static ALPHA_OUT: &'static str = "0000000 061141 062143 063145 064147 065
// Test that od can read one file and dump with default format // Test that od can read one file and dump with default format
#[test] #[test]
fn test_file() { fn test_file() {
let (_, mut ucmd) = testing(UTIL_NAME);
use std::env; use std::env;
let temp = env::temp_dir(); let temp = env::temp_dir();
let tmpdir = Path::new(&temp); let tmpdir = Path::new(&temp);
@ -30,7 +32,7 @@ fn test_file() {
} }
} }
let result = ucmd.arg(file.as_os_str()).run(); let result = new_ucmd().arg(file.as_os_str()).run();
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -42,7 +44,6 @@ fn test_file() {
// Test that od can read 2 files and concatenate the contents // Test that od can read 2 files and concatenate the contents
#[test] #[test]
fn test_2files() { fn test_2files() {
let (_, mut ucmd) = testing(UTIL_NAME);
let temp = env::temp_dir(); let temp = env::temp_dir();
let tmpdir = Path::new(&temp); let tmpdir = Path::new(&temp);
let file1 = tmpdir.join("test1"); let file1 = tmpdir.join("test1");
@ -60,7 +61,7 @@ fn test_2files() {
} }
} }
let result = ucmd.arg(file1.as_os_str()).arg(file2.as_os_str()).run(); let result = new_ucmd().arg(file1.as_os_str()).arg(file2.as_os_str()).run();
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -73,12 +74,11 @@ fn test_2files() {
// Test that od gives non-0 exit val for filename that dosen't exist. // Test that od gives non-0 exit val for filename that dosen't exist.
#[test] #[test]
fn test_no_file() { fn test_no_file() {
let (_, mut ucmd) = testing(UTIL_NAME);
let temp = env::temp_dir(); let temp = env::temp_dir();
let tmpdir = Path::new(&temp); let tmpdir = Path::new(&temp);
let file = tmpdir.join("}surely'none'would'thus'a'file'name"); let file = tmpdir.join("}surely'none'would'thus'a'file'name");
let result = ucmd.arg(file.as_os_str()).run(); let result = new_ucmd().arg(file.as_os_str()).run();
assert!(!result.success); assert!(!result.success);
} }
@ -86,10 +86,9 @@ fn test_no_file() {
// Test that od reads from stdin instead of a file // Test that od reads from stdin instead of a file
#[test] #[test]
fn test_from_stdin() { fn test_from_stdin() {
let (_, mut ucmd) = testing(UTIL_NAME);
let input = "abcdefghijklmnopqrstuvwxyz\n"; let input = "abcdefghijklmnopqrstuvwxyz\n";
let result = ucmd.run_piped_stdin(input.as_bytes()); let result = new_ucmd().run_piped_stdin(input.as_bytes());
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -100,7 +99,6 @@ fn test_from_stdin() {
// Test that od reads from stdin and also from files // Test that od reads from stdin and also from files
#[test] #[test]
fn test_from_mixed() { fn test_from_mixed() {
let (_, mut ucmd) = testing(UTIL_NAME);
let temp = env::temp_dir(); let temp = env::temp_dir();
let tmpdir = Path::new(&temp); let tmpdir = Path::new(&temp);
@ -116,7 +114,7 @@ fn test_from_mixed() {
} }
} }
let result = ucmd.arg(file1.as_os_str()).arg("--").arg(file3.as_os_str()).run_piped_stdin(data2.as_bytes()); let result = new_ucmd().arg(file1.as_os_str()).arg("--").arg(file3.as_os_str()).run_piped_stdin(data2.as_bytes());
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -126,10 +124,9 @@ fn test_from_mixed() {
#[test] #[test]
fn test_multiple_formats() { fn test_multiple_formats() {
let (_, mut ucmd) = testing(UTIL_NAME);
let input = "abcdefghijklmnopqrstuvwxyz\n"; let input = "abcdefghijklmnopqrstuvwxyz\n";
let result = ucmd.arg("-c").arg("-b").run_piped_stdin(input.as_bytes()); let result = new_ucmd().arg("-c").arg("-b").run_piped_stdin(input.as_bytes());
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -139,7 +136,6 @@ fn test_multiple_formats() {
#[test] #[test]
fn test_dec() { fn test_dec() {
let (_, mut ucmd) = testing(UTIL_NAME);
let input = [ let input = [
@ -151,7 +147,7 @@ fn test_dec() {
0x00u8,0x80u8, 0x00u8,0x80u8,
0x01u8,0x80u8,]; 0x01u8,0x80u8,];
let expected_output = "0000000 0 1 2 3 32767 -32768 -32767 \n0000016\n"; let expected_output = "0000000 0 1 2 3 32767 -32768 -32767 \n0000016\n";
let result = ucmd.arg("-i").run_piped_stdin(&input[..]); let result = new_ucmd().arg("-i").run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -164,8 +160,8 @@ fn test_dec() {
/* /*
#[test] #[test]
fn mit_die_umlauten_getesten() { fn mit_die_umlauten_getesten() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.run_piped_stdin("Universität Tübingen".as_bytes()); .run_piped_stdin("Universität Tübingen".as_bytes());
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert_eq!(result.stdout, assert_eq!(result.stdout,

View file

@ -1,16 +1,17 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "paste"; static UTIL_NAME: &'static str = "paste";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_combine_pairs_of_lines() { fn test_combine_pairs_of_lines() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let out = ucmd.arg("-s") .arg("-s")
.arg("-d") .arg("-d")
.arg("\t\n") .arg("\t\n")
.arg("html_colors.txt") .arg("html_colors.txt")
.run() .run()
.stdout; .stdout_is_fixture("html_colors.expected");
assert_eq!(out, at.read("html_colors.expected"));
} }

View file

@ -1,21 +1,24 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "pathchk"; static UTIL_NAME: &'static str = "pathchk";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_default_mode() { fn test_default_mode() {
// test the default mode // test the default mode
{ {
// accept some reasonable default // accept some reasonable default
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["abc/def"]).run(); .args(&["abc/def"]).run();
assert_eq!(result.stdout, ""); assert_eq!(result.stdout, "");
assert!(result.success); assert!(result.success);
} }
{ {
// fail on long inputs // fail on long inputs
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&[repeat_str("test", 20000)]).run(); .args(&[repeat_str("test", 20000)]).run();
assert_eq!(result.stdout, ""); assert_eq!(result.stdout, "");
assert!(!result.success); assert!(!result.success);
} }

View file

@ -1,6 +1,9 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "pinky"; static UTIL_NAME: &'static str = "pinky";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
extern crate uu_pinky; extern crate uu_pinky;
pub use self::uu_pinky::*; pub use self::uu_pinky::*;
@ -16,65 +19,54 @@ fn test_capitalize() {
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_long_format() { fn test_long_format() {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-l").arg("root"); .arg("-l").arg("root")
let expected = "Login name: root In real life: root\nDirectory: /root Shell: /bin/bash\n\n"; .run()
assert_eq!(expected, ucmd.run().stdout); .stdout_is("Login name: root In real life: root\nDirectory: /root Shell: /bin/bash\n\n");
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-lb").arg("root"); .arg("-lb").arg("root")
let expected = "Login name: root In real life: root\n\n"; .run()
assert_eq!(expected, ucmd.run().stdout); .stdout_is("Login name: root In real life: root\n\n");
} }
#[test] #[test]
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
fn test_long_format() { fn test_long_format() {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-l").arg("root"); .arg("-l").arg("root")
let expected = "Login name: root In real life: System Administrator\nDirectory: /var/root Shell: /bin/sh\n\n"; .run()
assert_eq!(expected, ucmd.run().stdout); .stdout_is("Login name: root In real life: System Administrator\nDirectory: /var/root Shell: /bin/sh\n\n");
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-lb").arg("root"); .arg("-lb").arg("root")
let expected = "Login name: root In real life: System Administrator\n\n"; .run()
assert_eq!(expected, ucmd.run().stdout); .stdout_is("Login name: root In real life: System Administrator\n\n");
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
#[test] #[test]
#[ignore] #[ignore]
fn test_short_format() { fn test_short_format() {
let (_, mut ucmd) = testing(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let args = ["-s"]; let args = ["-s"];
ucmd.args(&args); scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
assert_eq!(expected_result(&args), ucmd.run().stdout);
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-f"]; let args = ["-f"];
ucmd.args(&args); scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
assert_eq!(expected_result(&args), ucmd.run().stdout);
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-w"]; let args = ["-w"];
ucmd.args(&args); scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
assert_eq!(expected_result(&args), ucmd.run().stdout);
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-i"]; let args = ["-i"];
ucmd.args(&args); scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
assert_eq!(expected_result(&args), ucmd.run().stdout);
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-q"]; let args = ["-q"];
ucmd.args(&args); scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
assert_eq!(expected_result(&args), ucmd.run().stdout);
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn expected_result(args: &[&str]) -> String { fn expected_result(args: &[&str]) -> String {
use std::process::Command; TestScenario::new(UTIL_NAME).cmd(UTIL_NAME).args(args).run().stdout
let output = Command::new(UTIL_NAME).args(args).output().unwrap();
String::from_utf8_lossy(&output.stdout).into_owned()
} }

View file

@ -1,10 +1,13 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "printf"; static UTIL_NAME: &'static str = "printf";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
fn expect_stdout(input: Vec<&str>, expected: &str) { fn expect_stdout(input: Vec<&str>, expected: &str) {
let (_, mut ucmd) = testing(UTIL_NAME); let results = new_ucmd()
let results = ucmd.args(&input).run(); .args(&input).run();
// assert_empty_stderr!(result); // assert_empty_stderr!(result);
// assert!(result.success); // assert!(result.success);
assert_eq!(expected, results.stdout); assert_eq!(expected, results.stdout);

View file

@ -1,6 +1,9 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "ptx"; static UTIL_NAME: &'static str = "ptx";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn gnu_ext_disabled_roff_no_ref() { fn gnu_ext_disabled_roff_no_ref() {
@ -45,9 +48,5 @@ fn gnu_ext_disabled_ignore_and_only_file() {
} }
fn test_ptx(opts: &Vec<&str>, expected: &str) { fn test_ptx(opts: &Vec<&str>, expected: &str) {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().args(opts).arg("input").succeeds().stdout_only_fixture(expected);
let result = ucmd.args(opts).arg("input").run();
assert!(result.success);
assert_eq!(result.stdout, at.read(expected));
assert_empty_stderr!(&result);
} }

View file

@ -1,10 +1,15 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "pwd"; static UTIL_NAME: &'static str = "pwd";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
#[test] #[test]
fn test_default() { fn test_default() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let out = ucmd.run().stdout; let out = ucmd.run().stdout;
let expected = at.root_dir_resolved(); let expected = at.root_dir_resolved();

View file

@ -1,12 +1,20 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "readlink"; static UTIL_NAME: &'static str = "readlink";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
static GIBBERISH: &'static str = "supercalifragilisticexpialidocious"; static GIBBERISH: &'static str = "supercalifragilisticexpialidocious";
#[test] #[test]
fn test_canonicalize() { fn test_canonicalize() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let out = ucmd.arg("-f") let out = ucmd.arg("-f")
.arg(".") .arg(".")
.run() .run()
@ -17,7 +25,7 @@ fn test_canonicalize() {
#[test] #[test]
fn test_canonicalize_existing() { fn test_canonicalize_existing() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let out = ucmd.arg("-e") let out = ucmd.arg("-e")
.arg(".") .arg(".")
.run() .run()
@ -28,7 +36,7 @@ fn test_canonicalize_existing() {
#[test] #[test]
fn test_canonicalize_missing() { fn test_canonicalize_missing() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let expected = path_concat!(at.root_dir_resolved(), GIBBERISH); let expected = path_concat!(at.root_dir_resolved(), GIBBERISH);
let out = ucmd.arg("-m") let out = ucmd.arg("-m")
@ -41,7 +49,7 @@ fn test_canonicalize_missing() {
#[test] #[test]
fn test_long_redirection_to_current_dir() { fn test_long_redirection_to_current_dir() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
// Create a 256-character path to current directory // Create a 256-character path to current directory
let dir = path_concat!(".", ..128); let dir = path_concat!(".", ..128);
let out = ucmd.arg("-n") let out = ucmd.arg("-n")
@ -55,10 +63,10 @@ fn test_long_redirection_to_current_dir() {
#[test] #[test]
fn test_long_redirection_to_root() { fn test_long_redirection_to_root() {
let (_, mut ucmd) = testing(UTIL_NAME);
// Create a 255-character path to root // Create a 255-character path to root
let dir = path_concat!("..", ..85); let dir = path_concat!("..", ..85);
let out = ucmd.arg("-n") let out = new_ucmd()
.arg("-n")
.arg("-m") .arg("-m")
.arg(dir) .arg(dir)
.run() .run()

View file

@ -1,10 +1,18 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "realpath"; static UTIL_NAME: &'static str = "realpath";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_current_directory() { fn test_current_directory() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let out = ucmd.arg(".").run().stdout; let out = ucmd.arg(".").run().stdout;
assert_eq!(out.trim_right(), at.root_dir_resolved()); assert_eq!(out.trim_right(), at.root_dir_resolved());
@ -12,7 +20,7 @@ fn test_current_directory() {
#[test] #[test]
fn test_long_redirection_to_current_dir() { fn test_long_redirection_to_current_dir() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
// Create a 256-character path to current directory // Create a 256-character path to current directory
let dir = path_concat!(".", ..128); let dir = path_concat!(".", ..128);
let out = ucmd.arg(dir).run().stdout; let out = ucmd.arg(dir).run().stdout;
@ -22,10 +30,9 @@ fn test_long_redirection_to_current_dir() {
#[test] #[test]
fn test_long_redirection_to_root() { fn test_long_redirection_to_root() {
let (_, mut ucmd) = testing(UTIL_NAME);
// Create a 255-character path to root // Create a 255-character path to root
let dir = path_concat!("..", ..85); let dir = path_concat!("..", ..85);
let out = ucmd.arg(dir).run().stdout; let out = new_ucmd().arg(dir).run().stdout;
assert_eq!(out.trim_right(), get_root_path()); assert_eq!(out.trim_right(), get_root_path());
} }

View file

@ -1,10 +1,15 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "rm"; static UTIL_NAME: &'static str = "rm";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
#[test] #[test]
fn test_rm_one_file() { fn test_rm_one_file() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_rm_one_file"; let file = "test_rm_one_file";
at.touch(file); at.touch(file);
@ -18,7 +23,7 @@ fn test_rm_one_file() {
#[test] #[test]
fn test_rm_multiple_files() { fn test_rm_multiple_files() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file_a = "test_rm_multiple_file_a"; let file_a = "test_rm_multiple_file_a";
let file_b = "test_rm_multiple_file_b"; let file_b = "test_rm_multiple_file_b";
@ -35,8 +40,8 @@ fn test_rm_multiple_files() {
#[test] #[test]
fn test_rm_interactive() { fn test_rm_interactive() {
let ts = TestSet::new(UTIL_NAME); let scene = TestScenario::new(UTIL_NAME);
let at = &ts.fixtures; let at = &scene.fixtures;
let file_a = "test_rm_interactive_file_a"; let file_a = "test_rm_interactive_file_a";
let file_b = "test_rm_interactive_file_b"; let file_b = "test_rm_interactive_file_b";
@ -44,7 +49,7 @@ fn test_rm_interactive() {
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
let result1 = ts.util_cmd() let result1 = scene.ucmd()
.arg("-i") .arg("-i")
.arg(file_a) .arg(file_a)
.arg(file_b) .arg(file_b)
@ -55,7 +60,7 @@ fn test_rm_interactive() {
assert!(at.file_exists(file_a)); assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b)); assert!(at.file_exists(file_b));
let result2 = ts.util_cmd() let result2 = scene.ucmd()
.arg("-i") .arg("-i")
.arg(file_a) .arg(file_a)
.arg(file_b) .arg(file_b)
@ -69,7 +74,7 @@ fn test_rm_interactive() {
#[test] #[test]
fn test_rm_force() { fn test_rm_force() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file_a = "test_rm_force_a"; let file_a = "test_rm_force_a";
let file_b = "test_rm_force_b"; let file_b = "test_rm_force_b";
@ -86,7 +91,7 @@ fn test_rm_force() {
#[test] #[test]
fn test_rm_empty_directory() { fn test_rm_empty_directory() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rm_empty_directory"; let dir = "test_rm_empty_directory";
at.mkdir(dir); at.mkdir(dir);
@ -100,7 +105,7 @@ fn test_rm_empty_directory() {
#[test] #[test]
fn test_rm_recursive() { fn test_rm_recursive() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rm_recursive_directory"; let dir = "test_rm_recursive_directory";
let file_a = "test_rm_recursive_directory/test_rm_recursive_file_a"; let file_a = "test_rm_recursive_directory/test_rm_recursive_file_a";
let file_b = "test_rm_recursive_directory/test_rm_recursive_file_b"; let file_b = "test_rm_recursive_directory/test_rm_recursive_file_b";
@ -120,7 +125,7 @@ fn test_rm_recursive() {
#[test] #[test]
fn test_rm_errors() { fn test_rm_errors() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rm_errors_directory"; let dir = "test_rm_errors_directory";
let file_a = "test_rm_errors_directory/test_rm_errors_file_a"; let file_a = "test_rm_errors_directory/test_rm_errors_file_a";
let file_b = "test_rm_errors_directory/test_rm_errors_file_b"; let file_b = "test_rm_errors_directory/test_rm_errors_file_b";
@ -140,7 +145,7 @@ fn test_rm_errors() {
#[test] #[test]
fn test_rm_verbose() { fn test_rm_verbose() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file_a = "test_rm_verbose_file_a"; let file_a = "test_rm_verbose_file_a";
let file_b = "test_rm_verbose_file_b"; let file_b = "test_rm_verbose_file_b";

View file

@ -3,10 +3,15 @@ extern crate libc;
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "rmdir"; 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] #[test]
fn test_rmdir_empty_directory_no_parents() { fn test_rmdir_empty_directory_no_parents() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rmdir_empty_no_parents"; let dir = "test_rmdir_empty_no_parents";
at.mkdir(dir); at.mkdir(dir);
@ -21,7 +26,7 @@ fn test_rmdir_empty_directory_no_parents() {
#[test] #[test]
fn test_rmdir_empty_directory_with_parents() { fn test_rmdir_empty_directory_with_parents() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rmdir_empty/with/parents"; let dir = "test_rmdir_empty/with/parents";
at.mkdir_all(dir); at.mkdir_all(dir);
@ -36,7 +41,7 @@ fn test_rmdir_empty_directory_with_parents() {
#[test] #[test]
fn test_rmdir_nonempty_directory_no_parents() { fn test_rmdir_nonempty_directory_no_parents() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rmdir_nonempty_no_parents"; let dir = "test_rmdir_nonempty_no_parents";
let file = "test_rmdir_nonempty_no_parents/foo"; let file = "test_rmdir_nonempty_no_parents/foo";
@ -57,7 +62,7 @@ fn test_rmdir_nonempty_directory_no_parents() {
#[test] #[test]
fn test_rmdir_nonempty_directory_with_parents() { fn test_rmdir_nonempty_directory_with_parents() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rmdir_nonempty/with/parents"; let dir = "test_rmdir_nonempty/with/parents";
let file = "test_rmdir_nonempty/with/parents/foo"; let file = "test_rmdir_nonempty/with/parents/foo";
@ -80,7 +85,7 @@ fn test_rmdir_nonempty_directory_with_parents() {
#[test] #[test]
fn test_rmdir_ignore_nonempty_directory_no_parents() { fn test_rmdir_ignore_nonempty_directory_no_parents() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rmdir_ignore_nonempty_no_parents"; let dir = "test_rmdir_ignore_nonempty_no_parents";
let file = "test_rmdir_ignore_nonempty_no_parents/foo"; let file = "test_rmdir_ignore_nonempty_no_parents/foo";
@ -99,7 +104,7 @@ fn test_rmdir_ignore_nonempty_directory_no_parents() {
#[test] #[test]
fn test_rmdir_ignore_nonempty_directory_with_parents() { fn test_rmdir_ignore_nonempty_directory_with_parents() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_rmdir_ignore_nonempty/with/parents"; let dir = "test_rmdir_ignore_nonempty/with/parents";
let file = "test_rmdir_ignore_nonempty/with/parents/foo"; let file = "test_rmdir_ignore_nonempty/with/parents/foo";

View file

@ -1,31 +1,34 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "seq"; static UTIL_NAME: &'static str = "seq";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_count_up() { fn test_count_up() {
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.args(&["10"]).run().stdout; .args(&["10"]).run().stdout;
assert_eq!(out, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"); assert_eq!(out, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n");
} }
#[test] #[test]
fn test_count_down() { fn test_count_down() {
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.args(&["--", "5", "-1", "1"]).run().stdout; .args(&["--", "5", "-1", "1"]).run().stdout;
assert_eq!(out, "5\n4\n3\n2\n1\n"); assert_eq!(out, "5\n4\n3\n2\n1\n");
} }
#[test] #[test]
fn test_separator_and_terminator() { fn test_separator_and_terminator() {
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.args(&["-s", ",", "-t", "!", "2", "6"]).run().stdout; .args(&["-s", ",", "-t", "!", "2", "6"]).run().stdout;
assert_eq!(out, "2,3,4,5,6!"); assert_eq!(out, "2,3,4,5,6!");
} }
#[test] #[test]
fn test_equalize_widths() { fn test_equalize_widths() {
let (_, mut ucmd) = testing(UTIL_NAME); let out = new_ucmd()
let out = ucmd.args(&["-w", "5", "10"]).run().stdout; .args(&["-w", "5", "10"]).run().stdout;
assert_eq!(out, "05\n06\n07\n08\n09\n10\n"); assert_eq!(out, "05\n06\n07\n08\n09\n10\n");
} }

View file

@ -2,6 +2,10 @@ use common::util::*;
static UTIL_NAME: &'static str = "sort"; static UTIL_NAME: &'static str = "sort";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_numeric_floats_and_ints() { fn test_numeric_floats_and_ints() {
test_helper("numeric_floats_and_ints", "-n"); test_helper("numeric_floats_and_ints", "-n");
@ -54,39 +58,27 @@ fn test_version() {
#[test] #[test]
fn test_multiple_files() { fn test_multiple_files() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-n"); .arg("-n")
ucmd.arg("multiple_files1.txt"); .arg("multiple_files1.txt")
ucmd.arg("multiple_files2.txt"); .arg("multiple_files2.txt")
let res = ucmd.run(); .succeeds().stdout_is_fixture("multiple_files.expected");
assert_eq!(res.success, true);
assert_eq!(res.stdout, at.read("multiple_files.expected"));
} }
#[test] #[test]
fn test_check() { fn test_check() {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-c"); .arg("-c")
let res = ucmd.arg("check_fail.txt").run(); .arg("check_fail.txt")
.fails().stdout_is("sort: disorder in line 4\n");
assert_eq!(res.success, false); new_ucmd()
assert_eq!(res.stdout, "sort: disorder in line 4\n"); .arg("-c")
.arg("multiple_files.expected")
let (_, mut ucmd) = testing(UTIL_NAME); .succeeds().stdout_is("");
ucmd.arg("-c");
let res = ucmd.arg("multiple_files.expected").run();
assert_eq!(res.success, true);
assert_eq!(res.stdout, "");
} }
fn test_helper(file_name: &str, args: &str) { fn test_helper(file_name: &str, args: &str) {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().arg(args).arg(format!("{}{}", file_name, ".txt"))
ucmd.arg(args); .succeeds().stdout_is_fixture(format!("{}{}", file_name, ".expected"));
let res = ucmd.arg(format!("{}{}", file_name, ".txt")).run();
assert_eq!(res.success, true);
let filename = format!("{}{}", file_name, ".expected");
assert_eq!(res.stdout, at.read(&filename));
} }

View file

@ -9,6 +9,11 @@ use regex::Regex;
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "split"; static UTIL_NAME: &'static str = "split";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
fn random_chars(n: usize) -> String { fn random_chars(n: usize) -> String {
thread_rng().gen_ascii_chars().take(n).collect::<String>() thread_rng().gen_ascii_chars().take(n).collect::<String>()
@ -92,7 +97,7 @@ impl RandomFile {
#[test] #[test]
fn test_split_default() { fn test_split_default() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let name = "split_default"; let name = "split_default";
let glob = Glob::new(&at, ".", r"x[:alpha:][:alpha:]$"); let glob = Glob::new(&at, ".", r"x[:alpha:][:alpha:]$");
RandomFile::new(&at, name).add_lines(2000); RandomFile::new(&at, name).add_lines(2000);
@ -103,7 +108,7 @@ fn test_split_default() {
#[test] #[test]
fn test_split_num_prefixed_chunks_by_bytes() { fn test_split_num_prefixed_chunks_by_bytes() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let name = "split_num_prefixed_chunks_by_bytes"; let name = "split_num_prefixed_chunks_by_bytes";
let glob = Glob::new(&at, ".", r"a\d\d$"); let glob = Glob::new(&at, ".", r"a\d\d$");
RandomFile::new(&at, name).add_bytes(10000); RandomFile::new(&at, name).add_bytes(10000);
@ -114,7 +119,7 @@ fn test_split_num_prefixed_chunks_by_bytes() {
#[test] #[test]
fn test_split_str_prefixed_chunks_by_bytes() { fn test_split_str_prefixed_chunks_by_bytes() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let name = "split_str_prefixed_chunks_by_bytes"; let name = "split_str_prefixed_chunks_by_bytes";
let glob = Glob::new(&at, ".", r"b[:alpha:][:alpha:]$"); let glob = Glob::new(&at, ".", r"b[:alpha:][:alpha:]$");
RandomFile::new(&at, name).add_bytes(10000); RandomFile::new(&at, name).add_bytes(10000);
@ -125,7 +130,7 @@ fn test_split_str_prefixed_chunks_by_bytes() {
#[test] #[test]
fn test_split_num_prefixed_chunks_by_lines() { fn test_split_num_prefixed_chunks_by_lines() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let name = "split_num_prefixed_chunks_by_lines"; let name = "split_num_prefixed_chunks_by_lines";
let glob = Glob::new(&at, ".", r"c\d\d$"); let glob = Glob::new(&at, ".", r"c\d\d$");
RandomFile::new(&at, name).add_lines(10000); RandomFile::new(&at, name).add_lines(10000);
@ -136,7 +141,7 @@ fn test_split_num_prefixed_chunks_by_lines() {
#[test] #[test]
fn test_split_str_prefixed_chunks_by_lines() { fn test_split_str_prefixed_chunks_by_lines() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let name = "split_str_prefixed_chunks_by_lines"; let name = "split_str_prefixed_chunks_by_lines";
let glob = Glob::new(&at, ".", r"d[:alpha:][:alpha:]$"); let glob = Glob::new(&at, ".", r"d[:alpha:][:alpha:]$");
RandomFile::new(&at, name).add_lines(10000); RandomFile::new(&at, name).add_lines(10000);

View file

@ -4,6 +4,9 @@ extern crate uu_stat;
pub use self::uu_stat::*; pub use self::uu_stat::*;
static UTIL_NAME: &'static str = "stat"; static UTIL_NAME: &'static str = "stat";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[cfg(test)] #[cfg(test)]
mod test_fsext { mod test_fsext {
@ -140,9 +143,8 @@ mod test_generate_tokens {
#[test] #[test]
fn test_invalid_option() { fn test_invalid_option() {
let (_, mut ucmd) = testing(UTIL_NAME); new_ucmd()
ucmd.arg("-w").arg("-q").arg("/"); .arg("-w").arg("-q").arg("/").fails();
ucmd.fails();
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
@ -155,82 +157,82 @@ const FS_FMTSTR: &'static str = "%a %b %c %d %f %i %l %n %s %S %t %T";
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_terse_fs_format() { fn test_terse_fs_format() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-f", "-t", "/proc"]; let args = ["-f", "-t", "/proc"];
ucmd.args(&args); new_ucmd().args(&args)
assert_eq!(ucmd.run().stdout, expected_result(&args)); .run()
.stdout_is(expected_result(&args));
} }
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_fs_format() { fn test_fs_format() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-f", "-c", FS_FMTSTR, "/dev/shm"]; let args = ["-f", "-c", FS_FMTSTR, "/dev/shm"];
ucmd.args(&args); new_ucmd().args(&args)
assert_eq!(ucmd.run().stdout, expected_result(&args)); .run()
.stdout_is(expected_result(&args));
} }
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_terse_normal_format() { fn test_terse_normal_format() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-t", "/"]; let args = ["-t", "/"];
ucmd.args(&args); new_ucmd().args(&args)
assert_eq!(ucmd.run().stdout, expected_result(&args)); .run()
.stdout_is(expected_result(&args));
} }
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_normal_format() { fn test_normal_format() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-c", NORMAL_FMTSTR, "/boot"]; let args = ["-c", NORMAL_FMTSTR, "/boot"];
ucmd.args(&args); new_ucmd().args(&args)
assert_eq!(ucmd.run().stdout, expected_result(&args)); .run()
.stdout_is(expected_result(&args));
} }
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_follow_symlink() { fn test_follow_symlink() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-L", "-c", DEV_FMTSTR, "/dev/cdrom"]; let args = ["-L", "-c", DEV_FMTSTR, "/dev/cdrom"];
ucmd.args(&args); new_ucmd().args(&args)
assert_eq!(ucmd.run().stdout, expected_result(&args)); .run()
.stdout_is(expected_result(&args));
} }
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_symlink() { fn test_symlink() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-c", DEV_FMTSTR, "/dev/cdrom"]; let args = ["-c", DEV_FMTSTR, "/dev/cdrom"];
ucmd.args(&args); new_ucmd().args(&args)
assert_eq!(ucmd.run().stdout, expected_result(&args)); .run()
.stdout_is(expected_result(&args));
} }
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_char() { fn test_char() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-c", DEV_FMTSTR, "/dev/zero"]; let args = ["-c", DEV_FMTSTR, "/dev/zero"];
ucmd.args(&args); new_ucmd().args(&args)
assert_eq!(ucmd.run().stdout, expected_result(&args)); .run()
.stdout_is(expected_result(&args));
} }
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_multi_files() { fn test_multi_files() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-c", NORMAL_FMTSTR, "/dev", "/usr/lib", "/etc/fstab", "/var"]; let args = ["-c", NORMAL_FMTSTR, "/dev", "/usr/lib", "/etc/fstab", "/var"];
ucmd.args(&args); new_ucmd().args(&args)
assert_eq!(ucmd.run().stdout, expected_result(&args)); .run()
.stdout_is(expected_result(&args));
} }
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_printf() { fn test_printf() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["--printf=123%-# 15q\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.23m\\x12\\167\\132\\112\\n", "/"]; let args = ["--printf=123%-# 15q\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.23m\\x12\\167\\132\\112\\n", "/"];
ucmd.args(&args); new_ucmd().args(&args)
assert_eq!(ucmd.run().stdout, "123?\r\"\\\x07\x08\x1B\x0C\x0B /\x12wZJ\n"); .run()
.stdout_is(expected_result(&args));
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]

View file

@ -1,13 +1,15 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "stdbuf"; static UTIL_NAME: &'static str = "stdbuf";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_stdbuf_unbuffered_stdout() { fn test_stdbuf_unbuffered_stdout() {
if cfg!(target_os="linux") { if cfg!(target_os="linux") {
let (_, mut ucmd) = testing(UTIL_NAME);
// This is a basic smoke test // This is a basic smoke test
let result = ucmd.args(&["-o0", "head"]) let result = new_ucmd().args(&["-o0", "head"])
.run_piped_stdin("The quick brown fox jumps over the lazy dog."); .run_piped_stdin("The quick brown fox jumps over the lazy dog.");
assert_eq!(result.stdout, assert_eq!(result.stdout,
"The quick brown fox jumps over the lazy dog."); "The quick brown fox jumps over the lazy dog.");

View file

@ -1,70 +1,52 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "sum"; static UTIL_NAME: &'static str = "sum";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_bsd_single_file() { fn test_bsd_single_file() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.arg("lorem_ipsum.txt").run(); .arg("lorem_ipsum.txt")
.succeeds().stdout_only_fixture("bsd_single_file.expected");
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, at.read("bsd_single_file.expected"));
} }
#[test] #[test]
fn test_bsd_multiple_files() { fn test_bsd_multiple_files() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.arg("lorem_ipsum.txt") .arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt") .arg("alice_in_wonderland.txt")
.run(); .succeeds().stdout_only_fixture("bsd_multiple_files.expected");
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, at.read("bsd_multiple_files.expected"));
} }
#[test] #[test]
fn test_bsd_stdin() { fn test_bsd_stdin() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let input = at.read("lorem_ipsum.txt"); .pipe_in_fixture("lorem_ipsum.txt")
let result = ucmd.run_piped_stdin(input); .succeeds().stdout_only_fixture("bsd_stdin.expected");
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, at.read("bsd_stdin.expected"));
} }
#[test] #[test]
fn test_sysv_single_file() { fn test_sysv_single_file() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.arg("-s").arg("lorem_ipsum.txt").run(); .arg("-s").arg("lorem_ipsum.txt")
.succeeds().stdout_only_fixture("sysv_single_file.expected");
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, at.read("sysv_single_file.expected"));
} }
#[test] #[test]
fn test_sysv_multiple_files() { fn test_sysv_multiple_files() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.arg("-s") .arg("-s")
.arg("lorem_ipsum.txt") .arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt") .arg("alice_in_wonderland.txt")
.run(); .succeeds().stdout_only_fixture("sysv_multiple_files.expected");
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, at.read("sysv_multiple_files.expected"));
} }
#[test] #[test]
fn test_sysv_stdin() { fn test_sysv_stdin() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let input = at.read("lorem_ipsum.txt"); .arg("-s")
let result = ucmd.arg("-s").run_piped_stdin(input); .pipe_in_fixture("lorem_ipsum.txt")
.succeeds().stdout_only_fixture("sysv_stdin.expected");
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, at.read("sysv_stdin.expected"));
} }

View file

@ -1,45 +1,45 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "tac"; static UTIL_NAME: &'static str = "tac";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_stdin_default() { fn test_stdin_default() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.run_piped_stdin("100\n200\n300\n400\n500"); .run_piped_stdin("100\n200\n300\n400\n500");
assert_eq!(result.stdout, "500400\n300\n200\n100\n"); assert_eq!(result.stdout, "500400\n300\n200\n100\n");
} }
#[test] #[test]
fn test_stdin_non_newline_separator() { fn test_stdin_non_newline_separator() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-s", ":"]).run_piped_stdin("100:200:300:400:500"); .args(&["-s", ":"]).run_piped_stdin("100:200:300:400:500");
assert_eq!(result.stdout, "500400:300:200:100:"); assert_eq!(result.stdout, "500400:300:200:100:");
} }
#[test] #[test]
fn test_stdin_non_newline_separator_before() { fn test_stdin_non_newline_separator_before() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-b", "-s", ":"]).run_piped_stdin("100:200:300:400:500"); .args(&["-b", "-s", ":"]).run_piped_stdin("100:200:300:400:500");
assert_eq!(result.stdout, "500:400:300:200:100"); assert_eq!(result.stdout, "500:400:300:200:100");
} }
#[test] #[test]
fn test_single_default() { fn test_single_default() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().arg("prime_per_line.txt")
let result = ucmd.arg("prime_per_line.txt").run(); .run().stdout_is_fixture("prime_per_line.expected");
assert_eq!(result.stdout, at.read("prime_per_line.expected"));
} }
#[test] #[test]
fn test_single_non_newline_separator() { fn test_single_non_newline_separator() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().args(&["-s", ":", "delimited_primes.txt"])
let result = ucmd.args(&["-s", ":", "delimited_primes.txt"]).run(); .run().stdout_is_fixture("delimited_primes.expected");
assert_eq!(result.stdout, at.read("delimited_primes.expected"));
} }
#[test] #[test]
fn test_single_non_newline_separator_before() { fn test_single_non_newline_separator_before() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().args(&["-b", "-s", ":", "delimited_primes.txt"])
let result = ucmd.args(&["-b", "-s", ":", "delimited_primes.txt"]).run(); .run().stdout_is_fixture("delimited_primes_before.expected");
assert_eq!(result.stdout, at.read("delimited_primes_before.expected"));
} }

View file

@ -6,6 +6,14 @@ use std::io::Write;
use self::uu_tail::parse_size; use self::uu_tail::parse_size;
static UTIL_NAME: &'static str = "tail"; static UTIL_NAME: &'static str = "tail";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
static FOOBAR_TXT: &'static str = "foobar.txt"; static FOOBAR_TXT: &'static str = "foobar.txt";
static FOOBAR_2_TXT: &'static str = "foobar2.txt"; static FOOBAR_2_TXT: &'static str = "foobar2.txt";
@ -13,35 +21,28 @@ static FOOBAR_WITH_NULL_TXT: &'static str = "foobar_with_null.txt";
#[test] #[test]
fn test_stdin_default() { fn test_stdin_default() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().pipe_in_fixture(FOOBAR_TXT).run().stdout_is_fixture("foobar_stdin_default.expected");
let result = ucmd.run_piped_stdin(at.read(FOOBAR_TXT));
assert_eq!(result.stdout, at.read("foobar_stdin_default.expected"));
} }
#[test] #[test]
fn test_single_default() { fn test_single_default() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().arg(FOOBAR_TXT).run().stdout_is_fixture("foobar_single_default.expected");
let result = ucmd.arg(FOOBAR_TXT).run();
assert_eq!(result.stdout, at.read("foobar_single_default.expected"));
} }
#[test] #[test]
fn test_n_greater_than_number_of_lines() { fn test_n_greater_than_number_of_lines() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().arg("-n").arg("99999999").arg(FOOBAR_TXT).run()
let result = ucmd.arg("-n").arg("99999999").arg(FOOBAR_TXT).run(); .stdout_is_fixture(FOOBAR_TXT);
assert_eq!(result.stdout, at.read(FOOBAR_TXT));
} }
#[test] #[test]
fn test_null_default() { fn test_null_default() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().arg("-z").arg(FOOBAR_WITH_NULL_TXT).run().stdout_is_fixture("foobar_with_null_default.expected");
let result = ucmd.arg("-z").arg(FOOBAR_WITH_NULL_TXT).run();
assert_eq!(result.stdout, at.read("foobar_with_null_default.expected"));
} }
#[test] #[test]
fn test_follow() { fn test_follow() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let mut child = ucmd.arg("-f").arg(FOOBAR_TXT).run_no_wait(); let mut child = ucmd.arg("-f").arg(FOOBAR_TXT).run_no_wait();
@ -59,7 +60,7 @@ fn test_follow() {
#[test] #[test]
fn test_follow_multiple() { fn test_follow_multiple() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let mut child = ucmd.arg("-f").arg(FOOBAR_TXT).arg(FOOBAR_2_TXT).run_no_wait(); let mut child = ucmd.arg("-f").arg(FOOBAR_TXT).arg(FOOBAR_2_TXT).run_no_wait();
let expected = at.read("foobar_follow_multiple.expected"); let expected = at.read("foobar_follow_multiple.expected");
@ -79,7 +80,7 @@ fn test_follow_multiple() {
#[test] #[test]
fn test_follow_stdin() { fn test_follow_stdin() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let mut child = ucmd.arg("-f").pipe_in(at.read(FOOBAR_TXT)).run_no_wait(); let mut child = ucmd.arg("-f").pipe_in(at.read(FOOBAR_TXT)).run_no_wait();
let expected = at.read("follow_stdin.expected"); let expected = at.read("follow_stdin.expected");
@ -95,7 +96,7 @@ fn test_single_big_args() {
const LINES: usize = 1_000_000; const LINES: usize = 1_000_000;
const N_ARG: usize = 100_000; const N_ARG: usize = 100_000;
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let mut big_input = at.make_file(FILE); let mut big_input = at.make_file(FILE);
for i in 0..LINES { for i in 0..LINES {
@ -115,16 +116,14 @@ fn test_single_big_args() {
#[test] #[test]
fn test_bytes_single() { fn test_bytes_single() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().arg("-c").arg("10").arg(FOOBAR_TXT).run()
let result = ucmd.arg("-c").arg("10").arg(FOOBAR_TXT).run(); .stdout_is_fixture("foobar_bytes_single.expected");
assert_eq!(result.stdout, at.read("foobar_bytes_single.expected"));
} }
#[test] #[test]
fn test_bytes_stdin() { fn test_bytes_stdin() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd().arg("-c").arg("13").pipe_in_fixture(FOOBAR_TXT).run()
let result = ucmd.arg("-c").arg("13").run_piped_stdin(at.read(FOOBAR_TXT)); .stdout_is_fixture("foobar_bytes_stdin.expected");
assert_eq!(result.stdout, at.read("foobar_bytes_stdin.expected"));
} }
#[test] #[test]
@ -134,7 +133,7 @@ fn test_bytes_big() {
const BYTES: usize = 1_000_000; const BYTES: usize = 1_000_000;
const N_ARG: usize = 100_000; const N_ARG: usize = 100_000;
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let mut big_input = at.make_file(FILE); let mut big_input = at.make_file(FILE);
for i in 0..BYTES { for i in 0..BYTES {
@ -201,7 +200,7 @@ fn test_lines_with_size_suffix() {
const LINES: usize = 3_000; const LINES: usize = 3_000;
const N_ARG: usize = 2 * 1024; const N_ARG: usize = 2 * 1024;
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let mut big_input = at.make_file(FILE); let mut big_input = at.make_file(FILE);
for i in 0..LINES { for i in 0..LINES {

View file

@ -10,11 +10,14 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "test"; static UTIL_NAME: &'static str = "test";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_op_prec_and_or_1() { fn test_op_prec_and_or_1() {
let (_, mut ucmd) = testing(UTIL_NAME); let exit_success = new_ucmd()
let exit_success = ucmd.arg(" ") .arg(" ")
.arg("-o") .arg("-o")
.arg("") .arg("")
.arg("-a") .arg("-a")
@ -26,8 +29,8 @@ fn test_op_prec_and_or_1() {
#[test] #[test]
fn test_op_prec_and_or_2() { fn test_op_prec_and_or_2() {
let (_, mut ucmd) = testing(UTIL_NAME); let exit_success = new_ucmd()
let exit_success = ucmd.arg("") .arg("")
.arg("-a") .arg("-a")
.arg("") .arg("")
.arg("-o") .arg("-o")
@ -41,8 +44,8 @@ fn test_op_prec_and_or_2() {
#[test] #[test]
fn test_or_as_filename() { fn test_or_as_filename() {
let (_, mut ucmd) = testing(UTIL_NAME); let exit_success = new_ucmd()
let exit_success = ucmd.arg("x") .arg("x")
.arg("-a") .arg("-a")
.arg("-z") .arg("-z")
.arg("-o") .arg("-o")

View file

@ -5,6 +5,11 @@ use common::util::*;
use self::filetime::FileTime; use self::filetime::FileTime;
static UTIL_NAME: &'static str = "touch"; static UTIL_NAME: &'static str = "touch";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
fn get_file_times(at: &AtPath, path: &str) -> (FileTime, FileTime) { fn get_file_times(at: &AtPath, path: &str) -> (FileTime, FileTime) {
let m = at.metadata(path); let m = at.metadata(path);
@ -26,7 +31,7 @@ fn str_to_filetime(format: &str, s: &str) -> FileTime {
#[test] #[test]
fn test_touch_default() { fn test_touch_default() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_touch_default_file"; let file = "test_touch_default_file";
let result = ucmd.arg(file).run(); let result = ucmd.arg(file).run();
@ -38,7 +43,7 @@ fn test_touch_default() {
#[test] #[test]
fn test_touch_no_create_file_absent() { fn test_touch_no_create_file_absent() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_touch_no_create_file_absent"; let file = "test_touch_no_create_file_absent";
let result = ucmd.arg("-c").arg(file).run(); let result = ucmd.arg("-c").arg(file).run();
@ -50,7 +55,7 @@ fn test_touch_no_create_file_absent() {
#[test] #[test]
fn test_touch_no_create_file_exists() { fn test_touch_no_create_file_exists() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_touch_no_create_file_exists"; let file = "test_touch_no_create_file_exists";
at.touch(file); at.touch(file);
@ -65,7 +70,7 @@ fn test_touch_no_create_file_exists() {
#[test] #[test]
fn test_touch_set_mdhm_time() { fn test_touch_set_mdhm_time() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_touch_set_mdhm_time"; let file = "test_touch_set_mdhm_time";
let result = ucmd.args(&["-t", "01011234", file]).run(); let result = ucmd.args(&["-t", "01011234", file]).run();
@ -85,7 +90,7 @@ fn test_touch_set_mdhm_time() {
#[test] #[test]
fn test_touch_set_mdhms_time() { fn test_touch_set_mdhms_time() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_touch_set_mdhms_time"; let file = "test_touch_set_mdhms_time";
let result = ucmd.args(&["-t", "01011234.56", file]).run(); let result = ucmd.args(&["-t", "01011234.56", file]).run();
@ -105,7 +110,7 @@ fn test_touch_set_mdhms_time() {
#[test] #[test]
fn test_touch_set_ymdhm_time() { fn test_touch_set_ymdhm_time() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_touch_set_ymdhm_time"; let file = "test_touch_set_ymdhm_time";
let result = ucmd.args(&["-t", "1501011234", file]).run(); let result = ucmd.args(&["-t", "1501011234", file]).run();
@ -125,7 +130,7 @@ fn test_touch_set_ymdhm_time() {
#[test] #[test]
fn test_touch_set_ymdhms_time() { fn test_touch_set_ymdhms_time() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_touch_set_ymdhms_time"; let file = "test_touch_set_ymdhms_time";
let result = ucmd.args(&["-t", "1501011234.56", file]).run(); let result = ucmd.args(&["-t", "1501011234.56", file]).run();
@ -145,7 +150,7 @@ fn test_touch_set_ymdhms_time() {
#[test] #[test]
fn test_touch_set_cymdhm_time() { fn test_touch_set_cymdhm_time() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_touch_set_cymdhm_time"; let file = "test_touch_set_cymdhm_time";
let result = ucmd.args(&["-t", "201501011234", file]).run(); let result = ucmd.args(&["-t", "201501011234", file]).run();
@ -165,7 +170,7 @@ fn test_touch_set_cymdhm_time() {
#[test] #[test]
fn test_touch_set_cymdhms_time() { fn test_touch_set_cymdhms_time() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_touch_set_cymdhms_time"; let file = "test_touch_set_cymdhms_time";
let result = ucmd.args(&["-t", "201501011234.56", file]).run(); let result = ucmd.args(&["-t", "201501011234.56", file]).run();
@ -185,7 +190,7 @@ fn test_touch_set_cymdhms_time() {
#[test] #[test]
fn test_touch_set_only_atime() { fn test_touch_set_only_atime() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_touch_set_only_atime"; let file = "test_touch_set_only_atime";
let result = ucmd.args(&["-t", "201501011234", "-a", file]).run(); let result = ucmd.args(&["-t", "201501011234", "-a", file]).run();
@ -203,7 +208,7 @@ fn test_touch_set_only_atime() {
#[test] #[test]
fn test_touch_set_only_mtime() { fn test_touch_set_only_mtime() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_touch_set_only_mtime"; let file = "test_touch_set_only_mtime";
let result = ucmd.args(&["-t", "201501011234", "-m", file]).run(); let result = ucmd.args(&["-t", "201501011234", "-m", file]).run();
@ -221,7 +226,7 @@ fn test_touch_set_only_mtime() {
#[test] #[test]
fn test_touch_set_both() { fn test_touch_set_both() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_touch_set_both"; let file = "test_touch_set_both";
let result = ucmd.args(&["-t", "201501011234", "-a", "-m", file]).run(); let result = ucmd.args(&["-t", "201501011234", "-a", "-m", file]).run();
@ -241,7 +246,7 @@ fn test_touch_set_both() {
#[test] #[test]
fn test_touch_reference() { fn test_touch_reference() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file_a = "test_touch_reference_a"; let file_a = "test_touch_reference_a";
let file_b = "test_touch_reference_b"; let file_b = "test_touch_reference_b";
let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000"); let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000");
@ -264,7 +269,7 @@ fn test_touch_reference() {
#[test] #[test]
fn test_touch_set_date() { fn test_touch_set_date() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_touch_set_date"; let file = "test_touch_set_date";
let result = ucmd.args(&["-d", "Thu Jan 01 12:34:00 2015", file]).run(); let result = ucmd.args(&["-d", "Thu Jan 01 12:34:00 2015", file]).run();

View file

@ -1,39 +1,42 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "tr"; static UTIL_NAME: &'static str = "tr";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_toupper() { fn test_toupper() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["a-z", "A-Z"]).run_piped_stdin("!abcd!"); .args(&["a-z", "A-Z"]).run_piped_stdin("!abcd!");
assert_eq!(result.stdout, "!ABCD!"); assert_eq!(result.stdout, "!ABCD!");
} }
#[test] #[test]
fn test_small_set2() { fn test_small_set2() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["0-9", "X"]).run_piped_stdin("@0123456789"); .args(&["0-9", "X"]).run_piped_stdin("@0123456789");
assert_eq!(result.stdout, "@XXXXXXXXXX"); assert_eq!(result.stdout, "@XXXXXXXXXX");
} }
#[test] #[test]
fn test_unicode() { fn test_unicode() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&[", ┬─┬", "╯︵┻━┻"]) .args(&[", ┬─┬", "╯︵┻━┻"])
.run_piped_stdin("(,°□°), ┬─┬".as_bytes()); .run_piped_stdin("(,°□°), ┬─┬".as_bytes());
assert_eq!(result.stdout, "(╯°□°)╯︵┻━┻"); assert_eq!(result.stdout, "(╯°□°)╯︵┻━┻");
} }
#[test] #[test]
fn test_delete() { fn test_delete() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-d", "a-z"]).run_piped_stdin("aBcD"); .args(&["-d", "a-z"]).run_piped_stdin("aBcD");
assert_eq!(result.stdout, "BD"); assert_eq!(result.stdout, "BD");
} }
#[test] #[test]
fn test_delete_complement() { fn test_delete_complement() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-d", "-c", "a-z"]).run_piped_stdin("aBcD"); .args(&["-d", "-c", "a-z"]).run_piped_stdin("aBcD");
assert_eq!(result.stdout, "ac"); assert_eq!(result.stdout, "ac");
} }

View file

@ -1,10 +1,13 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "true"; static UTIL_NAME: &'static str = "true";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_exit_code() { fn test_exit_code() {
let (_, mut ucmd) = testing(UTIL_NAME); let exit_status = new_ucmd()
let exit_status = ucmd.run().success; .run().success;
assert_eq!(exit_status, true); assert_eq!(exit_status, true);
} }

View file

@ -2,13 +2,18 @@ use common::util::*;
use std::io::{Seek, SeekFrom, Write}; use std::io::{Seek, SeekFrom, Write};
static UTIL_NAME: &'static str = "truncate"; static UTIL_NAME: &'static str = "truncate";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
static TFILE1: &'static str = "truncate_test_1"; static TFILE1: &'static str = "truncate_test_1";
static TFILE2: &'static str = "truncate_test_2"; static TFILE2: &'static str = "truncate_test_2";
#[test] #[test]
fn test_increase_file_size() { fn test_increase_file_size() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let mut file = at.make_file(TFILE1); let mut file = at.make_file(TFILE1);
assert!(ucmd.args(&["-s", "+5K", TFILE1]).run().success); assert!(ucmd.args(&["-s", "+5K", TFILE1]).run().success);
@ -18,7 +23,7 @@ fn test_increase_file_size() {
#[test] #[test]
fn test_decrease_file_size() { fn test_decrease_file_size() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let mut file = at.make_file(TFILE2); let mut file = at.make_file(TFILE2);
file.write_all(b"1234567890").unwrap(); file.write_all(b"1234567890").unwrap();
assert!(ucmd.args(&["--size=-4", TFILE2]).run().success); assert!(ucmd.args(&["--size=-4", TFILE2]).run().success);

View file

@ -1,17 +1,14 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "tsort"; static UTIL_NAME: &'static str = "tsort";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_sort_call_graph() { fn test_sort_call_graph() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let input = "call_graph.txt"; .arg("call_graph.txt")
let output = "call_graph.expected";
let out = ucmd.arg(input)
.run() .run()
.stdout; .stdout_is_fixture("call_graph.expected");
assert_eq!(out,
String::from_utf8(at.read(output).into_bytes()).unwrap());
} }

View file

@ -1,68 +1,71 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "unexpand"; static UTIL_NAME: &'static str = "unexpand";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn unexpand_init_0() { fn unexpand_init_0() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-t4"]).run_piped_stdin(" 1\n 2\n 3\n 4\n"); .args(&["-t4"]).run_piped_stdin(" 1\n 2\n 3\n 4\n");
assert_eq!(result.stdout, " 1\n 2\n 3\n\t4\n"); assert_eq!(result.stdout, " 1\n 2\n 3\n\t4\n");
} }
#[test] #[test]
fn unexpand_init_1() { fn unexpand_init_1() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-t4"]).run_piped_stdin(" 5\n 6\n 7\n 8\n"); .args(&["-t4"]).run_piped_stdin(" 5\n 6\n 7\n 8\n");
assert_eq!(result.stdout, "\t 5\n\t 6\n\t 7\n\t\t8\n"); assert_eq!(result.stdout, "\t 5\n\t 6\n\t 7\n\t\t8\n");
} }
#[test] #[test]
fn unexpand_init_list_0() { fn unexpand_init_list_0() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-t2,4"]).run_piped_stdin(" 1\n 2\n 3\n 4\n"); .args(&["-t2,4"]).run_piped_stdin(" 1\n 2\n 3\n 4\n");
assert_eq!(result.stdout, " 1\n\t2\n\t 3\n\t\t4\n"); assert_eq!(result.stdout, " 1\n\t2\n\t 3\n\t\t4\n");
} }
#[test] #[test]
fn unexpand_init_list_1() { fn unexpand_init_list_1() {
// Once the list is exhausted, spaces are not converted anymore // Once the list is exhausted, spaces are not converted anymore
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-t2,4"]).run_piped_stdin(" 5\n 6\n 7\n 8\n"); .args(&["-t2,4"]).run_piped_stdin(" 5\n 6\n 7\n 8\n");
assert_eq!(result.stdout, "\t\t 5\n\t\t 6\n\t\t 7\n\t\t 8\n"); assert_eq!(result.stdout, "\t\t 5\n\t\t 6\n\t\t 7\n\t\t 8\n");
} }
#[test] #[test]
fn unexpand_aflag_0() { fn unexpand_aflag_0() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["--"]).run_piped_stdin("e E\nf F\ng G\nh H\n"); .args(&["--"]).run_piped_stdin("e E\nf F\ng G\nh H\n");
assert_eq!(result.stdout, "e E\nf F\ng G\nh H\n"); assert_eq!(result.stdout, "e E\nf F\ng G\nh H\n");
} }
#[test] #[test]
fn unexpand_aflag_1() { fn unexpand_aflag_1() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-a"]).run_piped_stdin("e E\nf F\ng G\nh H\n"); .args(&["-a"]).run_piped_stdin("e E\nf F\ng G\nh H\n");
assert_eq!(result.stdout, "e E\nf F\ng\tG\nh\t H\n"); assert_eq!(result.stdout, "e E\nf F\ng\tG\nh\t H\n");
} }
#[test] #[test]
fn unexpand_aflag_2() { fn unexpand_aflag_2() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-t8"]).run_piped_stdin("e E\nf F\ng G\nh H\n"); .args(&["-t8"]).run_piped_stdin("e E\nf F\ng G\nh H\n");
assert_eq!(result.stdout, "e E\nf F\ng\tG\nh\t H\n"); assert_eq!(result.stdout, "e E\nf F\ng\tG\nh\t H\n");
} }
#[test] #[test]
fn unexpand_first_only_0() { fn unexpand_first_only_0() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-t3"]).run_piped_stdin(" A B"); .args(&["-t3"]).run_piped_stdin(" A B");
assert_eq!(result.stdout, "\t\t A\t B"); assert_eq!(result.stdout, "\t\t A\t B");
} }
#[test] #[test]
fn unexpand_first_only_1() { fn unexpand_first_only_1() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-t3", "--first-only"]).run_piped_stdin(" A B"); .args(&["-t3", "--first-only"]).run_piped_stdin(" A B");
assert_eq!(result.stdout, "\t\t A B"); assert_eq!(result.stdout, "\t\t A B");
} }
@ -71,24 +74,24 @@ fn unexpand_trailing_space_0() {
// evil // evil
// Individual spaces before fields starting with non blanks should not be // Individual spaces before fields starting with non blanks should not be
// converted, unless they are at the beginning of the line. // converted, unless they are at the beginning of the line.
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-t4"]).run_piped_stdin("123 \t1\n123 1\n123 \n123 "); .args(&["-t4"]).run_piped_stdin("123 \t1\n123 1\n123 \n123 ");
assert_eq!(result.stdout, "123\t\t1\n123 1\n123 \n123 "); assert_eq!(result.stdout, "123\t\t1\n123 1\n123 \n123 ");
} }
#[test] #[test]
fn unexpand_trailing_space_1() { fn unexpand_trailing_space_1() {
// super evil // super evil
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-t1"]).run_piped_stdin(" abc d e f g "); .args(&["-t1"]).run_piped_stdin(" abc d e f g ");
assert_eq!(result.stdout, "\tabc d e\t\tf\t\tg "); assert_eq!(result.stdout, "\tabc d e\t\tf\t\tg ");
} }
#[test] #[test]
fn unexpand_spaces_follow_tabs_0() { fn unexpand_spaces_follow_tabs_0() {
// The two first spaces can be included into the first tab. // The two first spaces can be included into the first tab.
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.run_piped_stdin(" \t\t A"); .run_piped_stdin(" \t\t A");
assert_eq!(result.stdout, "\t\t A"); assert_eq!(result.stdout, "\t\t A");
} }
@ -100,14 +103,14 @@ fn unexpand_spaces_follow_tabs_1() {
// ' \t' -> '\t' // second tabstop (4) // ' \t' -> '\t' // second tabstop (4)
// ' ' -> '\t' // third tabstop (5) // ' ' -> '\t' // third tabstop (5)
// ' B \t' -> ' B \t' // after the list is exhausted, nothing must change // ' B \t' -> ' B \t' // after the list is exhausted, nothing must change
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-t1,4,5"]).run_piped_stdin("a \t B \t"); .args(&["-t1,4,5"]).run_piped_stdin("a \t B \t");
assert_eq!(result.stdout, "a\t\t B \t"); assert_eq!(result.stdout, "a\t\t B \t");
} }
#[test] #[test]
fn unexpand_spaces_after_fields() { fn unexpand_spaces_after_fields() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-a"]).run_piped_stdin(" \t A B C D A\t\n"); .args(&["-a"]).run_piped_stdin(" \t A B C D A\t\n");
assert_eq!(result.stdout, "\t\tA B C D\t\t A\t\n"); assert_eq!(result.stdout, "\t\tA B C D\t\t A\t\n");
} }

View file

@ -1,6 +1,9 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "uniq"; static UTIL_NAME: &'static str = "uniq";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
static INPUT: &'static str = "sorted.txt"; static INPUT: &'static str = "sorted.txt";
static SKIP_CHARS: &'static str = "skip-chars.txt"; static SKIP_CHARS: &'static str = "skip-chars.txt";
@ -8,84 +11,84 @@ static SKIP_FIELDS: &'static str = "skip-fields.txt";
#[test] #[test]
fn test_stdin_default() { fn test_stdin_default() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.run_piped_stdin(at.read(INPUT)); .pipe_in_fixture(INPUT)
assert_eq!(result.stdout, at.read("sorted-simple.expected")); .run().stdout_is_fixture("sorted-simple.expected");
} }
#[test] #[test]
fn test_single_default() { fn test_single_default() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.arg(INPUT).run(); .arg(INPUT)
assert_eq!(result.stdout, at.read("sorted-simple.expected")); .run().stdout_is_fixture("sorted-simple.expected");
} }
#[test] #[test]
fn test_stdin_counts() { fn test_stdin_counts() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-c"]).run_piped_stdin(at.read(INPUT)); .args(&["-c"]).pipe_in_fixture(INPUT)
assert_eq!(result.stdout, at.read("sorted-counts.expected")); .run().stdout_is_fixture("sorted-counts.expected");
} }
#[test] #[test]
fn test_stdin_skip_1_char() { fn test_stdin_skip_1_char() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-s1"]).run_piped_stdin(at.read(SKIP_CHARS)); .args(&["-s1"]).pipe_in_fixture(SKIP_CHARS)
assert_eq!(result.stdout, at.read("skip-1-char.expected")); .run().stdout_is_fixture("skip-1-char.expected");
} }
#[test] #[test]
fn test_stdin_skip_5_chars() { fn test_stdin_skip_5_chars() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-s5"]).run_piped_stdin(at.read(SKIP_CHARS)); .args(&["-s5"]).pipe_in_fixture(SKIP_CHARS)
assert_eq!(result.stdout, at.read("skip-5-chars.expected")); .run().stdout_is_fixture("skip-5-chars.expected");
} }
#[test] #[test]
fn test_stdin_skip_and_check_2_chars() { fn test_stdin_skip_and_check_2_chars() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-s3", "-w2"]).run_piped_stdin(at.read(SKIP_CHARS)); .args(&["-s3", "-w2"]).pipe_in_fixture(SKIP_CHARS)
assert_eq!(result.stdout, at.read("skip-3-check-2-chars.expected")); .run().stdout_is_fixture("skip-3-check-2-chars.expected");
} }
#[test] #[test]
fn test_stdin_skip_1_field() { fn test_stdin_skip_1_field() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-f2"]).run_piped_stdin(at.read(SKIP_FIELDS)); .args(&["-f2"]).pipe_in_fixture(SKIP_FIELDS)
assert_eq!(result.stdout, at.read("skip-2-fields.expected")); .run().stdout_is_fixture("skip-2-fields.expected");
} }
#[test] #[test]
fn test_stdin_all_repeated() { fn test_stdin_all_repeated() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["--all-repeated"]).run_piped_stdin(at.read(INPUT)); .args(&["--all-repeated"]).pipe_in_fixture(INPUT)
assert_eq!(result.stdout, at.read("sorted-all-repeated.expected")); .run().stdout_is_fixture("sorted-all-repeated.expected");
} }
#[test] #[test]
fn test_stdin_all_repeated_separate() { fn test_stdin_all_repeated_separate() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["--all-repeated", "separate"]).run_piped_stdin(at.read(INPUT)); .args(&["--all-repeated", "separate"]).pipe_in_fixture(INPUT)
assert_eq!(result.stdout, at.read("sorted-all-repeated-separate.expected")); .run().stdout_is_fixture("sorted-all-repeated-separate.expected");
} }
#[test] #[test]
fn test_stdin_all_repeated_prepend() { fn test_stdin_all_repeated_prepend() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["--all-repeated", "prepend"]).run_piped_stdin(at.read(INPUT)); .args(&["--all-repeated", "prepend"]).pipe_in_fixture(INPUT)
assert_eq!(result.stdout, at.read("sorted-all-repeated-prepend.expected")); .run().stdout_is_fixture("sorted-all-repeated-prepend.expected");
} }
#[test] #[test]
fn test_stdin_unique_only() { fn test_stdin_unique_only() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-u"]).run_piped_stdin(at.read(INPUT)); .args(&["-u"]).pipe_in_fixture(INPUT)
assert_eq!(result.stdout, at.read("sorted-unique-only.expected")); .run().stdout_is_fixture("sorted-unique-only.expected");
} }
#[test] #[test]
fn test_stdin_repeated_only() { fn test_stdin_repeated_only() {
let (at, mut ucmd) = testing(UTIL_NAME); new_ucmd()
let result = ucmd.args(&["-d"]).run_piped_stdin(at.read(INPUT)); .args(&["-d"]).pipe_in_fixture(INPUT)
assert_eq!(result.stdout, at.read("sorted-repeated-only.expected")); .run().stdout_is_fixture("sorted-repeated-only.expected");
} }

View file

@ -1,10 +1,18 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "unlink"; static UTIL_NAME: &'static str = "unlink";
fn at_and_ucmd() -> (AtPath, UCommand) {
let ts = TestScenario::new(UTIL_NAME);
let ucmd = ts.ucmd();
(ts.fixtures, ucmd)
}
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_unlink_file() { fn test_unlink_file() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file = "test_unlink_file"; let file = "test_unlink_file";
at.touch(file); at.touch(file);
@ -18,7 +26,7 @@ fn test_unlink_file() {
#[test] #[test]
fn test_unlink_multiple_files() { fn test_unlink_multiple_files() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let file_a = "test_unlink_multiple_file_a"; let file_a = "test_unlink_multiple_file_a";
let file_b = "test_unlink_multiple_file_b"; let file_b = "test_unlink_multiple_file_b";
@ -34,7 +42,7 @@ fn test_unlink_multiple_files() {
#[test] #[test]
fn test_unlink_directory() { fn test_unlink_directory() {
let (at, mut ucmd) = testing(UTIL_NAME); let (at, mut ucmd) = at_and_ucmd();
let dir = "test_unlink_empty_directory"; let dir = "test_unlink_empty_directory";
at.mkdir(dir); at.mkdir(dir);
@ -48,10 +56,9 @@ fn test_unlink_directory() {
#[test] #[test]
fn test_unlink_nonexistent() { fn test_unlink_nonexistent() {
let (_, mut ucmd) = testing(UTIL_NAME);
let file = "test_unlink_nonexistent"; let file = "test_unlink_nonexistent";
let result = ucmd.arg(file).run(); let result = new_ucmd().arg(file).run();
assert_eq!(result.stderr, assert_eq!(result.stderr,
"unlink: error: Cannot stat 'test_unlink_nonexistent': No such file or directory \ "unlink: error: Cannot stat 'test_unlink_nonexistent': No such file or directory \
(os error 2)\n"); (os error 2)\n");

View file

@ -1,55 +1,55 @@
use common::util::*; use common::util::*;
static UTIL_NAME: &'static str = "wc"; static UTIL_NAME: &'static str = "wc";
fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
#[test] #[test]
fn test_stdin_default() { fn test_stdin_default() {
let (at, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd().pipe_in_fixture("lorem_ipsum.txt").run();
let result = ucmd.run_piped_stdin(at.read("lorem_ipsum.txt"));
assert_eq!(result.stdout, " 13 109 772\n"); assert_eq!(result.stdout, " 13 109 772\n");
} }
#[test] #[test]
fn test_stdin_only_bytes() { fn test_stdin_only_bytes() {
let (at, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd().args(&["-c"]).pipe_in_fixture("lorem_ipsum.txt").run();
let result = ucmd.args(&["-c"]).run_piped_stdin(at.read("lorem_ipsum.txt"));
assert_eq!(result.stdout, " 772\n"); assert_eq!(result.stdout, " 772\n");
} }
#[test] #[test]
fn test_stdin_all_counts() { fn test_stdin_all_counts() {
let (at, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd().args(&["-c", "-m", "-l", "-L", "-w"])
let result = ucmd.args(&["-c", "-m", "-l", "-L", "-w"]) .pipe_in_fixture("alice_in_wonderland.txt").run();
.run_piped_stdin(at.read("alice_in_wonderland.txt"));
assert_eq!(result.stdout, " 5 57 302 302 66\n"); assert_eq!(result.stdout, " 5 57 302 302 66\n");
} }
#[test] #[test]
fn test_single_default() { fn test_single_default() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.arg("moby_dick.txt").run(); .arg("moby_dick.txt").run();
assert_eq!(result.stdout, " 18 204 1115 moby_dick.txt\n"); assert_eq!(result.stdout, " 18 204 1115 moby_dick.txt\n");
} }
#[test] #[test]
fn test_single_only_lines() { fn test_single_only_lines() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-l", "moby_dick.txt"]).run(); .args(&["-l", "moby_dick.txt"]).run();
assert_eq!(result.stdout, " 18 moby_dick.txt\n"); assert_eq!(result.stdout, " 18 moby_dick.txt\n");
} }
#[test] #[test]
fn test_single_all_counts() { fn test_single_all_counts() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["-c", "-l", "-L", "-m", "-w", "alice_in_wonderland.txt"]).run(); .args(&["-c", "-l", "-L", "-m", "-w", "alice_in_wonderland.txt"]).run();
assert_eq!(result.stdout, assert_eq!(result.stdout,
" 5 57 302 302 66 alice_in_wonderland.txt\n"); " 5 57 302 302 66 alice_in_wonderland.txt\n");
} }
#[test] #[test]
fn test_multiple_default() { fn test_multiple_default() {
let (_, mut ucmd) = testing(UTIL_NAME); let result = new_ucmd()
let result = ucmd.args(&["lorem_ipsum.txt", "moby_dick.txt", "alice_in_wonderland.txt"]).run(); .args(&["lorem_ipsum.txt", "moby_dick.txt", "alice_in_wonderland.txt"]).run();
assert_eq!(result.stdout, assert_eq!(result.stdout,
" 13 109 772 lorem_ipsum.txt\n 18 204 1115 moby_dick.txt\n 5 57 302 \ " 13 109 772 lorem_ipsum.txt\n 18 204 1115 moby_dick.txt\n 5 57 302 \
alice_in_wonderland.txt\n 36 370 2189 total\n"); alice_in_wonderland.txt\n 36 370 2189 total\n");