mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
tests: remove helper function boilerplate via macros
This commit is contained in:
@@ -46,3 +46,23 @@ macro_rules! path_concat {
|
||||
pb.to_str().unwrap().to_owned()
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! util_name {
|
||||
() => ( module_path!().split("_").nth(1).expect("no test name") )
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! new_ucmd {
|
||||
() => ( TestScenario::new(util_name!()).ucmd() )
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! at_and_ucmd {
|
||||
() => ({
|
||||
let ts = TestScenario::new(util_name!());
|
||||
#[allow(unused_mut)]
|
||||
let mut ucmd = ts.ucmd();
|
||||
(ts.fixtures, ucmd)
|
||||
})
|
||||
}
|
||||
|
||||
+7
-11
@@ -8,15 +8,11 @@
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "base32";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_encode() {
|
||||
let input = "Hello, World!";
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("JBSWY3DPFQQFO33SNRSCC===\n");
|
||||
@@ -26,7 +22,7 @@ fn test_encode() {
|
||||
fn test_decode() {
|
||||
for decode_param in vec!["-d", "--decode"] {
|
||||
let input = "JBSWY3DPFQQFO33SNRSCC===\n";
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg(decode_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
@@ -37,7 +33,7 @@ fn test_decode() {
|
||||
#[test]
|
||||
fn test_garbage() {
|
||||
let input = "aGVsbG8sIHdvcmxkIQ==\0";
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("-d")
|
||||
.pipe_in(input)
|
||||
.fails()
|
||||
@@ -48,7 +44,7 @@ fn test_garbage() {
|
||||
fn test_ignore_garbage() {
|
||||
for ignore_garbage_param in vec!["-i", "--ignore-garbage"] {
|
||||
let input = "JBSWY\x013DPFQ\x02QFO33SNRSCC===\n";
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("-d")
|
||||
.arg(ignore_garbage_param)
|
||||
.pipe_in(input)
|
||||
@@ -61,7 +57,7 @@ fn test_ignore_garbage() {
|
||||
fn test_wrap() {
|
||||
for wrap_param in vec!["-w", "--wrap"] {
|
||||
let input = "The quick brown fox jumps over the lazy dog.";
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg(wrap_param)
|
||||
.arg("20")
|
||||
.pipe_in(input)
|
||||
@@ -73,7 +69,7 @@ fn test_wrap() {
|
||||
#[test]
|
||||
fn test_wrap_no_arg() {
|
||||
for wrap_param in vec!["-w", "--wrap"] {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg(wrap_param)
|
||||
.fails()
|
||||
.stderr_only(format!("base32: error: Argument to option '{}' missing.\n",
|
||||
@@ -84,7 +80,7 @@ fn test_wrap_no_arg() {
|
||||
#[test]
|
||||
fn test_wrap_bad_arg() {
|
||||
for wrap_param in vec!["-w", "--wrap"] {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg(wrap_param).arg("b")
|
||||
.fails()
|
||||
.stderr_only("base32: error: invalid wrap size: ‘b’: invalid digit found in string\n");
|
||||
|
||||
+7
-11
@@ -1,14 +1,10 @@
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "base64";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_encode() {
|
||||
let input = "hello, world!";
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("aGVsbG8sIHdvcmxkIQ==\n");
|
||||
@@ -18,7 +14,7 @@ fn test_encode() {
|
||||
fn test_decode() {
|
||||
for decode_param in vec!["-d", "--decode"] {
|
||||
let input = "aGVsbG8sIHdvcmxkIQ==";
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg(decode_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
@@ -29,7 +25,7 @@ fn test_decode() {
|
||||
#[test]
|
||||
fn test_garbage() {
|
||||
let input = "aGVsbG8sIHdvcmxkIQ==\0";
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("-d")
|
||||
.pipe_in(input)
|
||||
.fails()
|
||||
@@ -40,7 +36,7 @@ fn test_garbage() {
|
||||
fn test_ignore_garbage() {
|
||||
for ignore_garbage_param in vec!["-i", "--ignore-garbage"] {
|
||||
let input = "aGVsbG8sIHdvcmxkIQ==\0";
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("-d")
|
||||
.arg(ignore_garbage_param)
|
||||
.pipe_in(input)
|
||||
@@ -53,7 +49,7 @@ fn test_ignore_garbage() {
|
||||
fn test_wrap() {
|
||||
for wrap_param in vec!["-w", "--wrap"] {
|
||||
let input = "The quick brown fox jumps over the lazy dog.";
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg(wrap_param)
|
||||
.arg("20")
|
||||
.pipe_in(input)
|
||||
@@ -65,7 +61,7 @@ fn test_wrap() {
|
||||
#[test]
|
||||
fn test_wrap_no_arg() {
|
||||
for wrap_param in vec!["-w", "--wrap"] {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg(wrap_param)
|
||||
.fails()
|
||||
.stderr_only(format!("base64: error: Argument to option '{}' missing.\n",
|
||||
@@ -76,7 +72,7 @@ fn test_wrap_no_arg() {
|
||||
#[test]
|
||||
fn test_wrap_bad_arg() {
|
||||
for wrap_param in vec!["-w", "--wrap"] {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg(wrap_param)
|
||||
.arg("b")
|
||||
.fails()
|
||||
|
||||
+8
-12
@@ -1,30 +1,26 @@
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "basename";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_directory() {
|
||||
new_ucmd().args(&["/root/alpha/beta/gamma/delta/epsilon/omega/"])
|
||||
new_ucmd!().args(&["/root/alpha/beta/gamma/delta/epsilon/omega/"])
|
||||
.succeeds().stdout_only("omega");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_file() {
|
||||
new_ucmd().args(&["/etc/passwd"]).succeeds().stdout_only("passwd");
|
||||
new_ucmd!().args(&["/etc/passwd"]).succeeds().stdout_only("passwd");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_remove_suffix() {
|
||||
new_ucmd().args(&["/usr/local/bin/reallylongexecutable.exe", ".exe"])
|
||||
new_ucmd!().args(&["/usr/local/bin/reallylongexecutable.exe", ".exe"])
|
||||
.succeeds().stdout_only("reallylongexecutable");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dont_remove_suffix() {
|
||||
new_ucmd().args(&["/foo/bar/baz", "baz"]).succeeds().stdout_only( "baz");
|
||||
new_ucmd!().args(&["/foo/bar/baz", "baz"]).succeeds().stdout_only( "baz");
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||
@@ -32,7 +28,7 @@ fn test_dont_remove_suffix() {
|
||||
fn test_multiple_param() {
|
||||
for multiple_param in vec!["-a", "--multiple"] {
|
||||
let path = "/foo/bar/baz";
|
||||
new_ucmd().args(&[multiple_param, path, path])
|
||||
new_ucmd!().args(&[multiple_param, path, path])
|
||||
.succeeds().stdout_only("baz\nbaz");
|
||||
}
|
||||
}
|
||||
@@ -42,7 +38,7 @@ fn test_multiple_param() {
|
||||
fn test_suffix_param() {
|
||||
for suffix_param in vec!["-s", "--suffix"] {
|
||||
let path = "/foo/bar/baz.exe";
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.args(&[suffix_param, ".exe", path, path])
|
||||
.succeeds().stdout_only("baz\nbaz");
|
||||
}
|
||||
@@ -53,14 +49,14 @@ fn test_suffix_param() {
|
||||
fn test_zero_param() {
|
||||
for zero_param in vec!["-z", "--zero"] {
|
||||
let path = "/foo/bar/baz";
|
||||
new_ucmd().args(&[zero_param, "-a", path, path])
|
||||
new_ucmd!().args(&[zero_param, "-a", path, path])
|
||||
.succeeds().stdout_only("baz\0baz\0");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn expect_error(input: Vec<&str>) {
|
||||
assert!(new_ucmd().args(&input)
|
||||
assert!(new_ucmd!().args(&input)
|
||||
.fails().no_stdout().stderr.len() > 0);
|
||||
}
|
||||
|
||||
|
||||
+11
-15
@@ -1,13 +1,9 @@
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "cat";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_output_multi_files_print_all_chars() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.args(&["alpha.txt", "256.txt", "-A", "-n"])
|
||||
.succeeds()
|
||||
.stdout_only(" 1\tabcde$\n 2\tfghij$\n 3\tklmno$\n 4\tpqrst$\n \
|
||||
@@ -26,7 +22,7 @@ fn test_output_multi_files_print_all_chars() {
|
||||
#[test]
|
||||
fn test_stdin_show_nonprinting() {
|
||||
for same_param in vec!["-v", "--show-nonprinting"] {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.args(&vec![same_param])
|
||||
.pipe_in("\t\0\n")
|
||||
.succeeds()
|
||||
@@ -37,7 +33,7 @@ fn test_stdin_show_nonprinting() {
|
||||
#[test]
|
||||
fn test_stdin_show_tabs() {
|
||||
for same_param in vec!["-T", "--show-tabs"] {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.args(&[same_param])
|
||||
.pipe_in("\t\0\n")
|
||||
.succeeds()
|
||||
@@ -49,7 +45,7 @@ fn test_stdin_show_tabs() {
|
||||
#[test]
|
||||
fn test_stdin_show_ends() {
|
||||
for same_param in vec!["-E", "--show-ends"] {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.args(&[same_param,"-"])
|
||||
.pipe_in("\t\0\n")
|
||||
.succeeds()
|
||||
@@ -60,7 +56,7 @@ fn test_stdin_show_ends() {
|
||||
#[test]
|
||||
fn test_stdin_show_all() {
|
||||
for same_param in vec!["-A", "--show-all"] {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.args(&[same_param])
|
||||
.pipe_in("\t\0\n")
|
||||
.succeeds()
|
||||
@@ -70,7 +66,7 @@ fn test_stdin_show_all() {
|
||||
|
||||
#[test]
|
||||
fn test_stdin_nonprinting_and_endofline() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.args(&["-e"])
|
||||
.pipe_in("\t\0\n")
|
||||
.succeeds()
|
||||
@@ -79,7 +75,7 @@ fn test_stdin_nonprinting_and_endofline() {
|
||||
|
||||
#[test]
|
||||
fn test_stdin_nonprinting_and_tabs() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.args(&["-t"])
|
||||
.pipe_in("\t\0\n")
|
||||
.succeeds()
|
||||
@@ -89,7 +85,7 @@ fn test_stdin_nonprinting_and_tabs() {
|
||||
#[test]
|
||||
fn test_stdin_squeeze_blank() {
|
||||
for same_param in vec!["-s", "--squeeze-blank"] {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg(same_param)
|
||||
.pipe_in("\n\na\n\n\n\n\nb\n\n\n")
|
||||
.succeeds()
|
||||
@@ -100,7 +96,7 @@ fn test_stdin_squeeze_blank() {
|
||||
#[test]
|
||||
fn test_stdin_number_non_blank() {
|
||||
for same_param in vec!["-b", "--number-nonblank"] {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg(same_param)
|
||||
.arg("-")
|
||||
.pipe_in("\na\nb\n\n\nc")
|
||||
@@ -112,7 +108,7 @@ fn test_stdin_number_non_blank() {
|
||||
#[test]
|
||||
fn test_non_blank_overrides_number() {
|
||||
for same_param in vec!["-b", "--number-nonblank"] {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.args(&[same_param, "-"])
|
||||
.pipe_in("\na\nb\n\n\nc")
|
||||
.succeeds()
|
||||
@@ -123,7 +119,7 @@ fn test_non_blank_overrides_number() {
|
||||
#[test]
|
||||
fn test_squeeze_blank_before_numbering() {
|
||||
for same_param in vec!["-s", "--squeeze-blank"] {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.args(&[same_param, "-n", "-"])
|
||||
.pipe_in("a\n\n\nb")
|
||||
.succeeds()
|
||||
|
||||
+9
-13
@@ -1,13 +1,9 @@
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "chgrp";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_option() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("-w")
|
||||
.arg("/")
|
||||
.fails();
|
||||
@@ -17,7 +13,7 @@ static DIR: &'static str = "/tmp";
|
||||
|
||||
#[test]
|
||||
fn test_invalid_group() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("nosuchgroup")
|
||||
.arg("/")
|
||||
.fails()
|
||||
@@ -26,7 +22,7 @@ fn test_invalid_group() {
|
||||
|
||||
#[test]
|
||||
fn test_1() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("bin")
|
||||
.arg(DIR)
|
||||
.fails()
|
||||
@@ -36,7 +32,7 @@ fn test_1() {
|
||||
#[test]
|
||||
fn test_fail_silently() {
|
||||
for opt in &["-f", "--silent", "--quiet"] {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.arg("bin")
|
||||
.arg(DIR)
|
||||
@@ -47,7 +43,7 @@ fn test_fail_silently() {
|
||||
|
||||
#[test]
|
||||
fn test_preserve_root() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("--preserve-root")
|
||||
.arg("-R")
|
||||
.arg("bin").arg("/")
|
||||
@@ -58,7 +54,7 @@ fn test_preserve_root() {
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_reference() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("-v")
|
||||
.arg("--reference=/etc/passwd")
|
||||
.arg("/etc")
|
||||
@@ -70,7 +66,7 @@ fn test_reference() {
|
||||
#[test]
|
||||
#[cfg(target_os = "macos")]
|
||||
fn test_reference() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("-v")
|
||||
.arg("--reference=/etc/passwd")
|
||||
.arg("/etc")
|
||||
@@ -80,7 +76,7 @@ fn test_reference() {
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_big_p() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("-RP")
|
||||
.arg("bin")
|
||||
.arg("/proc/self/cwd")
|
||||
@@ -91,7 +87,7 @@ fn test_big_p() {
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_big_h() {
|
||||
assert!(new_ucmd()
|
||||
assert!(new_ucmd!()
|
||||
.arg("-RH")
|
||||
.arg("bin")
|
||||
.arg("/proc/self/fd")
|
||||
|
||||
+2
-8
@@ -5,12 +5,6 @@ use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
||||
extern crate libc;
|
||||
use self::libc::umask;
|
||||
|
||||
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 REFERENCE_FILE: &'static str = "reference";
|
||||
@@ -53,7 +47,7 @@ fn run_single_test(test: &TestCase, at: AtPath, mut ucmd: UCommand) {
|
||||
|
||||
fn run_tests(tests: Vec<TestCase>) {
|
||||
for test in tests {
|
||||
let (at, ucmd) = at_and_ucmd();
|
||||
let (at, ucmd) = at_and_ucmd!();
|
||||
run_single_test(&test, at, ucmd);
|
||||
}
|
||||
}
|
||||
@@ -135,7 +129,7 @@ fn test_chmod_reference_file() {
|
||||
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},
|
||||
};
|
||||
let (at, ucmd) = at_and_ucmd();
|
||||
let (at, ucmd) = at_and_ucmd!();
|
||||
mkfile(&at.plus_as_string(REFERENCE_FILE), REFERENCE_PERMS);
|
||||
run_single_test(&tests[0], at, ucmd);
|
||||
}
|
||||
|
||||
+1
-5
@@ -3,10 +3,6 @@ use common::util::*;
|
||||
extern crate uu_chown;
|
||||
pub use self::uu_chown::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "chown";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_passgrp {
|
||||
@@ -49,7 +45,7 @@ mod test_passgrp {
|
||||
|
||||
#[test]
|
||||
fn test_invalid_option() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("-w").arg("-q").arg("/")
|
||||
.fails();
|
||||
}
|
||||
|
||||
+3
-7
@@ -1,19 +1,15 @@
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "cksum";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_file() {
|
||||
new_ucmd().arg("lorem_ipsum.txt")
|
||||
new_ucmd!().arg("lorem_ipsum.txt")
|
||||
.succeeds().stdout_is_fixture("single_file.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_files() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("lorem_ipsum.txt")
|
||||
.arg("alice_in_wonderland.txt")
|
||||
.succeeds().stdout_is_fixture("multiple_files.expected");
|
||||
@@ -21,7 +17,7 @@ fn test_multiple_files() {
|
||||
|
||||
#[test]
|
||||
fn test_stdin() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.pipe_in_fixture("lorem_ipsum.txt")
|
||||
.succeeds().stdout_is_fixture("stdin.expected");
|
||||
}
|
||||
|
||||
+17
-21
@@ -1,51 +1,47 @@
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "comm";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ab_no_args() {
|
||||
new_ucmd().args(&["a", "b"]).succeeds().stdout_only_fixture("ab.expected");
|
||||
new_ucmd!().args(&["a", "b"]).succeeds().stdout_only_fixture("ab.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ab_dash_one() {
|
||||
new_ucmd().args(&["a", "b", "-1"]).succeeds().stdout_only_fixture("ab1.expected");
|
||||
new_ucmd!().args(&["a", "b", "-1"]).succeeds().stdout_only_fixture("ab1.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ab_dash_two() {
|
||||
new_ucmd().args(&["a", "b", "-2"]).succeeds().stdout_only_fixture("ab2.expected");
|
||||
new_ucmd!().args(&["a", "b", "-2"]).succeeds().stdout_only_fixture("ab2.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ab_dash_three() {
|
||||
new_ucmd().args(&["a", "b", "-3"]).succeeds().stdout_only_fixture("ab3.expected");
|
||||
new_ucmd!().args(&["a", "b", "-3"]).succeeds().stdout_only_fixture("ab3.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn aempty() {
|
||||
new_ucmd().args(&["a", "empty"]).succeeds().stdout_only_fixture("aempty.expected");
|
||||
new_ucmd!().args(&["a", "empty"]).succeeds().stdout_only_fixture("aempty.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn emptyempty() {
|
||||
new_ucmd().args(&["empty", "empty"]).succeeds().stdout_only_fixture("emptyempty.expected");
|
||||
new_ucmd!().args(&["empty", "empty"]).succeeds().stdout_only_fixture("emptyempty.expected");
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||
#[test]
|
||||
fn output_delimiter() {
|
||||
new_ucmd().args(&["--output-delimiter=word", "a", "b"])
|
||||
new_ucmd!().args(&["--output-delimiter=word", "a", "b"])
|
||||
.succeeds().stdout_only_fixture("ab_delimiter_word.expected");
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||
#[test]
|
||||
fn output_delimiter_require_arg() {
|
||||
new_ucmd().args(&["--output-delimiter=", "a", "b"])
|
||||
new_ucmd!().args(&["--output-delimiter=", "a", "b"])
|
||||
.fails().stderr_only("error to be defined");
|
||||
}
|
||||
|
||||
@@ -58,14 +54,14 @@ fn output_delimiter_require_arg() {
|
||||
#[test]
|
||||
fn zero_terminated() {
|
||||
for param in vec!["-z", "--zero-terminated"] {
|
||||
new_ucmd().args(&[param, "a", "b"]).fails().stderr_only("error to be defined");
|
||||
new_ucmd!().args(&[param, "a", "b"]).fails().stderr_only("error to be defined");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||
#[test]
|
||||
fn check_order() {
|
||||
new_ucmd().args(&["--check-order", "bad_order_1", "bad_order_2"])
|
||||
new_ucmd!().args(&["--check-order", "bad_order_1", "bad_order_2"])
|
||||
.fails()
|
||||
.stdout_is_fixture("bad_order12.check_order.expected")
|
||||
.stderr_is("error to be defined");
|
||||
@@ -74,7 +70,7 @@ fn check_order() {
|
||||
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||
#[test]
|
||||
fn nocheck_order() {
|
||||
new_ucmd().args(&["--nocheck-order", "bad_order_1", "bad_order_2"])
|
||||
new_ucmd!().args(&["--nocheck-order", "bad_order_1", "bad_order_2"])
|
||||
.succeeds()
|
||||
.stdout_only_fixture("bad_order12.nocheck_order.expected");
|
||||
}
|
||||
@@ -85,7 +81,7 @@ fn nocheck_order() {
|
||||
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||
#[test]
|
||||
fn defaultcheck_order() {
|
||||
new_ucmd().args(&["a", "bad_order_1"]).fails().stderr_only("error to be defined");
|
||||
new_ucmd!().args(&["a", "bad_order_1"]).fails().stderr_only("error to be defined");
|
||||
}
|
||||
|
||||
// * the first: if both files are not in order, the default behavior is the only
|
||||
@@ -97,14 +93,14 @@ fn defaultcheck_order() {
|
||||
|
||||
#[test]
|
||||
fn defaultcheck_order_identical_bad_order_files() {
|
||||
new_ucmd().args(&["bad_order_1", "bad_order_1"])
|
||||
new_ucmd!().args(&["bad_order_1", "bad_order_1"])
|
||||
.succeeds().stdout_only_fixture("bad_order11.defaultcheck_order.expected");
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||
#[test]
|
||||
fn defaultcheck_order_two_different_bad_order_files() {
|
||||
new_ucmd().args(&["bad_order_1", "bad_order_2"])
|
||||
new_ucmd!().args(&["bad_order_1", "bad_order_2"])
|
||||
.fails()
|
||||
.stdout_is_fixture("bad_order12.nocheck_order.expected")
|
||||
.stderr_is("error to be defined");
|
||||
@@ -123,18 +119,18 @@ fn defaultcheck_order_two_different_bad_order_files() {
|
||||
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||
#[test]
|
||||
fn unintuitive_default_behavior_1() {
|
||||
new_ucmd().args(&["defaultcheck_unintuitive_1", "defaultcheck_unintuitive_2"])
|
||||
new_ucmd!().args(&["defaultcheck_unintuitive_1", "defaultcheck_unintuitive_2"])
|
||||
.succeeds().stdout_only_fixture("defaultcheck_unintuitive.expected");
|
||||
}
|
||||
|
||||
#[ignore] //bug? should help be stdout if not called via -h|--help?
|
||||
#[test]
|
||||
fn no_arguments() {
|
||||
new_ucmd().fails().no_stdout().no_stderr();
|
||||
new_ucmd!().fails().no_stdout().no_stderr();
|
||||
}
|
||||
|
||||
#[ignore] //bug? should help be stdout if not called via -h|--help?
|
||||
#[test]
|
||||
fn one_argument() {
|
||||
new_ucmd().arg("a").fails().no_stdout().no_stderr();
|
||||
new_ucmd!().arg("a").fails().no_stdout().no_stderr();
|
||||
}
|
||||
|
||||
+3
-9
@@ -1,10 +1,4 @@
|
||||
use common::util::*;
|
||||
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_DEST: &'static str = "copy_of_hello_world.txt";
|
||||
@@ -14,7 +8,7 @@ static TEST_COPY_FROM_FOLDER_FILE: &'static str = "hello_dir_with_file/hello_wor
|
||||
|
||||
#[test]
|
||||
fn test_cp_cp() {
|
||||
let (at, mut ucmd) = at_and_ucmd();
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
// Invoke our binary to make the copy.
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_HELLO_WORLD_DEST)
|
||||
@@ -30,7 +24,7 @@ fn test_cp_cp() {
|
||||
|
||||
#[test]
|
||||
fn test_cp_with_dirs_t() {
|
||||
let (at, mut ucmd) = at_and_ucmd();
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
//using -t option
|
||||
let result_to_dir_t = ucmd
|
||||
@@ -44,7 +38,7 @@ fn test_cp_with_dirs_t() {
|
||||
|
||||
#[test]
|
||||
fn test_cp_with_dirs() {
|
||||
let scene = TestScenario::new(UTIL_NAME);
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
//using -t option
|
||||
|
||||
+9
-13
@@ -1,9 +1,5 @@
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "cut";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
static INPUT: &'static str = "lists.txt";
|
||||
|
||||
@@ -27,7 +23,7 @@ static COMPLEX_SEQUENCE: &'static TestedSequence<'static> = &TestedSequence{ nam
|
||||
fn test_byte_sequence() {
|
||||
for param in vec!["-b", "--bytes"] {
|
||||
for example_seq in EXAMPLE_SEQUENCES {
|
||||
new_ucmd().args(&[param, example_seq.sequence, INPUT])
|
||||
new_ucmd!().args(&[param, example_seq.sequence, INPUT])
|
||||
.succeeds().stdout_only_fixture(format!("sequences/byte_{}.expected", example_seq.name));
|
||||
}
|
||||
}
|
||||
@@ -38,7 +34,7 @@ fn test_char_sequence() {
|
||||
for param in vec!["-c", "--characters"] {
|
||||
for example_seq in EXAMPLE_SEQUENCES {
|
||||
//as of coreutils 8.25 a char range is effectively the same as a byte range; there is no distinct treatment of utf8 chars.
|
||||
new_ucmd().args(&[param, example_seq.sequence, INPUT])
|
||||
new_ucmd!().args(&[param, example_seq.sequence, INPUT])
|
||||
.succeeds().stdout_only_fixture(format!("sequences/byte_{}.expected", example_seq.name));
|
||||
}
|
||||
}
|
||||
@@ -48,7 +44,7 @@ fn test_char_sequence() {
|
||||
fn test_field_sequence() {
|
||||
for param in vec!["-f", "--fields"] {
|
||||
for example_seq in EXAMPLE_SEQUENCES {
|
||||
new_ucmd().args(&[param, example_seq.sequence, INPUT])
|
||||
new_ucmd!().args(&[param, example_seq.sequence, INPUT])
|
||||
.succeeds().stdout_only_fixture(format!("sequences/field_{}.expected", example_seq.name));
|
||||
}
|
||||
}
|
||||
@@ -57,7 +53,7 @@ fn test_field_sequence() {
|
||||
#[test]
|
||||
fn test_specify_delimiter() {
|
||||
for param in vec!["-d", "--delimiter"] {
|
||||
new_ucmd().args(&[param, ":", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
|
||||
new_ucmd!().args(&[param, ":", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
|
||||
.succeeds().stdout_only_fixture("delimiter_specified.expected");
|
||||
}
|
||||
}
|
||||
@@ -66,20 +62,20 @@ fn test_specify_delimiter() {
|
||||
fn test_output_delimiter() {
|
||||
// we use -d here to ensure output delimiter
|
||||
// is applied to the current, and not just the default, input delimiter
|
||||
new_ucmd().args(&["-d:", "--output-delimiter=@", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
|
||||
new_ucmd!().args(&["-d:", "--output-delimiter=@", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
|
||||
.succeeds().stdout_only_fixture("output_delimiter.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_complement() {
|
||||
new_ucmd().args(&["-d_","--complement", "-f", "2"])
|
||||
new_ucmd!().args(&["-d_","--complement", "-f", "2"])
|
||||
.pipe_in("9_1\n8_2\n7_3")
|
||||
.succeeds().stdout_only("9\n8\n7\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zero_terminated() {
|
||||
new_ucmd().args(&["-d_","-z", "-f", "1"])
|
||||
new_ucmd!().args(&["-d_","-z", "-f", "1"])
|
||||
.pipe_in("9_1\n8_2\n\07_3")
|
||||
.succeeds().stdout_only("9\07\0");
|
||||
}
|
||||
@@ -87,7 +83,7 @@ fn test_zero_terminated() {
|
||||
#[test]
|
||||
fn test_only_delimited() {
|
||||
for param in vec!["-s", "--only-delimited"] {
|
||||
new_ucmd().args(&["-d_", param, "-f", "1"])
|
||||
new_ucmd!().args(&["-d_", param, "-f", "1"])
|
||||
.pipe_in("91\n82\n7_3")
|
||||
.succeeds().stdout_only("7\n");
|
||||
}
|
||||
@@ -95,7 +91,7 @@ fn test_only_delimited() {
|
||||
|
||||
#[test]
|
||||
fn test_zero_terminated_only_delimited() {
|
||||
new_ucmd().args(&["-d_","-z", "-s", "-f", "1"])
|
||||
new_ucmd!().args(&["-d_","-z", "-s", "-f", "1"])
|
||||
.pipe_in("91\n\082\n7_3")
|
||||
.succeeds().stdout_only("82\n7\0");
|
||||
}
|
||||
|
||||
+7
-11
@@ -3,10 +3,6 @@ use self::uu_dircolors::{StrUtils, guess_syntax, OutputFmt};
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "dircolors";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shell_syntax() {
|
||||
@@ -60,7 +56,7 @@ fn test_keywords() {
|
||||
|
||||
#[test]
|
||||
fn test_internal_db() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("-p")
|
||||
.run()
|
||||
.stdout_is_fixture("internal.expected");
|
||||
@@ -68,36 +64,36 @@ fn test_internal_db() {
|
||||
|
||||
#[test]
|
||||
fn test_bash_default() {
|
||||
new_ucmd().env("TERM", "screen").arg("-b").run().stdout_is_fixture("bash_def.expected");
|
||||
new_ucmd!().env("TERM", "screen").arg("-b").run().stdout_is_fixture("bash_def.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_csh_default() {
|
||||
new_ucmd().env("TERM", "screen").arg("-c").run().stdout_is_fixture("csh_def.expected");
|
||||
new_ucmd!().env("TERM", "screen").arg("-c").run().stdout_is_fixture("csh_def.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_env() {
|
||||
// no SHELL and TERM
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.fails();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_exclusive_option() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("-cp")
|
||||
.fails();
|
||||
}
|
||||
|
||||
fn test_helper(file_name: &str, term: &str) {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.env("TERM", term)
|
||||
.arg("-c")
|
||||
.arg(format!("{}.txt", file_name))
|
||||
.run().stdout_is_fixture(format!("{}.csh.expected", file_name));
|
||||
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.env("TERM", term)
|
||||
.arg("-b")
|
||||
.arg(format!("{}.txt", file_name))
|
||||
|
||||
@@ -1,33 +1,29 @@
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "dirname";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_path_with_trailing_slashes() {
|
||||
new_ucmd().arg("/root/alpha/beta/gamma/delta/epsilon/omega//")
|
||||
new_ucmd!().arg("/root/alpha/beta/gamma/delta/epsilon/omega//")
|
||||
.run().stdout_is("/root/alpha/beta/gamma/delta/epsilon");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_path_without_trailing_slashes() {
|
||||
new_ucmd().arg("/root/alpha/beta/gamma/delta/epsilon/omega")
|
||||
new_ucmd!().arg("/root/alpha/beta/gamma/delta/epsilon/omega")
|
||||
.run().stdout_is("/root/alpha/beta/gamma/delta/epsilon");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_root() {
|
||||
new_ucmd().arg("/").run().stdout_is("/");
|
||||
new_ucmd!().arg("/").run().stdout_is("/");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pwd() {
|
||||
new_ucmd().arg(".").run().stdout_is(".");
|
||||
new_ucmd!().arg(".").run().stdout_is(".");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty() {
|
||||
new_ucmd().arg("").run().stdout_is(".");
|
||||
new_ucmd!().arg("").run().stdout_is(".");
|
||||
}
|
||||
|
||||
+15
-19
@@ -1,86 +1,82 @@
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "echo";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default() {
|
||||
//CmdResult.stdout_only(...) trims trailing newlines
|
||||
assert_eq!("hi\n", new_ucmd().arg("hi").succeeds().no_stderr().stdout);
|
||||
assert_eq!("hi\n", new_ucmd!().arg("hi").succeeds().no_stderr().stdout);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_trailing_newline() {
|
||||
//CmdResult.stdout_only(...) trims trailing newlines
|
||||
assert_eq!("hi", new_ucmd().arg("-n").arg("hi").succeeds().no_stderr().stdout);
|
||||
assert_eq!("hi", new_ucmd!().arg("-n").arg("hi").succeeds().no_stderr().stdout);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_alert() {
|
||||
new_ucmd().args(&["-e", "\\a"]).succeeds().stdout_only("\x07\n");
|
||||
new_ucmd!().args(&["-e", "\\a"]).succeeds().stdout_only("\x07\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_backslash() {
|
||||
new_ucmd().args(&["-e", "\\\\"]).succeeds().stdout_only("\\\n");
|
||||
new_ucmd!().args(&["-e", "\\\\"]).succeeds().stdout_only("\\\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_backspace() {
|
||||
new_ucmd().args(&["-e", "\\b"]).succeeds().stdout_only("\x08\n");
|
||||
new_ucmd!().args(&["-e", "\\b"]).succeeds().stdout_only("\x08\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_carriage_return() {
|
||||
new_ucmd().args(&["-e", "\\r"]).succeeds().stdout_only("\r\n");
|
||||
new_ucmd!().args(&["-e", "\\r"]).succeeds().stdout_only("\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_escape() {
|
||||
new_ucmd().args(&["-e", "\\e"]).succeeds().stdout_only("\x1B\n");
|
||||
new_ucmd!().args(&["-e", "\\e"]).succeeds().stdout_only("\x1B\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_form_feed() {
|
||||
new_ucmd().args(&["-e", "\\f"]).succeeds().stdout_only("\x0C\n");
|
||||
new_ucmd!().args(&["-e", "\\f"]).succeeds().stdout_only("\x0C\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_hex() {
|
||||
new_ucmd().args(&["-e", "\\x41"]).succeeds().stdout_only("A");
|
||||
new_ucmd!().args(&["-e", "\\x41"]).succeeds().stdout_only("A");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_newline() {
|
||||
new_ucmd().args(&["-e", "\\na"]).succeeds().stdout_only("\na");
|
||||
new_ucmd!().args(&["-e", "\\na"]).succeeds().stdout_only("\na");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_no_further_output() {
|
||||
new_ucmd().args(&["-e", "a\\cb"]).succeeds().stdout_only("a\n");
|
||||
new_ucmd!().args(&["-e", "a\\cb"]).succeeds().stdout_only("a\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_octal() {
|
||||
new_ucmd().args(&["-e", "\\0100"]).succeeds().stdout_only("@");
|
||||
new_ucmd!().args(&["-e", "\\0100"]).succeeds().stdout_only("@");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_tab() {
|
||||
new_ucmd().args(&["-e", "\\t"]).succeeds().stdout_only("\t\n");
|
||||
new_ucmd!().args(&["-e", "\\t"]).succeeds().stdout_only("\t\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_vertical_tab() {
|
||||
new_ucmd().args(&["-e", "\\v"]).succeeds().stdout_only("\x0B\n");
|
||||
new_ucmd!().args(&["-e", "\\v"]).succeeds().stdout_only("\x0B\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_disable_escapes() {
|
||||
let input_str = "\\a \\\\ \\b \\r \\e \\f \\x41 \\n a\\cb \\u0100 \\t \\v";
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("-E")
|
||||
.arg(input_str)
|
||||
.succeeds()
|
||||
|
||||
+5
-9
@@ -1,13 +1,9 @@
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "env";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_name_value_pair() {
|
||||
let out = new_ucmd()
|
||||
let out = new_ucmd!()
|
||||
.arg("FOO=bar").run().stdout;
|
||||
|
||||
assert!(out.lines().any(|line| line == "FOO=bar"));
|
||||
@@ -15,7 +11,7 @@ fn test_single_name_value_pair() {
|
||||
|
||||
#[test]
|
||||
fn test_multiple_name_value_pairs() {
|
||||
let out = new_ucmd()
|
||||
let out = new_ucmd!()
|
||||
.arg("FOO=bar")
|
||||
.arg("ABC=xyz")
|
||||
.run()
|
||||
@@ -27,7 +23,7 @@ fn test_multiple_name_value_pairs() {
|
||||
|
||||
#[test]
|
||||
fn test_ignore_environment() {
|
||||
let scene = TestScenario::new(UTIL_NAME);
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
||||
let out = scene.ucmd()
|
||||
.arg("-i")
|
||||
@@ -46,7 +42,7 @@ fn test_ignore_environment() {
|
||||
|
||||
#[test]
|
||||
fn test_null_delimiter() {
|
||||
let out = new_ucmd()
|
||||
let out = new_ucmd!()
|
||||
.arg("-i")
|
||||
.arg("--null")
|
||||
.arg("FOO=bar")
|
||||
@@ -66,7 +62,7 @@ fn test_null_delimiter() {
|
||||
fn test_unset_variable() {
|
||||
// This test depends on the HOME variable being pre-defined by the
|
||||
// default shell
|
||||
let out = TestScenario::new(UTIL_NAME)
|
||||
let out = TestScenario::new(util_name!())
|
||||
.ucmd_keepenv()
|
||||
.arg("-u")
|
||||
.arg("HOME")
|
||||
|
||||
+9
-13
@@ -1,36 +1,32 @@
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "expr";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_simple_arithmetic() {
|
||||
new_ucmd().args(&["1", "+", "1"]).run().stdout_is("2\n");
|
||||
new_ucmd!().args(&["1", "+", "1"]).run().stdout_is("2\n");
|
||||
|
||||
new_ucmd().args(&["1", "-", "1"]).run().stdout_is("0\n");
|
||||
new_ucmd!().args(&["1", "-", "1"]).run().stdout_is("0\n");
|
||||
|
||||
new_ucmd().args(&["3", "*", "2"]).run().stdout_is("6\n");
|
||||
new_ucmd!().args(&["3", "*", "2"]).run().stdout_is("6\n");
|
||||
|
||||
new_ucmd().args(&["4", "/", "2"]).run().stdout_is("2\n");
|
||||
new_ucmd!().args(&["4", "/", "2"]).run().stdout_is("2\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parenthesis() {
|
||||
new_ucmd().args(&["(", "1", "+", "1", ")", "*", "2"]).run().stdout_is("4\n");
|
||||
new_ucmd!().args(&["(", "1", "+", "1", ")", "*", "2"]).run().stdout_is("4\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_or() {
|
||||
new_ucmd().args(&["0", "|", "foo"]).run().stdout_is("foo\n");
|
||||
new_ucmd!().args(&["0", "|", "foo"]).run().stdout_is("foo\n");
|
||||
|
||||
new_ucmd().args(&["foo", "|", "bar"]).run().stdout_is("foo\n");
|
||||
new_ucmd!().args(&["foo", "|", "bar"]).run().stdout_is("foo\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_and() {
|
||||
new_ucmd().args(&["foo", "&", "1"]).run().stdout_is("foo\n");
|
||||
new_ucmd!().args(&["foo", "&", "1"]).run().stdout_is("foo\n");
|
||||
|
||||
new_ucmd().args(&["", "&", "1"]).run().stdout_is("0\n");
|
||||
new_ucmd!().args(&["", "&", "1"]).run().stdout_is("0\n");
|
||||
}
|
||||
|
||||
@@ -22,10 +22,6 @@ const LOG_PRIMES: f64 = 14.0; // ceil(log2(NUM_PRIMES))
|
||||
|
||||
const NUM_TESTS: usize = 100;
|
||||
|
||||
static UTIL_NAME: &'static str = "factor";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_random() {
|
||||
@@ -166,7 +162,7 @@ fn test_big_primes() {
|
||||
|
||||
fn run(instring: &[u8], outstring: &[u8]) {
|
||||
// now run factor
|
||||
new_ucmd().pipe_in(instring).run().stdout_is(String::from_utf8(outstring.to_owned()).unwrap());
|
||||
new_ucmd!().pipe_in(instring).run().stdout_is(String::from_utf8(outstring.to_owned()).unwrap());
|
||||
}
|
||||
|
||||
const PRIMES_BY_BITS: &'static [&'static [u64]] = &[PRIMES14, PRIMES15, PRIMES16, PRIMES17,
|
||||
|
||||
+1
-5
@@ -1,11 +1,7 @@
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "false";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_exit_code() {
|
||||
new_ucmd().fails();
|
||||
new_ucmd!().fails();
|
||||
}
|
||||
|
||||
+3
-7
@@ -1,13 +1,9 @@
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "fold";
|
||||
fn new_ucmd() -> UCommand {
|
||||
TestScenario::new(UTIL_NAME).ucmd()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_80_column_wrap() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.arg("lorem_ipsum.txt")
|
||||
.run()
|
||||
.stdout_is_fixture("lorem_ipsum_80_column.expected");
|
||||
@@ -15,7 +11,7 @@ fn test_default_80_column_wrap() {
|
||||
|
||||
#[test]
|
||||
fn test_40_column_hard_cutoff() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.args(&["-w", "40", "lorem_ipsum.txt"])
|
||||
.run()
|
||||
.stdout_is_fixture("lorem_ipsum_40_column_hard.expected");
|
||||
@@ -23,7 +19,7 @@ fn test_40_column_hard_cutoff() {
|
||||
|
||||
#[test]
|
||||
fn test_40_column_word_boundary() {
|
||||
new_ucmd()
|
||||
new_ucmd!()
|
||||
.args(&["-s", "-w", "40", "lorem_ipsum.txt"])
|
||||
.run()
|
||||
.stdout_is_fixture("lorem_ipsum_40_column_word.expected");
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user