From aa6ee03be37a7ef5b7d5956317278fd52eca2910 Mon Sep 17 00:00:00 2001 From: nathanross Date: Tue, 23 Aug 2016 07:52:43 -0400 Subject: [PATCH 1/2] tests: remove helper function boilerplate via macros --- tests/common/macros.rs | 20 +++++++ tests/test_base32.rs | 18 +++---- tests/test_base64.rs | 18 +++---- tests/test_basename.rs | 20 +++---- tests/test_cat.rs | 26 ++++----- tests/test_chgrp.rs | 22 ++++---- tests/test_chmod.rs | 10 +--- tests/test_chown.rs | 6 +-- tests/test_cksum.rs | 10 ++-- tests/test_comm.rs | 38 ++++++-------- tests/test_cp.rs | 12 ++--- tests/test_cut.rs | 22 ++++---- tests/test_dircolors.rs | 18 +++---- tests/test_dirname.rs | 14 ++--- tests/test_echo.rs | 34 ++++++------ tests/test_env.rs | 14 ++--- tests/test_expr.rs | 22 ++++---- tests/test_factor.rs | 6 +-- tests/test_false.rs | 6 +-- tests/test_fold.rs | 10 ++-- tests/test_hashsum.rs | 19 +++---- tests/test_head.rs | 22 ++++---- tests/test_install.rs | 24 ++++----- tests/test_link.rs | 12 ++--- tests/test_ln.rs | 40 ++++++-------- tests/test_ls.rs | 6 +-- tests/test_mkdir.rs | 14 ++--- tests/test_mktemp.rs | 15 +++--- tests/test_mv.rs | 50 ++++++++---------- tests/test_nl.rs | 14 ++--- tests/test_od.rs | 20 +++---- tests/test_paste.rs | 6 +-- tests/test_pathchk.rs | 8 +-- tests/test_pinky.rs | 12 ++--- tests/test_printf.rs | 114 +++++++++++++++++++--------------------- tests/test_ptx.rs | 18 +++---- tests/test_pwd.rs | 8 +-- tests/test_readlink.rs | 19 ++----- tests/test_realpath.rs | 15 ++---- tests/test_rm.rs | 22 +++----- tests/test_rmdir.rs | 18 +++---- tests/test_seq.rs | 12 ++--- tests/test_sort.rs | 18 +++---- tests/test_split.rs | 16 ++---- tests/test_stat.rs | 26 ++++----- tests/test_stdbuf.rs | 6 +-- tests/test_sum.rs | 16 +++--- tests/test_tac.rs | 16 +++--- tests/test_tail.rs | 33 +++++------- tests/test_test.rs | 10 ++-- tests/test_touch.rs | 34 +++++------- tests/test_tr.rs | 14 ++--- tests/test_true.rs | 6 +-- tests/test_truncate.rs | 10 +--- tests/test_tsort.rs | 6 +-- tests/test_unexpand.rs | 32 +++++------ tests/test_uniq.rs | 32 +++++------ tests/test_unlink.rs | 17 ++---- tests/test_wc.rs | 18 +++---- tests/test_who.rs | 22 ++++---- 60 files changed, 453 insertions(+), 713 deletions(-) diff --git a/tests/common/macros.rs b/tests/common/macros.rs index c0005125b..54fbcab58 100644 --- a/tests/common/macros.rs +++ b/tests/common/macros.rs @@ -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) + }) +} diff --git a/tests/test_base32.rs b/tests/test_base32.rs index 5febba29d..ee6a2bf1f 100644 --- a/tests/test_base32.rs +++ b/tests/test_base32.rs @@ -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"); diff --git a/tests/test_base64.rs b/tests/test_base64.rs index 24ac408b3..60835bdcb 100644 --- a/tests/test_base64.rs +++ b/tests/test_base64.rs @@ -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() diff --git a/tests/test_basename.rs b/tests/test_basename.rs index f647b8076..6cc5187dd 100644 --- a/tests/test_basename.rs +++ b/tests/test_basename.rs @@ -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); } diff --git a/tests/test_cat.rs b/tests/test_cat.rs index 04af605f4..ae2615511 100644 --- a/tests/test_cat.rs +++ b/tests/test_cat.rs @@ -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() diff --git a/tests/test_chgrp.rs b/tests/test_chgrp.rs index 29af80912..06875215c 100644 --- a/tests/test_chgrp.rs +++ b/tests/test_chgrp.rs @@ -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") diff --git a/tests/test_chmod.rs b/tests/test_chmod.rs index fdb8a41e5..b7f0e8e8c 100644 --- a/tests/test_chmod.rs +++ b/tests/test_chmod.rs @@ -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) { 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); } diff --git a/tests/test_chown.rs b/tests/test_chown.rs index 3c021ff55..0f7124391 100644 --- a/tests/test_chown.rs +++ b/tests/test_chown.rs @@ -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(); } diff --git a/tests/test_cksum.rs b/tests/test_cksum.rs index ef9156a0b..f94b6785b 100644 --- a/tests/test_cksum.rs +++ b/tests/test_cksum.rs @@ -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"); } diff --git a/tests/test_comm.rs b/tests/test_comm.rs index cfb904cd1..b0f5d29f5 100644 --- a/tests/test_comm.rs +++ b/tests/test_comm.rs @@ -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(); } diff --git a/tests/test_cp.rs b/tests/test_cp.rs index c30be7d48..4429686f6 100644 --- a/tests/test_cp.rs +++ b/tests/test_cp.rs @@ -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 diff --git a/tests/test_cut.rs b/tests/test_cut.rs index b432284a1..055462e4a 100644 --- a/tests/test_cut.rs +++ b/tests/test_cut.rs @@ -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"); } diff --git a/tests/test_dircolors.rs b/tests/test_dircolors.rs index d1a3bf8cb..9deef78fd 100644 --- a/tests/test_dircolors.rs +++ b/tests/test_dircolors.rs @@ -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)) diff --git a/tests/test_dirname.rs b/tests/test_dirname.rs index e7a767268..4fa772c32 100644 --- a/tests/test_dirname.rs +++ b/tests/test_dirname.rs @@ -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("."); } diff --git a/tests/test_echo.rs b/tests/test_echo.rs index 4c0183058..1c9e7417f 100644 --- a/tests/test_echo.rs +++ b/tests/test_echo.rs @@ -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() diff --git a/tests/test_env.rs b/tests/test_env.rs index 068c70398..ea618db58 100644 --- a/tests/test_env.rs +++ b/tests/test_env.rs @@ -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") diff --git a/tests/test_expr.rs b/tests/test_expr.rs index d7dcaa54b..6119f4232 100644 --- a/tests/test_expr.rs +++ b/tests/test_expr.rs @@ -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"); } diff --git a/tests/test_factor.rs b/tests/test_factor.rs index 8ddc2ee4b..66c440958 100644 --- a/tests/test_factor.rs +++ b/tests/test_factor.rs @@ -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, diff --git a/tests/test_false.rs b/tests/test_false.rs index 630dd9702..037e113a5 100644 --- a/tests/test_false.rs +++ b/tests/test_false.rs @@ -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(); } diff --git a/tests/test_fold.rs b/tests/test_fold.rs index 81398cb65..9327ccf45 100644 --- a/tests/test_fold.rs +++ b/tests/test_fold.rs @@ -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"); diff --git a/tests/test_hashsum.rs b/tests/test_hashsum.rs index 54b356f36..6b7550d6c 100644 --- a/tests/test_hashsum.rs +++ b/tests/test_hashsum.rs @@ -9,28 +9,21 @@ macro_rules! test_digest { mod $t { use::common::util::*; - 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 EXPECTED_FILE: &'static str = concat!(stringify!($t), ".expected"); #[test] fn test_single_file() { - let (at, mut ucmd) = at_and_ucmd(); - assert_eq!(at.read(EXPECTED_FILE), - get_hash!(ucmd.arg(DIGEST_ARG).arg("input.txt").succeeds().no_stderr().stdout)); + let ts = TestScenario::new("hashsum"); + assert_eq!(ts.fixtures.read(EXPECTED_FILE), + get_hash!(ts.ucmd().arg(DIGEST_ARG).arg("input.txt").succeeds().no_stderr().stdout)); } #[test] fn test_stdin() { - let (at, mut ucmd) = at_and_ucmd(); - let input = at.read("input.txt"); - assert_eq!(at.read(EXPECTED_FILE), - get_hash!(ucmd.arg(DIGEST_ARG).pipe_in(input).succeeds().no_stderr().stdout)); + let ts = TestScenario::new("hashsum"); + assert_eq!(ts.fixtures.read(EXPECTED_FILE), + get_hash!(ts.ucmd().arg(DIGEST_ARG).pipe_in_fixture("input.txt").succeeds().no_stderr().stdout)); } } )*) diff --git a/tests/test_head.rs b/tests/test_head.rs index 9555e4643..d9ca4e29b 100644 --- a/tests/test_head.rs +++ b/tests/test_head.rs @@ -1,22 +1,18 @@ use common::util::*; -static UTIL_NAME: &'static str = "head"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} static INPUT: &'static str = "lorem_ipsum.txt"; #[test] fn test_stdin_default() { - new_ucmd() + new_ucmd!() .pipe_in_fixture(INPUT) .run().stdout_is_fixture("lorem_ipsum_default.expected"); } #[test] fn test_stdin_1_line_obsolete() { - new_ucmd() + new_ucmd!() .args(&["-1"]) .pipe_in_fixture(INPUT) .run().stdout_is_fixture("lorem_ipsum_1_line.expected"); @@ -24,7 +20,7 @@ fn test_stdin_1_line_obsolete() { #[test] fn test_stdin_1_line() { - new_ucmd() + new_ucmd!() .args(&["-n", "1"]) .pipe_in_fixture(INPUT) .run().stdout_is_fixture("lorem_ipsum_1_line.expected"); @@ -32,7 +28,7 @@ fn test_stdin_1_line() { #[test] fn test_stdin_5_chars() { - new_ucmd() + new_ucmd!() .args(&["-c", "5"]) .pipe_in_fixture(INPUT) .run().stdout_is_fixture("lorem_ipsum_5_chars.expected"); @@ -40,35 +36,35 @@ fn test_stdin_5_chars() { #[test] fn test_single_default() { - new_ucmd() + new_ucmd!() .arg(INPUT) .run().stdout_is_fixture("lorem_ipsum_default.expected"); } #[test] fn test_single_1_line_obsolete() { - new_ucmd() + new_ucmd!() .args(&["-1", INPUT]) .run().stdout_is_fixture("lorem_ipsum_1_line.expected"); } #[test] fn test_single_1_line() { - new_ucmd() + new_ucmd!() .args(&["-n", "1", INPUT]) .run().stdout_is_fixture("lorem_ipsum_1_line.expected"); } #[test] fn test_single_5_chars() { - new_ucmd() + new_ucmd!() .args(&["-c", "5", INPUT]) .run().stdout_is_fixture("lorem_ipsum_5_chars.expected"); } #[test] fn test_verbose() { - new_ucmd() + new_ucmd!() .args(&["-v", INPUT]) .run().stdout_is_fixture("lorem_ipsum_verbose.expected"); } diff --git a/tests/test_install.rs b/tests/test_install.rs index cd003c0d0..85585afc8 100644 --- a/tests/test_install.rs +++ b/tests/test_install.rs @@ -1,16 +1,10 @@ use common::util::*; use std::os::unix::fs::PermissionsExt; -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] fn test_install_help() { - let (_, mut ucmd) = at_and_ucmd(); + let (_, mut ucmd) = at_and_ucmd!(); assert!( ucmd.arg("--help").succeeds().no_stderr().stdout.contains("Options:")); @@ -18,7 +12,7 @@ fn test_install_help() { #[test] fn test_install_basic() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_install_target_dir_dir_a"; let file1 = "test_install_target_dir_file_a1"; let file2 = "test_install_target_dir_file_a2"; @@ -36,7 +30,7 @@ fn test_install_basic() { #[test] fn test_install_unimplemented_arg() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_install_target_dir_dir_b"; let file = "test_install_target_dir_file_b"; let context_arg = "--context"; @@ -51,7 +45,7 @@ fn test_install_unimplemented_arg() { #[test] fn test_install_component_directories() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let component1 = "test_install_target_dir_component_c1"; let component2 = "test_install_target_dir_component_c2"; let component3 = "test_install_target_dir_component_c3"; @@ -67,7 +61,7 @@ fn test_install_component_directories() { #[test] fn test_install_component_directories_failing() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let component = "test_install_target_dir_component_d1"; let directories_arg = "-d"; @@ -78,7 +72,7 @@ fn test_install_component_directories_failing() { #[test] fn test_install_mode_numeric() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_install_target_dir_dir_e"; let file = "test_install_target_dir_file_e"; let mode_arg = "--mode=333"; @@ -96,7 +90,7 @@ fn test_install_mode_numeric() { #[test] fn test_install_mode_symbolic() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_install_target_dir_dir_f"; let file = "test_install_target_dir_file_f"; let mode_arg = "--mode=o+wx"; @@ -114,7 +108,7 @@ fn test_install_mode_symbolic() { #[test] fn test_install_mode_failing() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_install_target_dir_dir_g"; let file = "test_install_target_dir_file_g"; let mode_arg = "--mode=999"; @@ -131,7 +125,7 @@ fn test_install_mode_failing() { #[test] fn test_install_mode_directories() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let component = "test_install_target_dir_component_h"; let directories_arg = "-d"; let mode_arg = "--mode=333"; diff --git a/tests/test_link.rs b/tests/test_link.rs index 79c0419da..126c1c89a 100644 --- a/tests/test_link.rs +++ b/tests/test_link.rs @@ -1,15 +1,9 @@ use common::util::*; -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] fn test_link_existing_file() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_link_existing_file"; let link = "test_link_existing_file_link"; @@ -25,7 +19,7 @@ fn test_link_existing_file() { #[test] fn test_link_no_circular() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let link = "test_link_no_circular"; ucmd.args(&[link, link]).fails() @@ -35,7 +29,7 @@ fn test_link_no_circular() { #[test] fn test_link_nonexistent_file() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_link_nonexistent_file"; let link = "test_link_nonexistent_file_link"; diff --git a/tests/test_ln.rs b/tests/test_ln.rs index aa3711e54..138e3b292 100644 --- a/tests/test_ln.rs +++ b/tests/test_ln.rs @@ -1,15 +1,9 @@ use common::util::*; -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] fn test_symlink_existing_file() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_symlink_existing_file"; let link = "test_symlink_existing_file_link"; @@ -24,7 +18,7 @@ fn test_symlink_existing_file() { #[test] fn test_symlink_dangling_file() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_symlink_dangling_file"; let link = "test_symlink_dangling_file_link"; @@ -36,7 +30,7 @@ fn test_symlink_dangling_file() { #[test] fn test_symlink_existing_directory() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_symlink_existing_dir"; let link = "test_symlink_existing_dir_link"; @@ -50,7 +44,7 @@ fn test_symlink_existing_directory() { #[test] fn test_symlink_dangling_directory() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_symlink_dangling_dir"; let link = "test_symlink_dangling_dir_link"; @@ -62,7 +56,7 @@ fn test_symlink_dangling_directory() { #[test] fn test_symlink_circular() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let link = "test_symlink_circular"; ucmd.args(&["-s", link]).succeeds().no_stderr(); @@ -72,7 +66,7 @@ fn test_symlink_circular() { #[test] fn test_symlink_dont_overwrite() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_symlink_dont_overwrite"; let link = "test_symlink_dont_overwrite_link"; @@ -87,7 +81,7 @@ fn test_symlink_dont_overwrite() { #[test] fn test_symlink_overwrite_force() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file_a = "test_symlink_overwrite_force_a"; let file_b = "test_symlink_overwrite_force_b"; let link = "test_symlink_overwrite_force_link"; @@ -105,7 +99,7 @@ fn test_symlink_overwrite_force() { #[test] fn test_symlink_interactive() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; let file = "test_symlink_interactive_file"; let link = "test_symlink_interactive_file_link"; @@ -131,7 +125,7 @@ fn test_symlink_interactive() { #[test] fn test_symlink_simple_backup() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_symlink_simple_backup"; let link = "test_symlink_simple_backup_link"; @@ -155,7 +149,7 @@ fn test_symlink_simple_backup() { #[test] fn test_symlink_custom_backup_suffix() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_symlink_custom_backup_suffix"; let link = "test_symlink_custom_backup_suffix_link"; let suffix = "super-suffix-of-the-century"; @@ -180,7 +174,7 @@ fn test_symlink_custom_backup_suffix() { #[test] fn test_symlink_backup_numbering() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_symlink_backup_numbering"; let link = "test_symlink_backup_numbering_link"; @@ -203,7 +197,7 @@ fn test_symlink_backup_numbering() { #[test] fn test_symlink_existing_backup() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_symlink_existing_backup"; let link = "test_symlink_existing_backup_link"; let link_backup = "test_symlink_existing_backup_link.~1~"; @@ -234,7 +228,7 @@ fn test_symlink_existing_backup() { #[test] fn test_symlink_target_dir() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_ln_target_dir_dir"; let file_a = "test_ln_target_dir_file_a"; let file_b = "test_ln_target_dir_file_b"; @@ -256,7 +250,7 @@ fn test_symlink_target_dir() { #[test] fn test_symlink_overwrite_dir() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let path_a = "test_symlink_overwrite_dir_a"; let path_b = "test_symlink_overwrite_dir_b"; @@ -272,7 +266,7 @@ fn test_symlink_overwrite_dir() { #[test] fn test_symlink_overwrite_nonempty_dir() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let path_a = "test_symlink_overwrite_nonempty_dir_a"; let path_b = "test_symlink_overwrite_nonempty_dir_b"; let dummy = "test_symlink_overwrite_nonempty_dir_b/file"; @@ -296,7 +290,7 @@ fn test_symlink_overwrite_nonempty_dir() { #[test] fn test_symlink_errors() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_symlink_errors_dir"; let file_a = "test_symlink_errors_file_a"; let file_b = "test_symlink_errors_file_b"; @@ -314,7 +308,7 @@ fn test_symlink_errors() { #[test] fn test_symlink_verbose() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; let file_a = "test_symlink_verbose_file_a"; let file_b = "test_symlink_verbose_file_b"; diff --git a/tests/test_ls.rs b/tests/test_ls.rs index 53fe8db18..cc4b54581 100644 --- a/tests/test_ls.rs +++ b/tests/test_ls.rs @@ -1,11 +1,7 @@ use common::util::*; -static UTIL_NAME: &'static str = "ls"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn test_ls_ls() { - new_ucmd().succeeds(); + new_ucmd!().succeeds(); } diff --git a/tests/test_mkdir.rs b/tests/test_mkdir.rs index bbef2d453..f9b011891 100644 --- a/tests/test_mkdir.rs +++ b/tests/test_mkdir.rs @@ -1,9 +1,5 @@ use common::util::*; -static UTIL_NAME: &'static str = "mkdir"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} static TEST_DIR1: &'static str = "mkdir_test1"; static TEST_DIR2: &'static str = "mkdir_test2"; @@ -13,19 +9,19 @@ static TEST_DIR5: &'static str = "mkdir_test5/mkdir_test5_1"; #[test] fn test_mkdir_mkdir() { - new_ucmd().arg(TEST_DIR1).succeeds(); + new_ucmd!().arg(TEST_DIR1).succeeds(); } #[test] fn test_mkdir_dup_dir() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); scene.ucmd().arg(TEST_DIR2).succeeds(); scene.ucmd().arg(TEST_DIR2).fails(); } #[test] fn test_mkdir_mode() { - new_ucmd() + new_ucmd!() .arg("-m") .arg("755") .arg(TEST_DIR3) @@ -34,10 +30,10 @@ fn test_mkdir_mode() { #[test] fn test_mkdir_parent() { - new_ucmd().arg("-p").arg(TEST_DIR4).succeeds(); + new_ucmd!().arg("-p").arg(TEST_DIR4).succeeds(); } #[test] fn test_mkdir_no_parent() { - new_ucmd().arg(TEST_DIR5).fails(); + new_ucmd!().arg(TEST_DIR5).fails(); } diff --git a/tests/test_mktemp.rs b/tests/test_mktemp.rs index 8ee272e35..255af89ca 100644 --- a/tests/test_mktemp.rs +++ b/tests/test_mktemp.rs @@ -2,7 +2,6 @@ use common::util::*; extern crate tempdir; use self::tempdir::TempDir; -static UTIL_NAME: &'static str = "mktemp"; static TEST_TEMPLATE1: &'static str = "tempXXXXXX"; static TEST_TEMPLATE2: &'static str = "temp"; @@ -20,7 +19,7 @@ const TMPDIR: &'static str = "TMPDIR"; #[test] fn test_mktemp_mktemp() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); let pathname = scene.fixtures.as_string(); @@ -36,7 +35,7 @@ fn test_mktemp_mktemp() { #[test] fn test_mktemp_make_temp_dir() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); let pathname = scene.fixtures.as_string(); @@ -52,7 +51,7 @@ fn test_mktemp_make_temp_dir() { #[test] fn test_mktemp_dry_run() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); let pathname = scene.fixtures.as_string(); @@ -69,7 +68,7 @@ fn test_mktemp_dry_run() { #[test] fn test_mktemp_quiet() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); scene.ucmd().arg("-p").arg("/definitely/not/exist/I/promise").arg("-q") .fails().no_stdout().no_stderr(); @@ -79,7 +78,7 @@ fn test_mktemp_quiet() { #[test] fn test_mktemp_suffix() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); let pathname = scene.fixtures.as_string(); @@ -95,9 +94,9 @@ fn test_mktemp_suffix() { #[test] fn test_mktemp_tmpdir() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); - let path = TempDir::new_in(scene.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(); scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE1).succeeds(); diff --git a/tests/test_mv.rs b/tests/test_mv.rs index 732b66647..4d08f799f 100644 --- a/tests/test_mv.rs +++ b/tests/test_mv.rs @@ -4,16 +4,10 @@ extern crate filetime; use self::filetime::*; use common::util::*; -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] fn test_mv_rename_dir() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir1 = "test_mv_rename_dir"; let dir2 = "test_mv_rename_dir2"; @@ -26,7 +20,7 @@ fn test_mv_rename_dir() { #[test] fn test_mv_rename_file() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file1 = "test_mv_rename_file"; let file2 = "test_mv_rename_file2"; @@ -38,7 +32,7 @@ fn test_mv_rename_file() { #[test] fn test_mv_move_file_into_dir() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_mv_move_file_into_dir_dir"; let file = "test_mv_move_file_into_dir_file"; @@ -52,7 +46,7 @@ fn test_mv_move_file_into_dir() { #[test] fn test_mv_strip_slashes() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; let dir = "test_mv_strip_slashes_dir"; let file = "test_mv_strip_slashes_file"; @@ -73,7 +67,7 @@ fn test_mv_strip_slashes() { #[test] fn test_mv_multiple_files() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let target_dir = "test_mv_multiple_files_dir"; let file_a = "test_mv_multiple_file_a"; let file_b = "test_mv_multiple_file_b"; @@ -90,7 +84,7 @@ fn test_mv_multiple_files() { #[test] fn test_mv_multiple_folders() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let target_dir = "test_mv_multiple_dirs_dir"; let dir_a = "test_mv_multiple_dir_a"; let dir_b = "test_mv_multiple_dir_b"; @@ -107,7 +101,7 @@ fn test_mv_multiple_folders() { #[test] fn test_mv_interactive() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; let file_a = "test_mv_interactive_file_a"; let file_b = "test_mv_interactive_file_b"; @@ -130,7 +124,7 @@ fn test_mv_interactive() { #[test] fn test_mv_no_clobber() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file_a = "test_mv_no_clobber_file_a"; let file_b = "test_mv_no_clobber_file_b"; @@ -145,7 +139,7 @@ fn test_mv_no_clobber() { #[test] fn test_mv_replace_file() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file_a = "test_mv_replace_file_a"; let file_b = "test_mv_replace_file_b"; @@ -160,7 +154,7 @@ fn test_mv_replace_file() { #[test] fn test_mv_force_replace_file() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file_a = "test_mv_force_replace_file_a"; let file_b = "test_mv_force_replace_file_b"; @@ -175,7 +169,7 @@ fn test_mv_force_replace_file() { #[test] fn test_mv_simple_backup() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file_a = "test_mv_simple_backup_file_a"; let file_b = "test_mv_simple_backup_file_b"; @@ -190,7 +184,7 @@ fn test_mv_simple_backup() { #[test] fn test_mv_custom_backup_suffix() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file_a = "test_mv_custom_backup_suffix_file_a"; let file_b = "test_mv_custom_backup_suffix_file_b"; let suffix = "super-suffix-of-the-century"; @@ -210,7 +204,7 @@ fn test_mv_custom_backup_suffix() { #[test] fn test_mv_custom_backup_suffix_via_env() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file_a = "test_mv_custom_backup_suffix_file_a"; let file_b = "test_mv_custom_backup_suffix_file_b"; let suffix = "super-suffix-of-the-century"; @@ -229,7 +223,7 @@ fn test_mv_custom_backup_suffix_via_env() { #[test] fn test_mv_backup_numbering() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file_a = "test_mv_backup_numbering_file_a"; let file_b = "test_mv_backup_numbering_file_b"; @@ -244,7 +238,7 @@ fn test_mv_backup_numbering() { #[test] fn test_mv_existing_backup() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file_a = "test_mv_existing_backup_file_a"; let file_b = "test_mv_existing_backup_file_b"; let file_b_backup = "test_mv_existing_backup_file_b.~1~"; @@ -263,7 +257,7 @@ fn test_mv_existing_backup() { #[test] fn test_mv_update_option() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; let file_a = "test_mv_update_option_file_a"; let file_b = "test_mv_update_option_file_b"; @@ -289,7 +283,7 @@ fn test_mv_update_option() { #[test] fn test_mv_target_dir() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_mv_target_dir_dir"; let file_a = "test_mv_target_dir_file_a"; let file_b = "test_mv_target_dir_file_b"; @@ -307,7 +301,7 @@ fn test_mv_target_dir() { #[test] fn test_mv_overwrite_dir() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir_a = "test_mv_overwrite_dir_a"; let dir_b = "test_mv_overwrite_dir_b"; @@ -321,7 +315,7 @@ fn test_mv_overwrite_dir() { #[test] fn test_mv_overwrite_nonempty_dir() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir_a = "test_mv_overwrite_nonempty_dir_a"; let dir_b = "test_mv_overwrite_nonempty_dir_b"; let dummy = "test_mv_overwrite_nonempty_dir_b/file"; @@ -343,7 +337,7 @@ fn test_mv_overwrite_nonempty_dir() { #[test] fn test_mv_backup_dir() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir_a = "test_mv_backup_dir_dir_a"; let dir_b = "test_mv_backup_dir_dir_b"; @@ -362,7 +356,7 @@ fn test_mv_backup_dir() { #[test] fn test_mv_errors() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; let dir = "test_mv_errors_dir"; let file_a = "test_mv_errors_file_a"; @@ -392,7 +386,7 @@ fn test_mv_errors() { #[test] fn test_mv_verbose() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; let dir = "test_mv_verbose_dir"; let file_a = "test_mv_verbose_file_a"; diff --git a/tests/test_nl.rs b/tests/test_nl.rs index da1721029..83bd202a0 100644 --- a/tests/test_nl.rs +++ b/tests/test_nl.rs @@ -1,17 +1,13 @@ use common::util::*; -static UTIL_NAME: &'static str = "nl"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn test_stdin_nonewline() { - new_ucmd().pipe_in("No Newline").run().stdout_is(" 1\tNo Newline\n"); + new_ucmd!().pipe_in("No Newline").run().stdout_is(" 1\tNo Newline\n"); } #[test] fn test_stdin_newline() { - new_ucmd() + new_ucmd!() .args(&["-s", "-", "-w", "1"]) .pipe_in("Line One\nLine Two\n") .run() @@ -20,7 +16,7 @@ fn test_stdin_newline() { #[test] fn test_padding_without_overflow() { - new_ucmd() + new_ucmd!() .args(&["-i", "1000", "-s", "x", "-n", "rz", "simple.txt"]).run() .stdout_is( "000001xL1\n001001xL2\n002001xL3\n003001xL4\n004001xL5\n005001xL6\n006001xL7\n0070\ @@ -30,7 +26,7 @@ fn test_padding_without_overflow() { #[test] fn test_padding_with_overflow() { - new_ucmd() + new_ucmd!() .args(&["-i", "1000", "-s", "x", "-n", "rz", "-w", "4", "simple.txt"]).run() .stdout_is( "0001xL1\n1001xL2\n2001xL3\n3001xL4\n4001xL5\n5001xL6\n6001xL7\n7001xL8\n8001xL9\n\ @@ -49,7 +45,7 @@ fn test_sections_and_styles() { |Followed by 4x empty\n\n\n\n\n9 |Nonempty\n10 |Nonempty\n11 \ |Nonempty.\n")] .iter() { - new_ucmd() + new_ucmd!() .args(&["-s", "|", "-n", "ln", "-w", "3", "-b", "a", "-l", "5", fixture]) .run() .stdout_is(output); diff --git a/tests/test_od.rs b/tests/test_od.rs index f65b0d0df..1933aa23c 100644 --- a/tests/test_od.rs +++ b/tests/test_od.rs @@ -5,10 +5,6 @@ use std::io::Write; use std::fs::File; use std::fs::remove_file; -static UTIL_NAME: &'static str = "od"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} // 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"; @@ -32,7 +28,7 @@ fn test_file() { } } - let result = new_ucmd().arg(file.as_os_str()).run(); + let result = new_ucmd!().arg(file.as_os_str()).run(); assert_empty_stderr!(result); assert!(result.success); @@ -61,7 +57,7 @@ fn test_2files() { } } - let result = new_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!(result.success); @@ -78,7 +74,7 @@ fn test_no_file() { let tmpdir = Path::new(&temp); let file = tmpdir.join("}surely'none'would'thus'a'file'name"); - let result = new_ucmd().arg(file.as_os_str()).run(); + let result = new_ucmd!().arg(file.as_os_str()).run(); assert!(!result.success); } @@ -88,7 +84,7 @@ fn test_no_file() { fn test_from_stdin() { let input = "abcdefghijklmnopqrstuvwxyz\n"; - let result = new_ucmd().run_piped_stdin(input.as_bytes()); + let result = new_ucmd!().run_piped_stdin(input.as_bytes()); assert_empty_stderr!(result); assert!(result.success); @@ -114,7 +110,7 @@ fn test_from_mixed() { } } - let result = new_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!(result.success); @@ -126,7 +122,7 @@ fn test_from_mixed() { fn test_multiple_formats() { let input = "abcdefghijklmnopqrstuvwxyz\n"; - let result = new_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!(result.success); @@ -147,7 +143,7 @@ fn test_dec() { 0x00u8,0x80u8, 0x01u8,0x80u8,]; let expected_output = "0000000 0 1 2 3 32767 -32768 -32767 \n0000016\n"; - let result = new_ucmd().arg("-i").run_piped_stdin(&input[..]); + let result = new_ucmd!().arg("-i").run_piped_stdin(&input[..]); assert_empty_stderr!(result); assert!(result.success); @@ -160,7 +156,7 @@ fn test_dec() { /* #[test] fn mit_die_umlauten_getesten() { - let result = new_ucmd() + let result = new_ucmd!() .run_piped_stdin("Universität Tübingen".as_bytes()); assert_empty_stderr!(result); assert!(result.success); diff --git a/tests/test_paste.rs b/tests/test_paste.rs index 714f0c3f6..1b73c8349 100644 --- a/tests/test_paste.rs +++ b/tests/test_paste.rs @@ -1,13 +1,9 @@ use common::util::*; -static UTIL_NAME: &'static str = "paste"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn test_combine_pairs_of_lines() { - new_ucmd() + new_ucmd!() .args(&["-s", "-d", "\t\n", "html_colors.txt"]) .run() .stdout_is_fixture("html_colors.expected"); diff --git a/tests/test_pathchk.rs b/tests/test_pathchk.rs index 5c93107ae..b478ccea1 100644 --- a/tests/test_pathchk.rs +++ b/tests/test_pathchk.rs @@ -1,17 +1,13 @@ use common::util::*; -static UTIL_NAME: &'static str = "pathchk"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn test_default_mode() { // test the default mode // accept some reasonable default - new_ucmd().args(&["abc/def"]).succeeds().no_stdout(); + new_ucmd!().args(&["abc/def"]).succeeds().no_stdout(); // fail on long inputs - new_ucmd().args(&[repeat_str("test", 20000)]).fails().no_stdout(); + new_ucmd!().args(&[repeat_str("test", 20000)]).fails().no_stdout(); } diff --git a/tests/test_pinky.rs b/tests/test_pinky.rs index a46c131e7..b15b3fd5f 100644 --- a/tests/test_pinky.rs +++ b/tests/test_pinky.rs @@ -1,9 +1,5 @@ use common::util::*; -static UTIL_NAME: &'static str = "pinky"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} use ::std::fs::File; use ::std::io::BufReader; @@ -35,12 +31,12 @@ fn test_capitalize() { fn test_long_format() { PASSWD.with(|v| { let gecos = v[4].replace("&", &v[4].capitalize()); - new_ucmd() + new_ucmd!() .arg("-l").arg("root") .run() .stdout_is(format!("Login name: {:<28}In real life: {}\nDirectory: {:<29}Shell: {}\n", v[0], gecos, v[5], v[6])); - new_ucmd() + new_ucmd!() .arg("-lb") .arg("root") .run() @@ -51,7 +47,7 @@ fn test_long_format() { #[cfg(target_os = "linux")] #[test] fn test_short_format() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); let args = ["-i"]; scene.ucmd().args(&args).run().stdout_is(expected_result(&args)); @@ -62,5 +58,5 @@ fn test_short_format() { #[cfg(target_os = "linux")] fn expected_result(args: &[&str]) -> String { - TestScenario::new(UTIL_NAME).cmd_keepenv(UTIL_NAME).args(args).run().stdout + TestScenario::new(util_name!()).cmd_keepenv(util_name!()).args(args).run().stdout } diff --git a/tests/test_printf.rs b/tests/test_printf.rs index 681331aca..fc5280416 100644 --- a/tests/test_printf.rs +++ b/tests/test_printf.rs @@ -1,283 +1,279 @@ use common::util::*; -static UTIL_NAME: &'static str = "printf"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn basic_literal() { - new_ucmd().args(&["hello world"]).succeeds().stdout_only("hello world"); + new_ucmd!().args(&["hello world"]).succeeds().stdout_only("hello world"); } #[test] fn escaped_tab() { - new_ucmd().args(&["hello\\t world"]).succeeds().stdout_only("hello\t world"); + new_ucmd!().args(&["hello\\t world"]).succeeds().stdout_only("hello\t world"); } #[test] fn escaped_newline() { - new_ucmd().args(&["hello\\n world"]).succeeds().stdout_only("hello\n world"); + new_ucmd!().args(&["hello\\n world"]).succeeds().stdout_only("hello\n world"); } #[test] fn escaped_slash() { - new_ucmd().args(&["hello\\\\ world"]).succeeds().stdout_only("hello\\ world"); + new_ucmd!().args(&["hello\\\\ world"]).succeeds().stdout_only("hello\\ world"); } #[test] fn escaped_hex() { - new_ucmd().args(&["\\x41"]).succeeds().stdout_only("A"); + new_ucmd!().args(&["\\x41"]).succeeds().stdout_only("A"); } #[test] fn escaped_octal() { - new_ucmd().args(&["\\101"]).succeeds().stdout_only("A"); + new_ucmd!().args(&["\\101"]).succeeds().stdout_only("A"); } #[test] fn escaped_unicode_fourdigit() { - new_ucmd().args(&["\\u0125"]).succeeds().stdout_only("ĥ"); + new_ucmd!().args(&["\\u0125"]).succeeds().stdout_only("ĥ"); } #[test] fn escaped_unicode_eightdigit() { - new_ucmd().args(&["\\U00000125"]).succeeds().stdout_only("ĥ"); + new_ucmd!().args(&["\\U00000125"]).succeeds().stdout_only("ĥ"); } #[test] fn escaped_percent_sign() { - new_ucmd().args(&["hello%% world"]).succeeds().stdout_only("hello% world"); + new_ucmd!().args(&["hello%% world"]).succeeds().stdout_only("hello% world"); } #[test] fn escaped_unrecognized() { - new_ucmd().args(&["c\\d"]).succeeds().stdout_only("c\\d"); + new_ucmd!().args(&["c\\d"]).succeeds().stdout_only("c\\d"); } #[test] fn sub_string() { - new_ucmd().args(&["hello %s", "world"]).succeeds().stdout_only("hello world"); + new_ucmd!().args(&["hello %s", "world"]).succeeds().stdout_only("hello world"); } #[test] fn sub_multifield() { - new_ucmd().args(&["%s %s", "hello", "world"]).succeeds().stdout_only("hello world"); + new_ucmd!().args(&["%s %s", "hello", "world"]).succeeds().stdout_only("hello world"); } #[test] fn sub_repeat_formatstr() { - new_ucmd().args(&["%s.", "hello", "world"]).succeeds().stdout_only("hello.world."); + new_ucmd!().args(&["%s.", "hello", "world"]).succeeds().stdout_only("hello.world."); } #[test] fn sub_string_ignore_escapes() { - new_ucmd().args(&["hello %s", "\\tworld"]).succeeds().stdout_only("hello \\tworld"); + new_ucmd!().args(&["hello %s", "\\tworld"]).succeeds().stdout_only("hello \\tworld"); } #[test] fn sub_bstring_handle_escapes() { - new_ucmd().args(&["hello %b", "\\tworld"]).succeeds().stdout_only("hello \tworld"); + new_ucmd!().args(&["hello %b", "\\tworld"]).succeeds().stdout_only("hello \tworld"); } #[test] fn sub_bstring_ignore_subs() { - new_ucmd().args(&["hello %b", "world %% %i"]).succeeds().stdout_only("hello world %% %i"); + new_ucmd!().args(&["hello %b", "world %% %i"]).succeeds().stdout_only("hello world %% %i"); } #[test] fn sub_char() { - new_ucmd().args(&["the letter %c", "A"]).succeeds().stdout_only("the letter A"); + new_ucmd!().args(&["the letter %c", "A"]).succeeds().stdout_only("the letter A"); } #[test] fn sub_num_int() { - new_ucmd().args(&["twenty is %i", "20"]).succeeds().stdout_only("twenty is 20"); + new_ucmd!().args(&["twenty is %i", "20"]).succeeds().stdout_only("twenty is 20"); } #[test] fn sub_num_int_minwidth() { - new_ucmd().args(&["twenty is %1i", "20"]).succeeds().stdout_only("twenty is 20"); + new_ucmd!().args(&["twenty is %1i", "20"]).succeeds().stdout_only("twenty is 20"); } #[test] fn sub_num_int_neg() { - new_ucmd().args(&["neg. twenty is %i", "-20"]).succeeds().stdout_only("neg. twenty is -20"); + new_ucmd!().args(&["neg. twenty is %i", "-20"]).succeeds().stdout_only("neg. twenty is -20"); } #[test] fn sub_num_int_oct_in() { - new_ucmd().args(&["twenty is %i", "024"]).succeeds().stdout_only("twenty is 20"); + new_ucmd!().args(&["twenty is %i", "024"]).succeeds().stdout_only("twenty is 20"); } #[test] fn sub_num_int_oct_in_neg() { - new_ucmd().args(&["neg. twenty is %i", "-024"]).succeeds().stdout_only("neg. twenty is -20"); + new_ucmd!().args(&["neg. twenty is %i", "-024"]).succeeds().stdout_only("neg. twenty is -20"); } #[test] fn sub_num_int_hex_in() { - new_ucmd().args(&["twenty is %i", "0x14"]).succeeds().stdout_only("twenty is 20"); + new_ucmd!().args(&["twenty is %i", "0x14"]).succeeds().stdout_only("twenty is 20"); } #[test] fn sub_num_int_hex_in_neg() { - new_ucmd().args(&["neg. twenty is %i", "-0x14"]).succeeds().stdout_only("neg. twenty is -20"); + new_ucmd!().args(&["neg. twenty is %i", "-0x14"]).succeeds().stdout_only("neg. twenty is -20"); } #[test] fn sub_num_int_charconst_in() { - new_ucmd().args(&["ninetyseven is %i", "'a"]).succeeds().stdout_only("ninetyseven is 97"); + new_ucmd!().args(&["ninetyseven is %i", "'a"]).succeeds().stdout_only("ninetyseven is 97"); } #[test] fn sub_num_uint() { - new_ucmd().args(&["twenty is %u", "20"]).succeeds().stdout_only("twenty is 20"); + new_ucmd!().args(&["twenty is %u", "20"]).succeeds().stdout_only("twenty is 20"); } #[test] fn sub_num_octal() { - new_ucmd().args(&["twenty in octal is %o", "20"]).succeeds().stdout_only("twenty in octal is 24"); + new_ucmd!().args(&["twenty in octal is %o", "20"]).succeeds().stdout_only("twenty in octal is 24"); } #[test] fn sub_num_hex_lower() { - new_ucmd().args(&["thirty in hex is %x", "30"]).succeeds().stdout_only("thirty in hex is 1e"); + new_ucmd!().args(&["thirty in hex is %x", "30"]).succeeds().stdout_only("thirty in hex is 1e"); } #[test] fn sub_num_hex_upper() { - new_ucmd().args(&["thirty in hex is %X", "30"]).succeeds().stdout_only("thirty in hex is 1E"); + new_ucmd!().args(&["thirty in hex is %X", "30"]).succeeds().stdout_only("thirty in hex is 1E"); } #[test] fn sub_num_float() { - new_ucmd().args(&["twenty is %f", "20"]).succeeds().stdout_only("twenty is 20.000000"); + new_ucmd!().args(&["twenty is %f", "20"]).succeeds().stdout_only("twenty is 20.000000"); } #[test] fn sub_num_float_round() { - new_ucmd().args(&["two is %f", "1.9999995"]).succeeds().stdout_only("two is 2.000000"); + new_ucmd!().args(&["two is %f", "1.9999995"]).succeeds().stdout_only("two is 2.000000"); } #[test] fn sub_num_sci_lower() { - new_ucmd().args(&["twenty is %e", "20"]).succeeds().stdout_only("twenty is 2.000000e+01"); + new_ucmd!().args(&["twenty is %e", "20"]).succeeds().stdout_only("twenty is 2.000000e+01"); } #[test] fn sub_num_sci_upper() { - new_ucmd().args(&["twenty is %E", "20"]).succeeds().stdout_only("twenty is 2.000000E+01"); + new_ucmd!().args(&["twenty is %E", "20"]).succeeds().stdout_only("twenty is 2.000000E+01"); } #[test] fn sub_num_sci_trunc() { - new_ucmd().args(&["pi is ~ %e", "3.1415926535"]).succeeds().stdout_only("pi is ~ 3.141593e+00"); + new_ucmd!().args(&["pi is ~ %e", "3.1415926535"]).succeeds().stdout_only("pi is ~ 3.141593e+00"); } #[test] fn sub_num_dec_trunc() { - new_ucmd().args(&["pi is ~ %g", "3.1415926535"]).succeeds().stdout_only("pi is ~ 3.141593"); + new_ucmd!().args(&["pi is ~ %g", "3.1415926535"]).succeeds().stdout_only("pi is ~ 3.141593"); } #[cfg_attr(not(feature="test_unimplemented"),ignore)] #[test] fn sub_num_hex_float_lower() { - new_ucmd().args(&["%a", ".875"]).succeeds().stdout_only("0xep-4"); + new_ucmd!().args(&["%a", ".875"]).succeeds().stdout_only("0xep-4"); } #[cfg_attr(not(feature="test_unimplemented"),ignore)] #[test] fn sub_num_hex_float_upper() { - new_ucmd().args(&["%A", ".875"]).succeeds().stdout_only("0XEP-4"); + new_ucmd!().args(&["%A", ".875"]).succeeds().stdout_only("0XEP-4"); } #[test] fn sub_minwidth() { - new_ucmd().args(&["hello %7s", "world"]).succeeds().stdout_only("hello world"); + new_ucmd!().args(&["hello %7s", "world"]).succeeds().stdout_only("hello world"); } #[test] fn sub_minwidth_negative() { - new_ucmd().args(&["hello %-7s", "world"]).succeeds().stdout_only("hello world "); + new_ucmd!().args(&["hello %-7s", "world"]).succeeds().stdout_only("hello world "); } #[test] fn sub_str_max_chars_input() { - new_ucmd().args(&["hello %7.2s", "world"]).succeeds().stdout_only("hello wo"); + new_ucmd!().args(&["hello %7.2s", "world"]).succeeds().stdout_only("hello wo"); } #[test] fn sub_int_decimal() { - new_ucmd().args(&["%0.i", "11"]).succeeds().stdout_only("11"); + new_ucmd!().args(&["%0.i", "11"]).succeeds().stdout_only("11"); } #[test] fn sub_int_leading_zeroes() { - new_ucmd().args(&["%.4i", "11"]).succeeds().stdout_only("0011"); + new_ucmd!().args(&["%.4i", "11"]).succeeds().stdout_only("0011"); } #[test] fn sub_int_leading_zeroes_prio() { - new_ucmd().args(&["%5.4i", "11"]).succeeds().stdout_only(" 0011"); + new_ucmd!().args(&["%5.4i", "11"]).succeeds().stdout_only(" 0011"); } #[test] fn sub_float_dec_places() { - new_ucmd().args(&["pi is ~ %.11f", "3.1415926535"]).succeeds().stdout_only("pi is ~ 3.14159265350"); + new_ucmd!().args(&["pi is ~ %.11f", "3.1415926535"]).succeeds().stdout_only("pi is ~ 3.14159265350"); } #[test] fn sub_float_hex_in() { - new_ucmd().args(&["%f", "0xF1.1F"]).succeeds().stdout_only("241.121094"); + new_ucmd!().args(&["%f", "0xF1.1F"]).succeeds().stdout_only("241.121094"); } #[test] fn sub_float_no_octal_in() { - new_ucmd().args(&["%f", "077"]).succeeds().stdout_only("77.000000"); + new_ucmd!().args(&["%f", "077"]).succeeds().stdout_only("77.000000"); } #[test] fn sub_any_asterisk_firstparam() { - new_ucmd().args(&["%*i", "3", "11", "4", "12"]).succeeds().stdout_only(" 11 12"); + new_ucmd!().args(&["%*i", "3", "11", "4", "12"]).succeeds().stdout_only(" 11 12"); } #[test] fn sub_any_asterisk_second_param() { - new_ucmd().args(&["%.*i", "3", "11", "4", "12"]).succeeds().stdout_only("0110012"); + new_ucmd!().args(&["%.*i", "3", "11", "4", "12"]).succeeds().stdout_only("0110012"); } #[test] fn sub_any_asterisk_both_params() { - new_ucmd().args(&["%*.*i", "4", "3", "11", "5", "4", "12"]).succeeds().stdout_only(" 011 0012"); + new_ucmd!().args(&["%*.*i", "4", "3", "11", "5", "4", "12"]).succeeds().stdout_only(" 011 0012"); } #[test] fn sub_any_asterisk_octal_arg() { - new_ucmd().args(&["%.*i", "011", "12345678"]).succeeds().stdout_only("012345678"); + new_ucmd!().args(&["%.*i", "011", "12345678"]).succeeds().stdout_only("012345678"); } #[test] fn sub_any_asterisk_hex_arg() { - new_ucmd().args(&["%.*i", "0xA", "123456789"]).succeeds().stdout_only("0123456789"); + new_ucmd!().args(&["%.*i", "0xA", "123456789"]).succeeds().stdout_only("0123456789"); } #[test] fn sub_any_specifiers_no_params() { - new_ucmd().args(&["%ztlhLji", "3"]).succeeds().stdout_only("3"); + new_ucmd!().args(&["%ztlhLji", "3"]).succeeds().stdout_only("3"); } #[test] fn sub_any_specifiers_after_first_param() { - new_ucmd().args(&["%0ztlhLji", "3"]).succeeds().stdout_only("3"); + new_ucmd!().args(&["%0ztlhLji", "3"]).succeeds().stdout_only("3"); } #[test] fn sub_any_specifiers_after_period() { - new_ucmd().args(&["%0.ztlhLji", "3"]).succeeds().stdout_only("3"); + new_ucmd!().args(&["%0.ztlhLji", "3"]).succeeds().stdout_only("3"); } #[test] fn sub_any_specifiers_after_second_param() { - new_ucmd().args(&["%0.0ztlhLji", "3"]).succeeds().stdout_only("3"); + new_ucmd!().args(&["%0.0ztlhLji", "3"]).succeeds().stdout_only("3"); } diff --git a/tests/test_ptx.rs b/tests/test_ptx.rs index 6aa450c25..231c03f13 100644 --- a/tests/test_ptx.rs +++ b/tests/test_ptx.rs @@ -1,48 +1,44 @@ use common::util::*; -static UTIL_NAME: &'static str = "ptx"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn gnu_ext_disabled_roff_no_ref() { - new_ucmd().args(&["-G", "-R", "input"]) + new_ucmd!().args(&["-G", "-R", "input"]) .succeeds().stdout_only_fixture("gnu_ext_disabled_roff_no_ref.expected"); } #[test] fn gnu_ext_disabled_roff_input_ref() { - new_ucmd().args(&["-G", "-r", "-R", "input"]) + new_ucmd!().args(&["-G", "-r", "-R", "input"]) .succeeds().stdout_only_fixture("gnu_ext_disabled_roff_input_ref.expected"); } #[test] fn gnu_ext_disabled_roff_auto_ref() { - new_ucmd().args(&["-G", "-A", "-R", "input"]) + new_ucmd!().args(&["-G", "-A", "-R", "input"]) .succeeds().stdout_only_fixture("gnu_ext_disabled_roff_auto_ref.expected"); } #[test] fn gnu_ext_disabled_tex_no_ref() { - new_ucmd().args(&["-G", "-T", "-R", "input"]) + new_ucmd!().args(&["-G", "-T", "-R", "input"]) .succeeds().stdout_only_fixture("gnu_ext_disabled_tex_no_ref.expected"); } #[test] fn gnu_ext_disabled_tex_input_ref() { - new_ucmd().args(&["-G", "-T", "-r", "-R", "input"]) + new_ucmd!().args(&["-G", "-T", "-r", "-R", "input"]) .succeeds().stdout_only_fixture("gnu_ext_disabled_tex_input_ref.expected"); } #[test] fn gnu_ext_disabled_tex_auto_ref() { - new_ucmd().args(&["-G", "-T", "-A", "-R", "input"]) + new_ucmd!().args(&["-G", "-T", "-A", "-R", "input"]) .succeeds().stdout_only_fixture("gnu_ext_disabled_tex_auto_ref.expected"); } #[test] fn gnu_ext_disabled_ignore_and_only_file() { - new_ucmd().args(&["-G", "-o", "only", "-i", "ignore", "input"]) + new_ucmd!().args(&["-G", "-o", "only", "-i", "ignore", "input"]) .succeeds().stdout_only_fixture("gnu_ext_disabled_ignore_and_only_file.expected"); } diff --git a/tests/test_pwd.rs b/tests/test_pwd.rs index 5b8351392..e003d1c36 100644 --- a/tests/test_pwd.rs +++ b/tests/test_pwd.rs @@ -1,14 +1,8 @@ use common::util::*; -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] fn test_default() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); ucmd.run().stdout_is(at.root_dir_resolved()); } diff --git a/tests/test_readlink.rs b/tests/test_readlink.rs index 399bd8f88..000c15584 100644 --- a/tests/test_readlink.rs +++ b/tests/test_readlink.rs @@ -1,20 +1,11 @@ use common::util::*; -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"; #[test] fn test_canonicalize() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); ucmd.arg("-f") .arg(".") .run() @@ -23,7 +14,7 @@ fn test_canonicalize() { #[test] fn test_canonicalize_existing() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); ucmd.arg("-e") .arg(".") .run() @@ -32,7 +23,7 @@ fn test_canonicalize_existing() { #[test] fn test_canonicalize_missing() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let expected = path_concat!(at.root_dir_resolved(), GIBBERISH); ucmd.arg("-m") .arg(GIBBERISH) @@ -42,7 +33,7 @@ fn test_canonicalize_missing() { #[test] fn test_long_redirection_to_current_dir() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); // Create a 256-character path to current directory let dir = path_concat!(".", ..128); ucmd.arg("-n") @@ -56,7 +47,7 @@ fn test_long_redirection_to_current_dir() { fn test_long_redirection_to_root() { // Create a 255-character path to root let dir = path_concat!("..", ..85); - new_ucmd() + new_ucmd!() .arg("-n") .arg("-m") .arg(dir) diff --git a/tests/test_realpath.rs b/tests/test_realpath.rs index d53c730ff..d0fb18f61 100644 --- a/tests/test_realpath.rs +++ b/tests/test_realpath.rs @@ -1,24 +1,15 @@ use common::util::*; -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] fn test_current_directory() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); ucmd.arg(".").run().stdout_is(at.root_dir_resolved()); } #[test] fn test_long_redirection_to_current_dir() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); // Create a 256-character path to current directory let dir = path_concat!(".", ..128); ucmd.arg(dir).run().stdout_is(at.root_dir_resolved()); @@ -28,5 +19,5 @@ fn test_long_redirection_to_current_dir() { fn test_long_redirection_to_root() { // Create a 255-character path to root let dir = path_concat!("..", ..85); - new_ucmd().arg(dir).run().stdout_is(get_root_path()); + new_ucmd!().arg(dir).run().stdout_is(get_root_path()); } diff --git a/tests/test_rm.rs b/tests/test_rm.rs index 77f956773..a3cac9dbf 100644 --- a/tests/test_rm.rs +++ b/tests/test_rm.rs @@ -1,15 +1,9 @@ use common::util::*; -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] fn test_rm_one_file() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_rm_one_file"; at.touch(file); @@ -21,7 +15,7 @@ fn test_rm_one_file() { #[test] fn test_rm_multiple_files() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file_a = "test_rm_multiple_file_a"; let file_b = "test_rm_multiple_file_b"; @@ -36,7 +30,7 @@ fn test_rm_multiple_files() { #[test] fn test_rm_interactive() { - let scene = TestScenario::new(UTIL_NAME); + let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; let file_a = "test_rm_interactive_file_a"; @@ -68,7 +62,7 @@ fn test_rm_interactive() { #[test] fn test_rm_force() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file_a = "test_rm_force_a"; let file_b = "test_rm_force_b"; @@ -84,7 +78,7 @@ fn test_rm_force() { #[test] fn test_rm_empty_directory() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_rm_empty_directory"; at.mkdir(dir); @@ -96,7 +90,7 @@ fn test_rm_empty_directory() { #[test] fn test_rm_recursive() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_rm_recursive_directory"; let file_a = "test_rm_recursive_directory/test_rm_recursive_file_a"; let file_b = "test_rm_recursive_directory/test_rm_recursive_file_b"; @@ -114,7 +108,7 @@ fn test_rm_recursive() { #[test] fn test_rm_errors() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_rm_errors_directory"; let file_a = "test_rm_errors_directory/test_rm_errors_file_a"; let file_b = "test_rm_errors_directory/test_rm_errors_file_b"; @@ -132,7 +126,7 @@ fn test_rm_errors() { #[test] fn test_rm_verbose() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file_a = "test_rm_verbose_file_a"; let file_b = "test_rm_verbose_file_b"; diff --git a/tests/test_rmdir.rs b/tests/test_rmdir.rs index 8d9a5dcae..3116ca665 100644 --- a/tests/test_rmdir.rs +++ b/tests/test_rmdir.rs @@ -1,15 +1,9 @@ use common::util::*; -static UTIL_NAME: &'static str = "rmdir"; -fn at_and_ucmd() -> (AtPath, UCommand) { - let ts = TestScenario::new(UTIL_NAME); - let ucmd = ts.ucmd(); - (ts.fixtures, ucmd) -} #[test] fn test_rmdir_empty_directory_no_parents() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_rmdir_empty_no_parents"; at.mkdir(dir); @@ -22,7 +16,7 @@ fn test_rmdir_empty_directory_no_parents() { #[test] fn test_rmdir_empty_directory_with_parents() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_rmdir_empty/with/parents"; at.mkdir_all(dir); @@ -35,7 +29,7 @@ fn test_rmdir_empty_directory_with_parents() { #[test] fn test_rmdir_nonempty_directory_no_parents() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_rmdir_nonempty_no_parents"; let file = "test_rmdir_nonempty_no_parents/foo"; @@ -54,7 +48,7 @@ fn test_rmdir_nonempty_directory_no_parents() { #[test] fn test_rmdir_nonempty_directory_with_parents() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_rmdir_nonempty/with/parents"; let file = "test_rmdir_nonempty/with/parents/foo"; @@ -76,7 +70,7 @@ fn test_rmdir_nonempty_directory_with_parents() { #[test] fn test_rmdir_ignore_nonempty_directory_no_parents() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_rmdir_ignore_nonempty_no_parents"; let file = "test_rmdir_ignore_nonempty_no_parents/foo"; @@ -93,7 +87,7 @@ fn test_rmdir_ignore_nonempty_directory_no_parents() { #[test] fn test_rmdir_ignore_nonempty_directory_with_parents() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_rmdir_ignore_nonempty/with/parents"; let file = "test_rmdir_ignore_nonempty/with/parents/foo"; diff --git a/tests/test_seq.rs b/tests/test_seq.rs index 804bd6c39..fc9f59140 100644 --- a/tests/test_seq.rs +++ b/tests/test_seq.rs @@ -1,30 +1,26 @@ use common::util::*; -static UTIL_NAME: &'static str = "seq"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn test_count_up() { - new_ucmd() + new_ucmd!() .args(&["10"]).run().stdout_is("1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"); } #[test] fn test_count_down() { - new_ucmd() + new_ucmd!() .args(&["--", "5", "-1", "1"]).run().stdout_is("5\n4\n3\n2\n1\n"); } #[test] fn test_separator_and_terminator() { - new_ucmd() + new_ucmd!() .args(&["-s", ",", "-t", "!", "2", "6"]).run().stdout_is("2,3,4,5,6!"); } #[test] fn test_equalize_widths() { - new_ucmd() + new_ucmd!() .args(&["-w", "5", "10"]).run().stdout_is("05\n06\n07\n08\n09\n10\n"); } diff --git a/tests/test_sort.rs b/tests/test_sort.rs index 18180d4a4..3ddb635da 100644 --- a/tests/test_sort.rs +++ b/tests/test_sort.rs @@ -1,10 +1,6 @@ use common::util::*; -static UTIL_NAME: &'static str = "sort"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn test_numeric_floats_and_ints() { @@ -63,7 +59,7 @@ fn test_version() { #[test] fn test_multiple_files() { - new_ucmd() + new_ucmd!() .arg("-n") .arg("multiple_files1.txt") .arg("multiple_files2.txt") @@ -72,7 +68,7 @@ fn test_multiple_files() { #[test] fn test_merge_interleaved() { - new_ucmd() + new_ucmd!() .arg("-m") .arg("merge_ints_interleaved_1.txt") .arg("merge_ints_interleaved_2.txt") @@ -82,7 +78,7 @@ fn test_merge_interleaved() { #[test] fn test_merge_unique() { - new_ucmd() + new_ucmd!() .arg("-m") .arg("--unique") .arg("merge_ints_interleaved_1.txt") @@ -96,7 +92,7 @@ fn test_merge_unique() { #[test] fn test_merge_reversed() { - new_ucmd() + new_ucmd!() .arg("-m") .arg("--reverse") .arg("merge_ints_reversed_1.txt") @@ -107,18 +103,18 @@ fn test_merge_reversed() { #[test] fn test_check() { - new_ucmd() + new_ucmd!() .arg("-c") .arg("check_fail.txt") .fails().stdout_is("sort: disorder in line 4\n"); - new_ucmd() + new_ucmd!() .arg("-c") .arg("multiple_files.expected") .succeeds().stdout_is(""); } fn test_helper(file_name: &str, args: &str) { - new_ucmd().arg(args).arg(format!("{}{}", file_name, ".txt")) + new_ucmd!().arg(args).arg(format!("{}{}", file_name, ".txt")) .succeeds().stdout_is_fixture(format!("{}{}", file_name, ".expected")); } diff --git a/tests/test_split.rs b/tests/test_split.rs index 4a789b864..fa84443c7 100644 --- a/tests/test_split.rs +++ b/tests/test_split.rs @@ -8,12 +8,6 @@ use self::rand::{Rng, thread_rng}; use self::regex::Regex; use common::util::*; -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 { thread_rng().gen_ascii_chars().take(n).collect::() @@ -97,7 +91,7 @@ impl RandomFile { #[test] fn test_split_default() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let name = "split_default"; let glob = Glob::new(&at, ".", r"x[:alpha:][:alpha:]$"); RandomFile::new(&at, name).add_lines(2000); @@ -108,7 +102,7 @@ fn test_split_default() { #[test] fn test_split_num_prefixed_chunks_by_bytes() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let name = "split_num_prefixed_chunks_by_bytes"; let glob = Glob::new(&at, ".", r"a\d\d$"); RandomFile::new(&at, name).add_bytes(10000); @@ -119,7 +113,7 @@ fn test_split_num_prefixed_chunks_by_bytes() { #[test] fn test_split_str_prefixed_chunks_by_bytes() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let name = "split_str_prefixed_chunks_by_bytes"; let glob = Glob::new(&at, ".", r"b[:alpha:][:alpha:]$"); RandomFile::new(&at, name).add_bytes(10000); @@ -130,7 +124,7 @@ fn test_split_str_prefixed_chunks_by_bytes() { #[test] fn test_split_num_prefixed_chunks_by_lines() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let name = "split_num_prefixed_chunks_by_lines"; let glob = Glob::new(&at, ".", r"c\d\d$"); RandomFile::new(&at, name).add_lines(10000); @@ -141,7 +135,7 @@ fn test_split_num_prefixed_chunks_by_lines() { #[test] fn test_split_str_prefixed_chunks_by_lines() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let name = "split_str_prefixed_chunks_by_lines"; let glob = Glob::new(&at, ".", r"d[:alpha:][:alpha:]$"); RandomFile::new(&at, name).add_lines(10000); diff --git a/tests/test_stat.rs b/tests/test_stat.rs index 8154bc510..68e4f991a 100644 --- a/tests/test_stat.rs +++ b/tests/test_stat.rs @@ -3,10 +3,6 @@ use common::util::*; extern crate uu_stat; pub use self::uu_stat::*; -static UTIL_NAME: &'static str = "stat"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[cfg(test)] mod test_fsext { @@ -143,7 +139,7 @@ mod test_generate_tokens { #[test] fn test_invalid_option() { - new_ucmd() + new_ucmd!() .arg("-w").arg("-q").arg("/").fails(); } @@ -158,7 +154,7 @@ const FS_FMTSTR: &'static str = "%a %b %c %d %f %i %l %n %s %S %t %T"; #[cfg(target_os = "linux")] fn test_terse_fs_format() { let args = ["-f", "-t", "/proc"]; - new_ucmd().args(&args) + new_ucmd!().args(&args) .run() .stdout_is(expected_result(&args)); } @@ -167,7 +163,7 @@ fn test_terse_fs_format() { #[cfg(target_os = "linux")] fn test_fs_format() { let args = ["-f", "-c", FS_FMTSTR, "/dev/shm"]; - new_ucmd().args(&args) + new_ucmd!().args(&args) .run() .stdout_is(expected_result(&args)); } @@ -176,7 +172,7 @@ fn test_fs_format() { #[cfg(target_os = "linux")] fn test_terse_normal_format() { let args = ["-t", "/"]; - new_ucmd().args(&args) + new_ucmd!().args(&args) .run() .stdout_is(expected_result(&args)); } @@ -185,7 +181,7 @@ fn test_terse_normal_format() { #[cfg(target_os = "linux")] fn test_normal_format() { let args = ["-c", NORMAL_FMTSTR, "/boot"]; - new_ucmd().args(&args) + new_ucmd!().args(&args) .run() .stdout_is(expected_result(&args)); } @@ -194,7 +190,7 @@ fn test_normal_format() { #[cfg(target_os = "linux")] fn test_follow_symlink() { let args = ["-L", "-c", DEV_FMTSTR, "/dev/cdrom"]; - new_ucmd().args(&args) + new_ucmd!().args(&args) .run() .stdout_is(expected_result(&args)); } @@ -203,7 +199,7 @@ fn test_follow_symlink() { #[cfg(target_os = "linux")] fn test_symlink() { let args = ["-c", DEV_FMTSTR, "/dev/cdrom"]; - new_ucmd().args(&args) + new_ucmd!().args(&args) .run() .stdout_is(expected_result(&args)); } @@ -212,7 +208,7 @@ fn test_symlink() { #[cfg(target_os = "linux")] fn test_char() { let args = ["-c", DEV_FMTSTR, "/dev/zero"]; - new_ucmd().args(&args) + new_ucmd!().args(&args) .run() .stdout_is(expected_result(&args)); } @@ -221,7 +217,7 @@ fn test_char() { #[cfg(target_os = "linux")] fn test_multi_files() { let args = ["-c", NORMAL_FMTSTR, "/dev", "/usr/lib", "/etc/fstab", "/var"]; - new_ucmd().args(&args) + new_ucmd!().args(&args) .run() .stdout_is(expected_result(&args)); } @@ -230,7 +226,7 @@ fn test_multi_files() { #[cfg(target_os = "linux")] fn test_printf() { let args = ["--printf=123%-# 15q\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.23m\\x12\\167\\132\\112\\n", "/"]; - new_ucmd().args(&args) + new_ucmd!().args(&args) .run() .stdout_is(expected_result(&args)); } @@ -239,6 +235,6 @@ fn test_printf() { fn expected_result(args: &[&str]) -> String { use std::process::Command; - let output = Command::new(UTIL_NAME).args(args).output().unwrap(); + let output = Command::new(util_name!()).args(args).output().unwrap(); String::from_utf8_lossy(&output.stdout).into_owned() } diff --git a/tests/test_stdbuf.rs b/tests/test_stdbuf.rs index 703d78ea2..27d8de26b 100644 --- a/tests/test_stdbuf.rs +++ b/tests/test_stdbuf.rs @@ -1,15 +1,11 @@ use common::util::*; -static UTIL_NAME: &'static str = "stdbuf"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn test_stdbuf_unbuffered_stdout() { if cfg!(target_os="linux") { // This is a basic smoke test - new_ucmd().args(&["-o0", "head"]) + new_ucmd!().args(&["-o0", "head"]) .pipe_in("The quick brown fox jumps over the lazy dog.").run() .stdout_is("The quick brown fox jumps over the lazy dog."); } diff --git a/tests/test_sum.rs b/tests/test_sum.rs index 9e10ac562..99a5ff566 100644 --- a/tests/test_sum.rs +++ b/tests/test_sum.rs @@ -1,20 +1,16 @@ use common::util::*; -static UTIL_NAME: &'static str = "sum"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn test_bsd_single_file() { - new_ucmd() + new_ucmd!() .arg("lorem_ipsum.txt") .succeeds().stdout_only_fixture("bsd_single_file.expected"); } #[test] fn test_bsd_multiple_files() { - new_ucmd() + new_ucmd!() .arg("lorem_ipsum.txt") .arg("alice_in_wonderland.txt") .succeeds().stdout_only_fixture("bsd_multiple_files.expected"); @@ -22,21 +18,21 @@ fn test_bsd_multiple_files() { #[test] fn test_bsd_stdin() { - new_ucmd() + new_ucmd!() .pipe_in_fixture("lorem_ipsum.txt") .succeeds().stdout_only_fixture("bsd_stdin.expected"); } #[test] fn test_sysv_single_file() { - new_ucmd() + new_ucmd!() .arg("-s").arg("lorem_ipsum.txt") .succeeds().stdout_only_fixture("sysv_single_file.expected"); } #[test] fn test_sysv_multiple_files() { - new_ucmd() + new_ucmd!() .arg("-s") .arg("lorem_ipsum.txt") .arg("alice_in_wonderland.txt") @@ -45,7 +41,7 @@ fn test_sysv_multiple_files() { #[test] fn test_sysv_stdin() { - new_ucmd() + new_ucmd!() .arg("-s") .pipe_in_fixture("lorem_ipsum.txt") .succeeds().stdout_only_fixture("sysv_stdin.expected"); diff --git a/tests/test_tac.rs b/tests/test_tac.rs index 74d61791e..aa78b946e 100644 --- a/tests/test_tac.rs +++ b/tests/test_tac.rs @@ -1,13 +1,9 @@ use common::util::*; -static UTIL_NAME: &'static str = "tac"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn test_stdin_default() { - new_ucmd() + new_ucmd!() .pipe_in("100\n200\n300\n400\n500") .run() .stdout_is("500400\n300\n200\n100\n"); @@ -15,7 +11,7 @@ fn test_stdin_default() { #[test] fn test_stdin_non_newline_separator() { - new_ucmd() + new_ucmd!() .args(&["-s", ":"]) .pipe_in("100:200:300:400:500") .run() @@ -24,7 +20,7 @@ fn test_stdin_non_newline_separator() { #[test] fn test_stdin_non_newline_separator_before() { - new_ucmd() + new_ucmd!() .args(&["-b", "-s", ":"]) .pipe_in("100:200:300:400:500") .run() @@ -33,18 +29,18 @@ fn test_stdin_non_newline_separator_before() { #[test] fn test_single_default() { - new_ucmd().arg("prime_per_line.txt") + new_ucmd!().arg("prime_per_line.txt") .run().stdout_is_fixture("prime_per_line.expected"); } #[test] fn test_single_non_newline_separator() { - new_ucmd().args(&["-s", ":", "delimited_primes.txt"]) + new_ucmd!().args(&["-s", ":", "delimited_primes.txt"]) .run().stdout_is_fixture("delimited_primes.expected"); } #[test] fn test_single_non_newline_separator_before() { - new_ucmd().args(&["-b", "-s", ":", "delimited_primes.txt"]) + new_ucmd!().args(&["-b", "-s", ":", "delimited_primes.txt"]) .run().stdout_is_fixture("delimited_primes_before.expected"); } diff --git a/tests/test_tail.rs b/tests/test_tail.rs index 333018621..06b96b2fd 100644 --- a/tests/test_tail.rs +++ b/tests/test_tail.rs @@ -5,15 +5,6 @@ use std::char::from_digit; use std::io::Write; use self::uu_tail::parse_size; -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_2_TXT: &'static str = "foobar2.txt"; @@ -21,28 +12,28 @@ static FOOBAR_WITH_NULL_TXT: &'static str = "foobar_with_null.txt"; #[test] fn test_stdin_default() { - new_ucmd().pipe_in_fixture(FOOBAR_TXT).run().stdout_is_fixture("foobar_stdin_default.expected"); + new_ucmd!().pipe_in_fixture(FOOBAR_TXT).run().stdout_is_fixture("foobar_stdin_default.expected"); } #[test] fn test_single_default() { - new_ucmd().arg(FOOBAR_TXT).run().stdout_is_fixture("foobar_single_default.expected"); + new_ucmd!().arg(FOOBAR_TXT).run().stdout_is_fixture("foobar_single_default.expected"); } #[test] fn test_n_greater_than_number_of_lines() { - new_ucmd().arg("-n").arg("99999999").arg(FOOBAR_TXT).run() + new_ucmd!().arg("-n").arg("99999999").arg(FOOBAR_TXT).run() .stdout_is_fixture(FOOBAR_TXT); } #[test] fn test_null_default() { - new_ucmd().arg("-z").arg(FOOBAR_WITH_NULL_TXT).run().stdout_is_fixture("foobar_with_null_default.expected"); + new_ucmd!().arg("-z").arg(FOOBAR_WITH_NULL_TXT).run().stdout_is_fixture("foobar_with_null_default.expected"); } #[test] fn test_follow() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let mut child = ucmd.arg("-f").arg(FOOBAR_TXT).run_no_wait(); @@ -60,7 +51,7 @@ fn test_follow() { #[test] fn test_follow_multiple() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let mut child = ucmd.arg("-f").arg(FOOBAR_TXT).arg(FOOBAR_2_TXT).run_no_wait(); let expected = at.read("foobar_follow_multiple.expected"); @@ -80,7 +71,7 @@ fn test_follow_multiple() { #[test] fn test_follow_stdin() { - new_ucmd().arg("-f").pipe_in_fixture(FOOBAR_TXT).run().stdout_is_fixture("follow_stdin.expected"); + new_ucmd!().arg("-f").pipe_in_fixture(FOOBAR_TXT).run().stdout_is_fixture("follow_stdin.expected"); } #[test] @@ -90,7 +81,7 @@ fn test_single_big_args() { const LINES: usize = 1_000_000; const N_ARG: usize = 100_000; - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let mut big_input = at.make_file(FILE); for i in 0..LINES { @@ -109,13 +100,13 @@ fn test_single_big_args() { #[test] fn test_bytes_single() { - new_ucmd().arg("-c").arg("10").arg(FOOBAR_TXT).run() + new_ucmd!().arg("-c").arg("10").arg(FOOBAR_TXT).run() .stdout_is_fixture("foobar_bytes_single.expected"); } #[test] fn test_bytes_stdin() { - new_ucmd().arg("-c").arg("13").pipe_in_fixture(FOOBAR_TXT).run() + new_ucmd!().arg("-c").arg("13").pipe_in_fixture(FOOBAR_TXT).run() .stdout_is_fixture("foobar_bytes_stdin.expected"); } @@ -126,7 +117,7 @@ fn test_bytes_big() { const BYTES: usize = 1_000_000; const N_ARG: usize = 100_000; - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let mut big_input = at.make_file(FILE); for i in 0..BYTES { @@ -193,7 +184,7 @@ fn test_lines_with_size_suffix() { const LINES: usize = 3_000; const N_ARG: usize = 2 * 1024; - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let mut big_input = at.make_file(FILE); for i in 0..LINES { diff --git a/tests/test_test.rs b/tests/test_test.rs index 0c1f54153..048a11489 100644 --- a/tests/test_test.rs +++ b/tests/test_test.rs @@ -9,28 +9,24 @@ use common::util::*; -static UTIL_NAME: &'static str = "test"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn test_op_prec_and_or_1() { - new_ucmd() + new_ucmd!() .args(&[" ", "-o", "", "-a", ""]) .succeeds(); } #[test] fn test_op_prec_and_or_2() { - new_ucmd() + new_ucmd!() .args(&["", "-a", "", "-o", " ", "-a", " "]) .succeeds(); } #[test] fn test_or_as_filename() { - new_ucmd() + new_ucmd!() .args(&["x", "-a", "-z", "-o"]) .fails(); } diff --git a/tests/test_touch.rs b/tests/test_touch.rs index 031c960e6..17069dc3a 100644 --- a/tests/test_touch.rs +++ b/tests/test_touch.rs @@ -4,12 +4,6 @@ extern crate time; use common::util::*; use self::filetime::FileTime; -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) { let m = at.metadata(path); @@ -31,7 +25,7 @@ fn str_to_filetime(format: &str, s: &str) -> FileTime { #[test] fn test_touch_default() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_touch_default_file"; ucmd.arg(file).succeeds().no_stderr(); @@ -42,7 +36,7 @@ fn test_touch_default() { #[test] fn test_touch_no_create_file_absent() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_touch_no_create_file_absent"; ucmd.arg("-c").arg(file).succeeds().no_stderr(); @@ -52,7 +46,7 @@ fn test_touch_no_create_file_absent() { #[test] fn test_touch_no_create_file_exists() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_touch_no_create_file_exists"; at.touch(file); @@ -65,7 +59,7 @@ fn test_touch_no_create_file_exists() { #[test] fn test_touch_set_mdhm_time() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_touch_set_mdhm_time"; ucmd.args(&["-t", "01011234", file]).succeeds().no_stderr(); @@ -83,7 +77,7 @@ fn test_touch_set_mdhm_time() { #[test] fn test_touch_set_mdhms_time() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_touch_set_mdhms_time"; ucmd.args(&["-t", "01011234.56", file]).succeeds().no_stderr(); @@ -101,7 +95,7 @@ fn test_touch_set_mdhms_time() { #[test] fn test_touch_set_ymdhm_time() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_touch_set_ymdhm_time"; ucmd.args(&["-t", "1501011234", file]).succeeds().no_stderr(); @@ -119,7 +113,7 @@ fn test_touch_set_ymdhm_time() { #[test] fn test_touch_set_ymdhms_time() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_touch_set_ymdhms_time"; ucmd.args(&["-t", "1501011234.56", file]).succeeds().no_stderr(); @@ -137,7 +131,7 @@ fn test_touch_set_ymdhms_time() { #[test] fn test_touch_set_cymdhm_time() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_touch_set_cymdhm_time"; ucmd.args(&["-t", "201501011234", file]).succeeds().no_stderr(); @@ -155,7 +149,7 @@ fn test_touch_set_cymdhm_time() { #[test] fn test_touch_set_cymdhms_time() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_touch_set_cymdhms_time"; ucmd.args(&["-t", "201501011234.56", file]).succeeds().no_stderr(); @@ -173,7 +167,7 @@ fn test_touch_set_cymdhms_time() { #[test] fn test_touch_set_only_atime() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_touch_set_only_atime"; ucmd.args(&["-t", "201501011234", "-a", file]).succeeds().no_stderr(); @@ -189,7 +183,7 @@ fn test_touch_set_only_atime() { #[test] fn test_touch_set_only_mtime() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_touch_set_only_mtime"; ucmd.args(&["-t", "201501011234", "-m", file]).succeeds().no_stderr(); @@ -205,7 +199,7 @@ fn test_touch_set_only_mtime() { #[test] fn test_touch_set_both() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_touch_set_both"; ucmd.args(&["-t", "201501011234", "-a", "-m", file]).succeeds().no_stderr(); @@ -223,7 +217,7 @@ fn test_touch_set_both() { #[test] fn test_touch_reference() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file_a = "test_touch_reference_a"; let file_b = "test_touch_reference_b"; let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000"); @@ -244,7 +238,7 @@ fn test_touch_reference() { #[test] fn test_touch_set_date() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_touch_set_date"; ucmd.args(&["-d", "Thu Jan 01 12:34:00 2015", file]).succeeds().no_stderr(); diff --git a/tests/test_tr.rs b/tests/test_tr.rs index b20d96e37..48a38d7a0 100644 --- a/tests/test_tr.rs +++ b/tests/test_tr.rs @@ -1,25 +1,21 @@ use common::util::*; -static UTIL_NAME: &'static str = "tr"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn test_toupper() { - new_ucmd() + new_ucmd!() .args(&["a-z", "A-Z"]).pipe_in("!abcd!").run().stdout_is("!ABCD!"); } #[test] fn test_small_set2() { - new_ucmd() + new_ucmd!() .args(&["0-9", "X"]).pipe_in("@0123456789").run().stdout_is("@XXXXXXXXXX"); } #[test] fn test_unicode() { - new_ucmd() + new_ucmd!() .args(&[", ┬─┬", "╯︵┻━┻"]) .pipe_in("(,°□°), ┬─┬").run() .stdout_is("(╯°□°)╯︵┻━┻"); @@ -27,12 +23,12 @@ fn test_unicode() { #[test] fn test_delete() { - new_ucmd() + new_ucmd!() .args(&["-d", "a-z"]).pipe_in("aBcD").run().stdout_is("BD"); } #[test] fn test_delete_complement() { - new_ucmd() + new_ucmd!() .args(&["-d", "-c", "a-z"]).pipe_in("aBcD").run().stdout_is("ac"); } diff --git a/tests/test_true.rs b/tests/test_true.rs index f8486ec71..e8dbb0fdc 100644 --- a/tests/test_true.rs +++ b/tests/test_true.rs @@ -1,11 +1,7 @@ use common::util::*; -static UTIL_NAME: &'static str = "true"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn test_exit_code() { - new_ucmd().succeeds(); + new_ucmd!().succeeds(); } diff --git a/tests/test_truncate.rs b/tests/test_truncate.rs index ca56fb477..005dc0ec5 100644 --- a/tests/test_truncate.rs +++ b/tests/test_truncate.rs @@ -1,19 +1,13 @@ use common::util::*; use std::io::{Seek, SeekFrom, Write}; -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 TFILE2: &'static str = "truncate_test_2"; #[test] fn test_increase_file_size() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let mut file = at.make_file(TFILE1); ucmd.args(&["-s", "+5K", TFILE1]).succeeds(); @@ -23,7 +17,7 @@ fn test_increase_file_size() { #[test] fn test_decrease_file_size() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let mut file = at.make_file(TFILE2); file.write_all(b"1234567890").unwrap(); ucmd.args(&["--size=-4", TFILE2]).succeeds(); diff --git a/tests/test_tsort.rs b/tests/test_tsort.rs index 513a86360..2fe199cdd 100644 --- a/tests/test_tsort.rs +++ b/tests/test_tsort.rs @@ -1,13 +1,9 @@ use common::util::*; -static UTIL_NAME: &'static str = "tsort"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn test_sort_call_graph() { - new_ucmd() + new_ucmd!() .arg("call_graph.txt") .run() .stdout_is_fixture("call_graph.expected"); diff --git a/tests/test_unexpand.rs b/tests/test_unexpand.rs index e4f000fcb..49220dcb7 100644 --- a/tests/test_unexpand.rs +++ b/tests/test_unexpand.rs @@ -1,27 +1,23 @@ use common::util::*; -static UTIL_NAME: &'static str = "unexpand"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn unexpand_init_0() { - new_ucmd() + new_ucmd!() .args(&["-t4"]).pipe_in(" 1\n 2\n 3\n 4\n") .run().stdout_is(" 1\n 2\n 3\n\t4\n"); } #[test] fn unexpand_init_1() { - new_ucmd() + new_ucmd!() .args(&["-t4"]).pipe_in(" 5\n 6\n 7\n 8\n") .run().stdout_is("\t 5\n\t 6\n\t 7\n\t\t8\n"); } #[test] fn unexpand_init_list_0() { - new_ucmd() + new_ucmd!() .args(&["-t2,4"]).pipe_in(" 1\n 2\n 3\n 4\n") .run().stdout_is(" 1\n\t2\n\t 3\n\t\t4\n"); } @@ -29,42 +25,42 @@ fn unexpand_init_list_0() { #[test] fn unexpand_init_list_1() { // Once the list is exhausted, spaces are not converted anymore - new_ucmd() + new_ucmd!() .args(&["-t2,4"]).pipe_in(" 5\n 6\n 7\n 8\n") .run().stdout_is("\t\t 5\n\t\t 6\n\t\t 7\n\t\t 8\n"); } #[test] fn unexpand_aflag_0() { - new_ucmd() + new_ucmd!() .args(&["--"]).pipe_in("e E\nf F\ng G\nh H\n") .run().stdout_is("e E\nf F\ng G\nh H\n"); } #[test] fn unexpand_aflag_1() { - new_ucmd() + new_ucmd!() .args(&["-a"]).pipe_in("e E\nf F\ng G\nh H\n") .run().stdout_is("e E\nf F\ng\tG\nh\t H\n"); } #[test] fn unexpand_aflag_2() { - new_ucmd() + new_ucmd!() .args(&["-t8"]).pipe_in("e E\nf F\ng G\nh H\n") .run().stdout_is("e E\nf F\ng\tG\nh\t H\n"); } #[test] fn unexpand_first_only_0() { - new_ucmd() + new_ucmd!() .args(&["-t3"]).pipe_in(" A B") .run().stdout_is("\t\t A\t B"); } #[test] fn unexpand_first_only_1() { - new_ucmd() + new_ucmd!() .args(&["-t3", "--first-only"]).pipe_in(" A B") .run().stdout_is("\t\t A B"); } @@ -74,7 +70,7 @@ fn unexpand_trailing_space_0() { // evil // Individual spaces before fields starting with non blanks should not be // converted, unless they are at the beginning of the line. - new_ucmd() + new_ucmd!() .args(&["-t4"]).pipe_in("123 \t1\n123 1\n123 \n123 ") .run().stdout_is("123\t\t1\n123 1\n123 \n123 "); } @@ -82,7 +78,7 @@ fn unexpand_trailing_space_0() { #[test] fn unexpand_trailing_space_1() { // super evil - new_ucmd() + new_ucmd!() .args(&["-t1"]).pipe_in(" abc d e f g ") .run().stdout_is("\tabc d e\t\tf\t\tg "); } @@ -90,7 +86,7 @@ fn unexpand_trailing_space_1() { #[test] fn unexpand_spaces_follow_tabs_0() { // The two first spaces can be included into the first tab. - new_ucmd() + new_ucmd!() .pipe_in(" \t\t A") .run().stdout_is("\t\t A"); } @@ -103,14 +99,14 @@ fn unexpand_spaces_follow_tabs_1() { // ' \t' -> '\t' // second tabstop (4) // ' ' -> '\t' // third tabstop (5) // ' B \t' -> ' B \t' // after the list is exhausted, nothing must change - new_ucmd() + new_ucmd!() .args(&["-t1,4,5"]).pipe_in("a \t B \t") .run().stdout_is("a\t\t B \t"); } #[test] fn unexpand_spaces_after_fields() { - new_ucmd() + new_ucmd!() .args(&["-a"]).pipe_in(" \t A B C D A\t\n") .run().stdout_is("\t\tA B C D\t\t A\t\n"); } diff --git a/tests/test_uniq.rs b/tests/test_uniq.rs index 481404b24..3d4f06b79 100644 --- a/tests/test_uniq.rs +++ b/tests/test_uniq.rs @@ -1,9 +1,5 @@ use common::util::*; -static UTIL_NAME: &'static str = "uniq"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} static INPUT: &'static str = "sorted.txt"; static SKIP_CHARS: &'static str = "skip-chars.txt"; @@ -12,98 +8,98 @@ static SORTED_ZERO_TERMINATED: &'static str = "sorted-zero-terminated.txt"; #[test] fn test_stdin_default() { - new_ucmd() + new_ucmd!() .pipe_in_fixture(INPUT) .run().stdout_is_fixture("sorted-simple.expected"); } #[test] fn test_single_default() { - new_ucmd() + new_ucmd!() .arg(INPUT) .run().stdout_is_fixture("sorted-simple.expected"); } #[test] fn test_stdin_counts() { - new_ucmd() + new_ucmd!() .args(&["-c"]).pipe_in_fixture(INPUT) .run().stdout_is_fixture("sorted-counts.expected"); } #[test] fn test_stdin_skip_1_char() { - new_ucmd() + new_ucmd!() .args(&["-s1"]).pipe_in_fixture(SKIP_CHARS) .run().stdout_is_fixture("skip-1-char.expected"); } #[test] fn test_stdin_skip_5_chars() { - new_ucmd() + new_ucmd!() .args(&["-s5"]).pipe_in_fixture(SKIP_CHARS) .run().stdout_is_fixture("skip-5-chars.expected"); } #[test] fn test_stdin_skip_and_check_2_chars() { - new_ucmd() + new_ucmd!() .args(&["-s3", "-w2"]).pipe_in_fixture(SKIP_CHARS) .run().stdout_is_fixture("skip-3-check-2-chars.expected"); } #[test] fn test_stdin_skip_1_field() { - new_ucmd() + new_ucmd!() .args(&["-f2"]).pipe_in_fixture(SKIP_FIELDS) .run().stdout_is_fixture("skip-2-fields.expected"); } #[test] fn test_stdin_all_repeated() { - new_ucmd() + new_ucmd!() .args(&["--all-repeated"]).pipe_in_fixture(INPUT) .run().stdout_is_fixture("sorted-all-repeated.expected"); } #[test] fn test_stdin_all_repeated_separate() { - new_ucmd() + new_ucmd!() .args(&["--all-repeated", "separate"]).pipe_in_fixture(INPUT) .run().stdout_is_fixture("sorted-all-repeated-separate.expected"); } #[test] fn test_stdin_all_repeated_prepend() { - new_ucmd() + new_ucmd!() .args(&["--all-repeated", "prepend"]).pipe_in_fixture(INPUT) .run().stdout_is_fixture("sorted-all-repeated-prepend.expected"); } #[test] fn test_stdin_unique_only() { - new_ucmd() + new_ucmd!() .args(&["-u"]).pipe_in_fixture(INPUT) .run().stdout_is_fixture("sorted-unique-only.expected"); } #[test] fn test_stdin_repeated_only() { - new_ucmd() + new_ucmd!() .args(&["-d"]).pipe_in_fixture(INPUT) .run().stdout_is_fixture("sorted-repeated-only.expected"); } #[test] fn test_stdin_ignore_case() { - new_ucmd() + new_ucmd!() .args(&["-i"]).pipe_in_fixture(INPUT) .run().stdout_is_fixture("sorted-ignore-case.expected"); } #[test] fn test_stdin_zero_terminated() { - new_ucmd() + new_ucmd!() .args(&["-z"]).pipe_in_fixture(SORTED_ZERO_TERMINATED) .run().stdout_is_fixture("sorted-zero-terminated.expected"); } diff --git a/tests/test_unlink.rs b/tests/test_unlink.rs index f5716b7ce..1146a4085 100644 --- a/tests/test_unlink.rs +++ b/tests/test_unlink.rs @@ -1,18 +1,9 @@ use common::util::*; -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] fn test_unlink_file() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file = "test_unlink_file"; at.touch(file); @@ -24,7 +15,7 @@ fn test_unlink_file() { #[test] fn test_unlink_multiple_files() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let file_a = "test_unlink_multiple_file_a"; let file_b = "test_unlink_multiple_file_b"; @@ -38,7 +29,7 @@ fn test_unlink_multiple_files() { #[test] fn test_unlink_directory() { - let (at, mut ucmd) = at_and_ucmd(); + let (at, mut ucmd) = at_and_ucmd!(); let dir = "test_unlink_empty_directory"; at.mkdir(dir); @@ -52,7 +43,7 @@ fn test_unlink_directory() { fn test_unlink_nonexistent() { let file = "test_unlink_nonexistent"; - new_ucmd().arg(file).fails() + new_ucmd!().arg(file).fails() .stderr_is("unlink: error: Cannot stat 'test_unlink_nonexistent': No such file or directory \ (os error 2)\n"); } diff --git a/tests/test_wc.rs b/tests/test_wc.rs index 98cba7e83..6d3027c2b 100644 --- a/tests/test_wc.rs +++ b/tests/test_wc.rs @@ -1,25 +1,21 @@ use common::util::*; -static UTIL_NAME: &'static str = "wc"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[test] fn test_stdin_default() { - new_ucmd().pipe_in_fixture("lorem_ipsum.txt") + new_ucmd!().pipe_in_fixture("lorem_ipsum.txt") .run().stdout_is(" 13 109 772\n"); } #[test] fn test_stdin_only_bytes() { - new_ucmd().args(&["-c"]).pipe_in_fixture("lorem_ipsum.txt") + new_ucmd!().args(&["-c"]).pipe_in_fixture("lorem_ipsum.txt") .run().stdout_is(" 772\n"); } #[test] fn test_stdin_all_counts() { - new_ucmd().args(&["-c", "-m", "-l", "-L", "-w"]) + new_ucmd!().args(&["-c", "-m", "-l", "-L", "-w"]) .pipe_in_fixture("alice_in_wonderland.txt") .run() .stdout_is(" 5 57 302 302 66\n"); @@ -27,26 +23,26 @@ fn test_stdin_all_counts() { #[test] fn test_single_default() { - new_ucmd() + new_ucmd!() .arg("moby_dick.txt").run().stdout_is(" 18 204 1115 moby_dick.txt\n"); } #[test] fn test_single_only_lines() { - new_ucmd() + new_ucmd!() .args(&["-l", "moby_dick.txt"]).run().stdout_is(" 18 moby_dick.txt\n"); } #[test] fn test_single_all_counts() { - new_ucmd() + new_ucmd!() .args(&["-c", "-l", "-L", "-m", "-w", "alice_in_wonderland.txt"]).run() .stdout_is(" 5 57 302 302 66 alice_in_wonderland.txt\n"); } #[test] fn test_multiple_default() { - new_ucmd() + new_ucmd!() .args(&["lorem_ipsum.txt", "moby_dick.txt", "alice_in_wonderland.txt"]).run() .stdout_is( " 13 109 772 lorem_ipsum.txt\n 18 204 1115 moby_dick.txt\n 5 57 302 \ diff --git a/tests/test_who.rs b/tests/test_who.rs index 6b7ae8431..c32adac19 100644 --- a/tests/test_who.rs +++ b/tests/test_who.rs @@ -1,16 +1,12 @@ use common::util::*; -static UTIL_NAME: &'static str = "who"; -fn new_ucmd() -> UCommand { - TestScenario::new(UTIL_NAME).ucmd() -} #[cfg(target_os = "linux")] #[test] fn test_count() { for opt in vec!["-q", "--count"] { - new_ucmd().arg(opt).run().stdout_is(expected_result(opt)); + new_ucmd!().arg(opt).run().stdout_is(expected_result(opt)); } } @@ -18,7 +14,7 @@ fn test_count() { #[test] fn test_boot() { for opt in vec!["-b", "--boot"] { - new_ucmd().arg(opt).run().stdout_is(expected_result(opt)); + new_ucmd!().arg(opt).run().stdout_is(expected_result(opt)); } } @@ -26,7 +22,7 @@ fn test_boot() { #[test] fn test_heading() { for opt in vec!["-H"] { - new_ucmd().arg(opt).run().stdout_is(expected_result(opt)); + new_ucmd!().arg(opt).run().stdout_is(expected_result(opt)); } } @@ -34,7 +30,7 @@ fn test_heading() { #[test] fn test_short() { for opt in vec!["-s", "--short"] { - new_ucmd().arg(opt).run().stdout_is(expected_result(opt)); + new_ucmd!().arg(opt).run().stdout_is(expected_result(opt)); } } @@ -42,7 +38,7 @@ fn test_short() { #[test] fn test_login() { for opt in vec!["-l", "--login"] { - new_ucmd().arg(opt).run().stdout_is(expected_result(opt)); + new_ucmd!().arg(opt).run().stdout_is(expected_result(opt)); } } @@ -50,7 +46,7 @@ fn test_login() { #[test] fn test_m() { for opt in vec!["-m"] { - new_ucmd().arg(opt).run().stdout_is(expected_result(opt)); + new_ucmd!().arg(opt).run().stdout_is(expected_result(opt)); } } @@ -58,7 +54,7 @@ fn test_m() { #[test] fn test_dead() { for opt in vec!["-d", "--dead"] { - new_ucmd().arg(opt).run().stdout_is(expected_result(opt)); + new_ucmd!().arg(opt).run().stdout_is(expected_result(opt)); } } @@ -66,11 +62,11 @@ fn test_dead() { #[test] fn test_all() { for opt in vec!["-a", "--all"] { - new_ucmd().arg(opt).run().stdout_is(expected_result(opt)); + new_ucmd!().arg(opt).run().stdout_is(expected_result(opt)); } } #[cfg(target_os = "linux")] fn expected_result(arg: &str) -> String { - TestScenario::new(UTIL_NAME).cmd_keepenv(UTIL_NAME).args(&[arg]).run().stdout + TestScenario::new(util_name!()).cmd_keepenv(util_name!()).args(&[arg]).run().stdout } From b667fce8ba6e7801e3e1bfdd888cd9a1b03f562a Mon Sep 17 00:00:00 2001 From: nathanross Date: Tue, 23 Aug 2016 08:57:13 -0400 Subject: [PATCH 2/2] clone atpath to avoid borrow issue --- tests/common/macros.rs | 4 +--- tests/common/util.rs | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/common/macros.rs b/tests/common/macros.rs index 54fbcab58..e36fdffdc 100644 --- a/tests/common/macros.rs +++ b/tests/common/macros.rs @@ -61,8 +61,6 @@ macro_rules! new_ucmd { macro_rules! at_and_ucmd { () => ({ let ts = TestScenario::new(util_name!()); - #[allow(unused_mut)] - let mut ucmd = ts.ucmd(); - (ts.fixtures, ucmd) + (ts.fixtures.clone(), ts.ucmd()) }) } diff --git a/tests/common/util.rs b/tests/common/util.rs index da05d4c38..3c20fdb2c 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -181,6 +181,7 @@ pub fn get_root_path() -> &'static str { /// Object-oriented path struct that represents and operates on /// paths relative to the directory it was constructed for. +#[derive(Clone)] pub struct AtPath { pub subdir: PathBuf, }