1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 03:57:44 +00:00

rustfmt the tests

This commit is contained in:
Sylvestre Ledru 2020-04-13 20:36:03 +02:00
parent 78624a53ee
commit cf35d75491
61 changed files with 3414 additions and 1975 deletions

View file

@ -20,51 +20,55 @@ mod test_generate_tokens {
#[test] #[test]
fn test_normal_format() { fn test_normal_format() {
let s = "%10.2ac%-5.w\n"; let s = "%10.2ac%-5.w\n";
let expected = vec![Token::Directive { let expected = vec![
flag: 0, Token::Directive {
width: 10, flag: 0,
precision: 2, width: 10,
format: 'a', precision: 2,
}, format: 'a',
Token::Char('c'), },
Token::Directive { Token::Char('c'),
flag: F_LEFT, Token::Directive {
width: 5, flag: F_LEFT,
precision: 0, width: 5,
format: 'w', precision: 0,
}, format: 'w',
Token::Char('\n')]; },
Token::Char('\n'),
];
assert_eq!(&expected, &Stater::generate_tokens(s, false).unwrap()); assert_eq!(&expected, &Stater::generate_tokens(s, false).unwrap());
} }
#[test] #[test]
fn test_printf_format() { fn test_printf_format() {
let s = "%-# 15a\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.-23w\\x12\\167\\132\\112\\n"; let s = "%-# 15a\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.-23w\\x12\\167\\132\\112\\n";
let expected = vec![Token::Directive { let expected = vec![
flag: F_LEFT | F_ALTER | F_SPACE, Token::Directive {
width: 15, flag: F_LEFT | F_ALTER | F_SPACE,
precision: -1, width: 15,
format: 'a', precision: -1,
}, format: 'a',
Token::Char('\r'), },
Token::Char('"'), Token::Char('\r'),
Token::Char('\\'), Token::Char('"'),
Token::Char('\x07'), Token::Char('\\'),
Token::Char('\x08'), Token::Char('\x07'),
Token::Char('\x1B'), Token::Char('\x08'),
Token::Char('\x0C'), Token::Char('\x1B'),
Token::Char('\x0B'), Token::Char('\x0C'),
Token::Directive { Token::Char('\x0B'),
flag: F_SIGN | F_ZERO, Token::Directive {
width: 20, flag: F_SIGN | F_ZERO,
precision: -1, width: 20,
format: 'w', precision: -1,
}, format: 'w',
Token::Char('\x12'), },
Token::Char('w'), Token::Char('\x12'),
Token::Char('Z'), Token::Char('w'),
Token::Char('J'), Token::Char('Z'),
Token::Char('\n')]; Token::Char('J'),
Token::Char('\n'),
];
assert_eq!(&expected, &Stater::generate_tokens(s, true).unwrap()); assert_eq!(&expected, &Stater::generate_tokens(s, true).unwrap());
} }
} }

View file

@ -8,7 +8,6 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_encode() { fn test_encode() {
let input = "Hello, World!"; let input = "Hello, World!";
@ -62,18 +61,19 @@ fn test_wrap() {
.arg("20") .arg("20")
.pipe_in(input) .pipe_in(input)
.succeeds() .succeeds()
.stdout_only("KRUGKIDROVUWG2ZAMJZG\n653OEBTG66BANJ2W24DT\nEBXXMZLSEB2GQZJANRQX\nU6JAMRXWOLQ=\n"); .stdout_only(
"KRUGKIDROVUWG2ZAMJZG\n653OEBTG66BANJ2W24DT\nEBXXMZLSEB2GQZJANRQX\nU6JAMRXWOLQ=\n",
);
} }
} }
#[test] #[test]
fn test_wrap_no_arg() { fn test_wrap_no_arg() {
for wrap_param in vec!["-w", "--wrap"] { for wrap_param in vec!["-w", "--wrap"] {
new_ucmd!() new_ucmd!().arg(wrap_param).fails().stderr_only(format!(
.arg(wrap_param) "base32: error: Argument to option '{}' missing\n",
.fails() if wrap_param == "-w" { "w" } else { "wrap" }
.stderr_only(format!("base32: error: Argument to option '{}' missing\n", ));
if wrap_param == "-w" { "w" } else { "wrap" }));
} }
} }
@ -81,7 +81,8 @@ fn test_wrap_no_arg() {
fn test_wrap_bad_arg() { fn test_wrap_bad_arg() {
for wrap_param in vec!["-w", "--wrap"] { for wrap_param in vec!["-w", "--wrap"] {
new_ucmd!() new_ucmd!()
.arg(wrap_param).arg("b") .arg(wrap_param)
.arg("b")
.fails() .fails()
.stderr_only("base32: error: invalid wrap size: b: invalid digit found in string\n"); .stderr_only("base32: error: invalid wrap size: b: invalid digit found in string\n");
} }

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_encode() { fn test_encode() {
let input = "hello, world!"; let input = "hello, world!";
@ -61,11 +60,10 @@ fn test_wrap() {
#[test] #[test]
fn test_wrap_no_arg() { fn test_wrap_no_arg() {
for wrap_param in vec!["-w", "--wrap"] { for wrap_param in vec!["-w", "--wrap"] {
new_ucmd!() new_ucmd!().arg(wrap_param).fails().stderr_only(format!(
.arg(wrap_param) "base64: error: Argument to option '{}' missing\n",
.fails() if wrap_param == "-w" { "w" } else { "wrap" }
.stderr_only(format!("base64: error: Argument to option '{}' missing\n", ));
if wrap_param == "-w" { "w" } else { "wrap" }));
} }
} }

View file

@ -1,34 +1,45 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_directory() { fn test_directory() {
new_ucmd!().args(&["/root/alpha/beta/gamma/delta/epsilon/omega/"]) new_ucmd!()
.succeeds().stdout_only("omega\n"); .args(&["/root/alpha/beta/gamma/delta/epsilon/omega/"])
.succeeds()
.stdout_only("omega\n");
} }
#[test] #[test]
fn test_file() { fn test_file() {
new_ucmd!().args(&["/etc/passwd"]).succeeds().stdout_only("passwd\n"); new_ucmd!()
.args(&["/etc/passwd"])
.succeeds()
.stdout_only("passwd\n");
} }
#[test] #[test]
fn test_remove_suffix() { fn test_remove_suffix() {
new_ucmd!().args(&["/usr/local/bin/reallylongexecutable.exe", ".exe"]) new_ucmd!()
.succeeds().stdout_only("reallylongexecutable\n"); .args(&["/usr/local/bin/reallylongexecutable.exe", ".exe"])
.succeeds()
.stdout_only("reallylongexecutable\n");
} }
#[test] #[test]
fn test_dont_remove_suffix() { fn test_dont_remove_suffix() {
new_ucmd!().args(&["/foo/bar/baz", "baz"]).succeeds().stdout_only( "baz\n"); new_ucmd!()
.args(&["/foo/bar/baz", "baz"])
.succeeds()
.stdout_only("baz\n");
} }
#[test] #[test]
fn test_multiple_param() { fn test_multiple_param() {
for multiple_param in vec!["-a", "--multiple"] { for multiple_param in vec!["-a", "--multiple"] {
let path = "/foo/bar/baz"; let path = "/foo/bar/baz";
new_ucmd!().args(&[multiple_param, path, path]) new_ucmd!()
.succeeds().stdout_only("baz\nbaz\n"); .args(&[multiple_param, path, path])
.succeeds()
.stdout_only("baz\nbaz\n");
} }
} }
@ -38,7 +49,8 @@ fn test_suffix_param() {
let path = "/foo/bar/baz.exe"; let path = "/foo/bar/baz.exe";
new_ucmd!() new_ucmd!()
.args(&[suffix_param, ".exe", path, path]) .args(&[suffix_param, ".exe", path, path])
.succeeds().stdout_only("baz\nbaz\n"); .succeeds()
.stdout_only("baz\nbaz\n");
} }
} }
@ -46,15 +58,15 @@ fn test_suffix_param() {
fn test_zero_param() { fn test_zero_param() {
for zero_param in vec!["-z", "--zero"] { for zero_param in vec!["-z", "--zero"] {
let path = "/foo/bar/baz"; let path = "/foo/bar/baz";
new_ucmd!().args(&[zero_param, "-a", path, path]) new_ucmd!()
.succeeds().stdout_only("baz\0baz\0"); .args(&[zero_param, "-a", path, path])
.succeeds()
.stdout_only("baz\0baz\0");
} }
} }
fn expect_error(input: Vec<&str>) { fn expect_error(input: Vec<&str>) {
assert!(new_ucmd!().args(&input) assert!(new_ucmd!().args(&input).fails().no_stdout().stderr.len() > 0);
.fails().no_stdout().stderr.len() > 0);
} }
#[test] #[test]

View file

@ -1,6 +1,6 @@
extern crate tempdir;
#[cfg(unix)] #[cfg(unix)]
extern crate unix_socket; extern crate unix_socket;
extern crate tempdir;
use common::util::*; use common::util::*;
@ -9,7 +9,8 @@ fn test_output_multi_files_print_all_chars() {
new_ucmd!() new_ucmd!()
.args(&["alpha.txt", "256.txt", "-A", "-n"]) .args(&["alpha.txt", "256.txt", "-A", "-n"])
.succeeds() .succeeds()
.stdout_only(" 1\tabcde$\n 2\tfghij$\n 3\tklmno$\n 4\tpqrst$\n \ .stdout_only(
" 1\tabcde$\n 2\tfghij$\n 3\tklmno$\n 4\tpqrst$\n \
5\tuvwxyz$\n 6\t^@^A^B^C^D^E^F^G^H^I$\n \ 5\tuvwxyz$\n 6\t^@^A^B^C^D^E^F^G^H^I$\n \
7\t^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\\^]^^^_ \ 7\t^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\\^]^^^_ \
!\"#$%&\'()*+,-./0123456789:;\ !\"#$%&\'()*+,-./0123456789:;\
@ -19,7 +20,8 @@ fn test_output_multi_files_print_all_chars() {
M-!M-\"M-#M-$M-%M-&M-\'M-(M-)M-*M-+M-,M--M-.M-/M-0M-1M-2M-3M-4M-5M-6M-7M-8M-9M-:\ M-!M-\"M-#M-$M-%M-&M-\'M-(M-)M-*M-+M-,M--M-.M-/M-0M-1M-2M-3M-4M-5M-6M-7M-8M-9M-:\
M-;M-<M-=M->M-?M-@M-AM-BM-CM-DM-EM-FM-GM-HM-IM-JM-KM-LM-MM-NM-OM-PM-QM-RM-SM-TM-U\ M-;M-<M-=M->M-?M-@M-AM-BM-CM-DM-EM-FM-GM-HM-IM-JM-KM-LM-MM-NM-OM-PM-QM-RM-SM-TM-U\
M-VM-WM-XM-YM-ZM-[M-\\M-]M-^M-_M-`M-aM-bM-cM-dM-eM-fM-gM-hM-iM-jM-kM-lM-mM-nM-oM-\ M-VM-WM-XM-YM-ZM-[M-\\M-]M-^M-_M-`M-aM-bM-cM-dM-eM-fM-gM-hM-iM-jM-kM-lM-mM-nM-oM-\
pM-qM-rM-sM-tM-uM-vM-wM-xM-yM-zM-{M-|M-}M-~M-^?"); pM-qM-rM-sM-tM-uM-vM-wM-xM-yM-zM-{M-|M-}M-~M-^?",
);
} }
#[test] #[test]
@ -27,8 +29,10 @@ fn test_numbered_lines_no_trailing_newline() {
new_ucmd!() new_ucmd!()
.args(&["nonewline.txt", "alpha.txt", "-n"]) .args(&["nonewline.txt", "alpha.txt", "-n"])
.succeeds() .succeeds()
.stdout_only(" 1\ttext without a trailing newlineabcde\n 2\tfghij\n \ .stdout_only(
3\tklmno\n 4\tpqrst\n 5\tuvwxyz\n"); " 1\ttext without a trailing newlineabcde\n 2\tfghij\n \
3\tklmno\n 4\tpqrst\n 5\tuvwxyz\n",
);
} }
#[test] #[test]
@ -53,12 +57,11 @@ fn test_stdin_show_tabs() {
} }
} }
#[test] #[test]
fn test_stdin_show_ends() { fn test_stdin_show_ends() {
for same_param in vec!["-E", "--show-ends"] { for same_param in vec!["-E", "--show-ends"] {
new_ucmd!() new_ucmd!()
.args(&[same_param,"-"]) .args(&[same_param, "-"])
.pipe_in("\t\0\n\t") .pipe_in("\t\0\n\t")
.succeeds() .succeeds()
.stdout_only("\t\0$\n\t"); .stdout_only("\t\0$\n\t");
@ -139,15 +142,13 @@ fn test_squeeze_blank_before_numbering() {
} }
} }
#[test] #[test]
#[cfg(foo)] #[cfg(foo)]
fn test_domain_socket() { fn test_domain_socket() {
use std::thread;
use self::unix_socket::UnixListener;
use self::tempdir::TempDir; use self::tempdir::TempDir;
use self::unix_socket::UnixListener;
use std::io::prelude::*; use std::io::prelude::*;
use std::thread;
let dir = TempDir::new("unix_socket").expect("failed to create dir"); let dir = TempDir::new("unix_socket").expect("failed to create dir");
let socket_path = dir.path().join("sock"); let socket_path = dir.path().join("sock");
@ -155,7 +156,9 @@ fn test_domain_socket() {
let thread = thread::spawn(move || { let thread = thread::spawn(move || {
let mut stream = listener.accept().expect("failed to accept connection").0; let mut stream = listener.accept().expect("failed to accept connection").0;
stream.write_all(b"a\tb").expect("failed to write test data"); stream
.write_all(b"a\tb")
.expect("failed to write test data");
}); });
new_ucmd!() new_ucmd!()

View file

@ -3,10 +3,7 @@ use rust_users::*;
#[test] #[test]
fn test_invalid_option() { fn test_invalid_option() {
new_ucmd!() new_ucmd!().arg("-w").arg("/").fails();
.arg("-w")
.arg("/")
.fails();
} }
static DIR: &'static str = "/tmp"; static DIR: &'static str = "/tmp";
@ -48,9 +45,12 @@ fn test_fail_silently() {
#[test] #[test]
fn test_preserve_root() { fn test_preserve_root() {
// It's weird that on OS X, `realpath /etc/..` returns '/private' // It's weird that on OS X, `realpath /etc/..` returns '/private'
for d in &["/", "/////tmp///../../../../", for d in &[
"../../../../../../../../../../../../../../", "/",
"./../../../../../../../../../../../../../../"] { "/////tmp///../../../../",
"../../../../../../../../../../../../../../",
"./../../../../../../../../../../../../../../",
] {
new_ucmd!() new_ucmd!()
.arg("--preserve-root") .arg("--preserve-root")
.arg("-R") .arg("-R")
@ -63,9 +63,12 @@ fn test_preserve_root() {
#[test] #[test]
fn test_preserve_root_symlink() { fn test_preserve_root_symlink() {
let file = "test_chgrp_symlink2root"; let file = "test_chgrp_symlink2root";
for d in &["/", "////tmp//../../../../", for d in &[
"..//../../..//../..//../../../../../../../../", "/",
".//../../../../../../..//../../../../../../../"] { "////tmp//../../../../",
"..//../../..//../..//../../../../../../../../",
".//../../../../../../..//../../../../../../../",
] {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
at.symlink_file(d, file); at.symlink_file(d, file);
ucmd.arg("--preserve-root") ucmd.arg("--preserve-root")
@ -91,7 +94,7 @@ fn test_preserve_root_symlink() {
.fails() .fails()
.stderr_is("chgrp: it is dangerous to operate recursively on '/'\nchgrp: use --no-preserve-root to override this failsafe"); .stderr_is("chgrp: it is dangerous to operate recursively on '/'\nchgrp: use --no-preserve-root to override this failsafe");
use ::std::fs; use std::fs;
fs::remove_file("/tmp/__root__").unwrap(); fs::remove_file("/tmp/__root__").unwrap();
} }
@ -131,7 +134,9 @@ fn test_big_p() {
.arg("bin") .arg("bin")
.arg("/proc/self/cwd") .arg("/proc/self/cwd")
.fails() .fails()
.stderr_is("chgrp: changing group of '/proc/self/cwd': Operation not permitted (os error 1)\n"); .stderr_is(
"chgrp: changing group of '/proc/self/cwd': Operation not permitted (os error 1)\n",
);
} }
} }
@ -139,13 +144,16 @@ fn test_big_p() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_big_h() { fn test_big_h() {
if get_effective_gid() != 0 { if get_effective_gid() != 0 {
assert!(new_ucmd!() assert!(
.arg("-RH") new_ucmd!()
.arg("bin") .arg("-RH")
.arg("/proc/self/fd") .arg("bin")
.fails() .arg("/proc/self/fd")
.stderr .fails()
.lines() .stderr
.fold(0, |acc, _| acc + 1) > 1); .lines()
.fold(0, |acc, _| acc + 1)
> 1
);
} }
} }

View file

@ -1,12 +1,11 @@
use common::util::*; use common::util::*;
use std::fs::{metadata, OpenOptions, set_permissions}; use std::fs::{metadata, set_permissions, OpenOptions};
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt}; use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
use std::sync::Mutex; use std::sync::Mutex;
extern crate libc; extern crate libc;
use self::libc::umask; use self::libc::umask;
static TEST_FILE: &'static str = "file"; static TEST_FILE: &'static str = "file";
static REFERENCE_FILE: &'static str = "reference"; static REFERENCE_FILE: &'static str = "reference";
static REFERENCE_PERMS: u32 = 0o247; static REFERENCE_PERMS: u32 = 0o247;
@ -17,36 +16,47 @@ lazy_static! {
struct TestCase { struct TestCase {
args: Vec<&'static str>, args: Vec<&'static str>,
before: u32, before: u32,
after: u32 after: u32,
} }
fn mkfile(file: &str, mode: u32) { fn mkfile(file: &str, mode: u32) {
OpenOptions::new().mode(mode).create(true).write(true).open(file).unwrap(); OpenOptions::new()
.mode(mode)
.create(true)
.write(true)
.open(file)
.unwrap();
let mut perms = metadata(file).unwrap().permissions(); let mut perms = metadata(file).unwrap().permissions();
perms.set_mode(mode); perms.set_mode(mode);
set_permissions(file, perms).unwrap(); set_permissions(file, perms).unwrap();
} }
fn run_single_test(test: &TestCase, at: AtPath, mut ucmd: UCommand) { fn run_single_test(test: &TestCase, at: AtPath, mut ucmd: UCommand) {
mkfile(&at.plus_as_string(TEST_FILE), test.before); mkfile(&at.plus_as_string(TEST_FILE), test.before);
let perms = at.metadata(TEST_FILE).permissions().mode(); let perms = at.metadata(TEST_FILE).permissions().mode();
if perms != test.before { if perms != test.before {
panic!(format!("{}: expected: {:o} got: {:o}", "setting permissions on test files before actual test run failed", test.after, perms)); panic!(format!(
} "{}: expected: {:o} got: {:o}",
"setting permissions on test files before actual test run failed", test.after, perms
));
}
for arg in &test.args { for arg in &test.args {
ucmd.arg(arg); ucmd.arg(arg);
} }
let r = ucmd.run(); let r = ucmd.run();
if !r.success { if !r.success {
println!("{}", r.stderr); println!("{}", r.stderr);
panic!(format!("{:?}: failed", ucmd.raw)); panic!(format!("{:?}: failed", ucmd.raw));
} }
let perms = at.metadata(TEST_FILE).permissions().mode(); let perms = at.metadata(TEST_FILE).permissions().mode();
if perms != test.after { if perms != test.after {
panic!(format!("{:?}: expected: {:o} got: {:o}", ucmd.raw, test.after, perms)); panic!(format!(
} "{:?}: expected: {:o} got: {:o}",
ucmd.raw, test.after, perms
));
}
} }
fn run_tests(tests: Vec<TestCase>) { fn run_tests(tests: Vec<TestCase>) {
@ -58,17 +68,53 @@ fn run_tests(tests: Vec<TestCase>) {
#[test] #[test]
fn test_chmod_octal() { fn test_chmod_octal() {
let tests = vec!{ let tests = vec![
TestCase{args: vec!{"0700", TEST_FILE}, before: 0o100000, after: 0o100700}, TestCase {
TestCase{args: vec!{"0070", TEST_FILE}, before: 0o100000, after: 0o100070}, args: vec!["0700", TEST_FILE],
TestCase{args: vec!{"0007", TEST_FILE}, before: 0o100000, after: 0o100007}, before: 0o100000,
TestCase{args: vec!{"-0700", TEST_FILE}, before: 0o100700, after: 0o100000}, after: 0o100700,
TestCase{args: vec!{"-0070", TEST_FILE}, before: 0o100060, after: 0o100000}, },
TestCase{args: vec!{"-0007", TEST_FILE}, before: 0o100001, after: 0o100000}, TestCase {
TestCase{args: vec!{"+0100", TEST_FILE}, before: 0o100600, after: 0o100700}, args: vec!["0070", TEST_FILE],
TestCase{args: vec!{"+0020", TEST_FILE}, before: 0o100050, after: 0o100070}, before: 0o100000,
TestCase{args: vec!{"+0004", TEST_FILE}, before: 0o100003, after: 0o100007}, after: 0o100070,
}; },
TestCase {
args: vec!["0007", TEST_FILE],
before: 0o100000,
after: 0o100007,
},
TestCase {
args: vec!["-0700", TEST_FILE],
before: 0o100700,
after: 0o100000,
},
TestCase {
args: vec!["-0070", TEST_FILE],
before: 0o100060,
after: 0o100000,
},
TestCase {
args: vec!["-0007", TEST_FILE],
before: 0o100001,
after: 0o100000,
},
TestCase {
args: vec!["+0100", TEST_FILE],
before: 0o100600,
after: 0o100700,
},
TestCase {
args: vec!["+0020", TEST_FILE],
before: 0o100050,
after: 0o100070,
},
TestCase {
args: vec!["+0004", TEST_FILE],
before: 0o100003,
after: 0o100007,
},
];
run_tests(tests); run_tests(tests);
} }
@ -76,33 +122,91 @@ fn test_chmod_octal() {
fn test_chmod_ugoa() { fn test_chmod_ugoa() {
let _guard = UMASK_MUTEX.lock(); let _guard = UMASK_MUTEX.lock();
let last = unsafe { let last = unsafe { umask(0) };
umask(0) let tests = vec![
}; TestCase {
let tests = vec!{ args: vec!["u=rwx", TEST_FILE],
TestCase{args: vec!{"u=rwx", TEST_FILE}, before: 0o100000, after: 0o100700}, before: 0o100000,
TestCase{args: vec!{"g=rwx", TEST_FILE}, before: 0o100000, after: 0o100070}, after: 0o100700,
TestCase{args: vec!{"o=rwx", TEST_FILE}, before: 0o100000, after: 0o100007}, },
TestCase{args: vec!{"a=rwx", TEST_FILE}, before: 0o100000, after: 0o100777}, TestCase {
TestCase{args: vec!{"-r", TEST_FILE}, before: 0o100777, after: 0o100333}, args: vec!["g=rwx", TEST_FILE],
TestCase{args: vec!{"-w", TEST_FILE}, before: 0o100777, after: 0o100555}, before: 0o100000,
TestCase{args: vec!{"-x", TEST_FILE}, before: 0o100777, after: 0o100666}, after: 0o100070,
}; },
TestCase {
args: vec!["o=rwx", TEST_FILE],
before: 0o100000,
after: 0o100007,
},
TestCase {
args: vec!["a=rwx", TEST_FILE],
before: 0o100000,
after: 0o100777,
},
TestCase {
args: vec!["-r", TEST_FILE],
before: 0o100777,
after: 0o100333,
},
TestCase {
args: vec!["-w", TEST_FILE],
before: 0o100777,
after: 0o100555,
},
TestCase {
args: vec!["-x", TEST_FILE],
before: 0o100777,
after: 0o100666,
},
];
run_tests(tests); run_tests(tests);
unsafe { unsafe {
umask(0o022); umask(0o022);
} }
let tests = vec!{ let tests = vec![
TestCase{args: vec!{"u=rwx", TEST_FILE}, before: 0o100000, after: 0o100700}, TestCase {
TestCase{args: vec!{"g=rwx", TEST_FILE}, before: 0o100000, after: 0o100070}, args: vec!["u=rwx", TEST_FILE],
TestCase{args: vec!{"o=rwx", TEST_FILE}, before: 0o100000, after: 0o100007}, before: 0o100000,
TestCase{args: vec!{"a=rwx", TEST_FILE}, before: 0o100000, after: 0o100777}, after: 0o100700,
TestCase{args: vec!{"+rw", TEST_FILE}, before: 0o100000, after: 0o100644}, },
TestCase{args: vec!{"=rwx", TEST_FILE}, before: 0o100000, after: 0o100755}, TestCase {
TestCase{args: vec!{"-w", TEST_FILE}, before: 0o100777, after: 0o100577}, args: vec!["g=rwx", TEST_FILE],
TestCase{args: vec!{"-x", TEST_FILE}, before: 0o100777, after: 0o100666}, before: 0o100000,
}; after: 0o100070,
},
TestCase {
args: vec!["o=rwx", TEST_FILE],
before: 0o100000,
after: 0o100007,
},
TestCase {
args: vec!["a=rwx", TEST_FILE],
before: 0o100000,
after: 0o100777,
},
TestCase {
args: vec!["+rw", TEST_FILE],
before: 0o100000,
after: 0o100644,
},
TestCase {
args: vec!["=rwx", TEST_FILE],
before: 0o100000,
after: 0o100755,
},
TestCase {
args: vec!["-w", TEST_FILE],
before: 0o100777,
after: 0o100577,
},
TestCase {
args: vec!["-x", TEST_FILE],
before: 0o100777,
after: 0o100666,
},
];
run_tests(tests); run_tests(tests);
unsafe { unsafe {
umask(last); umask(last);
@ -111,13 +215,33 @@ fn test_chmod_ugoa() {
#[test] #[test]
fn test_chmod_ugo_copy() { fn test_chmod_ugo_copy() {
let tests = vec!{ let tests = vec![
TestCase{args: vec!{"u=g", TEST_FILE}, before: 0o100070, after: 0o100770}, TestCase {
TestCase{args: vec!{"g=o", TEST_FILE}, before: 0o100005, after: 0o100055}, args: vec!["u=g", TEST_FILE],
TestCase{args: vec!{"o=u", TEST_FILE}, before: 0o100200, after: 0o100202}, before: 0o100070,
TestCase{args: vec!{"u-g", TEST_FILE}, before: 0o100710, after: 0o100610}, after: 0o100770,
TestCase{args: vec!{"u+g", TEST_FILE}, before: 0o100250, after: 0o100750}, },
}; TestCase {
args: vec!["g=o", TEST_FILE],
before: 0o100005,
after: 0o100055,
},
TestCase {
args: vec!["o=u", TEST_FILE],
before: 0o100200,
after: 0o100202,
},
TestCase {
args: vec!["u-g", TEST_FILE],
before: 0o100710,
after: 0o100610,
},
TestCase {
args: vec!["u+g", TEST_FILE],
before: 0o100250,
after: 0o100750,
},
];
run_tests(tests); run_tests(tests);
} }
@ -125,12 +249,12 @@ fn test_chmod_ugo_copy() {
fn test_chmod_many_options() { fn test_chmod_many_options() {
let _guard = UMASK_MUTEX.lock(); let _guard = UMASK_MUTEX.lock();
let original_umask = unsafe { let original_umask = unsafe { umask(0) };
umask(0) let tests = vec![TestCase {
}; args: vec!["-r,a+w", TEST_FILE],
let tests = vec!{ before: 0o100444,
TestCase{args: vec!{"-r,a+w", TEST_FILE}, before: 0o100444, after: 0o100222}, after: 0o100222,
}; }];
run_tests(tests); run_tests(tests);
unsafe { unsafe {
umask(original_umask); umask(original_umask);
@ -139,10 +263,18 @@ fn test_chmod_many_options() {
#[test] #[test]
fn test_chmod_reference_file() { fn test_chmod_reference_file() {
let tests = vec!{ let tests = vec![
TestCase{args: vec!{"--reference", REFERENCE_FILE, TEST_FILE}, before: 0o100070, after: 0o100247}, TestCase {
TestCase{args: vec!{"a-w", "--reference", REFERENCE_FILE, TEST_FILE}, before: 0o100070, after: 0o100247}, args: vec!["--reference", REFERENCE_FILE, TEST_FILE],
}; before: 0o100070,
after: 0o100247,
},
TestCase {
args: vec!["a-w", "--reference", REFERENCE_FILE, TEST_FILE],
before: 0o100070,
after: 0o100247,
},
];
let (at, ucmd) = at_and_ucmd!(); let (at, ucmd) = at_and_ucmd!();
mkfile(&at.plus_as_string(REFERENCE_FILE), REFERENCE_PERMS); mkfile(&at.plus_as_string(REFERENCE_FILE), REFERENCE_PERMS);
run_single_test(&tests[0], at, ucmd); run_single_test(&tests[0], at, ucmd);

View file

@ -3,10 +3,9 @@ use common::util::*;
extern crate uu_chown; extern crate uu_chown;
pub use self::uu_chown::*; pub use self::uu_chown::*;
#[cfg(test)] #[cfg(test)]
mod test_passgrp { mod test_passgrp {
use super::uu_chown::entries::{usr2uid,grp2gid,uid2usr,gid2grp}; use super::uu_chown::entries::{gid2grp, grp2gid, uid2usr, usr2uid};
#[test] #[test]
fn test_usr2uid() { fn test_usr2uid() {
@ -45,7 +44,5 @@ mod test_passgrp {
#[test] #[test]
fn test_invalid_option() { fn test_invalid_option() {
new_ucmd!() new_ucmd!().arg("-w").arg("-q").arg("/").fails();
.arg("-w").arg("-q").arg("/")
.fails();
} }

View file

@ -1,10 +1,11 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_single_file() { fn test_single_file() {
new_ucmd!().arg("lorem_ipsum.txt") new_ucmd!()
.succeeds().stdout_is_fixture("single_file.expected"); .arg("lorem_ipsum.txt")
.succeeds()
.stdout_is_fixture("single_file.expected");
} }
#[test] #[test]
@ -12,12 +13,14 @@ fn test_multiple_files() {
new_ucmd!() new_ucmd!()
.arg("lorem_ipsum.txt") .arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt") .arg("alice_in_wonderland.txt")
.succeeds().stdout_is_fixture("multiple_files.expected"); .succeeds()
.stdout_is_fixture("multiple_files.expected");
} }
#[test] #[test]
fn test_stdin() { fn test_stdin() {
new_ucmd!() new_ucmd!()
.pipe_in_fixture("lorem_ipsum.txt") .pipe_in_fixture("lorem_ipsum.txt")
.succeeds().stdout_is_fixture("stdin.expected"); .succeeds()
.stdout_is_fixture("stdin.expected");
} }

View file

@ -1,48 +1,69 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn ab_no_args() { 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] #[test]
fn ab_dash_one() { 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] #[test]
fn ab_dash_two() { 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] #[test]
fn ab_dash_three() { 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] #[test]
fn aempty() { 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] #[test]
fn emptyempty() { 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)] #[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test] #[test]
fn output_delimiter() { fn output_delimiter() {
new_ucmd!().args(&["--output-delimiter=word", "a", "b"]) new_ucmd!()
.succeeds().stdout_only_fixture("ab_delimiter_word.expected"); .args(&["--output-delimiter=word", "a", "b"])
.succeeds()
.stdout_only_fixture("ab_delimiter_word.expected");
} }
#[cfg_attr(not(feature="test_unimplemented"),ignore)] #[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test] #[test]
fn output_delimiter_require_arg() { fn output_delimiter_require_arg() {
new_ucmd!().args(&["--output-delimiter=", "a", "b"]) new_ucmd!()
.fails().stderr_only("error to be defined"); .args(&["--output-delimiter=", "a", "b"])
.fails()
.stderr_only("error to be defined");
} }
// even though (info) documentation suggests this is an option // even though (info) documentation suggests this is an option
@ -50,38 +71,46 @@ fn output_delimiter_require_arg() {
// this test is essentially an alarm in case someone well-intendingly // this test is essentially an alarm in case someone well-intendingly
// implements it. // implements it.
//marked as unimplemented as error message not set yet. //marked as unimplemented as error message not set yet.
#[cfg_attr(not(feature="test_unimplemented"),ignore)] #[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test] #[test]
fn zero_terminated() { fn zero_terminated() {
for param in vec!["-z", "--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)] #[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test] #[test]
fn check_order() { fn check_order() {
new_ucmd!().args(&["--check-order", "bad_order_1", "bad_order_2"]) new_ucmd!()
.fails() .args(&["--check-order", "bad_order_1", "bad_order_2"])
.stdout_is_fixture("bad_order12.check_order.expected") .fails()
.stderr_is("error to be defined"); .stdout_is_fixture("bad_order12.check_order.expected")
.stderr_is("error to be defined");
} }
#[cfg_attr(not(feature="test_unimplemented"),ignore)] #[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test] #[test]
fn nocheck_order() { fn nocheck_order() {
new_ucmd!().args(&["--nocheck-order", "bad_order_1", "bad_order_2"]) new_ucmd!()
.succeeds() .args(&["--nocheck-order", "bad_order_1", "bad_order_2"])
.stdout_only_fixture("bad_order12.nocheck_order.expected"); .succeeds()
.stdout_only_fixture("bad_order12.nocheck_order.expected");
} }
// when neither --check-order nor --no-check-order is provided, // when neither --check-order nor --no-check-order is provided,
// stderr and the error code behaves like check order, but stdout // stderr and the error code behaves like check order, but stdout
// behaves like nocheck_order. However with some quirks detailed below. // behaves like nocheck_order. However with some quirks detailed below.
#[cfg_attr(not(feature="test_unimplemented"),ignore)] #[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test] #[test]
fn defaultcheck_order() { 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 // * the first: if both files are not in order, the default behavior is the only
@ -93,17 +122,20 @@ fn defaultcheck_order() {
#[test] #[test]
fn defaultcheck_order_identical_bad_order_files() { fn defaultcheck_order_identical_bad_order_files() {
new_ucmd!().args(&["bad_order_1", "bad_order_1"]) new_ucmd!()
.succeeds().stdout_only_fixture("bad_order11.defaultcheck_order.expected"); .args(&["bad_order_1", "bad_order_1"])
.succeeds()
.stdout_only_fixture("bad_order11.defaultcheck_order.expected");
} }
#[cfg_attr(not(feature="test_unimplemented"),ignore)] #[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test] #[test]
fn defaultcheck_order_two_different_bad_order_files() { fn defaultcheck_order_two_different_bad_order_files() {
new_ucmd!().args(&["bad_order_1", "bad_order_2"]) new_ucmd!()
.fails() .args(&["bad_order_1", "bad_order_2"])
.stdout_is_fixture("bad_order12.nocheck_order.expected") .fails()
.stderr_is("error to be defined"); .stdout_is_fixture("bad_order12.nocheck_order.expected")
.stderr_is("error to be defined");
} }
// * the third: (it is not know whether this is a bug or not) // * the third: (it is not know whether this is a bug or not)
@ -116,11 +148,13 @@ fn defaultcheck_order_two_different_bad_order_files() {
// there are additional, not-yet-understood circumstances where an out-of-order // there are additional, not-yet-understood circumstances where an out-of-order
// pair is ignored and is not counted against the 1 maximum out-of-order line. // pair is ignored and is not counted against the 1 maximum out-of-order line.
#[cfg_attr(not(feature="test_unimplemented"),ignore)] #[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test] #[test]
fn unintuitive_default_behavior_1() { fn unintuitive_default_behavior_1() {
new_ucmd!().args(&["defaultcheck_unintuitive_1", "defaultcheck_unintuitive_2"]) new_ucmd!()
.succeeds().stdout_only_fixture("defaultcheck_unintuitive.expected"); .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? #[ignore] //bug? should help be stdout if not called via -h|--help?

View file

@ -2,25 +2,26 @@ use common::util::*;
#[cfg(not(windows))] #[cfg(not(windows))]
use std::fs::set_permissions; use std::fs::set_permissions;
static TEST_EXISTING_FILE: &str = "existing_file.txt"; static TEST_EXISTING_FILE: &str = "existing_file.txt";
static TEST_HELLO_WORLD_SOURCE: &str = "hello_world.txt"; static TEST_HELLO_WORLD_SOURCE: &str = "hello_world.txt";
static TEST_HELLO_WORLD_DEST: &str = "copy_of_hello_world.txt"; static TEST_HELLO_WORLD_DEST: &str = "copy_of_hello_world.txt";
static TEST_HOW_ARE_YOU_SOURCE: &str = "how_are_you.txt"; static TEST_HOW_ARE_YOU_SOURCE: &str = "how_are_you.txt";
static TEST_HOW_ARE_YOU_DEST: &str = "hello_dir/how_are_you.txt"; static TEST_HOW_ARE_YOU_DEST: &str = "hello_dir/how_are_you.txt";
static TEST_COPY_TO_FOLDER: &str = "hello_dir/"; static TEST_COPY_TO_FOLDER: &str = "hello_dir/";
static TEST_COPY_TO_FOLDER_FILE: &str = "hello_dir/hello_world.txt"; static TEST_COPY_TO_FOLDER_FILE: &str = "hello_dir/hello_world.txt";
static TEST_COPY_FROM_FOLDER: &str = "hello_dir_with_file/"; static TEST_COPY_FROM_FOLDER: &str = "hello_dir_with_file/";
static TEST_COPY_FROM_FOLDER_FILE: &str = "hello_dir_with_file/hello_world.txt"; static TEST_COPY_FROM_FOLDER_FILE: &str = "hello_dir_with_file/hello_world.txt";
static TEST_COPY_TO_FOLDER_NEW: &str = "hello_dir_new/"; static TEST_COPY_TO_FOLDER_NEW: &str = "hello_dir_new/";
static TEST_COPY_TO_FOLDER_NEW_FILE: &str = "hello_dir_new/hello_world.txt"; static TEST_COPY_TO_FOLDER_NEW_FILE: &str = "hello_dir_new/hello_world.txt";
#[test] #[test]
fn test_cp_cp() { 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. // Invoke our binary to make the copy.
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_DEST) .arg(TEST_HELLO_WORLD_SOURCE)
.run(); .arg(TEST_HELLO_WORLD_DEST)
.run();
// Check that the exit code represents a successful copy. // Check that the exit code represents a successful copy.
let exit_success = result.success; let exit_success = result.success;
@ -30,11 +31,11 @@ fn test_cp_cp() {
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n"); assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
} }
#[test] #[test]
fn test_cp_existing_target() { fn test_cp_existing_target() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_EXISTING_FILE) .arg(TEST_EXISTING_FILE)
.run(); .run();
@ -47,11 +48,11 @@ fn test_cp_existing_target() {
assert!(!at.file_exists(&*format!("{}~", TEST_EXISTING_FILE))); assert!(!at.file_exists(&*format!("{}~", TEST_EXISTING_FILE)));
} }
#[test] #[test]
fn test_cp_duplicate_files() { fn test_cp_duplicate_files() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_HELLO_WORLD_SOURCE) .arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_COPY_TO_FOLDER) .arg(TEST_COPY_TO_FOLDER)
.run(); .run();
@ -61,11 +62,11 @@ fn test_cp_duplicate_files() {
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n"); assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
} }
#[test] #[test]
fn test_cp_multiple_files_target_is_file() { fn test_cp_multiple_files_target_is_file() {
let (_, mut ucmd) = at_and_ucmd!(); let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_HELLO_WORLD_SOURCE) .arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_EXISTING_FILE) .arg(TEST_EXISTING_FILE)
.run(); .run();
@ -77,7 +78,8 @@ fn test_cp_multiple_files_target_is_file() {
#[test] #[test]
fn test_cp_directory_not_recursive() { fn test_cp_directory_not_recursive() {
let (_, mut ucmd) = at_and_ucmd!(); let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(TEST_COPY_TO_FOLDER) let result = ucmd
.arg(TEST_COPY_TO_FOLDER)
.arg(TEST_HELLO_WORLD_DEST) .arg(TEST_HELLO_WORLD_DEST)
.run(); .run();
@ -85,11 +87,11 @@ fn test_cp_directory_not_recursive() {
assert!(result.stderr.contains("omitting directory")); assert!(result.stderr.contains("omitting directory"));
} }
#[test] #[test]
fn test_cp_multiple_files() { fn test_cp_multiple_files() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_HOW_ARE_YOU_SOURCE) .arg(TEST_HOW_ARE_YOU_SOURCE)
.arg(TEST_COPY_TO_FOLDER) .arg(TEST_COPY_TO_FOLDER)
.run(); .run();
@ -134,14 +136,16 @@ fn test_cp_with_dirs() {
let at = &scene.fixtures; let at = &scene.fixtures;
//using -t option //using -t option
let result_to_dir = scene.ucmd() let result_to_dir = scene
.ucmd()
.arg(TEST_HELLO_WORLD_SOURCE) .arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_COPY_TO_FOLDER) .arg(TEST_COPY_TO_FOLDER)
.run(); .run();
assert!(result_to_dir.success); assert!(result_to_dir.success);
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n"); assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
let result_from_dir = scene.ucmd() let result_from_dir = scene
.ucmd()
.arg(TEST_COPY_FROM_FOLDER_FILE) .arg(TEST_COPY_FROM_FOLDER_FILE)
.arg(TEST_HELLO_WORLD_DEST) .arg(TEST_HELLO_WORLD_DEST)
.run(); .run();
@ -152,7 +156,8 @@ fn test_cp_with_dirs() {
#[test] #[test]
fn test_cp_arg_target_directory() { fn test_cp_arg_target_directory() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg("-t") .arg("-t")
.arg(TEST_COPY_TO_FOLDER) .arg(TEST_COPY_TO_FOLDER)
.run(); .run();
@ -164,7 +169,8 @@ fn test_cp_arg_target_directory() {
#[test] #[test]
fn test_cp_arg_no_target_directory() { fn test_cp_arg_no_target_directory() {
let (_, mut ucmd) = at_and_ucmd!(); let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg("-v") .arg("-v")
.arg("-T") .arg("-T")
.arg(TEST_COPY_TO_FOLDER) .arg(TEST_COPY_TO_FOLDER)
@ -177,7 +183,8 @@ fn test_cp_arg_no_target_directory() {
#[test] #[test]
fn test_cp_arg_interactive() { fn test_cp_arg_interactive() {
let (_, mut ucmd) = at_and_ucmd!(); let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_HOW_ARE_YOU_SOURCE) .arg(TEST_HOW_ARE_YOU_SOURCE)
.arg("-i") .arg("-i")
.pipe_in("N\n") .pipe_in("N\n")
@ -188,12 +195,13 @@ fn test_cp_arg_interactive() {
} }
#[test] #[test]
#[cfg(target_os="unix")] #[cfg(target_os = "unix")]
fn test_cp_arg_link() { fn test_cp_arg_link() {
use std::os::linux::fs::MetadataExt; use std::os::linux::fs::MetadataExt;
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg("--link") .arg("--link")
.arg(TEST_HELLO_WORLD_DEST) .arg(TEST_HELLO_WORLD_DEST)
.run(); .run();
@ -205,7 +213,8 @@ fn test_cp_arg_link() {
#[test] #[test]
fn test_cp_arg_symlink() { fn test_cp_arg_symlink() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg("--symbolic-link") .arg("--symbolic-link")
.arg(TEST_HELLO_WORLD_DEST) .arg(TEST_HELLO_WORLD_DEST)
.run(); .run();
@ -214,11 +223,11 @@ fn test_cp_arg_symlink() {
assert!(at.is_symlink(TEST_HELLO_WORLD_DEST)); assert!(at.is_symlink(TEST_HELLO_WORLD_DEST));
} }
#[test] #[test]
fn test_cp_arg_no_clobber() { fn test_cp_arg_no_clobber() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg("--no-clobber") .arg("--no-clobber")
.arg(TEST_HOW_ARE_YOU_SOURCE) .arg(TEST_HOW_ARE_YOU_SOURCE)
.run(); .run();
@ -234,11 +243,16 @@ fn test_cp_arg_force() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
// create dest without write permissions // create dest without write permissions
let mut permissions = at.make_file(TEST_HELLO_WORLD_DEST).metadata().unwrap().permissions(); let mut permissions = at
.make_file(TEST_HELLO_WORLD_DEST)
.metadata()
.unwrap()
.permissions();
permissions.set_readonly(true); permissions.set_readonly(true);
set_permissions(at.plus(TEST_HELLO_WORLD_DEST), permissions).unwrap(); set_permissions(at.plus(TEST_HELLO_WORLD_DEST), permissions).unwrap();
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg("--force") .arg("--force")
.arg(TEST_HELLO_WORLD_DEST) .arg(TEST_HELLO_WORLD_DEST)
.run(); .run();
@ -260,11 +274,16 @@ fn test_cp_arg_remove_destination() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
// create dest without write permissions // create dest without write permissions
let mut permissions = at.make_file(TEST_HELLO_WORLD_DEST).metadata().unwrap().permissions(); let mut permissions = at
.make_file(TEST_HELLO_WORLD_DEST)
.metadata()
.unwrap()
.permissions();
permissions.set_readonly(true); permissions.set_readonly(true);
set_permissions(at.plus(TEST_HELLO_WORLD_DEST), permissions).unwrap(); set_permissions(at.plus(TEST_HELLO_WORLD_DEST), permissions).unwrap();
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg("--remove-destination") .arg("--remove-destination")
.arg(TEST_HELLO_WORLD_DEST) .arg(TEST_HELLO_WORLD_DEST)
.run(); .run();
@ -277,21 +296,26 @@ fn test_cp_arg_remove_destination() {
fn test_cp_arg_backup() { fn test_cp_arg_backup() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg("--backup") .arg("--backup")
.arg(TEST_HOW_ARE_YOU_SOURCE) .arg(TEST_HOW_ARE_YOU_SOURCE)
.run(); .run();
assert!(result.success); assert!(result.success);
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n"); assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
assert_eq!(at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)), "How are you?\n"); assert_eq!(
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
"How are you?\n"
);
} }
#[test] #[test]
fn test_cp_arg_suffix() { fn test_cp_arg_suffix() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE) let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg("--suffix") .arg("--suffix")
.arg(".bak") .arg(".bak")
.arg(TEST_HOW_ARE_YOU_SOURCE) .arg(TEST_HOW_ARE_YOU_SOURCE)
@ -299,5 +323,8 @@ fn test_cp_arg_suffix() {
assert!(result.success); assert!(result.success);
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n"); assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
assert_eq!(at.read(&*format!("{}.bak", TEST_HOW_ARE_YOU_SOURCE)), "How are you?\n"); assert_eq!(
at.read(&*format!("{}.bak", TEST_HOW_ARE_YOU_SOURCE)),
"How are you?\n"
);
} }

View file

@ -1,30 +1,52 @@
use common::util::*; use common::util::*;
static INPUT: &'static str = "lists.txt"; static INPUT: &'static str = "lists.txt";
struct TestedSequence<'b> { struct TestedSequence<'b> {
name : &'b str, name: &'b str,
sequence: &'b str sequence: &'b str,
} }
static EXAMPLE_SEQUENCES: &'static [TestedSequence<'static>] = &[ static EXAMPLE_SEQUENCES: &'static [TestedSequence<'static>] = &[
TestedSequence{ name: "singular", sequence:"2" }, TestedSequence {
TestedSequence{ name: "prefix", sequence: "-2" }, name: "singular",
TestedSequence{ name: "suffix", sequence: "2-" }, sequence: "2",
TestedSequence{ name: "range", sequence: "2-4" }, },
TestedSequence{ name: "aggregate", sequence: "9-,6-7,-2,4" }, TestedSequence {
TestedSequence{ name: "subsumed", sequence: "2-,3" } name: "prefix",
sequence: "-2",
},
TestedSequence {
name: "suffix",
sequence: "2-",
},
TestedSequence {
name: "range",
sequence: "2-4",
},
TestedSequence {
name: "aggregate",
sequence: "9-,6-7,-2,4",
},
TestedSequence {
name: "subsumed",
sequence: "2-,3",
},
]; ];
static COMPLEX_SEQUENCE: &'static TestedSequence<'static> = &TestedSequence{ name: "", sequence: "9-,6-7,-2,4" }; static COMPLEX_SEQUENCE: &'static TestedSequence<'static> = &TestedSequence {
name: "",
sequence: "9-,6-7,-2,4",
};
#[test] #[test]
fn test_byte_sequence() { fn test_byte_sequence() {
for param in vec!["-b", "--bytes"] { for param in vec!["-b", "--bytes"] {
for example_seq in EXAMPLE_SEQUENCES { for example_seq in EXAMPLE_SEQUENCES {
new_ucmd!().args(&[param, example_seq.sequence, INPUT]) new_ucmd!()
.succeeds().stdout_only_fixture(format!("sequences/byte_{}.expected", example_seq.name)); .args(&[param, example_seq.sequence, INPUT])
.succeeds()
.stdout_only_fixture(format!("sequences/byte_{}.expected", example_seq.name));
} }
} }
} }
@ -34,8 +56,10 @@ fn test_char_sequence() {
for param in vec!["-c", "--characters"] { for param in vec!["-c", "--characters"] {
for example_seq in EXAMPLE_SEQUENCES { 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. //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!()
.succeeds().stdout_only_fixture(format!("sequences/byte_{}.expected", example_seq.name)); .args(&[param, example_seq.sequence, INPUT])
.succeeds()
.stdout_only_fixture(format!("sequences/byte_{}.expected", example_seq.name));
} }
} }
} }
@ -44,8 +68,10 @@ fn test_char_sequence() {
fn test_field_sequence() { fn test_field_sequence() {
for param in vec!["-f", "--fields"] { for param in vec!["-f", "--fields"] {
for example_seq in EXAMPLE_SEQUENCES { for example_seq in EXAMPLE_SEQUENCES {
new_ucmd!().args(&[param, example_seq.sequence, INPUT]) new_ucmd!()
.succeeds().stdout_only_fixture(format!("sequences/field_{}.expected", example_seq.name)); .args(&[param, example_seq.sequence, INPUT])
.succeeds()
.stdout_only_fixture(format!("sequences/field_{}.expected", example_seq.name));
} }
} }
} }
@ -53,45 +79,63 @@ fn test_field_sequence() {
#[test] #[test]
fn test_specify_delimiter() { fn test_specify_delimiter() {
for param in vec!["-d", "--delimiter"] { for param in vec!["-d", "--delimiter"] {
new_ucmd!().args(&[param, ":", "-f", COMPLEX_SEQUENCE.sequence, INPUT]) new_ucmd!()
.succeeds().stdout_only_fixture("delimiter_specified.expected"); .args(&[param, ":", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
.succeeds()
.stdout_only_fixture("delimiter_specified.expected");
} }
} }
#[test] #[test]
fn test_output_delimiter() { fn test_output_delimiter() {
// we use -d here to ensure output delimiter // we use -d here to ensure output delimiter
// is applied to the current, and not just the default, input 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!()
.succeeds().stdout_only_fixture("output_delimiter.expected"); .args(&[
"-d:",
"--output-delimiter=@",
"-f",
COMPLEX_SEQUENCE.sequence,
INPUT,
])
.succeeds()
.stdout_only_fixture("output_delimiter.expected");
} }
#[test] #[test]
fn test_complement() { 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") .pipe_in("9_1\n8_2\n7_3")
.succeeds().stdout_only("9\n8\n7\n"); .succeeds()
.stdout_only("9\n8\n7\n");
} }
#[test] #[test]
fn test_zero_terminated() { 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") .pipe_in("9_1\n8_2\n\07_3")
.succeeds().stdout_only("9\07\0"); .succeeds()
.stdout_only("9\07\0");
} }
#[test] #[test]
fn test_only_delimited() { fn test_only_delimited() {
for param in vec!["-s", "--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") .pipe_in("91\n82\n7_3")
.succeeds().stdout_only("7\n"); .succeeds()
.stdout_only("7\n");
} }
} }
#[test] #[test]
fn test_zero_terminated_only_delimited() { 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") .pipe_in("91\n\082\n7_3")
.succeeds().stdout_only("82\n7\0"); .succeeds()
.stdout_only("82\n7\0");
} }

View file

@ -1,9 +1,8 @@
extern crate uu_dircolors; extern crate uu_dircolors;
use self::uu_dircolors::{StrUtils, guess_syntax, OutputFmt}; use self::uu_dircolors::{guess_syntax, OutputFmt, StrUtils};
use common::util::*; use common::util::*;
#[test] #[test]
fn test_shell_syntax() { fn test_shell_syntax() {
use std::env; use std::env;
@ -64,26 +63,31 @@ fn test_internal_db() {
#[test] #[test]
fn test_bash_default() { 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] #[test]
fn test_csh_default() { 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] #[test]
fn test_no_env() { fn test_no_env() {
// no SHELL and TERM // no SHELL and TERM
new_ucmd!() new_ucmd!().fails();
.fails();
} }
#[test] #[test]
fn test_exclusive_option() { fn test_exclusive_option() {
new_ucmd!() new_ucmd!().arg("-cp").fails();
.arg("-cp")
.fails();
} }
fn test_helper(file_name: &str, term: &str) { fn test_helper(file_name: &str, term: &str) {
@ -91,11 +95,13 @@ fn test_helper(file_name: &str, term: &str) {
.env("TERM", term) .env("TERM", term)
.arg("-c") .arg("-c")
.arg(format!("{}.txt", file_name)) .arg(format!("{}.txt", file_name))
.run().stdout_is_fixture(format!("{}.csh.expected", file_name)); .run()
.stdout_is_fixture(format!("{}.csh.expected", file_name));
new_ucmd!() new_ucmd!()
.env("TERM", term) .env("TERM", term)
.arg("-b") .arg("-b")
.arg(format!("{}.txt", file_name)) .arg(format!("{}.txt", file_name))
.run().stdout_is_fixture(format!("{}.sh.expected", file_name)); .run()
.stdout_is_fixture(format!("{}.sh.expected", file_name));
} }

View file

@ -1,16 +1,19 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_path_with_trailing_slashes() { fn test_path_with_trailing_slashes() {
new_ucmd!().arg("/root/alpha/beta/gamma/delta/epsilon/omega//") new_ucmd!()
.run().stdout_is("/root/alpha/beta/gamma/delta/epsilon\n"); .arg("/root/alpha/beta/gamma/delta/epsilon/omega//")
.run()
.stdout_is("/root/alpha/beta/gamma/delta/epsilon\n");
} }
#[test] #[test]
fn test_path_without_trailing_slashes() { fn test_path_without_trailing_slashes() {
new_ucmd!().arg("/root/alpha/beta/gamma/delta/epsilon/omega") new_ucmd!()
.run().stdout_is("/root/alpha/beta/gamma/delta/epsilon\n"); .arg("/root/alpha/beta/gamma/delta/epsilon/omega")
.run()
.stdout_is("/root/alpha/beta/gamma/delta/epsilon\n");
} }
#[test] #[test]

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_default() { fn test_default() {
//CmdResult.stdout_only(...) trims trailing newlines //CmdResult.stdout_only(...) trims trailing newlines
@ -10,97 +9,159 @@ fn test_default() {
#[test] #[test]
fn test_no_trailing_newline() { fn test_no_trailing_newline() {
//CmdResult.stdout_only(...) trims trailing newlines //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] #[test]
fn test_escape_alert() { 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] #[test]
fn test_escape_backslash() { fn test_escape_backslash() {
new_ucmd!().args(&["-e", "\\\\"]).succeeds().stdout_only("\\\n"); new_ucmd!()
.args(&["-e", "\\\\"])
.succeeds()
.stdout_only("\\\n");
} }
#[test] #[test]
fn test_escape_backspace() { 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] #[test]
fn test_escape_carriage_return() { 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] #[test]
fn test_escape_escape() { 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] #[test]
fn test_escape_form_feed() { 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] #[test]
fn test_escape_hex() { fn test_escape_hex() {
new_ucmd!().args(&["-e", "\\x41"]).succeeds().stdout_only("A\n"); new_ucmd!()
.args(&["-e", "\\x41"])
.succeeds()
.stdout_only("A\n");
} }
#[test] #[test]
fn test_escape_short_hex() { fn test_escape_short_hex() {
new_ucmd!().args(&["-e", "foo\\xa bar"]).succeeds().stdout_only("foo\n bar\n"); new_ucmd!()
.args(&["-e", "foo\\xa bar"])
.succeeds()
.stdout_only("foo\n bar\n");
} }
#[test] #[test]
fn test_escape_no_hex() { fn test_escape_no_hex() {
new_ucmd!().args(&["-e", "foo\\x bar"]).succeeds().stdout_only("foo\\x bar\n"); new_ucmd!()
.args(&["-e", "foo\\x bar"])
.succeeds()
.stdout_only("foo\\x bar\n");
} }
#[test] #[test]
fn test_escape_one_slash() { fn test_escape_one_slash() {
new_ucmd!().args(&["-e", "foo\\ bar"]).succeeds().stdout_only("foo\\ bar\n"); new_ucmd!()
.args(&["-e", "foo\\ bar"])
.succeeds()
.stdout_only("foo\\ bar\n");
} }
#[test] #[test]
fn test_escape_one_slash_multi() { fn test_escape_one_slash_multi() {
new_ucmd!().args(&["-e", "foo\\", "bar"]).succeeds().stdout_only("foo\\ bar\n"); new_ucmd!()
.args(&["-e", "foo\\", "bar"])
.succeeds()
.stdout_only("foo\\ bar\n");
} }
#[test] #[test]
fn test_escape_newline() { fn test_escape_newline() {
new_ucmd!().args(&["-e", "\\na"]).succeeds().stdout_only("\na\n"); new_ucmd!()
.args(&["-e", "\\na"])
.succeeds()
.stdout_only("\na\n");
} }
#[test] #[test]
fn test_escape_no_further_output() { fn test_escape_no_further_output() {
new_ucmd!().args(&["-e", "a\\cb", "c"]).succeeds().stdout_only("a\n"); new_ucmd!()
.args(&["-e", "a\\cb", "c"])
.succeeds()
.stdout_only("a\n");
} }
#[test] #[test]
fn test_escape_octal() { fn test_escape_octal() {
new_ucmd!().args(&["-e", "\\0100"]).succeeds().stdout_only("@\n"); new_ucmd!()
.args(&["-e", "\\0100"])
.succeeds()
.stdout_only("@\n");
} }
#[test] #[test]
fn test_escape_short_octal() { fn test_escape_short_octal() {
new_ucmd!().args(&["-e", "foo\\040bar"]).succeeds().stdout_only("foo bar\n"); new_ucmd!()
.args(&["-e", "foo\\040bar"])
.succeeds()
.stdout_only("foo bar\n");
} }
#[test] #[test]
fn test_escape_no_octal() { fn test_escape_no_octal() {
new_ucmd!().args(&["-e", "foo\\0 bar"]).succeeds().stdout_only("foo\\0 bar\n"); new_ucmd!()
.args(&["-e", "foo\\0 bar"])
.succeeds()
.stdout_only("foo\\0 bar\n");
} }
#[test] #[test]
fn test_escape_tab() { 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] #[test]
fn test_escape_vertical_tab() { 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] #[test]

View file

@ -2,12 +2,22 @@ use common::util::*;
#[test] #[test]
fn test_env_help() { fn test_env_help() {
assert!(new_ucmd!().arg("--help").succeeds().no_stderr().stdout.contains("OPTIONS:")); assert!(new_ucmd!()
.arg("--help")
.succeeds()
.no_stderr()
.stdout
.contains("OPTIONS:"));
} }
#[test] #[test]
fn test_env_version() { fn test_env_version() {
assert!(new_ucmd!().arg("--version").succeeds().no_stderr().stdout.contains(util_name!())); assert!(new_ucmd!()
.arg("--version")
.succeeds()
.no_stderr()
.stdout
.contains(util_name!()));
} }
#[test] #[test]
@ -30,19 +40,24 @@ fn test_echo() {
#[test] #[test]
fn test_file_option() { fn test_file_option() {
let out = new_ucmd!() let out = new_ucmd!().arg("-f").arg("vars.conf.txt").run().stdout;
.arg("-f").arg("vars.conf.txt")
.run().stdout;
assert_eq!(out.lines().filter(|&line| line == "FOO=bar" || line == "BAR=bamf this").count(), 2); assert_eq!(
out.lines()
.filter(|&line| line == "FOO=bar" || line == "BAR=bamf this")
.count(),
2
);
} }
#[test] #[test]
fn test_combined_file_set() { fn test_combined_file_set() {
let out = new_ucmd!() let out = new_ucmd!()
.arg("-f").arg("vars.conf.txt") .arg("-f")
.arg("vars.conf.txt")
.arg("FOO=bar.alt") .arg("FOO=bar.alt")
.run().stdout; .run()
.stdout;
assert_eq!(out.lines().filter(|&line| line == "FOO=bar.alt").count(), 1); assert_eq!(out.lines().filter(|&line| line == "FOO=bar.alt").count(), 1);
} }
@ -50,49 +65,50 @@ fn test_combined_file_set() {
#[test] #[test]
fn test_combined_file_set_unset() { fn test_combined_file_set_unset() {
let out = new_ucmd!() let out = new_ucmd!()
.arg("-u").arg("BAR") .arg("-u")
.arg("-f").arg("vars.conf.txt") .arg("BAR")
.arg("-f")
.arg("vars.conf.txt")
.arg("FOO=bar.alt") .arg("FOO=bar.alt")
.run().stdout; .run()
.stdout;
assert_eq!(out.lines().filter(|&line| line == "FOO=bar.alt" || line.starts_with("BAR=")).count(), 1); assert_eq!(
out.lines()
.filter(|&line| line == "FOO=bar.alt" || line.starts_with("BAR="))
.count(),
1
);
} }
#[test] #[test]
fn test_single_name_value_pair() { fn test_single_name_value_pair() {
let out = new_ucmd!() let out = new_ucmd!().arg("FOO=bar").run().stdout;
.arg("FOO=bar").run().stdout;
assert!(out.lines().any(|line| line == "FOO=bar")); assert!(out.lines().any(|line| line == "FOO=bar"));
} }
#[test] #[test]
fn test_multiple_name_value_pairs() { fn test_multiple_name_value_pairs() {
let out = new_ucmd!() let out = new_ucmd!().arg("FOO=bar").arg("ABC=xyz").run().stdout;
.arg("FOO=bar")
.arg("ABC=xyz")
.run()
.stdout;
assert_eq!(out.lines().filter(|&line| line == "FOO=bar" || line == "ABC=xyz").count(), assert_eq!(
2); out.lines()
.filter(|&line| line == "FOO=bar" || line == "ABC=xyz")
.count(),
2
);
} }
#[test] #[test]
fn test_ignore_environment() { fn test_ignore_environment() {
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
let out = scene.ucmd() let out = scene.ucmd().arg("-i").run().stdout;
.arg("-i")
.run()
.stdout;
assert_eq!(out, ""); assert_eq!(out, "");
let out = scene.ucmd() let out = scene.ucmd().arg("-").run().stdout;
.arg("-")
.run()
.stdout;
assert_eq!(out, ""); assert_eq!(out, "");
} }
@ -100,14 +116,14 @@ fn test_ignore_environment() {
#[test] #[test]
fn test_null_delimiter() { fn test_null_delimiter() {
let out = new_ucmd!() let out = new_ucmd!()
.arg("-i") .arg("-i")
.arg("--null") .arg("--null")
.arg("FOO=bar") .arg("FOO=bar")
.arg("ABC=xyz") .arg("ABC=xyz")
.run() .run()
.stdout; .stdout;
let mut vars : Vec<_> = out.split('\0').collect(); let mut vars: Vec<_> = out.split('\0').collect();
assert_eq!(vars.len(), 3); assert_eq!(vars.len(), 3);
vars.sort(); vars.sort();
assert_eq!(vars[0], ""); assert_eq!(vars[0], "");
@ -120,11 +136,11 @@ fn test_unset_variable() {
// This test depends on the HOME variable being pre-defined by the // This test depends on the HOME variable being pre-defined by the
// default shell // default shell
let out = TestScenario::new(util_name!()) let out = TestScenario::new(util_name!())
.ucmd_keepenv() .ucmd_keepenv()
.arg("-u") .arg("-u")
.arg("HOME") .arg("HOME")
.run() .run()
.stdout; .stdout;
assert_eq!(out.lines().any(|line| line.starts_with("HOME=")), false); assert_eq!(out.lines().any(|line| line.starts_with("HOME=")), false);
} }

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_simple_arithmetic() { fn test_simple_arithmetic() {
new_ucmd!().args(&["1", "+", "1"]).run().stdout_is("2\n"); new_ucmd!().args(&["1", "+", "1"]).run().stdout_is("2\n");
@ -14,7 +13,9 @@ fn test_simple_arithmetic() {
#[test] #[test]
fn test_complex_arithmetic() { fn test_complex_arithmetic() {
let run = new_ucmd!().args(&["9223372036854775807", "+", "9223372036854775807"]).run(); let run = new_ucmd!()
.args(&["9223372036854775807", "+", "9223372036854775807"])
.run();
run.stdout_is(""); run.stdout_is("");
run.stderr_is("expr: error: +: Numerical result out of range"); run.stderr_is("expr: error: +: Numerical result out of range");
@ -25,19 +26,31 @@ fn test_complex_arithmetic() {
#[test] #[test]
fn test_parenthesis() { 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] #[test]
fn test_or() { 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] #[test]
fn test_and() { 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");
} }

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_exit_code() { fn test_exit_code() {
new_ucmd!().fails(); new_ucmd!().fails();

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_default_80_column_wrap() { fn test_default_80_column_wrap() {
new_ucmd!() new_ucmd!()

View file

@ -1,13 +1,13 @@
use common::util::*; use common::util::*;
static INPUT: &'static str = "lorem_ipsum.txt"; static INPUT: &'static str = "lorem_ipsum.txt";
#[test] #[test]
fn test_stdin_default() { fn test_stdin_default() {
new_ucmd!() new_ucmd!()
.pipe_in_fixture(INPUT) .pipe_in_fixture(INPUT)
.run().stdout_is_fixture("lorem_ipsum_default.expected"); .run()
.stdout_is_fixture("lorem_ipsum_default.expected");
} }
#[test] #[test]
@ -15,7 +15,8 @@ fn test_stdin_1_line_obsolete() {
new_ucmd!() new_ucmd!()
.args(&["-1"]) .args(&["-1"])
.pipe_in_fixture(INPUT) .pipe_in_fixture(INPUT)
.run().stdout_is_fixture("lorem_ipsum_1_line.expected"); .run()
.stdout_is_fixture("lorem_ipsum_1_line.expected");
} }
#[test] #[test]
@ -23,7 +24,8 @@ fn test_stdin_1_line() {
new_ucmd!() new_ucmd!()
.args(&["-n", "1"]) .args(&["-n", "1"])
.pipe_in_fixture(INPUT) .pipe_in_fixture(INPUT)
.run().stdout_is_fixture("lorem_ipsum_1_line.expected"); .run()
.stdout_is_fixture("lorem_ipsum_1_line.expected");
} }
#[test] #[test]
@ -31,40 +33,46 @@ fn test_stdin_5_chars() {
new_ucmd!() new_ucmd!()
.args(&["-c", "5"]) .args(&["-c", "5"])
.pipe_in_fixture(INPUT) .pipe_in_fixture(INPUT)
.run().stdout_is_fixture("lorem_ipsum_5_chars.expected"); .run()
.stdout_is_fixture("lorem_ipsum_5_chars.expected");
} }
#[test] #[test]
fn test_single_default() { fn test_single_default() {
new_ucmd!() new_ucmd!()
.arg(INPUT) .arg(INPUT)
.run().stdout_is_fixture("lorem_ipsum_default.expected"); .run()
.stdout_is_fixture("lorem_ipsum_default.expected");
} }
#[test] #[test]
fn test_single_1_line_obsolete() { fn test_single_1_line_obsolete() {
new_ucmd!() new_ucmd!()
.args(&["-1", INPUT]) .args(&["-1", INPUT])
.run().stdout_is_fixture("lorem_ipsum_1_line.expected"); .run()
.stdout_is_fixture("lorem_ipsum_1_line.expected");
} }
#[test] #[test]
fn test_single_1_line() { fn test_single_1_line() {
new_ucmd!() new_ucmd!()
.args(&["-n", "1", INPUT]) .args(&["-n", "1", INPUT])
.run().stdout_is_fixture("lorem_ipsum_1_line.expected"); .run()
.stdout_is_fixture("lorem_ipsum_1_line.expected");
} }
#[test] #[test]
fn test_single_5_chars() { fn test_single_5_chars() {
new_ucmd!() new_ucmd!()
.args(&["-c", "5", INPUT]) .args(&["-c", "5", INPUT])
.run().stdout_is_fixture("lorem_ipsum_5_chars.expected"); .run()
.stdout_is_fixture("lorem_ipsum_5_chars.expected");
} }
#[test] #[test]
fn test_verbose() { fn test_verbose() {
new_ucmd!() new_ucmd!()
.args(&["-v", INPUT]) .args(&["-v", INPUT])
.run().stdout_is_fixture("lorem_ipsum_verbose.expected"); .run()
.stdout_is_fixture("lorem_ipsum_verbose.expected");
} }

View file

@ -9,4 +9,3 @@ fn test_hostname() {
assert!(ls_default_res.stdout.len() >= ls_short_res.stdout.len()); assert!(ls_default_res.stdout.len() >= ls_short_res.stdout.len());
assert!(ls_default_res.stdout.len() >= ls_domain_res.stdout.len()); assert!(ls_default_res.stdout.len() >= ls_domain_res.stdout.len());
} }

View file

@ -1,13 +1,16 @@
use common::util::*; use common::util::*;
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
#[test] #[test]
fn test_install_help() { fn test_install_help() {
let (_, mut ucmd) = at_and_ucmd!(); let (_, mut ucmd) = at_and_ucmd!();
assert!( assert!(ucmd
ucmd.arg("--help").succeeds().no_stderr().stdout.contains("Options:")); .arg("--help")
.succeeds()
.no_stderr()
.stdout
.contains("Options:"));
} }
#[test] #[test]
@ -38,8 +41,13 @@ fn test_install_failing_not_dir() {
at.touch(file1); at.touch(file1);
at.touch(file2); at.touch(file2);
at.touch(file3); at.touch(file3);
assert!(ucmd.arg(file1).arg(file2).arg(file3) assert!(ucmd
.fails().stderr.contains("not a directory")); .arg(file1)
.arg(file2)
.arg(file3)
.fails()
.stderr
.contains("not a directory"));
} }
#[test] #[test]
@ -51,8 +59,13 @@ fn test_install_unimplemented_arg() {
at.touch(file); at.touch(file);
at.mkdir(dir); at.mkdir(dir);
assert!(ucmd.arg(context_arg).arg(file).arg(dir) assert!(ucmd
.fails().stderr.contains("Unimplemented")); .arg(context_arg)
.arg(file)
.arg(dir)
.fails()
.stderr
.contains("Unimplemented"));
assert!(!at.file_exists(&format!("{}/{}", dir, file))); assert!(!at.file_exists(&format!("{}/{}", dir, file)));
} }
@ -66,7 +79,8 @@ fn test_install_component_directories() {
let directories_arg = "-d"; let directories_arg = "-d";
ucmd.args(&[directories_arg, component1, component2, component3]) ucmd.args(&[directories_arg, component1, component2, component3])
.succeeds().no_stderr(); .succeeds()
.no_stderr();
assert!(at.dir_exists(component1)); assert!(at.dir_exists(component1));
assert!(at.dir_exists(component2)); assert!(at.dir_exists(component2));
@ -80,8 +94,12 @@ fn test_install_component_directories_failing() {
let directories_arg = "-d"; let directories_arg = "-d";
at.mkdir(component); at.mkdir(component);
assert!(ucmd.arg(directories_arg).arg(component) assert!(ucmd
.fails().stderr.contains("File exists")); .arg(directories_arg)
.arg(component)
.fails()
.stderr
.contains("File exists"));
} }
#[test] #[test]
@ -129,8 +147,13 @@ fn test_install_mode_failing() {
at.touch(file); at.touch(file);
at.mkdir(dir); at.mkdir(dir);
assert!(ucmd.arg(file).arg(dir).arg(mode_arg) assert!(ucmd
.fails().stderr.contains("Invalid mode string: invalid digit found in string")); .arg(file)
.arg(dir)
.arg(mode_arg)
.fails()
.stderr
.contains("Invalid mode string: invalid digit found in string"));
let dest_file = &format!("{}/{}", dir, file); let dest_file = &format!("{}/{}", dir, file);
assert!(at.file_exists(file)); assert!(at.file_exists(file));
@ -144,7 +167,11 @@ fn test_install_mode_directories() {
let directories_arg = "-d"; let directories_arg = "-d";
let mode_arg = "--mode=333"; let mode_arg = "--mode=333";
ucmd.arg(directories_arg).arg(component).arg(mode_arg).succeeds().no_stderr(); ucmd.arg(directories_arg)
.arg(component)
.arg(mode_arg)
.succeeds()
.no_stderr();
assert!(at.dir_exists(component)); assert!(at.dir_exists(component));
let permissions = at.metadata(component).permissions(); let permissions = at.metadata(component).permissions();
@ -173,7 +200,10 @@ fn test_install_target_new_file() {
at.touch(file); at.touch(file);
at.mkdir(dir); at.mkdir(dir);
ucmd.arg(file).arg(format!("{}/{}", dir, file)).succeeds().no_stderr(); ucmd.arg(file)
.arg(format!("{}/{}", dir, file))
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(at.file_exists(&format!("{}/{}", dir, file))); assert!(at.file_exists(&format!("{}/{}", dir, file)));
@ -188,9 +218,11 @@ fn test_install_target_new_file_failing_nonexistent_parent() {
at.touch(file1); at.touch(file1);
let err = ucmd.arg(file1).arg(format!("{}/{}", dir, file2)) let err = ucmd
.fails().stderr; .arg(file1)
.arg(format!("{}/{}", dir, file2))
.fails()
.stderr;
assert!(err.contains("not a directory")) assert!(err.contains("not a directory"))
} }

View file

@ -1,22 +1,24 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn empty_files() { fn empty_files() {
new_ucmd!() new_ucmd!()
.arg("empty.txt") .arg("empty.txt")
.arg("empty.txt") .arg("empty.txt")
.succeeds().stdout_only(""); .succeeds()
.stdout_only("");
new_ucmd!() new_ucmd!()
.arg("empty.txt") .arg("empty.txt")
.arg("fields_1.txt") .arg("fields_1.txt")
.succeeds().stdout_only(""); .succeeds()
.stdout_only("");
new_ucmd!() new_ucmd!()
.arg("fields_1.txt") .arg("fields_1.txt")
.arg("empty.txt") .arg("empty.txt")
.succeeds().stdout_only(""); .succeeds()
.stdout_only("");
} }
#[test] #[test]
@ -26,7 +28,8 @@ fn empty_intersection() {
.arg("fields_2.txt") .arg("fields_2.txt")
.arg("-2") .arg("-2")
.arg("2") .arg("2")
.succeeds().stdout_only(""); .succeeds()
.stdout_only("");
} }
#[test] #[test]
@ -34,7 +37,8 @@ fn default_arguments() {
new_ucmd!() new_ucmd!()
.arg("fields_1.txt") .arg("fields_1.txt")
.arg("fields_2.txt") .arg("fields_2.txt")
.succeeds().stdout_only_fixture("default.expected"); .succeeds()
.stdout_only_fixture("default.expected");
} }
#[test] #[test]
@ -44,7 +48,8 @@ fn different_fields() {
.arg("fields_4.txt") .arg("fields_4.txt")
.arg("-j") .arg("-j")
.arg("2") .arg("2")
.succeeds().stdout_only_fixture("different_fields.expected"); .succeeds()
.stdout_only_fixture("different_fields.expected");
new_ucmd!() new_ucmd!()
.arg("fields_2.txt") .arg("fields_2.txt")
@ -53,7 +58,8 @@ fn different_fields() {
.arg("2") .arg("2")
.arg("-2") .arg("-2")
.arg("2") .arg("2")
.succeeds().stdout_only_fixture("different_fields.expected"); .succeeds()
.stdout_only_fixture("different_fields.expected");
} }
#[test] #[test]
@ -63,7 +69,8 @@ fn different_field() {
.arg("fields_3.txt") .arg("fields_3.txt")
.arg("-2") .arg("-2")
.arg("2") .arg("2")
.succeeds().stdout_only_fixture("different_field.expected"); .succeeds()
.stdout_only_fixture("different_field.expected");
} }
#[test] #[test]
@ -73,7 +80,8 @@ fn unpaired_lines() {
.arg("fields_3.txt") .arg("fields_3.txt")
.arg("-a") .arg("-a")
.arg("1") .arg("1")
.succeeds().stdout_only_fixture("fields_2.txt"); .succeeds()
.stdout_only_fixture("fields_2.txt");
new_ucmd!() new_ucmd!()
.arg("fields_3.txt") .arg("fields_3.txt")
@ -82,7 +90,8 @@ fn unpaired_lines() {
.arg("2") .arg("2")
.arg("-a") .arg("-a")
.arg("2") .arg("2")
.succeeds().stdout_only_fixture("unpaired_lines.expected"); .succeeds()
.stdout_only_fixture("unpaired_lines.expected");
} }
#[test] #[test]
@ -94,7 +103,8 @@ fn suppress_joined() {
.arg("2") .arg("2")
.arg("-v") .arg("-v")
.arg("2") .arg("2")
.succeeds().stdout_only_fixture("suppress_joined.expected"); .succeeds()
.stdout_only_fixture("suppress_joined.expected");
} }
#[test] #[test]
@ -103,7 +113,8 @@ fn case_insensitive() {
.arg("capitalized.txt") .arg("capitalized.txt")
.arg("fields_3.txt") .arg("fields_3.txt")
.arg("-i") .arg("-i")
.succeeds().stdout_only_fixture("case_insensitive.expected"); .succeeds()
.stdout_only_fixture("case_insensitive.expected");
} }
#[test] #[test]
@ -113,7 +124,8 @@ fn semicolon_separated() {
.arg("semicolon_fields_2.txt") .arg("semicolon_fields_2.txt")
.arg("-t") .arg("-t")
.arg(";") .arg(";")
.succeeds().stdout_only_fixture("semicolon_separated.expected"); .succeeds()
.stdout_only_fixture("semicolon_separated.expected");
} }
#[test] #[test]
@ -124,7 +136,8 @@ fn new_line_separated() {
.arg("-t") .arg("-t")
.arg("") .arg("")
.pipe_in("1 a\n1 b\n8 h\n") .pipe_in("1 a\n1 b\n8 h\n")
.succeeds().stdout_only("1 a\n8 h\n"); .succeeds()
.stdout_only("1 a\n8 h\n");
} }
#[test] #[test]
@ -134,7 +147,8 @@ fn multitab_character() {
.arg("semicolon_fields_2.txt") .arg("semicolon_fields_2.txt")
.arg("-t") .arg("-t")
.arg("э") .arg("э")
.fails().stderr_is("join: error: multi-character tab э"); .fails()
.stderr_is("join: error: multi-character tab э");
} }
#[test] #[test]
@ -144,14 +158,16 @@ fn default_format() {
.arg("fields_2.txt") .arg("fields_2.txt")
.arg("-o") .arg("-o")
.arg("1.1 2.2") .arg("1.1 2.2")
.succeeds().stdout_only_fixture("default.expected"); .succeeds()
.stdout_only_fixture("default.expected");
new_ucmd!() new_ucmd!()
.arg("fields_1.txt") .arg("fields_1.txt")
.arg("fields_2.txt") .arg("fields_2.txt")
.arg("-o") .arg("-o")
.arg("0 2.2") .arg("0 2.2")
.succeeds().stdout_only_fixture("default.expected"); .succeeds()
.stdout_only_fixture("default.expected");
} }
#[test] #[test]
@ -163,7 +179,8 @@ fn unpaired_lines_format() {
.arg("2") .arg("2")
.arg("-o") .arg("-o")
.arg("1.2 1.1 2.4 2.3 2.2 0") .arg("1.2 1.1 2.4 2.3 2.2 0")
.succeeds().stdout_only_fixture("unpaired_lines_format.expected"); .succeeds()
.stdout_only_fixture("unpaired_lines_format.expected");
} }
#[test] #[test]
@ -173,7 +190,8 @@ fn autoformat() {
.arg("different_lengths.txt") .arg("different_lengths.txt")
.arg("-o") .arg("-o")
.arg("auto") .arg("auto")
.succeeds().stdout_only_fixture("autoformat.expected"); .succeeds()
.stdout_only_fixture("autoformat.expected");
new_ucmd!() new_ucmd!()
.arg("-") .arg("-")
@ -181,7 +199,8 @@ fn autoformat() {
.arg("-o") .arg("-o")
.arg("auto") .arg("auto")
.pipe_in("1 x y z\n2 p") .pipe_in("1 x y z\n2 p")
.succeeds().stdout_only("1 x y z a\n2 p b\n"); .succeeds()
.stdout_only("1 x y z a\n2 p b\n");
} }
#[test] #[test]
@ -191,7 +210,8 @@ fn empty_format() {
.arg("fields_2.txt") .arg("fields_2.txt")
.arg("-o") .arg("-o")
.arg("") .arg("")
.fails().stderr_is("join: error: invalid file number in field spec: ''"); .fails()
.stderr_is("join: error: invalid file number in field spec: ''");
} }
#[test] #[test]
@ -205,7 +225,8 @@ fn empty_key() {
.arg("1") .arg("1")
.arg("-e") .arg("-e")
.arg("x") .arg("x")
.succeeds().stdout_only_fixture("empty_key.expected"); .succeeds()
.stdout_only_fixture("empty_key.expected");
} }
#[test] #[test]
@ -217,7 +238,8 @@ fn missing_format_fields() {
.arg("0 1.2 2.4") .arg("0 1.2 2.4")
.arg("-e") .arg("-e")
.arg("x") .arg("x")
.succeeds().stdout_only_fixture("missing_format_fields.expected"); .succeeds()
.stdout_only_fixture("missing_format_fields.expected");
} }
#[test] #[test]
@ -225,7 +247,8 @@ fn wrong_line_order() {
new_ucmd!() new_ucmd!()
.arg("fields_2.txt") .arg("fields_2.txt")
.arg("fields_4.txt") .arg("fields_4.txt")
.fails().stderr_is("fields_4.txt:5: is not sorted"); .fails()
.stderr_is("fields_4.txt:5: is not sorted");
} }
#[test] #[test]
@ -234,7 +257,8 @@ fn headers() {
.arg("header_1.txt") .arg("header_1.txt")
.arg("header_2.txt") .arg("header_2.txt")
.arg("--header") .arg("--header")
.succeeds().stdout_only_fixture("header.expected"); .succeeds()
.stdout_only_fixture("header.expected");
} }
#[test] #[test]
@ -245,7 +269,8 @@ fn headers_autoformat() {
.arg("--header") .arg("--header")
.arg("-o") .arg("-o")
.arg("auto") .arg("auto")
.succeeds().stdout_only_fixture("header_autoformat.expected"); .succeeds()
.stdout_only_fixture("header_autoformat.expected");
} }
#[test] #[test]
@ -254,11 +279,13 @@ fn single_file_with_header() {
.arg("capitalized.txt") .arg("capitalized.txt")
.arg("empty.txt") .arg("empty.txt")
.arg("--header") .arg("--header")
.succeeds().stdout_is("A 1\n"); .succeeds()
.stdout_is("A 1\n");
new_ucmd!() new_ucmd!()
.arg("empty.txt") .arg("empty.txt")
.arg("capitalized.txt") .arg("capitalized.txt")
.arg("--header") .arg("--header")
.succeeds().stdout_is("A 1\n"); .succeeds()
.stdout_is("A 1\n");
} }

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_link_existing_file() { fn test_link_existing_file() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
@ -22,7 +21,8 @@ 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"; let link = "test_link_no_circular";
ucmd.args(&[link, link]).fails() ucmd.args(&[link, link])
.fails()
.stderr_is("link: error: No such file or directory (os error 2)\n"); .stderr_is("link: error: No such file or directory (os error 2)\n");
assert!(!at.file_exists(link)); assert!(!at.file_exists(link));
} }
@ -33,7 +33,8 @@ fn test_link_nonexistent_file() {
let file = "test_link_nonexistent_file"; let file = "test_link_nonexistent_file";
let link = "test_link_nonexistent_file_link"; let link = "test_link_nonexistent_file_link";
ucmd.args(&[file, link]).fails() ucmd.args(&[file, link])
.fails()
.stderr_is("link: error: No such file or directory (os error 2)\n"); .stderr_is("link: error: No such file or directory (os error 2)\n");
assert!(!at.file_exists(file)); assert!(!at.file_exists(file));
assert!(!at.file_exists(link)); assert!(!at.file_exists(link));

View file

@ -107,16 +107,22 @@ fn test_symlink_interactive() {
at.touch(file); at.touch(file);
at.touch(link); at.touch(link);
scene.ucmd() scene
.ucmd()
.args(&["-i", "-s", file, link]) .args(&["-i", "-s", file, link])
.pipe_in("n").succeeds().no_stderr(); .pipe_in("n")
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(!at.is_symlink(link)); assert!(!at.is_symlink(link));
scene.ucmd() scene
.ucmd()
.args(&["-i", "-s", file, link]) .args(&["-i", "-s", file, link])
.pipe_in("Yesh").succeeds().no_stderr(); .pipe_in("Yesh")
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(at.is_symlink(link)); assert!(at.is_symlink(link));
@ -161,7 +167,9 @@ fn test_symlink_custom_backup_suffix() {
assert_eq!(at.resolve_link(link), file); assert_eq!(at.resolve_link(link), file);
let arg = &format!("--suffix={}", suffix); let arg = &format!("--suffix={}", suffix);
ucmd.args(&["-b", arg, "-s", file, link]).succeeds().no_stderr(); ucmd.args(&["-b", arg, "-s", file, link])
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(at.is_symlink(link)); assert!(at.is_symlink(link));
@ -184,7 +192,9 @@ fn test_symlink_backup_numbering() {
assert!(at.is_symlink(link)); assert!(at.is_symlink(link));
assert_eq!(at.resolve_link(link), file); assert_eq!(at.resolve_link(link), file);
ucmd.args(&["-s", "--backup=t", file, link]).succeeds().no_stderr(); ucmd.args(&["-s", "--backup=t", file, link])
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(at.is_symlink(link)); assert!(at.is_symlink(link));
@ -216,7 +226,9 @@ fn test_symlink_existing_backup() {
assert!(at.is_symlink(link_backup)); assert!(at.is_symlink(link_backup));
assert_eq!(at.resolve_link(link_backup), file); assert_eq!(at.resolve_link(link_backup), file);
ucmd.args(&["-s", "--backup=nil", file, link]).succeeds().no_stderr(); ucmd.args(&["-s", "--backup=nil", file, link])
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(at.is_symlink(link_backup)); assert!(at.is_symlink(link_backup));
@ -237,7 +249,9 @@ fn test_symlink_target_dir() {
at.touch(file_b); at.touch(file_b);
at.mkdir(dir); at.mkdir(dir);
ucmd.args(&["-s", "-t", dir, file_a, file_b]).succeeds().no_stderr(); ucmd.args(&["-s", "-t", dir, file_a, file_b])
.succeeds()
.no_stderr();
let file_a_link = &format!("{}/{}", dir, file_a); let file_a_link = &format!("{}/{}", dir, file_a);
assert!(at.is_symlink(file_a_link)); assert!(at.is_symlink(file_a_link));
@ -263,7 +277,9 @@ fn test_symlink_target_dir_from_dir() {
at.touch(file_b); at.touch(file_b);
at.mkdir(dir); at.mkdir(dir);
ucmd.args(&["-s", "-t", dir, file_a, file_b]).succeeds().no_stderr(); ucmd.args(&["-s", "-t", dir, file_a, file_b])
.succeeds()
.no_stderr();
let file_a_link = &format!("{}/{}", dir, filename_a); let file_a_link = &format!("{}/{}", dir, filename_a);
assert!(at.is_symlink(file_a_link)); assert!(at.is_symlink(file_a_link));
@ -283,7 +299,13 @@ fn test_symlink_overwrite_dir_fail() {
at.touch(path_a); at.touch(path_a);
at.mkdir(path_b); at.mkdir(path_b);
assert!(ucmd.args(&["-s", "-T", path_a, path_b]).fails().stderr.len() > 0); assert!(
ucmd.args(&["-s", "-T", path_a, path_b])
.fails()
.stderr
.len()
> 0
);
} }
#[test] #[test]
@ -299,9 +321,12 @@ fn test_symlink_errors() {
// $ ln -T -t a b // $ ln -T -t a b
// ln: cannot combine --target-directory (-t) and --no-target-directory (-T) // ln: cannot combine --target-directory (-t) and --no-target-directory (-T)
ucmd.args(&["-T", "-t", dir, file_a, file_b]).fails() ucmd.args(&["-T", "-t", dir, file_a, file_b])
.stderr_is("ln: error: cannot combine --target-directory (-t) and --no-target-directory \ .fails()
(-T)\n"); .stderr_is(
"ln: error: cannot combine --target-directory (-t) and --no-target-directory \
(-T)\n",
);
} }
#[test] #[test]
@ -313,13 +338,22 @@ fn test_symlink_verbose() {
at.touch(file_a); at.touch(file_a);
scene.ucmd().args(&["-v", file_a, file_b]) scene
.succeeds().stdout_only(format!("'{}' -> '{}'\n", file_b, file_a)); .ucmd()
.args(&["-v", file_a, file_b])
.succeeds()
.stdout_only(format!("'{}' -> '{}'\n", file_b, file_a));
at.touch(file_b); at.touch(file_b);
scene.ucmd().args(&["-v", "-b", file_a, file_b]) scene
.succeeds().stdout_only(format!("'{}' -> '{}' (backup: '{}~')\n", file_b, file_a, file_b)); .ucmd()
.args(&["-v", "-b", file_a, file_b])
.succeeds()
.stdout_only(format!(
"'{}' -> '{}' (backup: '{}~')\n",
file_b, file_a, file_b
));
} }
#[test] #[test]
@ -377,6 +411,8 @@ fn test_symlink_missing_destination() {
at.touch(file); at.touch(file);
ucmd.args(&["-s", "-T", file]).fails() ucmd.args(&["-s", "-T", file]).fails().stderr_is(format!(
.stderr_is(format!("ln: error: missing destination file operand after '{}'", file)); "ln: error: missing destination file operand after '{}'",
file
));
} }

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_ls_ls() { fn test_ls_ls() {
new_ucmd!().succeeds(); new_ucmd!().succeeds();

View file

@ -22,11 +22,7 @@ fn test_mkdir_dup_dir() {
#[test] #[test]
fn test_mkdir_mode() { fn test_mkdir_mode() {
new_ucmd!() new_ucmd!().arg("-m").arg("755").arg(TEST_DIR3).succeeds();
.arg("-m")
.arg("755")
.arg(TEST_DIR3)
.succeeds();
} }
#[test] #[test]

View file

@ -2,7 +2,6 @@ use common::util::*;
extern crate tempdir; extern crate tempdir;
use self::tempdir::TempDir; use self::tempdir::TempDir;
static TEST_TEMPLATE1: &'static str = "tempXXXXXX"; static TEST_TEMPLATE1: &'static str = "tempXXXXXX";
static TEST_TEMPLATE2: &'static str = "temp"; static TEST_TEMPLATE2: &'static str = "temp";
static TEST_TEMPLATE3: &'static str = "tempX"; static TEST_TEMPLATE3: &'static str = "tempX";
@ -23,14 +22,46 @@ fn test_mktemp_mktemp() {
let pathname = scene.fixtures.as_string(); let pathname = scene.fixtures.as_string();
scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE1).succeeds(); scene
scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE2).fails(); .ucmd()
scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE3).fails(); .env(TMPDIR, &pathname)
scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE4).fails(); .arg(TEST_TEMPLATE1)
scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE5).succeeds(); .succeeds();
scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE6).succeeds(); scene
scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE7).succeeds(); .ucmd()
scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE8).fails(); .env(TMPDIR, &pathname)
.arg(TEST_TEMPLATE2)
.fails();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg(TEST_TEMPLATE3)
.fails();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg(TEST_TEMPLATE4)
.fails();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg(TEST_TEMPLATE5)
.succeeds();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg(TEST_TEMPLATE6)
.succeeds();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg(TEST_TEMPLATE7)
.succeeds();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg(TEST_TEMPLATE8)
.fails();
} }
#[test] #[test]
@ -39,14 +70,54 @@ fn test_mktemp_make_temp_dir() {
let pathname = scene.fixtures.as_string(); let pathname = scene.fixtures.as_string();
scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE1).succeeds(); scene
scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE2).fails(); .ucmd()
scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE3).fails(); .env(TMPDIR, &pathname)
scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE4).fails(); .arg("-d")
scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE5).succeeds(); .arg(TEST_TEMPLATE1)
scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE6).succeeds(); .succeeds();
scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE7).succeeds(); scene
scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE8).fails(); .ucmd()
.env(TMPDIR, &pathname)
.arg("-d")
.arg(TEST_TEMPLATE2)
.fails();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-d")
.arg(TEST_TEMPLATE3)
.fails();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-d")
.arg(TEST_TEMPLATE4)
.fails();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-d")
.arg(TEST_TEMPLATE5)
.succeeds();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-d")
.arg(TEST_TEMPLATE6)
.succeeds();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-d")
.arg(TEST_TEMPLATE7)
.succeeds();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-d")
.arg(TEST_TEMPLATE8)
.fails();
} }
#[test] #[test]
@ -55,25 +126,77 @@ fn test_mktemp_dry_run() {
let pathname = scene.fixtures.as_string(); let pathname = scene.fixtures.as_string();
scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE1).succeeds(); scene
scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE2).fails(); .ucmd()
scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE3).fails(); .env(TMPDIR, &pathname)
scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE4).fails(); .arg("-u")
scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE5).succeeds(); .arg(TEST_TEMPLATE1)
scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE6).succeeds(); .succeeds();
scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE7).succeeds(); scene
scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE8).fails(); .ucmd()
.env(TMPDIR, &pathname)
.arg("-u")
.arg(TEST_TEMPLATE2)
.fails();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-u")
.arg(TEST_TEMPLATE3)
.fails();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-u")
.arg(TEST_TEMPLATE4)
.fails();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-u")
.arg(TEST_TEMPLATE5)
.succeeds();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-u")
.arg(TEST_TEMPLATE6)
.succeeds();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-u")
.arg(TEST_TEMPLATE7)
.succeeds();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-u")
.arg(TEST_TEMPLATE8)
.fails();
} }
#[test] #[test]
fn test_mktemp_quiet() { 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") scene
.fails().no_stdout().no_stderr(); .ucmd()
scene.ucmd().arg("-d").arg("-p").arg("/definitely/not/exist/I/promise").arg("-q") .arg("-p")
.fails().no_stdout().no_stderr(); .arg("/definitely/not/exist/I/promise")
.arg("-q")
.fails()
.no_stdout()
.no_stderr();
scene
.ucmd()
.arg("-d")
.arg("-p")
.arg("/definitely/not/exist/I/promise")
.arg("-q")
.fails()
.no_stdout()
.no_stderr();
} }
#[test] #[test]
@ -82,14 +205,62 @@ fn test_mktemp_suffix() {
let pathname = scene.fixtures.as_string(); let pathname = scene.fixtures.as_string();
scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE1).succeeds(); scene
scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE2).fails(); .ucmd()
scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE3).fails(); .env(TMPDIR, &pathname)
scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE4).fails(); .arg("--suffix")
scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE5).succeeds(); .arg("suf")
scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE6).fails(); .arg(TEST_TEMPLATE1)
scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE7).fails(); .succeeds();
scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE8).fails(); scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("--suffix")
.arg("suf")
.arg(TEST_TEMPLATE2)
.fails();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("--suffix")
.arg("suf")
.arg(TEST_TEMPLATE3)
.fails();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("--suffix")
.arg("suf")
.arg(TEST_TEMPLATE4)
.fails();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("--suffix")
.arg("suf")
.arg(TEST_TEMPLATE5)
.succeeds();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("--suffix")
.arg("suf")
.arg(TEST_TEMPLATE6)
.fails();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("--suffix")
.arg("suf")
.arg(TEST_TEMPLATE7)
.fails();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("--suffix")
.arg("suf")
.arg(TEST_TEMPLATE8)
.fails();
} }
#[test] #[test]
@ -99,12 +270,52 @@ fn test_mktemp_tmpdir() {
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(); let pathname = path.path().as_os_str();
scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE1).succeeds(); scene
scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE2).fails(); .ucmd()
scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE3).fails(); .arg("-p")
scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE4).fails(); .arg(pathname)
scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE5).succeeds(); .arg(TEST_TEMPLATE1)
scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE6).succeeds(); .succeeds();
scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE7).succeeds(); scene
scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE8).fails(); .ucmd()
.arg("-p")
.arg(pathname)
.arg(TEST_TEMPLATE2)
.fails();
scene
.ucmd()
.arg("-p")
.arg(pathname)
.arg(TEST_TEMPLATE3)
.fails();
scene
.ucmd()
.arg("-p")
.arg(pathname)
.arg(TEST_TEMPLATE4)
.fails();
scene
.ucmd()
.arg("-p")
.arg(pathname)
.arg(TEST_TEMPLATE5)
.succeeds();
scene
.ucmd()
.arg("-p")
.arg(pathname)
.arg(TEST_TEMPLATE6)
.succeeds();
scene
.ucmd()
.arg("-p")
.arg(pathname)
.arg(TEST_TEMPLATE7)
.succeeds();
scene
.ucmd()
.arg("-p")
.arg(pathname)
.arg(TEST_TEMPLATE8)
.fails();
} }

View file

@ -1,10 +1,9 @@
extern crate time;
extern crate filetime; extern crate filetime;
extern crate time;
use self::filetime::*; use self::filetime::*;
use common::util::*; use common::util::*;
#[test] #[test]
fn test_mv_rename_dir() { fn test_mv_rename_dir() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
@ -57,7 +56,10 @@ fn test_mv_move_file_between_dirs() {
assert!(at.file_exists(&format!("{}/{}", dir1, file))); assert!(at.file_exists(&format!("{}/{}", dir1, file)));
ucmd.arg(&format!("{}/{}", dir1, file)).arg(dir2).succeeds().no_stderr(); ucmd.arg(&format!("{}/{}", dir1, file))
.arg(dir2)
.succeeds()
.no_stderr();
assert!(!at.file_exists(&format!("{}/{}", dir1, file))); assert!(!at.file_exists(&format!("{}/{}", dir1, file)));
assert!(at.file_exists(&format!("{}/{}", dir2, file))); assert!(at.file_exists(&format!("{}/{}", dir2, file)));
@ -79,7 +81,13 @@ fn test_mv_strip_slashes() {
assert!(!at.file_exists(&format!("{}/{}", dir, file))); assert!(!at.file_exists(&format!("{}/{}", dir, file)));
scene.ucmd().arg("--strip-trailing-slashes").arg(source).arg(dir).succeeds().no_stderr(); scene
.ucmd()
.arg("--strip-trailing-slashes")
.arg(source)
.arg(dir)
.succeeds()
.no_stderr();
assert!(at.file_exists(&format!("{}/{}", dir, file))); assert!(at.file_exists(&format!("{}/{}", dir, file)));
} }
@ -95,7 +103,11 @@ fn test_mv_multiple_files() {
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
ucmd.arg(file_a).arg(file_b).arg(target_dir).succeeds().no_stderr(); ucmd.arg(file_a)
.arg(file_b)
.arg(target_dir)
.succeeds()
.no_stderr();
assert!(at.file_exists(&format!("{}/{}", target_dir, file_a))); assert!(at.file_exists(&format!("{}/{}", target_dir, file_a)));
assert!(at.file_exists(&format!("{}/{}", target_dir, file_b))); assert!(at.file_exists(&format!("{}/{}", target_dir, file_b)));
@ -112,7 +124,11 @@ fn test_mv_multiple_folders() {
at.mkdir(dir_a); at.mkdir(dir_a);
at.mkdir(dir_b); at.mkdir(dir_b);
ucmd.arg(dir_a).arg(dir_b).arg(target_dir).succeeds().no_stderr(); ucmd.arg(dir_a)
.arg(dir_b)
.arg(target_dir)
.succeeds()
.no_stderr();
assert!(at.dir_exists(&format!("{}/{}", target_dir, dir_a))); assert!(at.dir_exists(&format!("{}/{}", target_dir, dir_a)));
assert!(at.dir_exists(&format!("{}/{}", target_dir, dir_b))); assert!(at.dir_exists(&format!("{}/{}", target_dir, dir_b)));
@ -128,14 +144,26 @@ fn test_mv_interactive() {
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
scene
scene.ucmd().arg("-i").arg(file_a).arg(file_b).pipe_in("n").succeeds().no_stderr(); .ucmd()
.arg("-i")
.arg(file_a)
.arg(file_b)
.pipe_in("n")
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a)); assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b)); assert!(at.file_exists(file_b));
scene
scene.ucmd().arg("-i").arg(file_a).arg(file_b).pipe_in("Yesh").succeeds().no_stderr(); .ucmd()
.arg("-i")
.arg(file_a)
.arg(file_b)
.pipe_in("Yesh")
.succeeds()
.no_stderr();
assert!(!at.file_exists(file_a)); assert!(!at.file_exists(file_a));
assert!(at.file_exists(file_b)); assert!(at.file_exists(file_b));
@ -150,7 +178,11 @@ fn test_mv_no_clobber() {
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
ucmd.arg("-n").arg(file_a).arg(file_b).succeeds().no_stderr(); ucmd.arg("-n")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a)); assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b)); assert!(at.file_exists(file_b));
@ -180,7 +212,11 @@ fn test_mv_force_replace_file() {
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
ucmd.arg("--force").arg(file_a).arg(file_b).succeeds().no_stderr(); ucmd.arg("--force")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(!at.file_exists(file_a)); assert!(!at.file_exists(file_a));
assert!(at.file_exists(file_b)); assert!(at.file_exists(file_b));
@ -194,7 +230,11 @@ fn test_mv_simple_backup() {
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
ucmd.arg("-b").arg(file_a).arg(file_b).succeeds().no_stderr(); ucmd.arg("-b")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(!at.file_exists(file_a)); assert!(!at.file_exists(file_a));
assert!(at.file_exists(file_b)); assert!(at.file_exists(file_b));
@ -214,7 +254,8 @@ fn test_mv_custom_backup_suffix() {
.arg(format!("--suffix={}", suffix)) .arg(format!("--suffix={}", suffix))
.arg(file_a) .arg(file_a)
.arg(file_b) .arg(file_b)
.succeeds().no_stderr(); .succeeds()
.no_stderr();
assert!(!at.file_exists(file_a)); assert!(!at.file_exists(file_a));
assert!(at.file_exists(file_b)); assert!(at.file_exists(file_b));
@ -233,7 +274,8 @@ fn test_mv_custom_backup_suffix_via_env() {
.env("SIMPLE_BACKUP_SUFFIX", suffix) .env("SIMPLE_BACKUP_SUFFIX", suffix)
.arg(file_a) .arg(file_a)
.arg(file_b) .arg(file_b)
.succeeds().no_stderr(); .succeeds()
.no_stderr();
assert!(!at.file_exists(file_a)); assert!(!at.file_exists(file_a));
assert!(at.file_exists(file_b)); assert!(at.file_exists(file_b));
@ -248,7 +290,11 @@ fn test_mv_backup_numbering() {
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
ucmd.arg("--backup=t").arg(file_a).arg(file_b).succeeds().no_stderr(); ucmd.arg("--backup=t")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(!at.file_exists(file_a)); assert!(!at.file_exists(file_a));
assert!(at.file_exists(file_b)); assert!(at.file_exists(file_b));
@ -266,7 +312,11 @@ fn test_mv_existing_backup() {
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
at.touch(file_b_backup); at.touch(file_b_backup);
ucmd.arg("--backup=nil").arg(file_a).arg(file_b).succeeds().no_stderr(); ucmd.arg("--backup=nil")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(!at.file_exists(file_a)); assert!(!at.file_exists(file_a));
assert!(at.file_exists(file_b)); assert!(at.file_exists(file_b));
@ -294,7 +344,13 @@ fn test_mv_update_option() {
assert!(at.file_exists(file_a)); assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b)); assert!(at.file_exists(file_b));
scene.ucmd().arg("--update").arg(file_b).arg(file_a).succeeds().no_stderr(); scene
.ucmd()
.arg("--update")
.arg(file_b)
.arg(file_a)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a)); assert!(at.file_exists(file_a));
assert!(!at.file_exists(file_b)); assert!(!at.file_exists(file_b));
@ -310,7 +366,12 @@ fn test_mv_target_dir() {
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
at.mkdir(dir); at.mkdir(dir);
ucmd.arg("-t").arg(dir).arg(file_a).arg(file_b).succeeds().no_stderr(); ucmd.arg("-t")
.arg(dir)
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(!at.file_exists(file_a)); assert!(!at.file_exists(file_a));
assert!(!at.file_exists(file_b)); assert!(!at.file_exists(file_b));
@ -348,7 +409,16 @@ fn test_mv_overwrite_nonempty_dir() {
// GNU: "mv: cannot move a to b: Directory not empty" // GNU: "mv: cannot move a to b: Directory not empty"
// Verbose output for the move should not be shown on failure // Verbose output for the move should not be shown on failure
assert!(ucmd.arg("-vT").arg(dir_a).arg(dir_b).fails().no_stdout().stderr.len() > 0); assert!(
ucmd.arg("-vT")
.arg(dir_a)
.arg(dir_b)
.fails()
.no_stdout()
.stderr
.len()
> 0
);
assert!(at.dir_exists(dir_a)); assert!(at.dir_exists(dir_a));
assert!(at.dir_exists(dir_b)); assert!(at.dir_exists(dir_b));
@ -362,11 +432,14 @@ fn test_mv_backup_dir() {
at.mkdir(dir_a); at.mkdir(dir_a);
at.mkdir(dir_b); at.mkdir(dir_b);
ucmd.arg("-vbT").arg(dir_a).arg(dir_b).succeeds() ucmd.arg("-vbT")
.stdout_only(format!("{} -> {} (backup: {}~)\n", .arg(dir_a)
dir_a, .arg(dir_b)
dir_b, .succeeds()
dir_b)); .stdout_only(format!(
"{} -> {} (backup: {}~)\n",
dir_a, dir_b, dir_b
));
assert!(!at.dir_exists(dir_a)); assert!(!at.dir_exists(dir_a));
assert!(at.dir_exists(dir_b)); assert!(at.dir_exists(dir_b));
@ -386,15 +459,31 @@ fn test_mv_errors() {
// $ mv -T -t a b // $ mv -T -t a b
// mv: cannot combine --target-directory (-t) and --no-target-directory (-T) // mv: cannot combine --target-directory (-t) and --no-target-directory (-T)
scene.ucmd().arg("-T").arg("-t").arg(dir).arg(file_a).arg(file_b).fails() scene
.stderr_is("mv: error: cannot combine --target-directory (-t) and --no-target-directory (-T)\n"); .ucmd()
.arg("-T")
.arg("-t")
.arg(dir)
.arg(file_a)
.arg(file_b)
.fails()
.stderr_is(
"mv: error: cannot combine --target-directory (-t) and --no-target-directory (-T)\n",
);
// $ at.touch file && at.mkdir dir // $ at.touch file && at.mkdir dir
// $ mv -T file dir // $ mv -T file dir
// err == mv: cannot overwrite directory dir with non-directory // err == mv: cannot overwrite directory dir with non-directory
scene.ucmd().arg("-T").arg(file_a).arg(dir).fails() scene
.stderr_is(format!("mv: error: cannot overwrite directory {} with non-directory\n", .ucmd()
dir)); .arg("-T")
.arg(file_a)
.arg(dir)
.fails()
.stderr_is(format!(
"mv: error: cannot overwrite directory {} with non-directory\n",
dir
));
// $ at.mkdir dir && at.touch file // $ at.mkdir dir && at.touch file
// $ mv dir file // $ mv dir file
@ -413,15 +502,25 @@ fn test_mv_verbose() {
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
scene.ucmd().arg("-v").arg(file_a).arg(file_b).succeeds() scene
.stdout_only(format!("{} -> {}\n", file_a, file_b)); .ucmd()
.arg("-v")
.arg(file_a)
.arg(file_b)
.succeeds()
.stdout_only(format!("{} -> {}\n", file_a, file_b));
at.touch(file_a); at.touch(file_a);
scene.ucmd().arg("-vb").arg(file_a).arg(file_b).succeeds() scene
.stdout_only(format!("{} -> {} (backup: {}~)\n", .ucmd()
file_a, .arg("-vb")
file_b, .arg(file_a)
file_b)); .arg(file_b)
.succeeds()
.stdout_only(format!(
"{} -> {} (backup: {}~)\n",
file_a, file_b, file_b
));
} }
// Todo: // Todo:

View file

@ -1,9 +1,11 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_stdin_nonewline() { 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] #[test]
fn test_stdin_newline() { fn test_stdin_newline() {
@ -17,36 +19,47 @@ fn test_stdin_newline() {
#[test] #[test]
fn test_padding_without_overflow() { fn test_padding_without_overflow() {
new_ucmd!() new_ucmd!()
.args(&["-i", "1000", "-s", "x", "-n", "rz", "simple.txt"]).run() .args(&["-i", "1000", "-s", "x", "-n", "rz", "simple.txt"])
.run()
.stdout_is( .stdout_is(
"000001xL1\n001001xL2\n002001xL3\n003001xL4\n004001xL5\n005001xL6\n006001xL7\n0070\ "000001xL1\n001001xL2\n002001xL3\n003001xL4\n004001xL5\n005001xL6\n006001xL7\n0070\
01xL8\n008001xL9\n009001xL10\n010001xL11\n011001xL12\n012001xL13\n013001xL14\n014\ 01xL8\n008001xL9\n009001xL10\n010001xL11\n011001xL12\n012001xL13\n013001xL14\n014\
001xL15\n"); 001xL15\n",
);
} }
#[test] #[test]
fn test_padding_with_overflow() { fn test_padding_with_overflow() {
new_ucmd!() new_ucmd!()
.args(&["-i", "1000", "-s", "x", "-n", "rz", "-w", "4", "simple.txt"]).run() .args(&["-i", "1000", "-s", "x", "-n", "rz", "-w", "4", "simple.txt"])
.run()
.stdout_is( .stdout_is(
"0001xL1\n1001xL2\n2001xL3\n3001xL4\n4001xL5\n5001xL6\n6001xL7\n7001xL8\n8001xL9\n\ "0001xL1\n1001xL2\n2001xL3\n3001xL4\n4001xL5\n5001xL6\n6001xL7\n7001xL8\n8001xL9\n\
9001xL10\n10001xL11\n11001xL12\n12001xL13\n13001xL14\n14001xL15\n"); 9001xL10\n10001xL11\n11001xL12\n12001xL13\n13001xL14\n14001xL15\n",
);
} }
#[test] #[test]
fn test_sections_and_styles() { fn test_sections_and_styles() {
for &(fixture, output) in &[("section.txt", for &(fixture, output) in &[
"\nHEADER1\nHEADER2\n\n1 |BODY1\n2 \ (
"section.txt",
"\nHEADER1\nHEADER2\n\n1 |BODY1\n2 \
|BODY2\n\nFOOTER1\nFOOTER2\n\nNEXTHEADER1\nNEXTHEADER2\n\n1 \ |BODY2\n\nFOOTER1\nFOOTER2\n\nNEXTHEADER1\nNEXTHEADER2\n\n1 \
|NEXTBODY1\n2 |NEXTBODY2\n\nNEXTFOOTER1\nNEXTFOOTER2\n"), |NEXTBODY1\n2 |NEXTBODY2\n\nNEXTFOOTER1\nNEXTFOOTER2\n",
("joinblanklines.txt", ),
"1 |Nonempty\n2 |Nonempty\n3 |Followed by 10x empty\n\n\n\n\n4 \ (
"joinblanklines.txt",
"1 |Nonempty\n2 |Nonempty\n3 |Followed by 10x empty\n\n\n\n\n4 \
|\n\n\n\n\n5 |\n6 |Followed by 5x empty\n\n\n\n\n7 |\n8 \ |\n\n\n\n\n5 |\n6 |Followed by 5x empty\n\n\n\n\n7 |\n8 \
|Followed by 4x empty\n\n\n\n\n9 |Nonempty\n10 |Nonempty\n11 \ |Followed by 4x empty\n\n\n\n\n9 |Nonempty\n10 |Nonempty\n11 \
|Nonempty.\n")] |Nonempty.\n",
{ ),
] {
new_ucmd!() new_ucmd!()
.args(&["-s", "|", "-n", "ln", "-w", "3", "-b", "a", "-l", "5", fixture]) .args(&[
"-s", "|", "-n", "ln", "-w", "3", "-b", "a", "-l", "5", fixture,
])
.run() .run()
.stdout_is(output); .stdout_is(output);
} }

View file

@ -1,13 +1,12 @@
extern crate unindent; extern crate unindent;
use common::util::*;
use std::path::Path;
use std::env;
use std::io::Write;
use std::fs::File;
use std::fs::remove_file;
use self::unindent::*; use self::unindent::*;
use common::util::*;
use std::env;
use std::fs::remove_file;
use std::fs::File;
use std::io::Write;
use std::path::Path;
// octal dump of 'abcdefghijklmnopqrstuvwxyz\n' // octal dump of 'abcdefghijklmnopqrstuvwxyz\n'
static ALPHA_OUT: &'static str = " static ALPHA_OUT: &'static str = "
@ -34,7 +33,10 @@ fn test_file() {
} }
} }
let result = new_ucmd!().arg("--endian=little").arg(file.as_os_str()).run(); let result = new_ucmd!()
.arg("--endian=little")
.arg(file.as_os_str())
.run();
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -51,18 +53,22 @@ fn test_2files() {
let file1 = tmpdir.join("test1"); let file1 = tmpdir.join("test1");
let file2 = tmpdir.join("test2"); let file2 = tmpdir.join("test2");
for &(n,a) in &[(1,"a"), (2,"b")] { for &(n, a) in &[(1, "a"), (2, "b")] {
println!("number: {} letter:{}", n, a); println!("number: {} letter:{}", n, a);
} }
for &(path,data)in &[(&file1, "abcdefghijklmnop"),(&file2, "qrstuvwxyz\n")] { for &(path, data) in &[(&file1, "abcdefghijklmnop"), (&file2, "qrstuvwxyz\n")] {
let mut f = File::create(&path).unwrap(); let mut f = File::create(&path).unwrap();
if f.write_all(data.as_bytes()).is_err() { if f.write_all(data.as_bytes()).is_err() {
panic!("Test setup failed - could not write file"); panic!("Test setup failed - could not write file");
} }
} }
let result = new_ucmd!().arg("--endian=little").arg(file1.as_os_str()).arg(file2.as_os_str()).run(); let result = new_ucmd!()
.arg("--endian=little")
.arg(file1.as_os_str())
.arg(file2.as_os_str())
.run();
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -88,7 +94,9 @@ fn test_no_file() {
#[test] #[test]
fn test_from_stdin() { fn test_from_stdin() {
let input = "abcdefghijklmnopqrstuvwxyz\n"; let input = "abcdefghijklmnopqrstuvwxyz\n";
let result = new_ucmd!().arg("--endian=little").run_piped_stdin(input.as_bytes()); let result = new_ucmd!()
.arg("--endian=little")
.run_piped_stdin(input.as_bytes());
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -103,15 +111,20 @@ fn test_from_mixed() {
let file1 = tmpdir.join("test-1"); let file1 = tmpdir.join("test-1");
let file3 = tmpdir.join("test-3"); let file3 = tmpdir.join("test-3");
let (data1, data2, data3) = ("abcdefg","hijklmnop","qrstuvwxyz\n"); let (data1, data2, data3) = ("abcdefg", "hijklmnop", "qrstuvwxyz\n");
for &(path,data)in &[(&file1, data1),(&file3, data3)] { for &(path, data) in &[(&file1, data1), (&file3, data3)] {
let mut f = File::create(&path).unwrap(); let mut f = File::create(&path).unwrap();
if f.write_all(data.as_bytes()).is_err() { if f.write_all(data.as_bytes()).is_err() {
panic!("Test setup failed - could not write file"); panic!("Test setup failed - could not write file");
} }
} }
let result = new_ucmd!().arg("--endian=little").arg(file1.as_os_str()).arg("-").arg(file3.as_os_str()).run_piped_stdin(data2.as_bytes()); let result = new_ucmd!()
.arg("--endian=little")
.arg(file1.as_os_str())
.arg("-")
.arg(file3.as_os_str())
.run_piped_stdin(data2.as_bytes());
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -121,34 +134,42 @@ fn test_from_mixed() {
#[test] #[test]
fn test_multiple_formats() { fn test_multiple_formats() {
let input = "abcdefghijklmnopqrstuvwxyz\n"; 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_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert_eq!(result.stdout, unindent(" assert_eq!(
result.stdout,
unindent(
"
0000000 a b c d e f g h i j k l m n o p 0000000 a b c d e f g h i j k l m n o p
141 142 143 144 145 146 147 150 151 152 153 154 155 156 157 160 141 142 143 144 145 146 147 150 151 152 153 154 155 156 157 160
0000020 q r s t u v w x y z \\n 0000020 q r s t u v w x y z \\n
161 162 163 164 165 166 167 170 171 172 012 161 162 163 164 165 166 167 170 171 172 012
0000033 0000033
")); "
)
);
} }
#[test] #[test]
fn test_dec() { fn test_dec() {
let input = [ let input = [
0u8, 0u8, 0u8, 0u8, 1u8, 0u8, 2u8, 0u8, 3u8, 0u8, 0xffu8, 0x7fu8, 0x00u8, 0x80u8, 0x01u8, 0x80u8,
1u8, 0u8, ];
2u8, 0u8, let expected_output = unindent(
3u8, 0u8, "
0xffu8,0x7fu8,
0x00u8,0x80u8,
0x01u8,0x80u8,];
let expected_output = unindent("
0000000 0 1 2 3 32767 -32768 -32767 0000000 0 1 2 3 32767 -32768 -32767
0000016 0000016
"); ",
let result = new_ucmd!().arg("--endian=little").arg("-s").run_piped_stdin(&input[..]); );
let result = new_ucmd!()
.arg("--endian=little")
.arg("-s")
.run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -156,14 +177,18 @@ fn test_dec() {
} }
#[test] #[test]
fn test_hex16(){ fn test_hex16() {
let input: [u8; 9] = [ let input: [u8; 9] = [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xff];
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xff]; let expected_output = unindent(
let expected_output = unindent(" "
0000000 2301 6745 ab89 efcd 00ff 0000000 2301 6745 ab89 efcd 00ff
0000011 0000011
"); ",
let result = new_ucmd!().arg("--endian=little").arg("-x").run_piped_stdin(&input[..]); );
let result = new_ucmd!()
.arg("--endian=little")
.arg("-x")
.run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -171,14 +196,18 @@ fn test_hex16(){
} }
#[test] #[test]
fn test_hex32(){ fn test_hex32() {
let input: [u8; 9] = [ let input: [u8; 9] = [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xff];
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xff]; let expected_output = unindent(
let expected_output = unindent(" "
0000000 67452301 efcdab89 000000ff 0000000 67452301 efcdab89 000000ff
0000011 0000011
"); ",
let result = new_ucmd!().arg("--endian=little").arg("-X").run_piped_stdin(&input[..]); );
let result = new_ucmd!()
.arg("--endian=little")
.arg("-X")
.run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -186,7 +215,7 @@ fn test_hex32(){
} }
#[test] #[test]
fn test_f16(){ fn test_f16() {
let input: [u8; 14] = [ let input: [u8; 14] = [
0x00, 0x3c, // 0x3C00 1.0 0x00, 0x3c, // 0x3C00 1.0
0x00, 0x00, // 0x0000 0.0 0x00, 0x00, // 0x0000 0.0
@ -194,13 +223,20 @@ fn test_f16(){
0x00, 0x7c, // 0x7C00 Inf 0x00, 0x7c, // 0x7C00 Inf
0x00, 0xfc, // 0xFC00 -Inf 0x00, 0xfc, // 0xFC00 -Inf
0x00, 0xfe, // 0xFE00 NaN 0x00, 0xfe, // 0xFE00 NaN
0x00, 0x84];// 0x8400 -6.104e-5 0x00, 0x84,
let expected_output = unindent(" ]; // 0x8400 -6.104e-5
let expected_output = unindent(
"
0000000 1.000 0 -0 inf 0000000 1.000 0 -0 inf
0000010 -inf NaN -6.104e-5 0000010 -inf NaN -6.104e-5
0000016 0000016
"); ",
let result = new_ucmd!().arg("--endian=little").arg("-tf2").arg("-w8").run_piped_stdin(&input[..]); );
let result = new_ucmd!()
.arg("--endian=little")
.arg("-tf2")
.arg("-w8")
.run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -208,7 +244,7 @@ fn test_f16(){
} }
#[test] #[test]
fn test_f32(){ fn test_f32() {
let input: [u8; 28] = [ let input: [u8; 28] = [
0x52, 0x06, 0x9e, 0xbf, // 0xbf9e0652 -1.2345679 0x52, 0x06, 0x9e, 0xbf, // 0xbf9e0652 -1.2345679
0x4e, 0x61, 0x3c, 0x4b, // 0x4b3c614e 12345678 0x4e, 0x61, 0x3c, 0x4b, // 0x4b3c614e 12345678
@ -216,13 +252,19 @@ fn test_f32(){
0x00, 0x00, 0x00, 0x80, // 0x80000000 -0.0 0x00, 0x00, 0x00, 0x80, // 0x80000000 -0.0
0xff, 0xff, 0xff, 0x7f, // 0x7fffffff NaN 0xff, 0xff, 0xff, 0x7f, // 0x7fffffff NaN
0xc2, 0x16, 0x01, 0x00, // 0x000116c2 1e-40 0xc2, 0x16, 0x01, 0x00, // 0x000116c2 1e-40
0x00, 0x00, 0x7f, 0x80];// 0x807f0000 -1.1663108E-38 0x00, 0x00, 0x7f, 0x80,
let expected_output = unindent(" ]; // 0x807f0000 -1.1663108E-38
let expected_output = unindent(
"
0000000 -1.2345679 12345678 -9.8765427e37 -0 0000000 -1.2345679 12345678 -9.8765427e37 -0
0000020 NaN 1e-40 -1.1663108e-38 0000020 NaN 1e-40 -1.1663108e-38
0000034 0000034
"); ",
let result = new_ucmd!().arg("--endian=little").arg("-f").run_piped_stdin(&input[..]); );
let result = new_ucmd!()
.arg("--endian=little")
.arg("-f")
.run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -230,20 +272,29 @@ fn test_f32(){
} }
#[test] #[test]
fn test_f64(){ fn test_f64() {
let input: [u8; 40] = [ let input: [u8; 40] = [
0x27, 0x6b, 0x0a, 0x2f, 0x2a, 0xee, 0x45, 0x43, // 0x4345EE2A2F0A6B27 12345678912345678 0x27, 0x6b, 0x0a, 0x2f, 0x2a, 0xee, 0x45,
0x43, // 0x4345EE2A2F0A6B27 12345678912345678
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0000000000000000 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0000000000000000 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x80, // 0x8010000000000000 -2.2250738585072014e-308 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0000000000000001 5e-324 (subnormal) 0x80, // 0x8010000000000000 -2.2250738585072014e-308
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0];// 0xc000000000000000 -2 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
let expected_output = unindent(" 0x00, // 0x0000000000000001 5e-324 (subnormal)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
]; // 0xc000000000000000 -2
let expected_output = unindent(
"
0000000 12345678912345678 0 0000000 12345678912345678 0
0000020 -2.2250738585072014e-308 5e-324 0000020 -2.2250738585072014e-308 5e-324
0000040 -2.0000000000000000 0000040 -2.0000000000000000
0000050 0000050
"); ",
let result = new_ucmd!().arg("--endian=little").arg("-F").run_piped_stdin(&input[..]); );
let result = new_ucmd!()
.arg("--endian=little")
.arg("-F")
.run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -252,26 +303,36 @@ fn test_f64(){
#[test] #[test]
fn test_multibyte() { fn test_multibyte() {
let result = new_ucmd!().arg("-c").arg("-w12").run_piped_stdin("Universität Tübingen \u{1B000}".as_bytes()); let result = new_ucmd!()
.arg("-c")
.arg("-w12")
.run_piped_stdin("Universität Tübingen \u{1B000}".as_bytes());
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert_eq!(result.stdout, unindent(" assert_eq!(
result.stdout,
unindent(
"
0000000 U n i v e r s i t ä ** t 0000000 U n i v e r s i t ä ** t
0000014 T ü ** b i n g e n \u{1B000} 0000014 T ü ** b i n g e n \u{1B000}
0000030 ** ** ** 0000030 ** ** **
0000033 0000033
")); "
)
);
} }
#[test] #[test]
fn test_width(){ fn test_width() {
let input: [u8; 8] = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; let input: [u8; 8] = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
let expected_output = unindent(" let expected_output = unindent(
"
0000000 000000 000000 0000000 000000 000000
0000004 000000 000000 0000004 000000 000000
0000010 0000010
"); ",
);
let result = new_ucmd!().arg("-w4").arg("-v").run_piped_stdin(&input[..]); let result = new_ucmd!().arg("-w4").arg("-v").run_piped_stdin(&input[..]);
@ -281,40 +342,50 @@ fn test_width(){
} }
#[test] #[test]
fn test_invalid_width(){ fn test_invalid_width() {
let input: [u8; 4] = [0x00, 0x00, 0x00, 0x00]; let input: [u8; 4] = [0x00, 0x00, 0x00, 0x00];
let expected_output = unindent(" let expected_output = unindent(
"
0000000 000000 0000000 000000
0000002 000000 0000002 000000
0000004 0000004
"); ",
);
let result = new_ucmd!().arg("-w5").arg("-v").run_piped_stdin(&input[..]); let result = new_ucmd!().arg("-w5").arg("-v").run_piped_stdin(&input[..]);
assert_eq!(result.stderr, "od: warning: invalid width 5; using 2 instead\n"); assert_eq!(
result.stderr,
"od: warning: invalid width 5; using 2 instead\n"
);
assert!(result.success); assert!(result.success);
assert_eq!(result.stdout, expected_output); assert_eq!(result.stdout, expected_output);
} }
#[test] #[test]
fn test_zero_width(){ fn test_zero_width() {
let input: [u8; 4] = [0x00, 0x00, 0x00, 0x00]; let input: [u8; 4] = [0x00, 0x00, 0x00, 0x00];
let expected_output = unindent(" let expected_output = unindent(
"
0000000 000000 0000000 000000
0000002 000000 0000002 000000
0000004 0000004
"); ",
);
let result = new_ucmd!().arg("-w0").arg("-v").run_piped_stdin(&input[..]); let result = new_ucmd!().arg("-w0").arg("-v").run_piped_stdin(&input[..]);
assert_eq!(result.stderr, "od: warning: invalid width 0; using 2 instead\n"); assert_eq!(
result.stderr,
"od: warning: invalid width 0; using 2 instead\n"
);
assert!(result.success); assert!(result.success);
assert_eq!(result.stdout, expected_output); assert_eq!(result.stdout, expected_output);
} }
#[test] #[test]
fn test_width_without_value(){ fn test_width_without_value() {
let input: [u8; 40] = [0 ; 40]; let input: [u8; 40] = [0; 40];
let expected_output = unindent(" let expected_output = unindent("
0000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 0000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
0000040 000000 000000 000000 000000 0000040 000000 000000 000000 000000
@ -329,20 +400,13 @@ fn test_width_without_value(){
} }
#[test] #[test]
fn test_suppress_duplicates(){ fn test_suppress_duplicates() {
let input: [u8; 41] = [ let input: [u8; 41] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, ];
0, 0, 0, 0, let expected_output = unindent(
1, 0, 0, 0, "
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0];
let expected_output = unindent("
0000000 00000000000 0000000 00000000000
0000 0000 0000 0000
* *
@ -354,9 +418,14 @@ fn test_suppress_duplicates(){
0000050 00000000000 0000050 00000000000
0000 0000
0000051 0000051
"); ",
);
let result = new_ucmd!().arg("-w4").arg("-O").arg("-x").run_piped_stdin(&input[..]); let result = new_ucmd!()
.arg("-w4")
.arg("-O")
.arg("-x")
.run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -365,18 +434,25 @@ fn test_suppress_duplicates(){
#[test] #[test]
fn test_big_endian() { fn test_big_endian() {
let input: [u8; 8] = [ let input: [u8; 8] = [0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; // 0xc000000000000000 -2
0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];// 0xc000000000000000 -2
let expected_output = unindent(" let expected_output = unindent(
"
0000000 -2.0000000000000000 0000000 -2.0000000000000000
-2.0000000 0 -2.0000000 0
c0000000 00000000 c0000000 00000000
c000 0000 0000 0000 c000 0000 0000 0000
0000010 0000010
"); ",
);
let result = new_ucmd!().arg("--endian=big").arg("-F").arg("-f").arg("-X").arg("-x").run_piped_stdin(&input[..]); let result = new_ucmd!()
.arg("--endian=big")
.arg("-F")
.arg("-f")
.arg("-X")
.arg("-x")
.run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -386,18 +462,24 @@ fn test_big_endian() {
#[test] #[test]
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn test_alignment_Xxa() { fn test_alignment_Xxa() {
let input: [u8; 8] = [ let input: [u8; 8] = [0x0A, 0x0D, 0x65, 0x66, 0x67, 0x00, 0x9e, 0x9f];
0x0A, 0x0D, 0x65, 0x66, 0x67, 0x00, 0x9e, 0x9f];
let expected_output = unindent(" let expected_output = unindent(
"
0000000 66650d0a 9f9e0067 0000000 66650d0a 9f9e0067
0d0a 6665 0067 9f9e 0d0a 6665 0067 9f9e
nl cr e f g nul rs us nl cr e f g nul rs us
0000010 0000010
"); ",
);
// in this case the width of the -a (8-bit) determines the alignment for the other fields // in this case the width of the -a (8-bit) determines the alignment for the other fields
let result = new_ucmd!().arg("--endian=little").arg("-X").arg("-x").arg("-a").run_piped_stdin(&input[..]); let result = new_ucmd!()
.arg("--endian=little")
.arg("-X")
.arg("-x")
.arg("-a")
.run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -407,17 +489,22 @@ fn test_alignment_Xxa() {
#[test] #[test]
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn test_alignment_Fx() { fn test_alignment_Fx() {
let input: [u8; 8] = [ let input: [u8; 8] = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0]; // 0xc000000000000000 -2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0];// 0xc000000000000000 -2
let expected_output = unindent(" let expected_output = unindent(
"
0000000 -2.0000000000000000 0000000 -2.0000000000000000
0000 0000 0000 c000 0000 0000 0000 c000
0000010 0000010
"); ",
);
// in this case the width of the -F (64-bit) determines the alignment for the other field // in this case the width of the -F (64-bit) determines the alignment for the other field
let result = new_ucmd!().arg("--endian=little").arg("-F").arg("-x").run_piped_stdin(&input[..]); let result = new_ucmd!()
.arg("--endian=little")
.arg("-F")
.arg("-x")
.run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -425,9 +512,10 @@ fn test_alignment_Fx() {
} }
#[test] #[test]
fn test_maxuint(){ fn test_maxuint() {
let input = [0xFFu8 ; 8]; let input = [0xFFu8; 8];
let expected_output = unindent(" let expected_output = unindent(
"
0000000 1777777777777777777777 0000000 1777777777777777777777
37777777777 37777777777 37777777777 37777777777
177777 177777 177777 177777 177777 177777 177777 177777
@ -437,9 +525,15 @@ fn test_maxuint(){
65535 65535 65535 65535 65535 65535 65535 65535
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
0000010 0000010
"); ",
);
let result = new_ucmd!().arg("--format=o8").arg("-Oobtu8").arg("-Dd").arg("--format=u1").run_piped_stdin(&input[..]); let result = new_ucmd!()
.arg("--format=o8")
.arg("-Oobtu8")
.arg("-Dd")
.arg("--format=u1")
.run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -447,17 +541,23 @@ fn test_maxuint(){
} }
#[test] #[test]
fn test_hex_offset(){ fn test_hex_offset() {
let input = [0u8 ; 0x1F]; let input = [0u8; 0x1F];
let expected_output = unindent(" let expected_output = unindent(
"
000000 00000000 00000000 00000000 00000000 000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
000010 00000000 00000000 00000000 00000000 000010 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00001F 00001F
"); ",
);
let result = new_ucmd!().arg("-Ax").arg("-X").arg("-X").run_piped_stdin(&input[..]); let result = new_ucmd!()
.arg("-Ax")
.arg("-X")
.arg("-X")
.run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -465,17 +565,23 @@ fn test_hex_offset(){
} }
#[test] #[test]
fn test_dec_offset(){ fn test_dec_offset() {
let input = [0u8 ; 19]; let input = [0u8; 19];
let expected_output = unindent(" let expected_output = unindent(
"
0000000 00000000 00000000 00000000 00000000 0000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
0000016 00000000 0000016 00000000
00000000 00000000
0000019 0000019
"); ",
);
let result = new_ucmd!().arg("-Ad").arg("-X").arg("-X").run_piped_stdin(&input[..]); let result = new_ucmd!()
.arg("-Ad")
.arg("-X")
.arg("-X")
.run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -483,12 +589,16 @@ fn test_dec_offset(){
} }
#[test] #[test]
fn test_no_offset(){ fn test_no_offset() {
let input = [0u8 ; 31]; let input = [0u8; 31];
const LINE: &'static str = " 00000000 00000000 00000000 00000000\n"; const LINE: &'static str = " 00000000 00000000 00000000 00000000\n";
let expected_output = [LINE, LINE, LINE, LINE].join(""); let expected_output = [LINE, LINE, LINE, LINE].join("");
let result = new_ucmd!().arg("-An").arg("-X").arg("-X").run_piped_stdin(&input[..]); let result = new_ucmd!()
.arg("-An")
.arg("-X")
.arg("-X")
.run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -496,37 +606,50 @@ fn test_no_offset(){
} }
#[test] #[test]
fn test_invalid_offset(){ fn test_invalid_offset() {
let result = new_ucmd!().arg("-Ab").run(); let result = new_ucmd!().arg("-Ab").run();
assert!(!result.success); assert!(!result.success);
} }
#[test] #[test]
fn test_skip_bytes(){ fn test_skip_bytes() {
let input = "abcdefghijklmnopq"; let input = "abcdefghijklmnopq";
let result = new_ucmd!().arg("-c").arg("--skip-bytes=5").run_piped_stdin(input.as_bytes()); let result = new_ucmd!()
.arg("-c")
.arg("--skip-bytes=5")
.run_piped_stdin(input.as_bytes());
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert_eq!(result.stdout, unindent(" assert_eq!(
result.stdout,
unindent(
"
0000005 f g h i j k l m n o p q 0000005 f g h i j k l m n o p q
0000021 0000021
")); "
)
);
} }
#[test] #[test]
fn test_skip_bytes_error(){ fn test_skip_bytes_error() {
let input = "12345"; let input = "12345";
let result = new_ucmd!().arg("--skip-bytes=10").run_piped_stdin(input.as_bytes()); let result = new_ucmd!()
.arg("--skip-bytes=10")
.run_piped_stdin(input.as_bytes());
assert!(!result.success); assert!(!result.success);
} }
#[test] #[test]
fn test_read_bytes(){ fn test_read_bytes() {
let input = "abcdefghijklmnopqrstuvwxyz\n12345678"; let input = "abcdefghijklmnopqrstuvwxyz\n12345678";
let result = new_ucmd!().arg("--endian=little").arg("--read-bytes=27").run_piped_stdin(input.as_bytes()); let result = new_ucmd!()
.arg("--endian=little")
.arg("--read-bytes=27")
.run_piped_stdin(input.as_bytes());
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
@ -534,15 +657,19 @@ fn test_read_bytes(){
} }
#[test] #[test]
fn test_ascii_dump(){ fn test_ascii_dump() {
let input: [u8; 22] = [ let input: [u8; 22] = [
0x00, 0x01, 0x0a, 0x0d, 0x10, 0x1f, 0x20, 0x61, 0x62, 0x63, 0x7d, 0x00, 0x01, 0x0a, 0x0d, 0x10, 0x1f, 0x20, 0x61, 0x62, 0x63, 0x7d, 0x7e, 0x7f, 0x80, 0x90,
0x7e, 0x7f, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0xff]; 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0xff,
];
let result = new_ucmd!().arg("-tx1zacz").run_piped_stdin(&input[..]); let result = new_ucmd!().arg("-tx1zacz").run_piped_stdin(&input[..]);
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert_eq!(result.stdout, unindent(r" assert_eq!(
result.stdout,
unindent(
r"
0000000 00 01 0a 0d 10 1f 20 61 62 63 7d 7e 7f 80 90 a0 >...... abc}~....< 0000000 00 01 0a 0d 10 1f 20 61 62 63 7d 7e 7f 80 90 a0 >...... abc}~....<
nul soh nl cr dle us sp a b c } ~ del nul dle sp nul soh nl cr dle us sp a b c } ~ del nul dle sp
\0 001 \n \r 020 037 a b c } ~ 177 ** ** ** >...... abc}~....< \0 001 \n \r 020 037 a b c } ~ 177 ** ** ** >...... abc}~....<
@ -550,113 +677,190 @@ fn test_ascii_dump(){
0 @ P ` p del 0 @ P ` p del
** 300 320 340 360 377 >......< ** 300 320 340 360 377 >......<
0000026 0000026
")); "
)
);
} }
#[test] #[test]
fn test_filename_parsing(){ fn test_filename_parsing() {
// files "a" and "x" both exists, but are no filenames in the commandline below // files "a" and "x" both exists, but are no filenames in the commandline below
// "-f" must be treated as a filename, it contains the text: minus lowercase f // "-f" must be treated as a filename, it contains the text: minus lowercase f
// so "-f" should not be interpreted as a formatting option. // so "-f" should not be interpreted as a formatting option.
let result = new_ucmd!().arg("--format").arg("a").arg("-A").arg("x").arg("--").arg("-f").run(); let result = new_ucmd!()
.arg("--format")
.arg("a")
.arg("-A")
.arg("x")
.arg("--")
.arg("-f")
.run();
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert_eq!(result.stdout, unindent(" assert_eq!(
result.stdout,
unindent(
"
000000 m i n u s sp l o w e r c a s e sp 000000 m i n u s sp l o w e r c a s e sp
000010 f nl 000010 f nl
000012 000012
")); "
)
);
} }
#[test] #[test]
fn test_stdin_offset(){ fn test_stdin_offset() {
let input = "abcdefghijklmnopq"; let input = "abcdefghijklmnopq";
let result = new_ucmd!().arg("-c").arg("+5").run_piped_stdin(input.as_bytes()); let result = new_ucmd!()
.arg("-c")
.arg("+5")
.run_piped_stdin(input.as_bytes());
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert_eq!(result.stdout, unindent(" assert_eq!(
result.stdout,
unindent(
"
0000005 f g h i j k l m n o p q 0000005 f g h i j k l m n o p q
0000021 0000021
")); "
)
);
} }
#[test] #[test]
fn test_file_offset(){ fn test_file_offset() {
let result = new_ucmd!().arg("-c").arg("--").arg("-f").arg("10").run(); let result = new_ucmd!().arg("-c").arg("--").arg("-f").arg("10").run();
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert_eq!(result.stdout, unindent(r" assert_eq!(
result.stdout,
unindent(
r"
0000010 w e r c a s e f \n 0000010 w e r c a s e f \n
0000022 0000022
")); "
)
);
} }
#[test] #[test]
fn test_traditional(){ fn test_traditional() {
// note gnu od does not align both lines // note gnu od does not align both lines
let input = "abcdefghijklmnopq"; let input = "abcdefghijklmnopq";
let result = new_ucmd!().arg("--traditional").arg("-a").arg("-c").arg("-").arg("10").arg("0").run_piped_stdin(input.as_bytes()); let result = new_ucmd!()
.arg("--traditional")
.arg("-a")
.arg("-c")
.arg("-")
.arg("10")
.arg("0")
.run_piped_stdin(input.as_bytes());
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert_eq!(result.stdout, unindent(r" assert_eq!(
result.stdout,
unindent(
r"
0000010 (0000000) i j k l m n o p q 0000010 (0000000) i j k l m n o p q
i j k l m n o p q i j k l m n o p q
0000021 (0000011) 0000021 (0000011)
")); "
)
);
} }
#[test] #[test]
fn test_traditional_with_skip_bytes_override(){ fn test_traditional_with_skip_bytes_override() {
// --skip-bytes is ignored in this case // --skip-bytes is ignored in this case
let input = "abcdefghijklmnop"; let input = "abcdefghijklmnop";
let result = new_ucmd!().arg("--traditional").arg("--skip-bytes=10").arg("-c").arg("0").run_piped_stdin(input.as_bytes()); let result = new_ucmd!()
.arg("--traditional")
.arg("--skip-bytes=10")
.arg("-c")
.arg("0")
.run_piped_stdin(input.as_bytes());
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert_eq!(result.stdout, unindent(r" assert_eq!(
result.stdout,
unindent(
r"
0000000 a b c d e f g h i j k l m n o p 0000000 a b c d e f g h i j k l m n o p
0000020 0000020
")); "
)
);
} }
#[test] #[test]
fn test_traditional_with_skip_bytes_non_override(){ fn test_traditional_with_skip_bytes_non_override() {
// no offset specified in the traditional way, so --skip-bytes is used // no offset specified in the traditional way, so --skip-bytes is used
let input = "abcdefghijklmnop"; let input = "abcdefghijklmnop";
let result = new_ucmd!().arg("--traditional").arg("--skip-bytes=10").arg("-c").run_piped_stdin(input.as_bytes()); let result = new_ucmd!()
.arg("--traditional")
.arg("--skip-bytes=10")
.arg("-c")
.run_piped_stdin(input.as_bytes());
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert_eq!(result.stdout, unindent(r" assert_eq!(
result.stdout,
unindent(
r"
0000012 k l m n o p 0000012 k l m n o p
0000020 0000020
")); "
)
);
} }
#[test] #[test]
fn test_traditional_error(){ fn test_traditional_error() {
// file "0" exists - don't fail on that, but --traditional only accepts a single input // file "0" exists - don't fail on that, but --traditional only accepts a single input
let result = new_ucmd!().arg("--traditional").arg("0").arg("0").arg("0").arg("0").run(); let result = new_ucmd!()
.arg("--traditional")
.arg("0")
.arg("0")
.arg("0")
.arg("0")
.run();
assert!(!result.success); assert!(!result.success);
} }
#[test] #[test]
fn test_traditional_only_label(){ fn test_traditional_only_label() {
let input = "abcdefghijklmnopqrstuvwxyz"; let input = "abcdefghijklmnopqrstuvwxyz";
let result = new_ucmd!().arg("-An").arg("--traditional").arg("-a").arg("-c").arg("-").arg("10").arg("0x10").run_piped_stdin(input.as_bytes()); let result = new_ucmd!()
.arg("-An")
.arg("--traditional")
.arg("-a")
.arg("-c")
.arg("-")
.arg("10")
.arg("0x10")
.run_piped_stdin(input.as_bytes());
assert_empty_stderr!(result); assert_empty_stderr!(result);
assert!(result.success); assert!(result.success);
assert_eq!(result.stdout, unindent(r" assert_eq!(
result.stdout,
unindent(
r"
(0000020) i j k l m n o p q r s t u v w x (0000020) i j k l m n o p q r s t u v w x
i j k l m n o p q r s t u v w x i j k l m n o p q r s t u v w x
(0000040) y z (0000040) y z
y z y z
(0000042) (0000042)
")); "
)
);
} }

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_combine_pairs_of_lines() { fn test_combine_pairs_of_lines() {
new_ucmd!() new_ucmd!()

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_default_mode() { fn test_default_mode() {
// test the default mode // test the default mode
@ -9,5 +8,8 @@ fn test_default_mode() {
new_ucmd!().args(&["abc/def"]).succeeds().no_stdout(); new_ucmd!().args(&["abc/def"]).succeeds().no_stdout();
// fail on long inputs // fail on long inputs
new_ucmd!().args(&[repeat_str("test", 20000)]).fails().no_stdout(); new_ucmd!()
.args(&[repeat_str("test", 20000)])
.fails()
.no_stdout();
} }

View file

@ -20,18 +20,18 @@ fn test_long_format() {
let ulogin = "root"; let ulogin = "root";
let pw: Passwd = Passwd::locate(ulogin).unwrap(); let pw: Passwd = Passwd::locate(ulogin).unwrap();
let real_name = pw.user_info().replace("&", &pw.name().capitalize()); let real_name = pw.user_info().replace("&", &pw.name().capitalize());
new_ucmd!() new_ucmd!().arg("-l").arg(ulogin).run().stdout_is(format!(
.arg("-l").arg(ulogin) "Login name: {:<28}In real life: {}\nDirectory: {:<29}Shell: {}\n\n",
.run() ulogin,
.stdout_is(format!("Login name: {:<28}In real life: {}\nDirectory: {:<29}Shell: {}\n\n", real_name,
ulogin, real_name, pw.user_dir(), pw.user_shell())); pw.user_dir(),
pw.user_shell()
));
new_ucmd!() new_ucmd!().arg("-lb").arg(ulogin).run().stdout_is(format!(
.arg("-lb") "Login name: {:<28}In real life: {1}\n\n",
.arg(ulogin) ulogin, real_name
.run() ));
.stdout_is(format!("Login name: {:<28}In real life: {1}\n\n",
ulogin, real_name));
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
@ -40,7 +40,11 @@ fn test_short_format_i() {
// allow whitespace variation // allow whitespace variation
// * minor whitespace differences occur between platform built-in outputs; specifically, the number of trailing TABs may be variant // * minor whitespace differences occur between platform built-in outputs; specifically, the number of trailing TABs may be variant
let args = ["-i"]; let args = ["-i"];
let actual = TestScenario::new(util_name!()).ucmd().args(&args).run().stdout; let actual = TestScenario::new(util_name!())
.ucmd()
.args(&args)
.run()
.stdout;
let expect = expected_result(&args); let expect = expected_result(&args);
println!("actual: {:?}", actual); println!("actual: {:?}", actual);
println!("expect: {:?}", expect); println!("expect: {:?}", expect);
@ -55,7 +59,11 @@ fn test_short_format_q() {
// allow whitespace variation // allow whitespace variation
// * minor whitespace differences occur between platform built-in outputs; specifically, the number of trailing TABs may be variant // * minor whitespace differences occur between platform built-in outputs; specifically, the number of trailing TABs may be variant
let args = ["-q"]; let args = ["-q"];
let actual = TestScenario::new(util_name!()).ucmd().args(&args).run().stdout; let actual = TestScenario::new(util_name!())
.ucmd()
.args(&args)
.run()
.stdout;
let expect = expected_result(&args); let expect = expected_result(&args);
println!("actual: {:?}", actual); println!("actual: {:?}", actual);
println!("expect: {:?}", expect); println!("expect: {:?}", expect);
@ -66,5 +74,10 @@ fn test_short_format_q() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn expected_result(args: &[&str]) -> String { fn expected_result(args: &[&str]) -> String {
TestScenario::new(util_name!()).cmd_keepenv(util_name!()).env("LANGUAGE", "C").args(args).run().stdout TestScenario::new(util_name!())
.cmd_keepenv(util_name!())
.env("LANGUAGE", "C")
.args(args)
.run()
.stdout
} }

View file

@ -1,24 +1,35 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn basic_literal() { fn basic_literal() {
new_ucmd!().args(&["hello world"]).succeeds().stdout_only("hello world"); new_ucmd!()
.args(&["hello world"])
.succeeds()
.stdout_only("hello world");
} }
#[test] #[test]
fn escaped_tab() { 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] #[test]
fn escaped_newline() { 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] #[test]
fn escaped_slash() { fn escaped_slash() {
new_ucmd!().args(&["hello\\\\ world"]).succeeds().stdout_only("hello\\ world"); new_ucmd!()
.args(&["hello\\\\ world"])
.succeeds()
.stdout_only("hello\\ world");
} }
#[test] #[test]
@ -38,12 +49,18 @@ fn escaped_unicode_fourdigit() {
#[test] #[test]
fn escaped_unicode_eightdigit() { fn escaped_unicode_eightdigit() {
new_ucmd!().args(&["\\U00000125"]).succeeds().stdout_only("ĥ"); new_ucmd!()
.args(&["\\U00000125"])
.succeeds()
.stdout_only("ĥ");
} }
#[test] #[test]
fn escaped_percent_sign() { 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] #[test]
@ -53,227 +70,362 @@ fn escaped_unrecognized() {
#[test] #[test]
fn sub_string() { 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] #[test]
fn sub_multifield() { 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] #[test]
fn sub_repeat_formatstr() { 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] #[test]
fn sub_string_ignore_escapes() { 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] #[test]
fn sub_bstring_handle_escapes() { 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] #[test]
fn sub_bstring_ignore_subs() { 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] #[test]
fn sub_char() { 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] #[test]
fn sub_num_int() { 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] #[test]
fn sub_num_int_minwidth() { 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] #[test]
fn sub_num_int_neg() { 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] #[test]
fn sub_num_int_oct_in() { 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] #[test]
fn sub_num_int_oct_in_neg() { 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] #[test]
fn sub_num_int_hex_in() { 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] #[test]
fn sub_num_int_hex_in_neg() { 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] #[test]
fn sub_num_int_charconst_in() { 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] #[test]
fn sub_num_uint() { 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] #[test]
fn sub_num_octal() { 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] #[test]
fn sub_num_hex_lower() { 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] #[test]
fn sub_num_hex_upper() { 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] #[test]
fn sub_num_float() { 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] #[test]
fn sub_num_float_round() { 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] #[test]
fn sub_num_sci_lower() { 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] #[test]
fn sub_num_sci_upper() { 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] #[test]
fn sub_num_sci_trunc() { 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] #[test]
fn sub_num_dec_trunc() { 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)] #[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test] #[test]
fn sub_num_hex_float_lower() { 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)] #[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test] #[test]
fn sub_num_hex_float_upper() { 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] #[test]
fn sub_minwidth() { 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] #[test]
fn sub_minwidth_negative() { 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] #[test]
fn sub_str_max_chars_input() { 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] #[test]
fn sub_int_decimal() { 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] #[test]
fn sub_int_leading_zeroes() { fn sub_int_leading_zeroes() {
new_ucmd!().args(&["%.4i", "11"]).succeeds().stdout_only("0011"); new_ucmd!()
.args(&["%.4i", "11"])
.succeeds()
.stdout_only("0011");
} }
#[test] #[test]
fn sub_int_leading_zeroes_prio() { 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] #[test]
fn sub_float_dec_places() { 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] #[test]
fn sub_float_hex_in() { 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] #[test]
fn sub_float_no_octal_in() { 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] #[test]
fn sub_any_asterisk_firstparam() { 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] #[test]
fn sub_any_asterisk_second_param() { 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] #[test]
fn sub_any_asterisk_both_params() { 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] #[test]
fn sub_any_asterisk_octal_arg() { 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] #[test]
fn sub_any_asterisk_hex_arg() { 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] #[test]
fn sub_any_specifiers_no_params() { 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] #[test]
fn sub_any_specifiers_after_first_param() { 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] #[test]
fn sub_any_specifiers_after_period() { 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] #[test]
fn sub_any_specifiers_after_second_param() { 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");
} }

View file

@ -1,44 +1,57 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn gnu_ext_disabled_roff_no_ref() { fn gnu_ext_disabled_roff_no_ref() {
new_ucmd!().args(&["-G", "-R", "input"]) new_ucmd!()
.succeeds().stdout_only_fixture("gnu_ext_disabled_roff_no_ref.expected"); .args(&["-G", "-R", "input"])
.succeeds()
.stdout_only_fixture("gnu_ext_disabled_roff_no_ref.expected");
} }
#[test] #[test]
fn gnu_ext_disabled_roff_input_ref() { fn gnu_ext_disabled_roff_input_ref() {
new_ucmd!().args(&["-G", "-r", "-R", "input"]) new_ucmd!()
.succeeds().stdout_only_fixture("gnu_ext_disabled_roff_input_ref.expected"); .args(&["-G", "-r", "-R", "input"])
.succeeds()
.stdout_only_fixture("gnu_ext_disabled_roff_input_ref.expected");
} }
#[test] #[test]
fn gnu_ext_disabled_roff_auto_ref() { fn gnu_ext_disabled_roff_auto_ref() {
new_ucmd!().args(&["-G", "-A", "-R", "input"]) new_ucmd!()
.succeeds().stdout_only_fixture("gnu_ext_disabled_roff_auto_ref.expected"); .args(&["-G", "-A", "-R", "input"])
.succeeds()
.stdout_only_fixture("gnu_ext_disabled_roff_auto_ref.expected");
} }
#[test] #[test]
fn gnu_ext_disabled_tex_no_ref() { fn gnu_ext_disabled_tex_no_ref() {
new_ucmd!().args(&["-G", "-T", "-R", "input"]) new_ucmd!()
.succeeds().stdout_only_fixture("gnu_ext_disabled_tex_no_ref.expected"); .args(&["-G", "-T", "-R", "input"])
.succeeds()
.stdout_only_fixture("gnu_ext_disabled_tex_no_ref.expected");
} }
#[test] #[test]
fn gnu_ext_disabled_tex_input_ref() { fn gnu_ext_disabled_tex_input_ref() {
new_ucmd!().args(&["-G", "-T", "-r", "-R", "input"]) new_ucmd!()
.succeeds().stdout_only_fixture("gnu_ext_disabled_tex_input_ref.expected"); .args(&["-G", "-T", "-r", "-R", "input"])
.succeeds()
.stdout_only_fixture("gnu_ext_disabled_tex_input_ref.expected");
} }
#[test] #[test]
fn gnu_ext_disabled_tex_auto_ref() { fn gnu_ext_disabled_tex_auto_ref() {
new_ucmd!().args(&["-G", "-T", "-A", "-R", "input"]) new_ucmd!()
.succeeds().stdout_only_fixture("gnu_ext_disabled_tex_auto_ref.expected"); .args(&["-G", "-T", "-A", "-R", "input"])
.succeeds()
.stdout_only_fixture("gnu_ext_disabled_tex_auto_ref.expected");
} }
#[test] #[test]
fn gnu_ext_disabled_ignore_and_only_file() { fn gnu_ext_disabled_ignore_and_only_file() {
new_ucmd!().args(&["-G", "-o", "only", "-i", "ignore", "input"]) new_ucmd!()
.succeeds().stdout_only_fixture("gnu_ext_disabled_ignore_and_only_file.expected"); .args(&["-G", "-o", "only", "-i", "ignore", "input"])
.succeeds()
.stdout_only_fixture("gnu_ext_disabled_ignore_and_only_file.expected");
} }

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_default() { fn test_default() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
static GIBBERISH: &'static str = "supercalifragilisticexpialidocious"; static GIBBERISH: &'static str = "supercalifragilisticexpialidocious";
#[test] #[test]

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_current_directory() { fn test_current_directory() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_rm_one_file() { fn test_rm_one_file() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
@ -39,7 +38,8 @@ fn test_rm_interactive() {
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
scene.ucmd() scene
.ucmd()
.arg("-i") .arg("-i")
.arg(file_a) .arg(file_a)
.arg(file_b) .arg(file_b)
@ -49,7 +49,8 @@ fn test_rm_interactive() {
assert!(at.file_exists(file_a)); assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b)); assert!(at.file_exists(file_b));
scene.ucmd() scene
.ucmd()
.arg("-i") .arg("-i")
.arg(file_a) .arg(file_a)
.arg(file_b) .arg(file_b)
@ -119,9 +120,10 @@ fn test_rm_errors() {
// $ rm test_rm_errors_directory // $ rm test_rm_errors_directory
// rm: error: could not remove directory 'test_rm_errors_directory' (did you mean to pass '-r'?) // rm: error: could not remove directory 'test_rm_errors_directory' (did you mean to pass '-r'?)
ucmd.arg(dir).fails() ucmd.arg(dir).fails().stderr_is(
.stderr_is("rm: error: could not remove directory 'test_rm_errors_directory' (did you mean \ "rm: error: could not remove directory 'test_rm_errors_directory' (did you mean \
to pass '-r'?)\n"); to pass '-r'?)\n",
);
} }
#[test] #[test]
@ -133,7 +135,10 @@ fn test_rm_verbose() {
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
ucmd.arg("-v").arg(file_a).arg(file_b).succeeds() ucmd.arg("-v")
.arg(file_a)
.arg(file_b)
.succeeds()
.stdout_only(format!("removed '{}'\nremoved '{}'\n", file_a, file_b)); .stdout_only(format!("removed '{}'\nremoved '{}'\n", file_a, file_b));
} }

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_rmdir_empty_directory_no_parents() { fn test_rmdir_empty_directory_no_parents() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
@ -39,9 +38,10 @@ fn test_rmdir_nonempty_directory_no_parents() {
at.touch(file); at.touch(file);
assert!(at.file_exists(file)); assert!(at.file_exists(file));
ucmd.arg(dir).fails() ucmd.arg(dir).fails().stderr_is(
.stderr_is("rmdir: error: failed to remove 'test_rmdir_nonempty_no_parents': Directory not \ "rmdir: error: failed to remove 'test_rmdir_nonempty_no_parents': Directory not \
empty\n"); empty\n",
);
assert!(at.dir_exists(dir)); assert!(at.dir_exists(dir));
} }
@ -58,12 +58,12 @@ fn test_rmdir_nonempty_directory_with_parents() {
at.touch(file); at.touch(file);
assert!(at.file_exists(file)); assert!(at.file_exists(file));
ucmd.arg("-p").arg(dir).fails() ucmd.arg("-p").arg(dir).fails().stderr_is(
.stderr_is( "rmdir: error: failed to remove 'test_rmdir_nonempty/with/parents': Directory not \
"rmdir: error: failed to remove 'test_rmdir_nonempty/with/parents': Directory not \
empty\nrmdir: error: failed to remove 'test_rmdir_nonempty/with': Directory not \ empty\nrmdir: error: failed to remove 'test_rmdir_nonempty/with': Directory not \
empty\nrmdir: error: failed to remove 'test_rmdir_nonempty': Directory not \ empty\nrmdir: error: failed to remove 'test_rmdir_nonempty': Directory not \
empty\n"); empty\n",
);
assert!(at.dir_exists(dir)); assert!(at.dir_exists(dir));
} }
@ -80,7 +80,10 @@ fn test_rmdir_ignore_nonempty_directory_no_parents() {
at.touch(file); at.touch(file);
assert!(at.file_exists(file)); assert!(at.file_exists(file));
ucmd.arg("--ignore-fail-on-non-empty").arg(dir).succeeds().no_stderr(); ucmd.arg("--ignore-fail-on-non-empty")
.arg(dir)
.succeeds()
.no_stderr();
assert!(at.dir_exists(dir)); assert!(at.dir_exists(dir));
} }
@ -97,7 +100,11 @@ fn test_rmdir_ignore_nonempty_directory_with_parents() {
at.touch(file); at.touch(file);
assert!(at.file_exists(file)); assert!(at.file_exists(file));
ucmd.arg("--ignore-fail-on-non-empty").arg("-p").arg(dir).succeeds().no_stderr(); ucmd.arg("--ignore-fail-on-non-empty")
.arg("-p")
.arg(dir)
.succeeds()
.no_stderr();
assert!(at.dir_exists(dir)); assert!(at.dir_exists(dir));
} }

View file

@ -1,26 +1,33 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_count_up() { fn test_count_up() {
new_ucmd!() new_ucmd!()
.args(&["10"]).run().stdout_is("1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"); .args(&["10"])
.run()
.stdout_is("1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n");
} }
#[test] #[test]
fn test_count_down() { fn test_count_down() {
new_ucmd!() new_ucmd!()
.args(&["--", "5", "-1", "1"]).run().stdout_is("5\n4\n3\n2\n1\n"); .args(&["--", "5", "-1", "1"])
.run()
.stdout_is("5\n4\n3\n2\n1\n");
} }
#[test] #[test]
fn test_separator_and_terminator() { fn test_separator_and_terminator() {
new_ucmd!() new_ucmd!()
.args(&["-s", ",", "-t", "!", "2", "6"]).run().stdout_is("2,3,4,5,6!"); .args(&["-s", ",", "-t", "!", "2", "6"])
.run()
.stdout_is("2,3,4,5,6!");
} }
#[test] #[test]
fn test_equalize_widths() { fn test_equalize_widths() {
new_ucmd!() new_ucmd!()
.args(&["-w", "5", "10"]).run().stdout_is("05\n06\n07\n08\n09\n10\n"); .args(&["-w", "5", "10"])
.run()
.stdout_is("05\n06\n07\n08\n09\n10\n");
} }

View file

@ -1,7 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_numeric_floats_and_ints() { fn test_numeric_floats_and_ints() {
test_helper("numeric_floats_and_ints", "-n"); test_helper("numeric_floats_and_ints", "-n");
@ -73,7 +71,8 @@ fn test_multiple_files() {
.arg("-n") .arg("-n")
.arg("multiple_files1.txt") .arg("multiple_files1.txt")
.arg("multiple_files2.txt") .arg("multiple_files2.txt")
.succeeds().stdout_only_fixture("multiple_files.expected"); .succeeds()
.stdout_only_fixture("multiple_files.expected");
} }
#[test] #[test]
@ -83,7 +82,8 @@ fn test_merge_interleaved() {
.arg("merge_ints_interleaved_1.txt") .arg("merge_ints_interleaved_1.txt")
.arg("merge_ints_interleaved_2.txt") .arg("merge_ints_interleaved_2.txt")
.arg("merge_ints_interleaved_3.txt") .arg("merge_ints_interleaved_3.txt")
.succeeds().stdout_only_fixture("merge_ints_interleaved.expected"); .succeeds()
.stdout_only_fixture("merge_ints_interleaved.expected");
} }
#[test] #[test]
@ -97,7 +97,8 @@ fn test_merge_unique() {
.arg("merge_ints_interleaved_3.txt") .arg("merge_ints_interleaved_3.txt")
.arg("merge_ints_interleaved_2.txt") .arg("merge_ints_interleaved_2.txt")
.arg("merge_ints_interleaved_1.txt") .arg("merge_ints_interleaved_1.txt")
.succeeds().stdout_only_fixture("merge_ints_interleaved.expected"); .succeeds()
.stdout_only_fixture("merge_ints_interleaved.expected");
} }
#[test] #[test]
@ -108,7 +109,8 @@ fn test_merge_reversed() {
.arg("merge_ints_reversed_1.txt") .arg("merge_ints_reversed_1.txt")
.arg("merge_ints_reversed_2.txt") .arg("merge_ints_reversed_2.txt")
.arg("merge_ints_reversed_3.txt") .arg("merge_ints_reversed_3.txt")
.succeeds().stdout_only_fixture("merge_ints_reversed.expected"); .succeeds()
.stdout_only_fixture("merge_ints_reversed.expected");
} }
#[test] #[test]
@ -116,15 +118,20 @@ fn test_check() {
new_ucmd!() new_ucmd!()
.arg("-c") .arg("-c")
.arg("check_fail.txt") .arg("check_fail.txt")
.fails().stdout_is("sort: disorder in line 4\n"); .fails()
.stdout_is("sort: disorder in line 4\n");
new_ucmd!() new_ucmd!()
.arg("-c") .arg("-c")
.arg("multiple_files.expected") .arg("multiple_files.expected")
.succeeds().stdout_is(""); .succeeds()
.stdout_is("");
} }
fn test_helper(file_name: &str, args: &str) { fn test_helper(file_name: &str, args: &str) {
new_ucmd!().arg(args).arg(format!("{}{}", file_name, ".txt")) new_ucmd!()
.succeeds().stdout_is_fixture(format!("{}{}", file_name, ".expected")); .arg(args)
.arg(format!("{}{}", file_name, ".txt"))
.succeeds()
.stdout_is_fixture(format!("{}{}", file_name, ".expected"));
} }

View file

@ -1,16 +1,18 @@
extern crate rand; extern crate rand;
extern crate regex; extern crate regex;
use std::fs::{File, read_dir}; use self::rand::{thread_rng, Rng};
use std::io::Write;
use std::path::Path;
use self::rand::{Rng, thread_rng};
use self::regex::Regex; use self::regex::Regex;
use common::util::*; use common::util::*;
use std::fs::{read_dir, File};
use std::io::Write;
use std::path::Path;
fn random_chars(n: usize) -> String { fn random_chars(n: usize) -> String {
thread_rng().sample_iter(&rand::distributions::Alphanumeric).take(n).collect::<String>() thread_rng()
.sample_iter(&rand::distributions::Alphanumeric)
.take(n)
.collect::<String>()
} }
struct Glob { struct Glob {
@ -35,7 +37,9 @@ impl Glob {
.unwrap() .unwrap()
.filter_map(|entry| { .filter_map(|entry| {
let path = entry.unwrap().path(); let path = entry.unwrap().path();
let name = self.directory.minus_as_string(path.as_path().to_str().unwrap_or("")); let name = self
.directory
.minus_as_string(path.as_path().to_str().unwrap_or(""));
if self.regex.is_match(&name) { if self.regex.is_match(&name) {
Some(name) Some(name)
} else { } else {
@ -62,15 +66,13 @@ struct RandomFile {
impl RandomFile { impl RandomFile {
fn new(at: &AtPath, name: &str) -> RandomFile { fn new(at: &AtPath, name: &str) -> RandomFile {
RandomFile { inner: File::create(&at.plus(name)).unwrap() } RandomFile {
inner: File::create(&at.plus(name)).unwrap(),
}
} }
fn add_bytes(&mut self, bytes: usize) { fn add_bytes(&mut self, bytes: usize) {
let chunk_size: usize = if bytes >= 1024 { let chunk_size: usize = if bytes >= 1024 { 1024 } else { bytes };
1024
} else {
bytes
};
let mut n = bytes; let mut n = bytes;
while n > chunk_size { while n > chunk_size {
let _ = write!(self.inner, "{}", random_chars(chunk_size)); let _ = write!(self.inner, "{}", random_chars(chunk_size));

View file

@ -5,7 +5,6 @@ use common::util::*;
extern crate uu_stat; extern crate uu_stat;
pub use self::uu_stat::*; pub use self::uu_stat::*;
#[cfg(test)] #[cfg(test)]
mod test_fsext { mod test_fsext {
use super::*; use super::*;
@ -18,20 +17,32 @@ mod test_fsext {
assert_eq!("lrw-r-xr-x", pretty_access(S_IFLNK | 0o655)); assert_eq!("lrw-r-xr-x", pretty_access(S_IFLNK | 0o655));
assert_eq!("?rw-r-xr-x", pretty_access(0o655)); assert_eq!("?rw-r-xr-x", pretty_access(0o655));
assert_eq!("brwSr-xr-x", assert_eq!(
pretty_access(S_IFBLK | S_ISUID as mode_t | 0o655)); "brwSr-xr-x",
assert_eq!("brwsr-xr-x", pretty_access(S_IFBLK | S_ISUID as mode_t | 0o655)
pretty_access(S_IFBLK | S_ISUID as mode_t | 0o755)); );
assert_eq!(
"brwsr-xr-x",
pretty_access(S_IFBLK | S_ISUID as mode_t | 0o755)
);
assert_eq!("prw---sr--", assert_eq!(
pretty_access(S_IFIFO | S_ISGID as mode_t | 0o614)); "prw---sr--",
assert_eq!("prw---Sr--", pretty_access(S_IFIFO | S_ISGID as mode_t | 0o614)
pretty_access(S_IFIFO | S_ISGID as mode_t | 0o604)); );
assert_eq!(
"prw---Sr--",
pretty_access(S_IFIFO | S_ISGID as mode_t | 0o604)
);
assert_eq!("c---r-xr-t", assert_eq!(
pretty_access(S_IFCHR | S_ISVTX as mode_t | 0o055)); "c---r-xr-t",
assert_eq!("c---r-xr-T", pretty_access(S_IFCHR | S_ISVTX as mode_t | 0o055)
pretty_access(S_IFCHR | S_ISVTX as mode_t | 0o054)); );
assert_eq!(
"c---r-xr-T",
pretty_access(S_IFCHR | S_ISVTX as mode_t | 0o054)
);
} }
#[test] #[test]
@ -90,65 +101,70 @@ mod test_generate_tokens {
#[test] #[test]
fn normal_format() { fn normal_format() {
let s = "%'010.2ac%-#5.w\n"; let s = "%'010.2ac%-#5.w\n";
let expected = vec![Token::Directive { let expected = vec![
flag: F_GROUP | F_ZERO, Token::Directive {
width: 10, flag: F_GROUP | F_ZERO,
precision: 2, width: 10,
format: 'a', precision: 2,
}, format: 'a',
Token::Char('c'), },
Token::Directive { Token::Char('c'),
flag: F_LEFT | F_ALTER, Token::Directive {
width: 5, flag: F_LEFT | F_ALTER,
precision: 0, width: 5,
format: 'w', precision: 0,
}, format: 'w',
Token::Char('\n')]; },
Token::Char('\n'),
];
assert_eq!(&expected, &Stater::generate_tokens(s, false).unwrap()); assert_eq!(&expected, &Stater::generate_tokens(s, false).unwrap());
} }
#[test] #[test]
fn printf_format() { fn printf_format() {
let s = "%-# 15a\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.-23w\\x12\\167\\132\\112\\n"; let s = "%-# 15a\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.-23w\\x12\\167\\132\\112\\n";
let expected = vec![Token::Directive { let expected = vec![
flag: F_LEFT | F_ALTER | F_SPACE, Token::Directive {
width: 15, flag: F_LEFT | F_ALTER | F_SPACE,
precision: -1, width: 15,
format: 'a', precision: -1,
}, format: 'a',
Token::Char('\r'), },
Token::Char('"'), Token::Char('\r'),
Token::Char('\\'), Token::Char('"'),
Token::Char('\x07'), Token::Char('\\'),
Token::Char('\x08'), Token::Char('\x07'),
Token::Char('\x1B'), Token::Char('\x08'),
Token::Char('\x0C'), Token::Char('\x1B'),
Token::Char('\x0B'), Token::Char('\x0C'),
Token::Directive { Token::Char('\x0B'),
flag: F_SIGN | F_ZERO, Token::Directive {
width: 20, flag: F_SIGN | F_ZERO,
precision: -1, width: 20,
format: 'w', precision: -1,
}, format: 'w',
Token::Char('\x12'), },
Token::Char('w'), Token::Char('\x12'),
Token::Char('Z'), Token::Char('w'),
Token::Char('J'), Token::Char('Z'),
Token::Char('\n')]; Token::Char('J'),
Token::Char('\n'),
];
assert_eq!(&expected, &Stater::generate_tokens(s, true).unwrap()); assert_eq!(&expected, &Stater::generate_tokens(s, true).unwrap());
} }
} }
#[test] #[test]
fn test_invalid_option() { fn test_invalid_option() {
new_ucmd!() new_ucmd!().arg("-w").arg("-q").arg("/").fails();
.arg("-w").arg("-q").arg("/").fails();
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
const NORMAL_FMTSTR: &'static str = "%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s %u %U %x %X %y %Y %z %Z"; // avoid "%w %W" (birth/creation) due to `stat` limitations and linux kernel & rust version capability variations const NORMAL_FMTSTR: &'static str =
"%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s %u %U %x %X %y %Y %z %Z"; // avoid "%w %W" (birth/creation) due to `stat` limitations and linux kernel & rust version capability variations
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
const DEV_FMTSTR: &'static str = "%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s (%t/%T) %u %U %w %W %x %X %y %Y %z %Z"; const DEV_FMTSTR: &'static str =
"%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s (%t/%T) %u %U %w %W %x %X %y %Y %z %Z";
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
const FS_FMTSTR: &'static str = "%b %c %i %l %n %s %S %t %T"; // avoid "%a %d %f" which can cause test failure due to race conditions const FS_FMTSTR: &'static str = "%b %c %i %l %n %s %S %t %T"; // avoid "%a %d %f" which can cause test failure due to race conditions
@ -156,7 +172,8 @@ const FS_FMTSTR: &'static str = "%b %c %i %l %n %s %S %t %T"; // avoid "%a %d %f
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_terse_fs_format() { fn test_terse_fs_format() {
let args = ["-f", "-t", "/proc"]; let args = ["-f", "-t", "/proc"];
new_ucmd!().args(&args) new_ucmd!()
.args(&args)
.run() .run()
.stdout_is(expected_result(&args)); .stdout_is(expected_result(&args));
} }
@ -165,7 +182,8 @@ fn test_terse_fs_format() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_fs_format() { fn test_fs_format() {
let args = ["-f", "-c", FS_FMTSTR, "/dev/shm"]; let args = ["-f", "-c", FS_FMTSTR, "/dev/shm"];
new_ucmd!().args(&args) new_ucmd!()
.args(&args)
.run() .run()
.stdout_is(expected_result(&args)); .stdout_is(expected_result(&args));
} }
@ -183,7 +201,10 @@ fn test_terse_normal_format() {
let v_actual: Vec<&str> = actual.split(' ').collect(); let v_actual: Vec<&str> = actual.split(' ').collect();
let v_expect: Vec<&str> = expect.split(' ').collect(); let v_expect: Vec<&str> = expect.split(' ').collect();
// * allow for inequality if `stat` (aka, expect) returns "0" (unknown value) // * allow for inequality if `stat` (aka, expect) returns "0" (unknown value)
assert!(v_actual.iter().zip(v_expect.iter()).all(|(a,e)| a == e || *e == "0")); assert!(v_actual
.iter()
.zip(v_expect.iter())
.all(|(a, e)| a == e || *e == "0"));
} }
#[test] #[test]
@ -199,7 +220,10 @@ fn test_format_created_time() {
let v_actual: Vec<&str> = re.split(&actual).collect(); let v_actual: Vec<&str> = re.split(&actual).collect();
let v_expect: Vec<&str> = re.split(&expect).collect(); let v_expect: Vec<&str> = re.split(&expect).collect();
// * allow for inequality if `stat` (aka, expect) returns "-" (unknown value) // * allow for inequality if `stat` (aka, expect) returns "-" (unknown value)
assert!(v_actual.iter().zip(v_expect.iter()).all(|(a,e)| a == e || *e == "-")); assert!(v_actual
.iter()
.zip(v_expect.iter())
.all(|(a, e)| a == e || *e == "-"));
} }
#[test] #[test]
@ -215,14 +239,18 @@ fn test_format_created_seconds() {
let v_actual: Vec<&str> = re.split(&actual).collect(); let v_actual: Vec<&str> = re.split(&actual).collect();
let v_expect: Vec<&str> = re.split(&expect).collect(); let v_expect: Vec<&str> = re.split(&expect).collect();
// * allow for inequality if `stat` (aka, expect) returns "0" (unknown value) // * allow for inequality if `stat` (aka, expect) returns "0" (unknown value)
assert!(v_actual.iter().zip(v_expect.iter()).all(|(a,e)| a == e || *e == "0")); assert!(v_actual
.iter()
.zip(v_expect.iter())
.all(|(a, e)| a == e || *e == "0"));
} }
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_normal_format() { fn test_normal_format() {
let args = ["-c", NORMAL_FMTSTR, "/boot"]; let args = ["-c", NORMAL_FMTSTR, "/boot"];
new_ucmd!().args(&args) new_ucmd!()
.args(&args)
.run() .run()
.stdout_is(expected_result(&args)); .stdout_is(expected_result(&args));
} }
@ -231,7 +259,8 @@ fn test_normal_format() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_follow_symlink() { fn test_follow_symlink() {
let args = ["-L", "-c", DEV_FMTSTR, "/dev/cdrom"]; let args = ["-L", "-c", DEV_FMTSTR, "/dev/cdrom"];
new_ucmd!().args(&args) new_ucmd!()
.args(&args)
.run() .run()
.stdout_is(expected_result(&args)); .stdout_is(expected_result(&args));
} }
@ -240,7 +269,8 @@ fn test_follow_symlink() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_symlink() { fn test_symlink() {
let args = ["-c", DEV_FMTSTR, "/dev/cdrom"]; let args = ["-c", DEV_FMTSTR, "/dev/cdrom"];
new_ucmd!().args(&args) new_ucmd!()
.args(&args)
.run() .run()
.stdout_is(expected_result(&args)); .stdout_is(expected_result(&args));
} }
@ -249,7 +279,8 @@ fn test_symlink() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_char() { fn test_char() {
let args = ["-c", DEV_FMTSTR, "/dev/pts/ptmx"]; let args = ["-c", DEV_FMTSTR, "/dev/pts/ptmx"];
new_ucmd!().args(&args) new_ucmd!()
.args(&args)
.run() .run()
.stdout_is(expected_result(&args)); .stdout_is(expected_result(&args));
} }
@ -257,8 +288,16 @@ fn test_char() {
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_multi_files() { fn test_multi_files() {
let args = ["-c", NORMAL_FMTSTR, "/dev", "/usr/lib", "/etc/fstab", "/var"]; let args = [
new_ucmd!().args(&args) "-c",
NORMAL_FMTSTR,
"/dev",
"/usr/lib",
"/etc/fstab",
"/var",
];
new_ucmd!()
.args(&args)
.run() .run()
.stdout_is(expected_result(&args)); .stdout_is(expected_result(&args));
} }
@ -266,13 +305,22 @@ fn test_multi_files() {
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_printf() { fn test_printf() {
let args = ["--printf=123%-# 15q\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.23m\\x12\\167\\132\\112\\n", "/"]; let args = [
new_ucmd!().args(&args) "--printf=123%-# 15q\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.23m\\x12\\167\\132\\112\\n",
"/",
];
new_ucmd!()
.args(&args)
.run() .run()
.stdout_is(expected_result(&args)); .stdout_is(expected_result(&args));
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn expected_result(args: &[&str]) -> String { fn expected_result(args: &[&str]) -> String {
TestScenario::new(util_name!()).cmd_keepenv(util_name!()).env("LANGUAGE", "C").args(args).run().stdout TestScenario::new(util_name!())
.cmd_keepenv(util_name!())
.env("LANGUAGE", "C")
.args(args)
.run()
.stdout
} }

View file

@ -1,12 +1,13 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_stdbuf_unbuffered_stdout() { fn test_stdbuf_unbuffered_stdout() {
if cfg!(target_os="linux") { if cfg!(target_os = "linux") {
// This is a basic smoke test // This is a basic smoke test
new_ucmd!().args(&["-o0", "head"]) new_ucmd!()
.pipe_in("The quick brown fox jumps over the lazy dog.").run() .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."); .stdout_is("The quick brown fox jumps over the lazy dog.");
} }
} }

View file

@ -1,11 +1,11 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_bsd_single_file() { fn test_bsd_single_file() {
new_ucmd!() new_ucmd!()
.arg("lorem_ipsum.txt") .arg("lorem_ipsum.txt")
.succeeds().stdout_only_fixture("bsd_single_file.expected"); .succeeds()
.stdout_only_fixture("bsd_single_file.expected");
} }
#[test] #[test]
@ -13,21 +13,25 @@ fn test_bsd_multiple_files() {
new_ucmd!() new_ucmd!()
.arg("lorem_ipsum.txt") .arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt") .arg("alice_in_wonderland.txt")
.succeeds().stdout_only_fixture("bsd_multiple_files.expected"); .succeeds()
.stdout_only_fixture("bsd_multiple_files.expected");
} }
#[test] #[test]
fn test_bsd_stdin() { fn test_bsd_stdin() {
new_ucmd!() new_ucmd!()
.pipe_in_fixture("lorem_ipsum.txt") .pipe_in_fixture("lorem_ipsum.txt")
.succeeds().stdout_only_fixture("bsd_stdin.expected"); .succeeds()
.stdout_only_fixture("bsd_stdin.expected");
} }
#[test] #[test]
fn test_sysv_single_file() { fn test_sysv_single_file() {
new_ucmd!() new_ucmd!()
.arg("-s").arg("lorem_ipsum.txt") .arg("-s")
.succeeds().stdout_only_fixture("sysv_single_file.expected"); .arg("lorem_ipsum.txt")
.succeeds()
.stdout_only_fixture("sysv_single_file.expected");
} }
#[test] #[test]
@ -36,7 +40,8 @@ fn test_sysv_multiple_files() {
.arg("-s") .arg("-s")
.arg("lorem_ipsum.txt") .arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt") .arg("alice_in_wonderland.txt")
.succeeds().stdout_only_fixture("sysv_multiple_files.expected"); .succeeds()
.stdout_only_fixture("sysv_multiple_files.expected");
} }
#[test] #[test]
@ -44,5 +49,6 @@ fn test_sysv_stdin() {
new_ucmd!() new_ucmd!()
.arg("-s") .arg("-s")
.pipe_in_fixture("lorem_ipsum.txt") .pipe_in_fixture("lorem_ipsum.txt")
.succeeds().stdout_only_fixture("sysv_stdin.expected"); .succeeds()
.stdout_only_fixture("sysv_stdin.expected");
} }

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_stdin_default() { fn test_stdin_default() {
new_ucmd!() new_ucmd!()
@ -29,18 +28,24 @@ fn test_stdin_non_newline_separator_before() {
#[test] #[test]
fn test_single_default() { fn test_single_default() {
new_ucmd!().arg("prime_per_line.txt") new_ucmd!()
.run().stdout_is_fixture("prime_per_line.expected"); .arg("prime_per_line.txt")
.run()
.stdout_is_fixture("prime_per_line.expected");
} }
#[test] #[test]
fn test_single_non_newline_separator() { fn test_single_non_newline_separator() {
new_ucmd!().args(&["-s", ":", "delimited_primes.txt"]) new_ucmd!()
.run().stdout_is_fixture("delimited_primes.expected"); .args(&["-s", ":", "delimited_primes.txt"])
.run()
.stdout_is_fixture("delimited_primes.expected");
} }
#[test] #[test]
fn test_single_non_newline_separator_before() { fn test_single_non_newline_separator_before() {
new_ucmd!().args(&["-b", "-s", ":", "delimited_primes.txt"]) new_ucmd!()
.run().stdout_is_fixture("delimited_primes_before.expected"); .args(&["-b", "-s", ":", "delimited_primes.txt"])
.run()
.stdout_is_fixture("delimited_primes_before.expected");
} }

View file

@ -1,37 +1,50 @@
extern crate uu_tail; extern crate uu_tail;
use self::uu_tail::parse_size;
use common::util::*; use common::util::*;
use std::char::from_digit; use std::char::from_digit;
use self::uu_tail::parse_size;
use std::io::Write; use std::io::Write;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; use std::time::Duration;
static FOOBAR_TXT: &'static str = "foobar.txt"; static FOOBAR_TXT: &'static str = "foobar.txt";
static FOOBAR_2_TXT: &'static str = "foobar2.txt"; static FOOBAR_2_TXT: &'static str = "foobar2.txt";
static FOOBAR_WITH_NULL_TXT: &'static str = "foobar_with_null.txt"; static FOOBAR_WITH_NULL_TXT: &'static str = "foobar_with_null.txt";
#[test] #[test]
fn test_stdin_default() { 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] #[test]
fn test_single_default() { 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] #[test]
fn test_n_greater_than_number_of_lines() { 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); .stdout_is_fixture(FOOBAR_TXT);
} }
#[test] #[test]
fn test_null_default() { 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] #[test]
@ -55,7 +68,11 @@ fn test_follow() {
#[test] #[test]
fn test_follow_multiple() { 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 mut child = ucmd
.arg("-f")
.arg(FOOBAR_TXT)
.arg(FOOBAR_2_TXT)
.run_no_wait();
let expected = at.read("foobar_follow_multiple.expected"); let expected = at.read("foobar_follow_multiple.expected");
assert_eq!(read_size(&mut child, expected.len()), expected); assert_eq!(read_size(&mut child, expected.len()), expected);
@ -74,7 +91,11 @@ fn test_follow_multiple() {
#[test] #[test]
fn test_follow_stdin() { 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] #[test]
@ -86,10 +107,18 @@ fn test_follow_with_pid() {
#[cfg(windows)] #[cfg(windows)]
let dummy_cmd = "cmd"; let dummy_cmd = "cmd";
let mut dummy = Command::new(dummy_cmd).stdout(Stdio::null()).spawn().unwrap(); let mut dummy = Command::new(dummy_cmd)
.stdout(Stdio::null())
.spawn()
.unwrap();
let pid = dummy.id(); let pid = dummy.id();
let mut child = ucmd.arg("-f").arg(format!("--pid={}", pid)).arg(FOOBAR_TXT).arg(FOOBAR_2_TXT).run_no_wait(); let mut child = ucmd
.arg("-f")
.arg(format!("--pid={}", pid))
.arg(FOOBAR_TXT)
.arg(FOOBAR_2_TXT)
.run_no_wait();
let expected = at.read("foobar_follow_multiple.expected"); let expected = at.read("foobar_follow_multiple.expected");
assert_eq!(read_size(&mut child, expected.len()), expected); assert_eq!(read_size(&mut child, expected.len()), expected);
@ -140,19 +169,31 @@ fn test_single_big_args() {
} }
big_expected.flush().expect("Could not flush EXPECTED_FILE"); big_expected.flush().expect("Could not flush EXPECTED_FILE");
ucmd.arg(FILE).arg("-n").arg(format!("{}", N_ARG)).run().stdout_is(at.read(EXPECTED_FILE)); ucmd.arg(FILE)
.arg("-n")
.arg(format!("{}", N_ARG))
.run()
.stdout_is(at.read(EXPECTED_FILE));
} }
#[test] #[test]
fn test_bytes_single() { 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"); .stdout_is_fixture("foobar_bytes_single.expected");
} }
#[test] #[test]
fn test_bytes_stdin() { fn test_bytes_stdin() {
new_ucmd!().arg("-c").arg("13").pipe_in_fixture(FOOBAR_TXT).run() new_ucmd!()
.stdout_is_fixture("foobar_bytes_stdin.expected"); .arg("-c")
.arg("13")
.pipe_in_fixture(FOOBAR_TXT)
.run()
.stdout_is_fixture("foobar_bytes_stdin.expected");
} }
#[test] #[test]
@ -178,7 +219,12 @@ fn test_bytes_big() {
} }
big_expected.flush().expect("Could not flush EXPECTED_FILE"); big_expected.flush().expect("Could not flush EXPECTED_FILE");
let result = ucmd.arg(FILE).arg("-c").arg(format!("{}", N_ARG)).run().stdout; let result = ucmd
.arg(FILE)
.arg("-c")
.arg(format!("{}", N_ARG))
.run()
.stdout;
let expected = at.read(EXPECTED_FILE); let expected = at.read(EXPECTED_FILE);
assert_eq!(result.len(), expected.len()); assert_eq!(result.len(), expected.len());
@ -243,21 +289,40 @@ fn test_lines_with_size_suffix() {
} }
big_expected.flush().expect("Could not flush EXPECTED_FILE"); big_expected.flush().expect("Could not flush EXPECTED_FILE");
ucmd.arg(FILE).arg("-n").arg("2K").run().stdout_is_fixture(EXPECTED_FILE); ucmd.arg(FILE)
.arg("-n")
.arg("2K")
.run()
.stdout_is_fixture(EXPECTED_FILE);
} }
#[test] #[test]
fn test_multiple_input_files() { fn test_multiple_input_files() {
new_ucmd!().arg(FOOBAR_TXT).arg(FOOBAR_2_TXT).run().stdout_is_fixture("foobar_follow_multiple.expected"); new_ucmd!()
.arg(FOOBAR_TXT)
.arg(FOOBAR_2_TXT)
.run()
.stdout_is_fixture("foobar_follow_multiple.expected");
} }
#[test] #[test]
fn test_multiple_input_files_with_suppressed_headers() { fn test_multiple_input_files_with_suppressed_headers() {
new_ucmd!().arg(FOOBAR_TXT).arg(FOOBAR_2_TXT).arg("-q").run().stdout_is_fixture("foobar_multiple_quiet.expected"); new_ucmd!()
.arg(FOOBAR_TXT)
.arg(FOOBAR_2_TXT)
.arg("-q")
.run()
.stdout_is_fixture("foobar_multiple_quiet.expected");
} }
#[test] #[test]
fn test_multiple_input_quiet_flag_overrides_verbose_flag_for_suppressing_headers() { fn test_multiple_input_quiet_flag_overrides_verbose_flag_for_suppressing_headers() {
// TODO: actually the later one should win, i.e. -qv should lead to headers being printed, -vq to them being suppressed // TODO: actually the later one should win, i.e. -qv should lead to headers being printed, -vq to them being suppressed
new_ucmd!().arg(FOOBAR_TXT).arg(FOOBAR_2_TXT).arg("-q").arg("-v").run().stdout_is_fixture("foobar_multiple_quiet.expected"); new_ucmd!()
.arg(FOOBAR_TXT)
.arg(FOOBAR_2_TXT)
.arg("-q")
.arg("-v")
.run()
.stdout_is_fixture("foobar_multiple_quiet.expected");
} }

View file

@ -9,12 +9,9 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_op_prec_and_or_1() { fn test_op_prec_and_or_1() {
new_ucmd!() new_ucmd!().args(&[" ", "-o", "", "-a", ""]).succeeds();
.args(&[" ", "-o", "", "-a", ""])
.succeeds();
} }
#[test] #[test]
@ -26,7 +23,5 @@ fn test_op_prec_and_or_2() {
#[test] #[test]
fn test_or_as_filename() { fn test_or_as_filename() {
new_ucmd!() new_ucmd!().args(&["x", "-a", "-z", "-o"]).fails();
.args(&["x", "-a", "-z", "-o"])
.fails();
} }

View file

@ -7,14 +7,18 @@ use common::util::*;
fn get_file_times(at: &AtPath, path: &str) -> (FileTime, FileTime) { fn get_file_times(at: &AtPath, path: &str) -> (FileTime, FileTime) {
let m = at.metadata(path); let m = at.metadata(path);
(FileTime::from_last_access_time(&m), (
FileTime::from_last_modification_time(&m)) FileTime::from_last_access_time(&m),
FileTime::from_last_modification_time(&m),
)
} }
fn get_symlink_times(at: &AtPath, path: &str) -> (FileTime, FileTime) { fn get_symlink_times(at: &AtPath, path: &str) -> (FileTime, FileTime) {
let m = at.symlink_metadata(path); let m = at.symlink_metadata(path);
(FileTime::from_last_access_time(&m), (
FileTime::from_last_modification_time(&m)) FileTime::from_last_access_time(&m),
FileTime::from_last_modification_time(&m),
)
} }
fn set_file_times(at: &AtPath, path: &str, atime: FileTime, mtime: FileTime) { fn set_file_times(at: &AtPath, path: &str, atime: FileTime, mtime: FileTime) {
@ -36,7 +40,6 @@ fn test_touch_default() {
ucmd.arg(file).succeeds().no_stderr(); ucmd.arg(file).succeeds().no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
} }
@ -72,13 +75,14 @@ fn test_touch_set_mdhm_time() {
assert!(at.file_exists(file)); assert!(at.file_exists(file));
let start_of_year = str_to_filetime("%Y%m%d%H%M", &format!("{}01010000", 1900+time::now().tm_year)); let start_of_year = str_to_filetime(
"%Y%m%d%H%M",
&format!("{}01010000", 1900 + time::now().tm_year),
);
let (atime, mtime) = get_file_times(&at, file); let (atime, mtime) = get_file_times(&at, file);
assert_eq!(atime, mtime); assert_eq!(atime, mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45240);
45240); assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45240);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45240);
} }
#[test] #[test]
@ -86,17 +90,20 @@ 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"; let file = "test_touch_set_mdhms_time";
ucmd.args(&["-t", "01011234.56", file]).succeeds().no_stderr(); ucmd.args(&["-t", "01011234.56", file])
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
let start_of_year = str_to_filetime("%Y%m%d%H%M.%S", &format!("{}01010000.00", 1900+time::now().tm_year)); let start_of_year = str_to_filetime(
"%Y%m%d%H%M.%S",
&format!("{}01010000.00", 1900 + time::now().tm_year),
);
let (atime, mtime) = get_file_times(&at, file); let (atime, mtime) = get_file_times(&at, file);
assert_eq!(atime, mtime); assert_eq!(atime, mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45296);
45296); assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45296);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45296);
} }
#[test] #[test]
@ -104,17 +111,17 @@ 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"; let file = "test_touch_set_ymdhm_time";
ucmd.args(&["-t", "1501011234", file]).succeeds().no_stderr(); ucmd.args(&["-t", "1501011234", file])
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
let start_of_year = str_to_filetime("%y%m%d%H%M", "1501010000"); let start_of_year = str_to_filetime("%y%m%d%H%M", "1501010000");
let (atime, mtime) = get_file_times(&at, file); let (atime, mtime) = get_file_times(&at, file);
assert_eq!(atime, mtime); assert_eq!(atime, mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45240);
45240); assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45240);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45240);
} }
#[test] #[test]
@ -122,17 +129,17 @@ 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"; let file = "test_touch_set_ymdhms_time";
ucmd.args(&["-t", "1501011234.56", file]).succeeds().no_stderr(); ucmd.args(&["-t", "1501011234.56", file])
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
let start_of_year = str_to_filetime("%y%m%d%H%M.%S", "1501010000.00"); let start_of_year = str_to_filetime("%y%m%d%H%M.%S", "1501010000.00");
let (atime, mtime) = get_file_times(&at, file); let (atime, mtime) = get_file_times(&at, file);
assert_eq!(atime, mtime); assert_eq!(atime, mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45296);
45296); assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45296);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45296);
} }
#[test] #[test]
@ -140,17 +147,17 @@ 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"; let file = "test_touch_set_cymdhm_time";
ucmd.args(&["-t", "201501011234", file]).succeeds().no_stderr(); ucmd.args(&["-t", "201501011234", file])
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000"); let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000");
let (atime, mtime) = get_file_times(&at, file); let (atime, mtime) = get_file_times(&at, file);
assert_eq!(atime, mtime); assert_eq!(atime, mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45240);
45240); assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45240);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45240);
} }
#[test] #[test]
@ -158,17 +165,17 @@ 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"; let file = "test_touch_set_cymdhms_time";
ucmd.args(&["-t", "201501011234.56", file]).succeeds().no_stderr(); ucmd.args(&["-t", "201501011234.56", file])
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
let start_of_year = str_to_filetime("%Y%m%d%H%M.%S", "201501010000.00"); let start_of_year = str_to_filetime("%Y%m%d%H%M.%S", "201501010000.00");
let (atime, mtime) = get_file_times(&at, file); let (atime, mtime) = get_file_times(&at, file);
assert_eq!(atime, mtime); assert_eq!(atime, mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45296);
45296); assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45296);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45296);
} }
#[test] #[test]
@ -176,15 +183,16 @@ 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"; let file = "test_touch_set_only_atime";
ucmd.args(&["-t", "201501011234", "-a", file]).succeeds().no_stderr(); ucmd.args(&["-t", "201501011234", "-a", file])
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000"); let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000");
let (atime, mtime) = get_file_times(&at, file); let (atime, mtime) = get_file_times(&at, file);
assert!(atime != mtime); assert!(atime != mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45240);
45240);
} }
#[test] #[test]
@ -192,15 +200,16 @@ 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"; let file = "test_touch_set_only_mtime";
ucmd.args(&["-t", "201501011234", "-m", file]).succeeds().no_stderr(); ucmd.args(&["-t", "201501011234", "-m", file])
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000"); let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000");
let (atime, mtime) = get_file_times(&at, file); let (atime, mtime) = get_file_times(&at, file);
assert!(atime != mtime); assert!(atime != mtime);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45240);
45240);
} }
#[test] #[test]
@ -208,17 +217,17 @@ 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"; let file = "test_touch_set_both";
ucmd.args(&["-t", "201501011234", "-a", "-m", file]).succeeds().no_stderr(); ucmd.args(&["-t", "201501011234", "-a", "-m", file])
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000"); let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000");
let (atime, mtime) = get_file_times(&at, file); let (atime, mtime) = get_file_times(&at, file);
assert_eq!(atime, mtime); assert_eq!(atime, mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45240);
45240); assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45240);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45240);
} }
#[test] #[test]
@ -235,7 +244,9 @@ fn test_touch_no_dereference() {
assert!(at.file_exists(file_a)); assert!(at.file_exists(file_a));
assert!(at.is_symlink(file_b)); assert!(at.is_symlink(file_b));
ucmd.args(&["-t", "201512312359", "-h", file_b]).succeeds().no_stderr(); ucmd.args(&["-t", "201512312359", "-h", file_b])
.succeeds()
.no_stderr();
let (atime, mtime) = get_symlink_times(&at, file_b); let (atime, mtime) = get_symlink_times(&at, file_b);
assert_eq!(atime, mtime); assert_eq!(atime, mtime);
@ -274,7 +285,9 @@ 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"; let file = "test_touch_set_date";
ucmd.args(&["-d", "Thu Jan 01 12:34:00 2015", file]).succeeds().no_stderr(); ucmd.args(&["-d", "Thu Jan 01 12:34:00 2015", file])
.succeeds()
.no_stderr();
assert!(at.file_exists(file)); assert!(at.file_exists(file));

View file

@ -1,83 +1,118 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_toupper() { fn test_toupper() {
new_ucmd!() new_ucmd!()
.args(&["a-z", "A-Z"]).pipe_in("!abcd!").run().stdout_is("!ABCD!"); .args(&["a-z", "A-Z"])
.pipe_in("!abcd!")
.run()
.stdout_is("!ABCD!");
} }
#[test] #[test]
fn test_small_set2() { fn test_small_set2() {
new_ucmd!() new_ucmd!()
.args(&["0-9", "X"]).pipe_in("@0123456789").run().stdout_is("@XXXXXXXXXX"); .args(&["0-9", "X"])
.pipe_in("@0123456789")
.run()
.stdout_is("@XXXXXXXXXX");
} }
#[test] #[test]
fn test_unicode() { fn test_unicode() {
new_ucmd!() new_ucmd!()
.args(&[", ┬─┬", "╯︵┻━┻"]) .args(&[", ┬─┬", "╯︵┻━┻"])
.pipe_in("(,°□°), ┬─┬").run() .pipe_in("(,°□°), ┬─┬")
.run()
.stdout_is("(╯°□°)╯︵┻━┻"); .stdout_is("(╯°□°)╯︵┻━┻");
} }
#[test] #[test]
fn test_delete() { fn test_delete() {
new_ucmd!() new_ucmd!()
.args(&["-d", "a-z"]).pipe_in("aBcD").run().stdout_is("BD"); .args(&["-d", "a-z"])
.pipe_in("aBcD")
.run()
.stdout_is("BD");
} }
#[test] #[test]
fn test_delete_complement() { fn test_delete_complement() {
new_ucmd!() new_ucmd!()
.args(&["-d", "-c", "a-z"]).pipe_in("aBcD").run().stdout_is("ac"); .args(&["-d", "-c", "a-z"])
.pipe_in("aBcD")
.run()
.stdout_is("ac");
} }
#[test] #[test]
fn test_squeeze() { fn test_squeeze() {
new_ucmd!() new_ucmd!()
.args(&["-s", "a-z"]).pipe_in("aaBBcDcc").run().stdout_is("aBBcDc"); .args(&["-s", "a-z"])
.pipe_in("aaBBcDcc")
.run()
.stdout_is("aBBcDc");
} }
#[test] #[test]
fn test_squeeze_complement() { fn test_squeeze_complement() {
new_ucmd!() new_ucmd!()
.args(&["-sc", "a-z"]).pipe_in("aaBBcDcc").run().stdout_is("aaBcDcc"); .args(&["-sc", "a-z"])
.pipe_in("aaBBcDcc")
.run()
.stdout_is("aaBcDcc");
} }
#[test] #[test]
fn test_delete_and_squeeze() { fn test_delete_and_squeeze() {
new_ucmd!() new_ucmd!()
.args(&["-ds", "a-z", "A-Z"]).pipe_in("abBcB").run().stdout_is("B"); .args(&["-ds", "a-z", "A-Z"])
.pipe_in("abBcB")
.run()
.stdout_is("B");
} }
#[test] #[test]
fn test_delete_and_squeeze_complement() { fn test_delete_and_squeeze_complement() {
new_ucmd!() new_ucmd!()
.args(&["-dsc", "a-z", "A-Z"]).pipe_in("abBcB").run().stdout_is("abc"); .args(&["-dsc", "a-z", "A-Z"])
.pipe_in("abBcB")
.run()
.stdout_is("abc");
} }
#[test] #[test]
fn test_set1_longer_than_set2() { fn test_set1_longer_than_set2() {
new_ucmd!() new_ucmd!()
.args(&["abc", "xy"]).pipe_in("abcde").run().stdout_is("xyyde"); .args(&["abc", "xy"])
.pipe_in("abcde")
.run()
.stdout_is("xyyde");
} }
#[test] #[test]
fn test_set1_shorter_than_set2() { fn test_set1_shorter_than_set2() {
new_ucmd!() new_ucmd!()
.args(&["ab", "xyz"]).pipe_in("abcde").run().stdout_is("xycde"); .args(&["ab", "xyz"])
.pipe_in("abcde")
.run()
.stdout_is("xycde");
} }
#[test] #[test]
fn test_truncate() { fn test_truncate() {
new_ucmd!() new_ucmd!()
.args(&["-t", "abc", "xy"]).pipe_in("abcde").run().stdout_is("xycde"); .args(&["-t", "abc", "xy"])
.pipe_in("abcde")
.run()
.stdout_is("xycde");
} }
#[test] #[test]
fn test_truncate_with_set1_shorter_than_set2() { fn test_truncate_with_set1_shorter_than_set2() {
new_ucmd!() new_ucmd!()
.args(&["-t", "ab", "xyz"]).pipe_in("abcde").run().stdout_is("xycde"); .args(&["-t", "ab", "xyz"])
.pipe_in("abcde")
.run()
.stdout_is("xycde");
} }

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_exit_code() { fn test_exit_code() {
new_ucmd!().succeeds(); new_ucmd!().succeeds();

View file

@ -1,7 +1,6 @@
use common::util::*; use common::util::*;
use std::io::{Seek, SeekFrom, Write}; use std::io::{Seek, SeekFrom, Write};
static TFILE1: &'static str = "truncate_test_1"; static TFILE1: &'static str = "truncate_test_1";
static TFILE2: &'static str = "truncate_test_2"; static TFILE2: &'static str = "truncate_test_2";

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_sort_call_graph() { fn test_sort_call_graph() {
new_ucmd!() new_ucmd!()
@ -13,5 +12,6 @@ fn test_sort_call_graph() {
fn test_sort_self_loop() { fn test_sort_self_loop() {
new_ucmd!() new_ucmd!()
.pipe_in("first first\nfirst second second second") .pipe_in("first first\nfirst second second second")
.succeeds().stdout_only("first\nsecond\n"); .succeeds()
.stdout_only("first\nsecond\n");
} }

View file

@ -1,68 +1,85 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn unexpand_init_0() { fn unexpand_init_0() {
new_ucmd!() new_ucmd!()
.args(&["-t4"]).pipe_in(" 1\n 2\n 3\n 4\n") .args(&["-t4"])
.run().stdout_is(" 1\n 2\n 3\n\t4\n"); .pipe_in(" 1\n 2\n 3\n 4\n")
.run()
.stdout_is(" 1\n 2\n 3\n\t4\n");
} }
#[test] #[test]
fn unexpand_init_1() { fn unexpand_init_1() {
new_ucmd!() new_ucmd!()
.args(&["-t4"]).pipe_in(" 5\n 6\n 7\n 8\n") .args(&["-t4"])
.run().stdout_is("\t 5\n\t 6\n\t 7\n\t\t8\n"); .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] #[test]
fn unexpand_init_list_0() { fn unexpand_init_list_0() {
new_ucmd!() new_ucmd!()
.args(&["-t2,4"]).pipe_in(" 1\n 2\n 3\n 4\n") .args(&["-t2,4"])
.run().stdout_is(" 1\n\t2\n\t 3\n\t\t4\n"); .pipe_in(" 1\n 2\n 3\n 4\n")
.run()
.stdout_is(" 1\n\t2\n\t 3\n\t\t4\n");
} }
#[test] #[test]
fn unexpand_init_list_1() { fn unexpand_init_list_1() {
// Once the list is exhausted, spaces are not converted anymore // Once the list is exhausted, spaces are not converted anymore
new_ucmd!() new_ucmd!()
.args(&["-t2,4"]).pipe_in(" 5\n 6\n 7\n 8\n") .args(&["-t2,4"])
.run().stdout_is("\t\t 5\n\t\t 6\n\t\t 7\n\t\t 8\n"); .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] #[test]
fn unexpand_aflag_0() { fn unexpand_aflag_0() {
new_ucmd!() new_ucmd!()
.args(&["--"]).pipe_in("e E\nf F\ng G\nh H\n") .args(&["--"])
.run().stdout_is("e E\nf F\ng G\nh H\n"); .pipe_in("e E\nf F\ng G\nh H\n")
.run()
.stdout_is("e E\nf F\ng G\nh H\n");
} }
#[test] #[test]
fn unexpand_aflag_1() { fn unexpand_aflag_1() {
new_ucmd!() new_ucmd!()
.args(&["-a"]).pipe_in("e E\nf F\ng G\nh H\n") .args(&["-a"])
.run().stdout_is("e E\nf F\ng\tG\nh\t H\n"); .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] #[test]
fn unexpand_aflag_2() { fn unexpand_aflag_2() {
new_ucmd!() new_ucmd!()
.args(&["-t8"]).pipe_in("e E\nf F\ng G\nh H\n") .args(&["-t8"])
.run().stdout_is("e E\nf F\ng\tG\nh\t H\n"); .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] #[test]
fn unexpand_first_only_0() { fn unexpand_first_only_0() {
new_ucmd!() new_ucmd!()
.args(&["-t3"]).pipe_in(" A B") .args(&["-t3"])
.run().stdout_is("\t\t A\t B"); .pipe_in(" A B")
.run()
.stdout_is("\t\t A\t B");
} }
#[test] #[test]
fn unexpand_first_only_1() { fn unexpand_first_only_1() {
new_ucmd!() new_ucmd!()
.args(&["-t3", "--first-only"]).pipe_in(" A B") .args(&["-t3", "--first-only"])
.run().stdout_is("\t\t A B"); .pipe_in(" A B")
.run()
.stdout_is("\t\t A B");
} }
#[test] #[test]
@ -71,16 +88,20 @@ fn unexpand_trailing_space_0() {
// Individual spaces before fields starting with non blanks should not be // Individual spaces before fields starting with non blanks should not be
// converted, unless they are at the beginning of the line. // converted, unless they are at the beginning of the line.
new_ucmd!() new_ucmd!()
.args(&["-t4"]).pipe_in("123 \t1\n123 1\n123 \n123 ") .args(&["-t4"])
.run().stdout_is("123\t\t1\n123 1\n123 \n123 "); .pipe_in("123 \t1\n123 1\n123 \n123 ")
.run()
.stdout_is("123\t\t1\n123 1\n123 \n123 ");
} }
#[test] #[test]
fn unexpand_trailing_space_1() { fn unexpand_trailing_space_1() {
// super evil // super evil
new_ucmd!() new_ucmd!()
.args(&["-t1"]).pipe_in(" abc d e f g ") .args(&["-t1"])
.run().stdout_is("\tabc d e\t\tf\t\tg "); .pipe_in(" abc d e f g ")
.run()
.stdout_is("\tabc d e\t\tf\t\tg ");
} }
#[test] #[test]
@ -88,7 +109,8 @@ fn unexpand_spaces_follow_tabs_0() {
// The two first spaces can be included into the first tab. // The two first spaces can be included into the first tab.
new_ucmd!() new_ucmd!()
.pipe_in(" \t\t A") .pipe_in(" \t\t A")
.run().stdout_is("\t\t A"); .run()
.stdout_is("\t\t A");
} }
#[test] #[test]
@ -100,13 +122,17 @@ fn unexpand_spaces_follow_tabs_1() {
// ' ' -> '\t' // third tabstop (5) // ' ' -> '\t' // third tabstop (5)
// ' B \t' -> ' B \t' // after the list is exhausted, nothing must change // ' B \t' -> ' B \t' // after the list is exhausted, nothing must change
new_ucmd!() new_ucmd!()
.args(&["-t1,4,5"]).pipe_in("a \t B \t") .args(&["-t1,4,5"])
.run().stdout_is("a\t\t B \t"); .pipe_in("a \t B \t")
.run()
.stdout_is("a\t\t B \t");
} }
#[test] #[test]
fn unexpand_spaces_after_fields() { fn unexpand_spaces_after_fields() {
new_ucmd!() new_ucmd!()
.args(&["-a"]).pipe_in(" \t A B C D A\t\n") .args(&["-a"])
.run().stdout_is("\t\tA B C D\t\t A\t\n"); .pipe_in(" \t A B C D A\t\n")
.run()
.stdout_is("\t\tA B C D\t\t A\t\n");
} }

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
static INPUT: &'static str = "sorted.txt"; static INPUT: &'static str = "sorted.txt";
static SKIP_CHARS: &'static str = "skip-chars.txt"; static SKIP_CHARS: &'static str = "skip-chars.txt";
static SKIP_FIELDS: &'static str = "skip-fields.txt"; static SKIP_FIELDS: &'static str = "skip-fields.txt";
@ -10,96 +9,122 @@ static SORTED_ZERO_TERMINATED: &'static str = "sorted-zero-terminated.txt";
fn test_stdin_default() { fn test_stdin_default() {
new_ucmd!() new_ucmd!()
.pipe_in_fixture(INPUT) .pipe_in_fixture(INPUT)
.run().stdout_is_fixture("sorted-simple.expected"); .run()
.stdout_is_fixture("sorted-simple.expected");
} }
#[test] #[test]
fn test_single_default() { fn test_single_default() {
new_ucmd!() new_ucmd!()
.arg(INPUT) .arg(INPUT)
.run().stdout_is_fixture("sorted-simple.expected"); .run()
.stdout_is_fixture("sorted-simple.expected");
} }
#[test] #[test]
fn test_stdin_counts() { fn test_stdin_counts() {
new_ucmd!() new_ucmd!()
.args(&["-c"]).pipe_in_fixture(INPUT) .args(&["-c"])
.run().stdout_is_fixture("sorted-counts.expected"); .pipe_in_fixture(INPUT)
.run()
.stdout_is_fixture("sorted-counts.expected");
} }
#[test] #[test]
fn test_stdin_skip_1_char() { fn test_stdin_skip_1_char() {
new_ucmd!() new_ucmd!()
.args(&["-s1"]).pipe_in_fixture(SKIP_CHARS) .args(&["-s1"])
.run().stdout_is_fixture("skip-1-char.expected"); .pipe_in_fixture(SKIP_CHARS)
.run()
.stdout_is_fixture("skip-1-char.expected");
} }
#[test] #[test]
fn test_stdin_skip_5_chars() { fn test_stdin_skip_5_chars() {
new_ucmd!() new_ucmd!()
.args(&["-s5"]).pipe_in_fixture(SKIP_CHARS) .args(&["-s5"])
.run().stdout_is_fixture("skip-5-chars.expected"); .pipe_in_fixture(SKIP_CHARS)
.run()
.stdout_is_fixture("skip-5-chars.expected");
} }
#[test] #[test]
fn test_stdin_skip_and_check_2_chars() { fn test_stdin_skip_and_check_2_chars() {
new_ucmd!() new_ucmd!()
.args(&["-s3", "-w2"]).pipe_in_fixture(SKIP_CHARS) .args(&["-s3", "-w2"])
.run().stdout_is_fixture("skip-3-check-2-chars.expected"); .pipe_in_fixture(SKIP_CHARS)
.run()
.stdout_is_fixture("skip-3-check-2-chars.expected");
} }
#[test] #[test]
fn test_stdin_skip_1_field() { fn test_stdin_skip_1_field() {
new_ucmd!() new_ucmd!()
.args(&["-f2"]).pipe_in_fixture(SKIP_FIELDS) .args(&["-f2"])
.run().stdout_is_fixture("skip-2-fields.expected"); .pipe_in_fixture(SKIP_FIELDS)
.run()
.stdout_is_fixture("skip-2-fields.expected");
} }
#[test] #[test]
fn test_stdin_all_repeated() { fn test_stdin_all_repeated() {
new_ucmd!() new_ucmd!()
.args(&["--all-repeated"]).pipe_in_fixture(INPUT) .args(&["--all-repeated"])
.run().stdout_is_fixture("sorted-all-repeated.expected"); .pipe_in_fixture(INPUT)
.run()
.stdout_is_fixture("sorted-all-repeated.expected");
} }
#[test] #[test]
fn test_stdin_all_repeated_separate() { fn test_stdin_all_repeated_separate() {
new_ucmd!() new_ucmd!()
.args(&["--all-repeated=separate"]).pipe_in_fixture(INPUT) .args(&["--all-repeated=separate"])
.run().stdout_is_fixture("sorted-all-repeated-separate.expected"); .pipe_in_fixture(INPUT)
.run()
.stdout_is_fixture("sorted-all-repeated-separate.expected");
} }
#[test] #[test]
fn test_stdin_all_repeated_prepend() { fn test_stdin_all_repeated_prepend() {
new_ucmd!() new_ucmd!()
.args(&["--all-repeated=prepend"]).pipe_in_fixture(INPUT) .args(&["--all-repeated=prepend"])
.run().stdout_is_fixture("sorted-all-repeated-prepend.expected"); .pipe_in_fixture(INPUT)
.run()
.stdout_is_fixture("sorted-all-repeated-prepend.expected");
} }
#[test] #[test]
fn test_stdin_unique_only() { fn test_stdin_unique_only() {
new_ucmd!() new_ucmd!()
.args(&["-u"]).pipe_in_fixture(INPUT) .args(&["-u"])
.run().stdout_is_fixture("sorted-unique-only.expected"); .pipe_in_fixture(INPUT)
.run()
.stdout_is_fixture("sorted-unique-only.expected");
} }
#[test] #[test]
fn test_stdin_repeated_only() { fn test_stdin_repeated_only() {
new_ucmd!() new_ucmd!()
.args(&["-d"]).pipe_in_fixture(INPUT) .args(&["-d"])
.run().stdout_is_fixture("sorted-repeated-only.expected"); .pipe_in_fixture(INPUT)
.run()
.stdout_is_fixture("sorted-repeated-only.expected");
} }
#[test] #[test]
fn test_stdin_ignore_case() { fn test_stdin_ignore_case() {
new_ucmd!() new_ucmd!()
.args(&["-i"]).pipe_in_fixture(INPUT) .args(&["-i"])
.run().stdout_is_fixture("sorted-ignore-case.expected"); .pipe_in_fixture(INPUT)
.run()
.stdout_is_fixture("sorted-ignore-case.expected");
} }
#[test] #[test]
fn test_stdin_zero_terminated() { fn test_stdin_zero_terminated() {
new_ucmd!() new_ucmd!()
.args(&["-z"]).pipe_in_fixture(SORTED_ZERO_TERMINATED) .args(&["-z"])
.run().stdout_is_fixture("sorted-zero-terminated.expected"); .pipe_in_fixture(SORTED_ZERO_TERMINATED)
.run()
.stdout_is_fixture("sorted-zero-terminated.expected");
} }

View file

@ -1,6 +1,5 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_unlink_file() { fn test_unlink_file() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
@ -22,9 +21,10 @@ fn test_unlink_multiple_files() {
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
ucmd.arg(file_a).arg(file_b).fails() ucmd.arg(file_a).arg(file_b).fails().stderr_is(
.stderr_is("unlink: error: extra operand: 'test_unlink_multiple_file_b'\nTry 'unlink --help' \ "unlink: error: extra operand: 'test_unlink_multiple_file_b'\nTry 'unlink --help' \
for more information.\n"); for more information.\n",
);
} }
#[test] #[test]
@ -34,16 +34,18 @@ fn test_unlink_directory() {
at.mkdir(dir); at.mkdir(dir);
ucmd.arg(dir).fails() ucmd.arg(dir).fails().stderr_is(
.stderr_is("unlink: error: cannot unlink 'test_unlink_empty_directory': Not a regular file \ "unlink: error: cannot unlink 'test_unlink_empty_directory': Not a regular file \
or symlink\n"); or symlink\n",
);
} }
#[test] #[test]
fn test_unlink_nonexistent() { fn test_unlink_nonexistent() {
let file = "test_unlink_nonexistent"; let file = "test_unlink_nonexistent";
new_ucmd!().arg(file).fails() new_ucmd!().arg(file).fails().stderr_is(
.stderr_is("unlink: error: Cannot stat 'test_unlink_nonexistent': No such file or directory \ "unlink: error: Cannot stat 'test_unlink_nonexistent': No such file or directory \
(os error 2)\n"); (os error 2)\n",
);
} }

View file

@ -1,21 +1,26 @@
use common::util::*; use common::util::*;
#[test] #[test]
fn test_stdin_default() { fn test_stdin_default() {
new_ucmd!().pipe_in_fixture("lorem_ipsum.txt") new_ucmd!()
.run().stdout_is(" 13 109 772\n"); .pipe_in_fixture("lorem_ipsum.txt")
.run()
.stdout_is(" 13 109 772\n");
} }
#[test] #[test]
fn test_stdin_only_bytes() { fn test_stdin_only_bytes() {
new_ucmd!().args(&["-c"]).pipe_in_fixture("lorem_ipsum.txt") new_ucmd!()
.run().stdout_is(" 772\n"); .args(&["-c"])
.pipe_in_fixture("lorem_ipsum.txt")
.run()
.stdout_is(" 772\n");
} }
#[test] #[test]
fn test_stdin_all_counts() { 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") .pipe_in_fixture("alice_in_wonderland.txt")
.run() .run()
.stdout_is(" 5 57 302 302 66\n"); .stdout_is(" 5 57 302 302 66\n");
@ -24,27 +29,38 @@ fn test_stdin_all_counts() {
#[test] #[test]
fn test_single_default() { fn test_single_default() {
new_ucmd!() new_ucmd!()
.arg("moby_dick.txt").run().stdout_is(" 18 204 1115 moby_dick.txt\n"); .arg("moby_dick.txt")
.run()
.stdout_is(" 18 204 1115 moby_dick.txt\n");
} }
#[test] #[test]
fn test_single_only_lines() { fn test_single_only_lines() {
new_ucmd!() new_ucmd!()
.args(&["-l", "moby_dick.txt"]).run().stdout_is(" 18 moby_dick.txt\n"); .args(&["-l", "moby_dick.txt"])
.run()
.stdout_is(" 18 moby_dick.txt\n");
} }
#[test] #[test]
fn test_single_all_counts() { fn test_single_all_counts() {
new_ucmd!() new_ucmd!()
.args(&["-c", "-l", "-L", "-m", "-w", "alice_in_wonderland.txt"]).run() .args(&["-c", "-l", "-L", "-m", "-w", "alice_in_wonderland.txt"])
.run()
.stdout_is(" 5 57 302 302 66 alice_in_wonderland.txt\n"); .stdout_is(" 5 57 302 302 66 alice_in_wonderland.txt\n");
} }
#[test] #[test]
fn test_multiple_default() { fn test_multiple_default() {
new_ucmd!() new_ucmd!()
.args(&["lorem_ipsum.txt", "moby_dick.txt", "alice_in_wonderland.txt"]).run() .args(&[
"lorem_ipsum.txt",
"moby_dick.txt",
"alice_in_wonderland.txt",
])
.run()
.stdout_is( .stdout_is(
" 13 109 772 lorem_ipsum.txt\n 18 204 1115 moby_dick.txt\n 5 57 302 \ " 13 109 772 lorem_ipsum.txt\n 18 204 1115 moby_dick.txt\n 5 57 302 \
alice_in_wonderland.txt\n 36 370 2189 total\n"); alice_in_wonderland.txt\n 36 370 2189 total\n",
);
} }

View file

@ -1,7 +1,6 @@
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
use common::util::*; use common::util::*;
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
#[test] #[test]
fn test_count() { fn test_count() {
@ -76,5 +75,10 @@ fn test_all() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn expected_result(arg: &str) -> String { fn expected_result(arg: &str) -> String {
TestScenario::new(util_name!()).cmd_keepenv(util_name!()).env("LANGUAGE", "C").args(&[arg]).run().stdout TestScenario::new(util_name!())
.cmd_keepenv(util_name!())
.env("LANGUAGE", "C")
.args(&[arg])
.run()
.stdout
} }