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,7 +20,8 @@ mod test_generate_tokens {
#[test]
fn test_normal_format() {
let s = "%10.2ac%-5.w\n";
let expected = vec![Token::Directive {
let expected = vec![
Token::Directive {
flag: 0,
width: 10,
precision: 2,
@ -33,14 +34,16 @@ mod test_generate_tokens {
precision: 0,
format: 'w',
},
Token::Char('\n')];
Token::Char('\n'),
];
assert_eq!(&expected, &Stater::generate_tokens(s, false).unwrap());
}
#[test]
fn test_printf_format() {
let s = "%-# 15a\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.-23w\\x12\\167\\132\\112\\n";
let expected = vec![Token::Directive {
let expected = vec![
Token::Directive {
flag: F_LEFT | F_ALTER | F_SPACE,
width: 15,
precision: -1,
@ -64,7 +67,8 @@ mod test_generate_tokens {
Token::Char('w'),
Token::Char('Z'),
Token::Char('J'),
Token::Char('\n')];
Token::Char('\n'),
];
assert_eq!(&expected, &Stater::generate_tokens(s, true).unwrap());
}
}

View file

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

View file

@ -1,6 +1,5 @@
use common::util::*;
#[test]
fn test_encode() {
let input = "hello, world!";
@ -61,11 +60,10 @@ fn test_wrap() {
#[test]
fn test_wrap_no_arg() {
for wrap_param in vec!["-w", "--wrap"] {
new_ucmd!()
.arg(wrap_param)
.fails()
.stderr_only(format!("base64: error: Argument to option '{}' missing\n",
if wrap_param == "-w" { "w" } else { "wrap" }));
new_ucmd!().arg(wrap_param).fails().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::*;
#[test]
fn test_directory() {
new_ucmd!().args(&["/root/alpha/beta/gamma/delta/epsilon/omega/"])
.succeeds().stdout_only("omega\n");
new_ucmd!()
.args(&["/root/alpha/beta/gamma/delta/epsilon/omega/"])
.succeeds()
.stdout_only("omega\n");
}
#[test]
fn test_file() {
new_ucmd!().args(&["/etc/passwd"]).succeeds().stdout_only("passwd\n");
new_ucmd!()
.args(&["/etc/passwd"])
.succeeds()
.stdout_only("passwd\n");
}
#[test]
fn test_remove_suffix() {
new_ucmd!().args(&["/usr/local/bin/reallylongexecutable.exe", ".exe"])
.succeeds().stdout_only("reallylongexecutable\n");
new_ucmd!()
.args(&["/usr/local/bin/reallylongexecutable.exe", ".exe"])
.succeeds()
.stdout_only("reallylongexecutable\n");
}
#[test]
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]
fn test_multiple_param() {
for multiple_param in vec!["-a", "--multiple"] {
let path = "/foo/bar/baz";
new_ucmd!().args(&[multiple_param, path, path])
.succeeds().stdout_only("baz\nbaz\n");
new_ucmd!()
.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";
new_ucmd!()
.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() {
for zero_param in vec!["-z", "--zero"] {
let path = "/foo/bar/baz";
new_ucmd!().args(&[zero_param, "-a", path, path])
.succeeds().stdout_only("baz\0baz\0");
new_ucmd!()
.args(&[zero_param, "-a", path, path])
.succeeds()
.stdout_only("baz\0baz\0");
}
}
fn expect_error(input: Vec<&str>) {
assert!(new_ucmd!().args(&input)
.fails().no_stdout().stderr.len() > 0);
assert!(new_ucmd!().args(&input).fails().no_stdout().stderr.len() > 0);
}
#[test]

View file

@ -1,6 +1,6 @@
extern crate tempdir;
#[cfg(unix)]
extern crate unix_socket;
extern crate tempdir;
use common::util::*;
@ -9,7 +9,8 @@ fn test_output_multi_files_print_all_chars() {
new_ucmd!()
.args(&["alpha.txt", "256.txt", "-A", "-n"])
.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 \
7\t^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\\^]^^^_ \
!\"#$%&\'()*+,-./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-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-\
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]
@ -27,8 +29,10 @@ fn test_numbered_lines_no_trailing_newline() {
new_ucmd!()
.args(&["nonewline.txt", "alpha.txt", "-n"])
.succeeds()
.stdout_only(" 1\ttext without a trailing newlineabcde\n 2\tfghij\n \
3\tklmno\n 4\tpqrst\n 5\tuvwxyz\n");
.stdout_only(
" 1\ttext without a trailing newlineabcde\n 2\tfghij\n \
3\tklmno\n 4\tpqrst\n 5\tuvwxyz\n",
);
}
#[test]
@ -53,12 +57,11 @@ fn test_stdin_show_tabs() {
}
}
#[test]
fn test_stdin_show_ends() {
for same_param in vec!["-E", "--show-ends"] {
new_ucmd!()
.args(&[same_param,"-"])
.args(&[same_param, "-"])
.pipe_in("\t\0\n\t")
.succeeds()
.stdout_only("\t\0$\n\t");
@ -139,15 +142,13 @@ fn test_squeeze_blank_before_numbering() {
}
}
#[test]
#[cfg(foo)]
fn test_domain_socket() {
use std::thread;
use self::unix_socket::UnixListener;
use self::tempdir::TempDir;
use self::unix_socket::UnixListener;
use std::io::prelude::*;
use std::thread;
let dir = TempDir::new("unix_socket").expect("failed to create dir");
let socket_path = dir.path().join("sock");
@ -155,7 +156,9 @@ fn test_domain_socket() {
let thread = thread::spawn(move || {
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!()

View file

@ -3,10 +3,7 @@ use rust_users::*;
#[test]
fn test_invalid_option() {
new_ucmd!()
.arg("-w")
.arg("/")
.fails();
new_ucmd!().arg("-w").arg("/").fails();
}
static DIR: &'static str = "/tmp";
@ -48,9 +45,12 @@ fn test_fail_silently() {
#[test]
fn test_preserve_root() {
// It's weird that on OS X, `realpath /etc/..` returns '/private'
for d in &["/", "/////tmp///../../../../",
for d in &[
"/",
"/////tmp///../../../../",
"../../../../../../../../../../../../../../",
"./../../../../../../../../../../../../../../"] {
"./../../../../../../../../../../../../../../",
] {
new_ucmd!()
.arg("--preserve-root")
.arg("-R")
@ -63,9 +63,12 @@ fn test_preserve_root() {
#[test]
fn test_preserve_root_symlink() {
let file = "test_chgrp_symlink2root";
for d in &["/", "////tmp//../../../../",
for d in &[
"/",
"////tmp//../../../../",
"..//../../..//../..//../../../../../../../../",
".//../../../../../../..//../../../../../../../"] {
".//../../../../../../..//../../../../../../../",
] {
let (at, mut ucmd) = at_and_ucmd!();
at.symlink_file(d, file);
ucmd.arg("--preserve-root")
@ -91,7 +94,7 @@ fn test_preserve_root_symlink() {
.fails()
.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();
}
@ -131,7 +134,9 @@ fn test_big_p() {
.arg("bin")
.arg("/proc/self/cwd")
.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")]
fn test_big_h() {
if get_effective_gid() != 0 {
assert!(new_ucmd!()
assert!(
new_ucmd!()
.arg("-RH")
.arg("bin")
.arg("/proc/self/fd")
.fails()
.stderr
.lines()
.fold(0, |acc, _| acc + 1) > 1);
.fold(0, |acc, _| acc + 1)
> 1
);
}
}

View file

@ -1,12 +1,11 @@
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::sync::Mutex;
extern crate libc;
use self::libc::umask;
static TEST_FILE: &'static str = "file";
static REFERENCE_FILE: &'static str = "reference";
static REFERENCE_PERMS: u32 = 0o247;
@ -17,11 +16,16 @@ lazy_static! {
struct TestCase {
args: Vec<&'static str>,
before: u32,
after: u32
after: 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();
perms.set_mode(mode);
set_permissions(file, perms).unwrap();
@ -31,7 +35,10 @@ fn run_single_test(test: &TestCase, at: AtPath, mut ucmd: UCommand) {
mkfile(&at.plus_as_string(TEST_FILE), test.before);
let perms = at.metadata(TEST_FILE).permissions().mode();
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 {
@ -45,7 +52,10 @@ fn run_single_test(test: &TestCase, at: AtPath, mut ucmd: UCommand) {
let perms = at.metadata(TEST_FILE).permissions().mode();
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
));
}
}
@ -58,17 +68,53 @@ fn run_tests(tests: Vec<TestCase>) {
#[test]
fn test_chmod_octal() {
let tests = vec!{
TestCase{args: vec!{"0700", TEST_FILE}, before: 0o100000, after: 0o100700},
TestCase{args: vec!{"0070", TEST_FILE}, before: 0o100000, 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},
};
let tests = vec![
TestCase {
args: vec!["0700", TEST_FILE],
before: 0o100000,
after: 0o100700,
},
TestCase {
args: vec!["0070", TEST_FILE],
before: 0o100000,
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);
}
@ -76,33 +122,91 @@ fn test_chmod_octal() {
fn test_chmod_ugoa() {
let _guard = UMASK_MUTEX.lock();
let last = unsafe {
umask(0)
};
let tests = vec!{
TestCase{args: vec!{"u=rwx", TEST_FILE}, before: 0o100000, after: 0o100700},
TestCase{args: vec!{"g=rwx", TEST_FILE}, 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!{"-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},
};
let last = unsafe { umask(0) };
let tests = vec![
TestCase {
args: vec!["u=rwx", TEST_FILE],
before: 0o100000,
after: 0o100700,
},
TestCase {
args: vec!["g=rwx", TEST_FILE],
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!["-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);
unsafe {
umask(0o022);
}
let tests = vec!{
TestCase{args: vec!{"u=rwx", TEST_FILE}, before: 0o100000, after: 0o100700},
TestCase{args: vec!{"g=rwx", TEST_FILE}, 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},
};
let tests = vec![
TestCase {
args: vec!["u=rwx", TEST_FILE],
before: 0o100000,
after: 0o100700,
},
TestCase {
args: vec!["g=rwx", TEST_FILE],
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);
unsafe {
umask(last);
@ -111,13 +215,33 @@ fn test_chmod_ugoa() {
#[test]
fn test_chmod_ugo_copy() {
let tests = vec!{
TestCase{args: vec!{"u=g", TEST_FILE}, before: 0o100070, after: 0o100770},
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},
};
let tests = vec![
TestCase {
args: vec!["u=g", TEST_FILE],
before: 0o100070,
after: 0o100770,
},
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);
}
@ -125,12 +249,12 @@ fn test_chmod_ugo_copy() {
fn test_chmod_many_options() {
let _guard = UMASK_MUTEX.lock();
let original_umask = unsafe {
umask(0)
};
let tests = vec!{
TestCase{args: vec!{"-r,a+w", TEST_FILE}, before: 0o100444, after: 0o100222},
};
let original_umask = unsafe { umask(0) };
let tests = vec![TestCase {
args: vec!["-r,a+w", TEST_FILE],
before: 0o100444,
after: 0o100222,
}];
run_tests(tests);
unsafe {
umask(original_umask);
@ -139,10 +263,18 @@ fn test_chmod_many_options() {
#[test]
fn test_chmod_reference_file() {
let tests = vec!{
TestCase{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 tests = vec![
TestCase {
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!();
mkfile(&at.plus_as_string(REFERENCE_FILE), REFERENCE_PERMS);
run_single_test(&tests[0], at, ucmd);

View file

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

View file

@ -1,10 +1,11 @@
use common::util::*;
#[test]
fn test_single_file() {
new_ucmd!().arg("lorem_ipsum.txt")
.succeeds().stdout_is_fixture("single_file.expected");
new_ucmd!()
.arg("lorem_ipsum.txt")
.succeeds()
.stdout_is_fixture("single_file.expected");
}
#[test]
@ -12,12 +13,14 @@ fn test_multiple_files() {
new_ucmd!()
.arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt")
.succeeds().stdout_is_fixture("multiple_files.expected");
.succeeds()
.stdout_is_fixture("multiple_files.expected");
}
#[test]
fn test_stdin() {
new_ucmd!()
.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::*;
#[test]
fn ab_no_args() {
new_ucmd!().args(&["a", "b"]).succeeds().stdout_only_fixture("ab.expected");
new_ucmd!()
.args(&["a", "b"])
.succeeds()
.stdout_only_fixture("ab.expected");
}
#[test]
fn ab_dash_one() {
new_ucmd!().args(&["a", "b", "-1"]).succeeds().stdout_only_fixture("ab1.expected");
new_ucmd!()
.args(&["a", "b", "-1"])
.succeeds()
.stdout_only_fixture("ab1.expected");
}
#[test]
fn ab_dash_two() {
new_ucmd!().args(&["a", "b", "-2"]).succeeds().stdout_only_fixture("ab2.expected");
new_ucmd!()
.args(&["a", "b", "-2"])
.succeeds()
.stdout_only_fixture("ab2.expected");
}
#[test]
fn ab_dash_three() {
new_ucmd!().args(&["a", "b", "-3"]).succeeds().stdout_only_fixture("ab3.expected");
new_ucmd!()
.args(&["a", "b", "-3"])
.succeeds()
.stdout_only_fixture("ab3.expected");
}
#[test]
fn aempty() {
new_ucmd!().args(&["a", "empty"]).succeeds().stdout_only_fixture("aempty.expected");
new_ucmd!()
.args(&["a", "empty"])
.succeeds()
.stdout_only_fixture("aempty.expected");
}
#[test]
fn emptyempty() {
new_ucmd!().args(&["empty", "empty"]).succeeds().stdout_only_fixture("emptyempty.expected");
new_ucmd!()
.args(&["empty", "empty"])
.succeeds()
.stdout_only_fixture("emptyempty.expected");
}
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test]
fn output_delimiter() {
new_ucmd!().args(&["--output-delimiter=word", "a", "b"])
.succeeds().stdout_only_fixture("ab_delimiter_word.expected");
new_ucmd!()
.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]
fn output_delimiter_require_arg() {
new_ucmd!().args(&["--output-delimiter=", "a", "b"])
.fails().stderr_only("error to be defined");
new_ucmd!()
.args(&["--output-delimiter=", "a", "b"])
.fails()
.stderr_only("error to be defined");
}
// even though (info) documentation suggests this is an option
@ -50,27 +71,32 @@ fn output_delimiter_require_arg() {
// this test is essentially an alarm in case someone well-intendingly
// implements it.
//marked as unimplemented as error message not set yet.
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test]
fn zero_terminated() {
for param in vec!["-z", "--zero-terminated"] {
new_ucmd!().args(&[param, "a", "b"]).fails().stderr_only("error to be defined");
new_ucmd!()
.args(&[param, "a", "b"])
.fails()
.stderr_only("error to be defined");
}
}
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test]
fn check_order() {
new_ucmd!().args(&["--check-order", "bad_order_1", "bad_order_2"])
new_ucmd!()
.args(&["--check-order", "bad_order_1", "bad_order_2"])
.fails()
.stdout_is_fixture("bad_order12.check_order.expected")
.stderr_is("error to be defined");
}
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test]
fn nocheck_order() {
new_ucmd!().args(&["--nocheck-order", "bad_order_1", "bad_order_2"])
new_ucmd!()
.args(&["--nocheck-order", "bad_order_1", "bad_order_2"])
.succeeds()
.stdout_only_fixture("bad_order12.nocheck_order.expected");
}
@ -78,10 +104,13 @@ fn nocheck_order() {
// when neither --check-order nor --no-check-order is provided,
// stderr and the error code behaves like check order, but stdout
// 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]
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
@ -93,14 +122,17 @@ fn defaultcheck_order() {
#[test]
fn defaultcheck_order_identical_bad_order_files() {
new_ucmd!().args(&["bad_order_1", "bad_order_1"])
.succeeds().stdout_only_fixture("bad_order11.defaultcheck_order.expected");
new_ucmd!()
.args(&["bad_order_1", "bad_order_1"])
.succeeds()
.stdout_only_fixture("bad_order11.defaultcheck_order.expected");
}
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test]
fn defaultcheck_order_two_different_bad_order_files() {
new_ucmd!().args(&["bad_order_1", "bad_order_2"])
new_ucmd!()
.args(&["bad_order_1", "bad_order_2"])
.fails()
.stdout_is_fixture("bad_order12.nocheck_order.expected")
.stderr_is("error to be defined");
@ -116,11 +148,13 @@ fn defaultcheck_order_two_different_bad_order_files() {
// 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.
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test]
fn unintuitive_default_behavior_1() {
new_ucmd!().args(&["defaultcheck_unintuitive_1", "defaultcheck_unintuitive_2"])
.succeeds().stdout_only_fixture("defaultcheck_unintuitive.expected");
new_ucmd!()
.args(&["defaultcheck_unintuitive_1", "defaultcheck_unintuitive_2"])
.succeeds()
.stdout_only_fixture("defaultcheck_unintuitive.expected");
}
#[ignore] //bug? should help be stdout if not called via -h|--help?

View file

@ -18,7 +18,8 @@ static TEST_COPY_TO_FOLDER_NEW_FILE: &str = "hello_dir_new/hello_world.txt";
fn test_cp_cp() {
let (at, mut ucmd) = at_and_ucmd!();
// Invoke our binary to make the copy.
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
let result = ucmd
.arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_HELLO_WORLD_DEST)
.run();
@ -30,11 +31,11 @@ fn test_cp_cp() {
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
}
#[test]
fn test_cp_existing_target() {
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)
.run();
@ -47,11 +48,11 @@ fn test_cp_existing_target() {
assert!(!at.file_exists(&*format!("{}~", TEST_EXISTING_FILE)));
}
#[test]
fn test_cp_duplicate_files() {
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_COPY_TO_FOLDER)
.run();
@ -61,11 +62,11 @@ fn test_cp_duplicate_files() {
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
}
#[test]
fn test_cp_multiple_files_target_is_file() {
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_EXISTING_FILE)
.run();
@ -77,7 +78,8 @@ fn test_cp_multiple_files_target_is_file() {
#[test]
fn test_cp_directory_not_recursive() {
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)
.run();
@ -85,11 +87,11 @@ fn test_cp_directory_not_recursive() {
assert!(result.stderr.contains("omitting directory"));
}
#[test]
fn test_cp_multiple_files() {
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_COPY_TO_FOLDER)
.run();
@ -134,14 +136,16 @@ fn test_cp_with_dirs() {
let at = &scene.fixtures;
//using -t option
let result_to_dir = scene.ucmd()
let result_to_dir = scene
.ucmd()
.arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_COPY_TO_FOLDER)
.run();
assert!(result_to_dir.success);
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_HELLO_WORLD_DEST)
.run();
@ -152,7 +156,8 @@ fn test_cp_with_dirs() {
#[test]
fn test_cp_arg_target_directory() {
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(TEST_COPY_TO_FOLDER)
.run();
@ -164,7 +169,8 @@ fn test_cp_arg_target_directory() {
#[test]
fn test_cp_arg_no_target_directory() {
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("-T")
.arg(TEST_COPY_TO_FOLDER)
@ -177,7 +183,8 @@ fn test_cp_arg_no_target_directory() {
#[test]
fn test_cp_arg_interactive() {
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("-i")
.pipe_in("N\n")
@ -188,12 +195,13 @@ fn test_cp_arg_interactive() {
}
#[test]
#[cfg(target_os="unix")]
#[cfg(target_os = "unix")]
fn test_cp_arg_link() {
use std::os::linux::fs::MetadataExt;
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(TEST_HELLO_WORLD_DEST)
.run();
@ -205,7 +213,8 @@ fn test_cp_arg_link() {
#[test]
fn test_cp_arg_symlink() {
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(TEST_HELLO_WORLD_DEST)
.run();
@ -214,11 +223,11 @@ fn test_cp_arg_symlink() {
assert!(at.is_symlink(TEST_HELLO_WORLD_DEST));
}
#[test]
fn test_cp_arg_no_clobber() {
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(TEST_HOW_ARE_YOU_SOURCE)
.run();
@ -234,11 +243,16 @@ fn test_cp_arg_force() {
let (at, mut ucmd) = at_and_ucmd!();
// 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);
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(TEST_HELLO_WORLD_DEST)
.run();
@ -260,11 +274,16 @@ fn test_cp_arg_remove_destination() {
let (at, mut ucmd) = at_and_ucmd!();
// 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);
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(TEST_HELLO_WORLD_DEST)
.run();
@ -277,21 +296,26 @@ fn test_cp_arg_remove_destination() {
fn test_cp_arg_backup() {
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(TEST_HOW_ARE_YOU_SOURCE)
.run();
assert!(result.success);
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]
fn test_cp_arg_suffix() {
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(".bak")
.arg(TEST_HOW_ARE_YOU_SOURCE)
@ -299,5 +323,8 @@ fn test_cp_arg_suffix() {
assert!(result.success);
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::*;
static INPUT: &'static str = "lists.txt";
struct TestedSequence<'b> {
name : &'b str,
sequence: &'b str
name: &'b str,
sequence: &'b str,
}
static EXAMPLE_SEQUENCES: &'static [TestedSequence<'static>] = &[
TestedSequence{ name: "singular", sequence:"2" },
TestedSequence{ 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" }
TestedSequence {
name: "singular",
sequence: "2",
},
TestedSequence {
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]
fn test_byte_sequence() {
for param in vec!["-b", "--bytes"] {
for example_seq in EXAMPLE_SEQUENCES {
new_ucmd!().args(&[param, example_seq.sequence, INPUT])
.succeeds().stdout_only_fixture(format!("sequences/byte_{}.expected", example_seq.name));
new_ucmd!()
.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 example_seq in EXAMPLE_SEQUENCES {
//as of coreutils 8.25 a char range is effectively the same as a byte range; there is no distinct treatment of utf8 chars.
new_ucmd!().args(&[param, example_seq.sequence, INPUT])
.succeeds().stdout_only_fixture(format!("sequences/byte_{}.expected", example_seq.name));
new_ucmd!()
.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() {
for param in vec!["-f", "--fields"] {
for example_seq in EXAMPLE_SEQUENCES {
new_ucmd!().args(&[param, example_seq.sequence, INPUT])
.succeeds().stdout_only_fixture(format!("sequences/field_{}.expected", example_seq.name));
new_ucmd!()
.args(&[param, example_seq.sequence, INPUT])
.succeeds()
.stdout_only_fixture(format!("sequences/field_{}.expected", example_seq.name));
}
}
}
@ -53,8 +79,10 @@ fn test_field_sequence() {
#[test]
fn test_specify_delimiter() {
for param in vec!["-d", "--delimiter"] {
new_ucmd!().args(&[param, ":", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
.succeeds().stdout_only_fixture("delimiter_specified.expected");
new_ucmd!()
.args(&[param, ":", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
.succeeds()
.stdout_only_fixture("delimiter_specified.expected");
}
}
@ -62,36 +90,52 @@ fn test_specify_delimiter() {
fn test_output_delimiter() {
// we use -d here to ensure output delimiter
// is applied to the current, and not just the default, input delimiter
new_ucmd!().args(&["-d:", "--output-delimiter=@", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
.succeeds().stdout_only_fixture("output_delimiter.expected");
new_ucmd!()
.args(&[
"-d:",
"--output-delimiter=@",
"-f",
COMPLEX_SEQUENCE.sequence,
INPUT,
])
.succeeds()
.stdout_only_fixture("output_delimiter.expected");
}
#[test]
fn test_complement() {
new_ucmd!().args(&["-d_","--complement", "-f", "2"])
new_ucmd!()
.args(&["-d_", "--complement", "-f", "2"])
.pipe_in("9_1\n8_2\n7_3")
.succeeds().stdout_only("9\n8\n7\n");
.succeeds()
.stdout_only("9\n8\n7\n");
}
#[test]
fn test_zero_terminated() {
new_ucmd!().args(&["-d_","-z", "-f", "1"])
new_ucmd!()
.args(&["-d_", "-z", "-f", "1"])
.pipe_in("9_1\n8_2\n\07_3")
.succeeds().stdout_only("9\07\0");
.succeeds()
.stdout_only("9\07\0");
}
#[test]
fn test_only_delimited() {
for param in vec!["-s", "--only-delimited"] {
new_ucmd!().args(&["-d_", param, "-f", "1"])
new_ucmd!()
.args(&["-d_", param, "-f", "1"])
.pipe_in("91\n82\n7_3")
.succeeds().stdout_only("7\n");
.succeeds()
.stdout_only("7\n");
}
}
#[test]
fn test_zero_terminated_only_delimited() {
new_ucmd!().args(&["-d_","-z", "-s", "-f", "1"])
new_ucmd!()
.args(&["-d_", "-z", "-s", "-f", "1"])
.pipe_in("91\n\082\n7_3")
.succeeds().stdout_only("82\n7\0");
.succeeds()
.stdout_only("82\n7\0");
}

View file

@ -1,9 +1,8 @@
extern crate uu_dircolors;
use self::uu_dircolors::{StrUtils, guess_syntax, OutputFmt};
use self::uu_dircolors::{guess_syntax, OutputFmt, StrUtils};
use common::util::*;
#[test]
fn test_shell_syntax() {
use std::env;
@ -64,26 +63,31 @@ fn test_internal_db() {
#[test]
fn test_bash_default() {
new_ucmd!().env("TERM", "screen").arg("-b").run().stdout_is_fixture("bash_def.expected");
new_ucmd!()
.env("TERM", "screen")
.arg("-b")
.run()
.stdout_is_fixture("bash_def.expected");
}
#[test]
fn test_csh_default() {
new_ucmd!().env("TERM", "screen").arg("-c").run().stdout_is_fixture("csh_def.expected");
new_ucmd!()
.env("TERM", "screen")
.arg("-c")
.run()
.stdout_is_fixture("csh_def.expected");
}
#[test]
fn test_no_env() {
// no SHELL and TERM
new_ucmd!()
.fails();
new_ucmd!().fails();
}
#[test]
fn test_exclusive_option() {
new_ucmd!()
.arg("-cp")
.fails();
new_ucmd!().arg("-cp").fails();
}
fn test_helper(file_name: &str, term: &str) {
@ -91,11 +95,13 @@ fn test_helper(file_name: &str, term: &str) {
.env("TERM", term)
.arg("-c")
.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!()
.env("TERM", term)
.arg("-b")
.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::*;
#[test]
fn test_path_with_trailing_slashes() {
new_ucmd!().arg("/root/alpha/beta/gamma/delta/epsilon/omega//")
.run().stdout_is("/root/alpha/beta/gamma/delta/epsilon\n");
new_ucmd!()
.arg("/root/alpha/beta/gamma/delta/epsilon/omega//")
.run()
.stdout_is("/root/alpha/beta/gamma/delta/epsilon\n");
}
#[test]
fn test_path_without_trailing_slashes() {
new_ucmd!().arg("/root/alpha/beta/gamma/delta/epsilon/omega")
.run().stdout_is("/root/alpha/beta/gamma/delta/epsilon\n");
new_ucmd!()
.arg("/root/alpha/beta/gamma/delta/epsilon/omega")
.run()
.stdout_is("/root/alpha/beta/gamma/delta/epsilon\n");
}
#[test]

View file

@ -1,6 +1,5 @@
use common::util::*;
#[test]
fn test_default() {
//CmdResult.stdout_only(...) trims trailing newlines
@ -10,97 +9,159 @@ fn test_default() {
#[test]
fn test_no_trailing_newline() {
//CmdResult.stdout_only(...) trims trailing newlines
assert_eq!("hi", new_ucmd!().arg("-n").arg("hi").succeeds().no_stderr().stdout);
assert_eq!(
"hi",
new_ucmd!()
.arg("-n")
.arg("hi")
.succeeds()
.no_stderr()
.stdout
);
}
#[test]
fn test_escape_alert() {
new_ucmd!().args(&["-e", "\\a"]).succeeds().stdout_only("\x07\n");
new_ucmd!()
.args(&["-e", "\\a"])
.succeeds()
.stdout_only("\x07\n");
}
#[test]
fn test_escape_backslash() {
new_ucmd!().args(&["-e", "\\\\"]).succeeds().stdout_only("\\\n");
new_ucmd!()
.args(&["-e", "\\\\"])
.succeeds()
.stdout_only("\\\n");
}
#[test]
fn test_escape_backspace() {
new_ucmd!().args(&["-e", "\\b"]).succeeds().stdout_only("\x08\n");
new_ucmd!()
.args(&["-e", "\\b"])
.succeeds()
.stdout_only("\x08\n");
}
#[test]
fn test_escape_carriage_return() {
new_ucmd!().args(&["-e", "\\r"]).succeeds().stdout_only("\r\n");
new_ucmd!()
.args(&["-e", "\\r"])
.succeeds()
.stdout_only("\r\n");
}
#[test]
fn test_escape_escape() {
new_ucmd!().args(&["-e", "\\e"]).succeeds().stdout_only("\x1B\n");
new_ucmd!()
.args(&["-e", "\\e"])
.succeeds()
.stdout_only("\x1B\n");
}
#[test]
fn test_escape_form_feed() {
new_ucmd!().args(&["-e", "\\f"]).succeeds().stdout_only("\x0C\n");
new_ucmd!()
.args(&["-e", "\\f"])
.succeeds()
.stdout_only("\x0C\n");
}
#[test]
fn test_escape_hex() {
new_ucmd!().args(&["-e", "\\x41"]).succeeds().stdout_only("A\n");
new_ucmd!()
.args(&["-e", "\\x41"])
.succeeds()
.stdout_only("A\n");
}
#[test]
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]
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]
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]
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]
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]
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]
fn test_escape_octal() {
new_ucmd!().args(&["-e", "\\0100"]).succeeds().stdout_only("@\n");
new_ucmd!()
.args(&["-e", "\\0100"])
.succeeds()
.stdout_only("@\n");
}
#[test]
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]
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]
fn test_escape_tab() {
new_ucmd!().args(&["-e", "\\t"]).succeeds().stdout_only("\t\n");
new_ucmd!()
.args(&["-e", "\\t"])
.succeeds()
.stdout_only("\t\n");
}
#[test]
fn test_escape_vertical_tab() {
new_ucmd!().args(&["-e", "\\v"]).succeeds().stdout_only("\x0B\n");
new_ucmd!()
.args(&["-e", "\\v"])
.succeeds()
.stdout_only("\x0B\n");
}
#[test]

View file

@ -2,12 +2,22 @@ use common::util::*;
#[test]
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]
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]
@ -30,19 +40,24 @@ fn test_echo() {
#[test]
fn test_file_option() {
let out = new_ucmd!()
.arg("-f").arg("vars.conf.txt")
.run().stdout;
let out = new_ucmd!().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]
fn test_combined_file_set() {
let out = new_ucmd!()
.arg("-f").arg("vars.conf.txt")
.arg("-f")
.arg("vars.conf.txt")
.arg("FOO=bar.alt")
.run().stdout;
.run()
.stdout;
assert_eq!(out.lines().filter(|&line| line == "FOO=bar.alt").count(), 1);
}
@ -50,49 +65,50 @@ fn test_combined_file_set() {
#[test]
fn test_combined_file_set_unset() {
let out = new_ucmd!()
.arg("-u").arg("BAR")
.arg("-f").arg("vars.conf.txt")
.arg("-u")
.arg("BAR")
.arg("-f")
.arg("vars.conf.txt")
.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]
fn test_single_name_value_pair() {
let out = new_ucmd!()
.arg("FOO=bar").run().stdout;
let out = new_ucmd!().arg("FOO=bar").run().stdout;
assert!(out.lines().any(|line| line == "FOO=bar"));
}
#[test]
fn test_multiple_name_value_pairs() {
let out = new_ucmd!()
.arg("FOO=bar")
.arg("ABC=xyz")
.run()
.stdout;
let out = new_ucmd!().arg("FOO=bar").arg("ABC=xyz").run().stdout;
assert_eq!(out.lines().filter(|&line| line == "FOO=bar" || line == "ABC=xyz").count(),
2);
assert_eq!(
out.lines()
.filter(|&line| line == "FOO=bar" || line == "ABC=xyz")
.count(),
2
);
}
#[test]
fn test_ignore_environment() {
let scene = TestScenario::new(util_name!());
let out = scene.ucmd()
.arg("-i")
.run()
.stdout;
let out = scene.ucmd().arg("-i").run().stdout;
assert_eq!(out, "");
let out = scene.ucmd()
.arg("-")
.run()
.stdout;
let out = scene.ucmd().arg("-").run().stdout;
assert_eq!(out, "");
}
@ -107,7 +123,7 @@ fn test_null_delimiter() {
.run()
.stdout;
let mut vars : Vec<_> = out.split('\0').collect();
let mut vars: Vec<_> = out.split('\0').collect();
assert_eq!(vars.len(), 3);
vars.sort();
assert_eq!(vars[0], "");

View file

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

View file

@ -9,20 +9,19 @@
use common::util::*;
#[path="../src/factor/sieve.rs"]
#[path = "../src/factor/sieve.rs"]
mod sieve;
use self::sieve::Sieve;
extern crate rand;
use self::rand::{rngs::SmallRng, Rng, FromEntropy};
use self::rand::distributions::{Distribution, Uniform};
use self::rand::{rngs::SmallRng, FromEntropy, Rng};
const NUM_PRIMES: usize = 10000;
const LOG_PRIMES: f64 = 14.0; // ceil(log2(NUM_PRIMES))
const NUM_TESTS: usize = 100;
#[test]
fn test_random() {
let primes = Sieve::primes().take(NUM_PRIMES).collect::<Vec<u64>>();
@ -104,7 +103,8 @@ fn test_random_big() {
// compute sequential differences here. We leave off the +14 bits
// so we can just index PRIMES_BY_BITS
let mut f_bits = f_bits.iter()
let mut f_bits = f_bits
.iter()
.scan(0, |st, &x| {
let ret = x - *st; // + 14 would give actual number of bits
*st = x;
@ -162,21 +162,22 @@ fn test_big_primes() {
fn run(instring: &[u8], outstring: &[u8]) {
// now run factor
new_ucmd!().pipe_in(instring).run().stdout_is(String::from_utf8(outstring.to_owned()).unwrap());
new_ucmd!()
.pipe_in(instring)
.run()
.stdout_is(String::from_utf8(outstring.to_owned()).unwrap());
}
const PRIMES_BY_BITS: &'static [&'static [u64]] = &[PRIMES14, PRIMES15, PRIMES16, PRIMES17,
PRIMES18, PRIMES19, PRIMES20, PRIMES21,
PRIMES22, PRIMES23, PRIMES24, PRIMES25,
PRIMES26, PRIMES27, PRIMES28, PRIMES29,
PRIMES30, PRIMES31, PRIMES32, PRIMES33,
PRIMES34, PRIMES35, PRIMES36, PRIMES37,
PRIMES38, PRIMES39, PRIMES40, PRIMES41,
PRIMES42, PRIMES43, PRIMES44, PRIMES45,
PRIMES46, PRIMES47, PRIMES48, PRIMES49,
PRIMES50];
const PRIMES_BY_BITS: &'static [&'static [u64]] = &[
PRIMES14, PRIMES15, PRIMES16, PRIMES17, PRIMES18, PRIMES19, PRIMES20, PRIMES21, PRIMES22,
PRIMES23, PRIMES24, PRIMES25, PRIMES26, PRIMES27, PRIMES28, PRIMES29, PRIMES30, PRIMES31,
PRIMES32, PRIMES33, PRIMES34, PRIMES35, PRIMES36, PRIMES37, PRIMES38, PRIMES39, PRIMES40,
PRIMES41, PRIMES42, PRIMES43, PRIMES44, PRIMES45, PRIMES46, PRIMES47, PRIMES48, PRIMES49,
PRIMES50,
];
const PRIMES64: &'static [u64] = &[18446744073709551557,
const PRIMES64: &'static [u64] = &[
18446744073709551557,
18446744073709551533,
18446744073709551521,
18446744073709551437,
@ -224,235 +225,212 @@ const PRIMES64: &'static [u64] = &[18446744073709551557,
18446744073709549621,
18446744073709549613,
18446744073709549583,
18446744073709549571];
18446744073709549571,
];
const PRIMES14: &'static [u64] = &[16381, 16369, 16363, 16361, 16349, 16339, 16333, 16319, 16301,
16273, 16267, 16253, 16249, 16231, 16229, 16223, 16217, 16193,
16189, 16187, 16183, 16141, 16139, 16127, 16111, 16103, 16097,
16091, 16087, 16073, 16069, 16067, 16063, 16061, 16057, 16033,
16007, 16001, 15991, 15973, 15971, 15959, 15937, 15923, 15919,
15913, 15907, 15901, 15889, 15887, 15881, 15877, 15859, 15823,
15817, 15809, 15803, 15797, 15791, 15787, 15773, 15767, 15761,
15749, 15739, 15737, 15733, 15731, 15727, 15683, 15679, 15671,
15667, 15661, 15649, 15647, 15643, 15641, 15629, 15619, 15607,
15601, 15583, 15581, 15569, 15559, 15551, 15541, 15527, 15511,
15497, 15493, 15473, 15467, 15461, 15451, 15443, 15439, 15427,
15413, 15401, 15391, 15383, 15377, 15373];
const PRIMES14: &'static [u64] = &[
16381, 16369, 16363, 16361, 16349, 16339, 16333, 16319, 16301, 16273, 16267, 16253, 16249,
16231, 16229, 16223, 16217, 16193, 16189, 16187, 16183, 16141, 16139, 16127, 16111, 16103,
16097, 16091, 16087, 16073, 16069, 16067, 16063, 16061, 16057, 16033, 16007, 16001, 15991,
15973, 15971, 15959, 15937, 15923, 15919, 15913, 15907, 15901, 15889, 15887, 15881, 15877,
15859, 15823, 15817, 15809, 15803, 15797, 15791, 15787, 15773, 15767, 15761, 15749, 15739,
15737, 15733, 15731, 15727, 15683, 15679, 15671, 15667, 15661, 15649, 15647, 15643, 15641,
15629, 15619, 15607, 15601, 15583, 15581, 15569, 15559, 15551, 15541, 15527, 15511, 15497,
15493, 15473, 15467, 15461, 15451, 15443, 15439, 15427, 15413, 15401, 15391, 15383, 15377,
15373,
];
const PRIMES15: &'static [u64] = &[32749, 32719, 32717, 32713, 32707, 32693, 32687, 32653, 32647,
32633, 32621, 32611, 32609, 32603, 32587, 32579, 32573, 32569,
32563, 32561, 32537, 32533, 32531, 32507, 32503, 32497, 32491,
32479, 32467, 32443, 32441, 32429, 32423, 32413, 32411, 32401,
32381, 32377, 32371, 32369, 32363, 32359, 32353, 32341, 32327,
32323, 32321, 32309, 32303, 32299, 32297, 32261, 32257, 32251,
32237, 32233, 32213, 32203, 32191, 32189, 32183, 32173, 32159,
32143, 32141, 32119, 32117, 32099, 32089, 32083, 32077, 32069,
32063, 32059, 32057, 32051, 32029, 32027, 32009, 32003, 31991,
31981, 31973, 31963, 31957, 31907, 31891, 31883, 31873, 31859,
31849, 31847, 31817, 31799, 31793, 31771, 31769, 31751];
const PRIMES15: &'static [u64] = &[
32749, 32719, 32717, 32713, 32707, 32693, 32687, 32653, 32647, 32633, 32621, 32611, 32609,
32603, 32587, 32579, 32573, 32569, 32563, 32561, 32537, 32533, 32531, 32507, 32503, 32497,
32491, 32479, 32467, 32443, 32441, 32429, 32423, 32413, 32411, 32401, 32381, 32377, 32371,
32369, 32363, 32359, 32353, 32341, 32327, 32323, 32321, 32309, 32303, 32299, 32297, 32261,
32257, 32251, 32237, 32233, 32213, 32203, 32191, 32189, 32183, 32173, 32159, 32143, 32141,
32119, 32117, 32099, 32089, 32083, 32077, 32069, 32063, 32059, 32057, 32051, 32029, 32027,
32009, 32003, 31991, 31981, 31973, 31963, 31957, 31907, 31891, 31883, 31873, 31859, 31849,
31847, 31817, 31799, 31793, 31771, 31769, 31751,
];
const PRIMES16: &'static [u64] = &[65521, 65519, 65497, 65479, 65449, 65447, 65437, 65423, 65419,
65413, 65407, 65393, 65381, 65371, 65357, 65353, 65327, 65323,
65309, 65293, 65287, 65269, 65267, 65257, 65239, 65213, 65203,
65183, 65179, 65173, 65171, 65167, 65147, 65141, 65129, 65123,
65119, 65111, 65101, 65099, 65089, 65071, 65063, 65053, 65033,
65029, 65027, 65011, 65003, 64997, 64969, 64951, 64937, 64927,
64921, 64919, 64901, 64891, 64879, 64877, 64871, 64853, 64849,
64817, 64811, 64793, 64783, 64781, 64763, 64747, 64717, 64709,
64693, 64679, 64667, 64663, 64661, 64633, 64627, 64621, 64613,
64609, 64601, 64591, 64579, 64577, 64567, 64553];
const PRIMES16: &'static [u64] = &[
65521, 65519, 65497, 65479, 65449, 65447, 65437, 65423, 65419, 65413, 65407, 65393, 65381,
65371, 65357, 65353, 65327, 65323, 65309, 65293, 65287, 65269, 65267, 65257, 65239, 65213,
65203, 65183, 65179, 65173, 65171, 65167, 65147, 65141, 65129, 65123, 65119, 65111, 65101,
65099, 65089, 65071, 65063, 65053, 65033, 65029, 65027, 65011, 65003, 64997, 64969, 64951,
64937, 64927, 64921, 64919, 64901, 64891, 64879, 64877, 64871, 64853, 64849, 64817, 64811,
64793, 64783, 64781, 64763, 64747, 64717, 64709, 64693, 64679, 64667, 64663, 64661, 64633,
64627, 64621, 64613, 64609, 64601, 64591, 64579, 64577, 64567, 64553,
];
const PRIMES17: &'static [u64] = &[131071, 131063, 131059, 131041, 131023, 131011, 131009, 130987,
130981, 130973, 130969, 130957, 130927, 130873, 130859, 130843,
130841, 130829, 130817, 130811, 130807, 130787, 130783, 130769,
130729, 130699, 130693, 130687, 130681, 130657, 130651, 130649,
130643, 130639, 130633, 130631, 130621, 130619, 130589, 130579,
130553, 130547, 130531, 130523, 130517, 130513, 130489, 130483,
130477, 130469, 130457, 130447, 130439, 130423, 130411, 130409,
130399, 130379, 130369, 130367, 130363, 130349, 130343, 130337,
130307, 130303, 130279, 130267, 130261, 130259, 130253, 130241,
130223, 130211, 130201, 130199, 130183, 130171, 130147, 130127,
130121, 130099, 130087, 130079, 130073, 130069, 130057, 130051];
const PRIMES17: &'static [u64] = &[
131071, 131063, 131059, 131041, 131023, 131011, 131009, 130987, 130981, 130973, 130969, 130957,
130927, 130873, 130859, 130843, 130841, 130829, 130817, 130811, 130807, 130787, 130783, 130769,
130729, 130699, 130693, 130687, 130681, 130657, 130651, 130649, 130643, 130639, 130633, 130631,
130621, 130619, 130589, 130579, 130553, 130547, 130531, 130523, 130517, 130513, 130489, 130483,
130477, 130469, 130457, 130447, 130439, 130423, 130411, 130409, 130399, 130379, 130369, 130367,
130363, 130349, 130343, 130337, 130307, 130303, 130279, 130267, 130261, 130259, 130253, 130241,
130223, 130211, 130201, 130199, 130183, 130171, 130147, 130127, 130121, 130099, 130087, 130079,
130073, 130069, 130057, 130051,
];
const PRIMES18: &'static [u64] = &[262139, 262133, 262127, 262121, 262111, 262109, 262103, 262079,
262069, 262051, 262049, 262027, 262007, 261983, 261977, 261973,
261971, 261959, 261917, 261887, 261881, 261847, 261823, 261799,
261791, 261787, 261773, 261761, 261757, 261739, 261721, 261713,
261707, 261697, 261673, 261643, 261641, 261637, 261631, 261619,
261601, 261593, 261587, 261581, 261577, 261563, 261557, 261529,
261523, 261509, 261467, 261463, 261451, 261439, 261433, 261431,
261427, 261407, 261389, 261379, 261353, 261347, 261337, 261329,
261323, 261301, 261281, 261271, 261251, 261241, 261229, 261223,
261169, 261167, 261127];
const PRIMES18: &'static [u64] = &[
262139, 262133, 262127, 262121, 262111, 262109, 262103, 262079, 262069, 262051, 262049, 262027,
262007, 261983, 261977, 261973, 261971, 261959, 261917, 261887, 261881, 261847, 261823, 261799,
261791, 261787, 261773, 261761, 261757, 261739, 261721, 261713, 261707, 261697, 261673, 261643,
261641, 261637, 261631, 261619, 261601, 261593, 261587, 261581, 261577, 261563, 261557, 261529,
261523, 261509, 261467, 261463, 261451, 261439, 261433, 261431, 261427, 261407, 261389, 261379,
261353, 261347, 261337, 261329, 261323, 261301, 261281, 261271, 261251, 261241, 261229, 261223,
261169, 261167, 261127,
];
const PRIMES19: &'static [u64] = &[524287, 524269, 524261, 524257, 524243, 524231, 524221, 524219,
524203, 524201, 524197, 524189, 524171, 524149, 524123, 524119,
524113, 524099, 524087, 524081, 524071, 524063, 524057, 524053,
524047, 523997, 523987, 523969, 523949, 523937, 523927, 523907,
523903, 523877, 523867, 523847, 523829, 523801, 523793, 523777,
523771, 523763, 523759, 523741, 523729, 523717, 523681, 523673,
523669, 523667, 523657, 523639, 523637, 523631, 523603, 523597,
523577, 523573, 523571, 523553, 523543, 523541, 523519, 523511,
523493, 523489, 523487, 523463, 523459, 523433, 523427, 523417,
523403, 523387, 523357, 523351, 523349, 523333, 523307, 523297];
const PRIMES19: &'static [u64] = &[
524287, 524269, 524261, 524257, 524243, 524231, 524221, 524219, 524203, 524201, 524197, 524189,
524171, 524149, 524123, 524119, 524113, 524099, 524087, 524081, 524071, 524063, 524057, 524053,
524047, 523997, 523987, 523969, 523949, 523937, 523927, 523907, 523903, 523877, 523867, 523847,
523829, 523801, 523793, 523777, 523771, 523763, 523759, 523741, 523729, 523717, 523681, 523673,
523669, 523667, 523657, 523639, 523637, 523631, 523603, 523597, 523577, 523573, 523571, 523553,
523543, 523541, 523519, 523511, 523493, 523489, 523487, 523463, 523459, 523433, 523427, 523417,
523403, 523387, 523357, 523351, 523349, 523333, 523307, 523297,
];
const PRIMES20: &'static [u64] = &[1048573, 1048571, 1048559, 1048549, 1048517, 1048507, 1048447,
1048433, 1048423, 1048391, 1048387, 1048367, 1048361, 1048357,
1048343, 1048309, 1048291, 1048273, 1048261, 1048219, 1048217,
1048213, 1048193, 1048189, 1048139, 1048129, 1048127, 1048123,
1048063, 1048051, 1048049, 1048043, 1048027, 1048013, 1048009,
1048007, 1047997, 1047989, 1047979, 1047971, 1047961, 1047941,
1047929, 1047923, 1047887, 1047883, 1047881, 1047859, 1047841,
1047833, 1047821, 1047779, 1047773, 1047763, 1047751, 1047737,
1047721, 1047713, 1047703, 1047701, 1047691, 1047689, 1047671,
1047667, 1047653, 1047649, 1047647, 1047589, 1047587, 1047559];
const PRIMES20: &'static [u64] = &[
1048573, 1048571, 1048559, 1048549, 1048517, 1048507, 1048447, 1048433, 1048423, 1048391,
1048387, 1048367, 1048361, 1048357, 1048343, 1048309, 1048291, 1048273, 1048261, 1048219,
1048217, 1048213, 1048193, 1048189, 1048139, 1048129, 1048127, 1048123, 1048063, 1048051,
1048049, 1048043, 1048027, 1048013, 1048009, 1048007, 1047997, 1047989, 1047979, 1047971,
1047961, 1047941, 1047929, 1047923, 1047887, 1047883, 1047881, 1047859, 1047841, 1047833,
1047821, 1047779, 1047773, 1047763, 1047751, 1047737, 1047721, 1047713, 1047703, 1047701,
1047691, 1047689, 1047671, 1047667, 1047653, 1047649, 1047647, 1047589, 1047587, 1047559,
];
const PRIMES21: &'static [u64] = &[2097143, 2097133, 2097131, 2097097, 2097091, 2097083, 2097047,
2097041, 2097031, 2097023, 2097013, 2096993, 2096987, 2096971,
2096959, 2096957, 2096947, 2096923, 2096911, 2096909, 2096893,
2096881, 2096873, 2096867, 2096851, 2096837, 2096807, 2096791,
2096789, 2096777, 2096761, 2096741, 2096737, 2096713, 2096693,
2096687, 2096681, 2096639, 2096629, 2096621, 2096599, 2096597,
2096569, 2096539, 2096533, 2096483, 2096449, 2096431, 2096429,
2096411, 2096407, 2096401, 2096399, 2096377, 2096357, 2096291,
2096273, 2096261, 2096233, 2096231, 2096221, 2096209, 2096191,
2096183, 2096147];
const PRIMES21: &'static [u64] = &[
2097143, 2097133, 2097131, 2097097, 2097091, 2097083, 2097047, 2097041, 2097031, 2097023,
2097013, 2096993, 2096987, 2096971, 2096959, 2096957, 2096947, 2096923, 2096911, 2096909,
2096893, 2096881, 2096873, 2096867, 2096851, 2096837, 2096807, 2096791, 2096789, 2096777,
2096761, 2096741, 2096737, 2096713, 2096693, 2096687, 2096681, 2096639, 2096629, 2096621,
2096599, 2096597, 2096569, 2096539, 2096533, 2096483, 2096449, 2096431, 2096429, 2096411,
2096407, 2096401, 2096399, 2096377, 2096357, 2096291, 2096273, 2096261, 2096233, 2096231,
2096221, 2096209, 2096191, 2096183, 2096147,
];
const PRIMES22: &'static [u64] = &[4194301, 4194287, 4194277, 4194271, 4194247, 4194217, 4194199,
4194191, 4194187, 4194181, 4194173, 4194167, 4194143, 4194137,
4194131, 4194107, 4194103, 4194023, 4194011, 4194007, 4193977,
4193971, 4193963, 4193957, 4193939, 4193929, 4193909, 4193869,
4193807, 4193803, 4193801, 4193789, 4193759, 4193753, 4193743,
4193701, 4193663, 4193633, 4193573, 4193569, 4193551, 4193549,
4193531, 4193513, 4193507, 4193459, 4193447, 4193443, 4193417,
4193411, 4193393, 4193389, 4193381, 4193377, 4193369, 4193359,
4193353, 4193327, 4193309, 4193303, 4193297];
const PRIMES22: &'static [u64] = &[
4194301, 4194287, 4194277, 4194271, 4194247, 4194217, 4194199, 4194191, 4194187, 4194181,
4194173, 4194167, 4194143, 4194137, 4194131, 4194107, 4194103, 4194023, 4194011, 4194007,
4193977, 4193971, 4193963, 4193957, 4193939, 4193929, 4193909, 4193869, 4193807, 4193803,
4193801, 4193789, 4193759, 4193753, 4193743, 4193701, 4193663, 4193633, 4193573, 4193569,
4193551, 4193549, 4193531, 4193513, 4193507, 4193459, 4193447, 4193443, 4193417, 4193411,
4193393, 4193389, 4193381, 4193377, 4193369, 4193359, 4193353, 4193327, 4193309, 4193303,
4193297,
];
const PRIMES23: &'static [u64] = &[8388593, 8388587, 8388581, 8388571, 8388547, 8388539, 8388473,
8388461, 8388451, 8388449, 8388439, 8388427, 8388421, 8388409,
8388377, 8388371, 8388319, 8388301, 8388287, 8388283, 8388277,
8388239, 8388209, 8388187, 8388113, 8388109, 8388091, 8388071,
8388059, 8388019, 8388013, 8387999, 8387993, 8387959, 8387957,
8387947, 8387933, 8387921, 8387917, 8387891, 8387879, 8387867,
8387861, 8387857, 8387839, 8387831, 8387809, 8387807, 8387741,
8387737, 8387723, 8387707, 8387671, 8387611, 8387609, 8387591];
const PRIMES23: &'static [u64] = &[
8388593, 8388587, 8388581, 8388571, 8388547, 8388539, 8388473, 8388461, 8388451, 8388449,
8388439, 8388427, 8388421, 8388409, 8388377, 8388371, 8388319, 8388301, 8388287, 8388283,
8388277, 8388239, 8388209, 8388187, 8388113, 8388109, 8388091, 8388071, 8388059, 8388019,
8388013, 8387999, 8387993, 8387959, 8387957, 8387947, 8387933, 8387921, 8387917, 8387891,
8387879, 8387867, 8387861, 8387857, 8387839, 8387831, 8387809, 8387807, 8387741, 8387737,
8387723, 8387707, 8387671, 8387611, 8387609, 8387591,
];
const PRIMES24: &'static [u64] = &[16777213, 16777199, 16777183, 16777153, 16777141, 16777139,
16777127, 16777121, 16777099, 16777049, 16777027, 16776989,
16776973, 16776971, 16776967, 16776961, 16776941, 16776937,
16776931, 16776919, 16776901, 16776899, 16776869, 16776857,
16776839, 16776833, 16776817, 16776763, 16776731, 16776719,
16776713, 16776691, 16776689, 16776679, 16776659, 16776631,
16776623, 16776619, 16776607, 16776593, 16776581, 16776547,
16776521, 16776491, 16776481, 16776469, 16776451, 16776401,
16776391, 16776379, 16776371, 16776367, 16776343, 16776337,
16776317, 16776313, 16776289, 16776217, 16776211];
const PRIMES24: &'static [u64] = &[
16777213, 16777199, 16777183, 16777153, 16777141, 16777139, 16777127, 16777121, 16777099,
16777049, 16777027, 16776989, 16776973, 16776971, 16776967, 16776961, 16776941, 16776937,
16776931, 16776919, 16776901, 16776899, 16776869, 16776857, 16776839, 16776833, 16776817,
16776763, 16776731, 16776719, 16776713, 16776691, 16776689, 16776679, 16776659, 16776631,
16776623, 16776619, 16776607, 16776593, 16776581, 16776547, 16776521, 16776491, 16776481,
16776469, 16776451, 16776401, 16776391, 16776379, 16776371, 16776367, 16776343, 16776337,
16776317, 16776313, 16776289, 16776217, 16776211,
];
const PRIMES25: &'static [u64] = &[33554393, 33554383, 33554371, 33554347, 33554341, 33554317,
33554291, 33554273, 33554267, 33554249, 33554239, 33554221,
33554201, 33554167, 33554159, 33554137, 33554123, 33554093,
33554083, 33554077, 33554051, 33554021, 33554011, 33554009,
33553999, 33553991, 33553969, 33553967, 33553909, 33553901,
33553879, 33553837, 33553799, 33553787, 33553771, 33553769,
33553759, 33553747, 33553739, 33553727, 33553697, 33553693,
33553679, 33553661, 33553657, 33553651, 33553649, 33553633,
33553613, 33553607, 33553577, 33553549, 33553547, 33553537,
33553519, 33553517, 33553511, 33553489, 33553463, 33553451,
33553417];
const PRIMES25: &'static [u64] = &[
33554393, 33554383, 33554371, 33554347, 33554341, 33554317, 33554291, 33554273, 33554267,
33554249, 33554239, 33554221, 33554201, 33554167, 33554159, 33554137, 33554123, 33554093,
33554083, 33554077, 33554051, 33554021, 33554011, 33554009, 33553999, 33553991, 33553969,
33553967, 33553909, 33553901, 33553879, 33553837, 33553799, 33553787, 33553771, 33553769,
33553759, 33553747, 33553739, 33553727, 33553697, 33553693, 33553679, 33553661, 33553657,
33553651, 33553649, 33553633, 33553613, 33553607, 33553577, 33553549, 33553547, 33553537,
33553519, 33553517, 33553511, 33553489, 33553463, 33553451, 33553417,
];
const PRIMES26: &'static [u64] = &[67108859, 67108837, 67108819, 67108777, 67108763, 67108757,
67108753, 67108747, 67108739, 67108729, 67108721, 67108709,
67108693, 67108669, 67108667, 67108661, 67108649, 67108633,
67108597, 67108579, 67108529, 67108511, 67108507, 67108493,
67108471, 67108463, 67108453, 67108439, 67108387, 67108373,
67108369, 67108351, 67108331, 67108313, 67108303, 67108289,
67108271, 67108219, 67108207, 67108201, 67108199, 67108187,
67108183, 67108177, 67108127, 67108109, 67108081, 67108049,
67108039, 67108037, 67108033, 67108009, 67108007, 67108003,
67107983, 67107977, 67107967, 67107941, 67107919, 67107913,
67107883, 67107881, 67107871, 67107863];
const PRIMES26: &'static [u64] = &[
67108859, 67108837, 67108819, 67108777, 67108763, 67108757, 67108753, 67108747, 67108739,
67108729, 67108721, 67108709, 67108693, 67108669, 67108667, 67108661, 67108649, 67108633,
67108597, 67108579, 67108529, 67108511, 67108507, 67108493, 67108471, 67108463, 67108453,
67108439, 67108387, 67108373, 67108369, 67108351, 67108331, 67108313, 67108303, 67108289,
67108271, 67108219, 67108207, 67108201, 67108199, 67108187, 67108183, 67108177, 67108127,
67108109, 67108081, 67108049, 67108039, 67108037, 67108033, 67108009, 67108007, 67108003,
67107983, 67107977, 67107967, 67107941, 67107919, 67107913, 67107883, 67107881, 67107871,
67107863,
];
const PRIMES27: &'static [u64] = &[134217689, 134217649, 134217617, 134217613, 134217593,
134217541, 134217529, 134217509, 134217497, 134217493,
134217487, 134217467, 134217439, 134217437, 134217409,
134217403, 134217401, 134217367, 134217361, 134217353,
134217323, 134217301, 134217277, 134217257, 134217247,
134217221, 134217199, 134217173, 134217163, 134217157,
134217131, 134217103, 134217089, 134217079, 134217049,
134217047, 134217043, 134217001, 134216987, 134216947,
134216939, 134216933, 134216911, 134216899, 134216881,
134216869, 134216867, 134216861, 134216837, 134216827,
134216807, 134216801, 134216791, 134216783, 134216777,
134216759, 134216737, 134216729];
const PRIMES27: &'static [u64] = &[
134217689, 134217649, 134217617, 134217613, 134217593, 134217541, 134217529, 134217509,
134217497, 134217493, 134217487, 134217467, 134217439, 134217437, 134217409, 134217403,
134217401, 134217367, 134217361, 134217353, 134217323, 134217301, 134217277, 134217257,
134217247, 134217221, 134217199, 134217173, 134217163, 134217157, 134217131, 134217103,
134217089, 134217079, 134217049, 134217047, 134217043, 134217001, 134216987, 134216947,
134216939, 134216933, 134216911, 134216899, 134216881, 134216869, 134216867, 134216861,
134216837, 134216827, 134216807, 134216801, 134216791, 134216783, 134216777, 134216759,
134216737, 134216729,
];
const PRIMES28: &'static [u64] = &[268435399, 268435367, 268435361, 268435337, 268435331,
268435313, 268435291, 268435273, 268435243, 268435183,
268435171, 268435157, 268435147, 268435133, 268435129,
268435121, 268435109, 268435091, 268435067, 268435043,
268435039, 268435033, 268435019, 268435009, 268435007,
268434997, 268434979, 268434977, 268434961, 268434949,
268434941, 268434937, 268434857, 268434841, 268434827,
268434821, 268434787, 268434781, 268434779, 268434773,
268434731, 268434721, 268434713, 268434707, 268434703,
268434697, 268434659, 268434623, 268434619, 268434581,
268434577, 268434563, 268434557, 268434547, 268434511,
268434499, 268434479, 268434461];
const PRIMES28: &'static [u64] = &[
268435399, 268435367, 268435361, 268435337, 268435331, 268435313, 268435291, 268435273,
268435243, 268435183, 268435171, 268435157, 268435147, 268435133, 268435129, 268435121,
268435109, 268435091, 268435067, 268435043, 268435039, 268435033, 268435019, 268435009,
268435007, 268434997, 268434979, 268434977, 268434961, 268434949, 268434941, 268434937,
268434857, 268434841, 268434827, 268434821, 268434787, 268434781, 268434779, 268434773,
268434731, 268434721, 268434713, 268434707, 268434703, 268434697, 268434659, 268434623,
268434619, 268434581, 268434577, 268434563, 268434557, 268434547, 268434511, 268434499,
268434479, 268434461,
];
const PRIMES29: &'static [u64] = &[536870909, 536870879, 536870869, 536870849, 536870839,
536870837, 536870819, 536870813, 536870791, 536870779,
536870767, 536870743, 536870729, 536870723, 536870717,
536870701, 536870683, 536870657, 536870641, 536870627,
536870611, 536870603, 536870599, 536870573, 536870569,
536870563, 536870561, 536870513, 536870501, 536870497,
536870473, 536870401, 536870363, 536870317, 536870303,
536870297, 536870273, 536870267, 536870239, 536870233,
536870219, 536870171, 536870167, 536870153, 536870123,
536870063, 536870057, 536870041, 536870027, 536869999,
536869951, 536869943, 536869937, 536869919, 536869901,
536869891];
const PRIMES29: &'static [u64] = &[
536870909, 536870879, 536870869, 536870849, 536870839, 536870837, 536870819, 536870813,
536870791, 536870779, 536870767, 536870743, 536870729, 536870723, 536870717, 536870701,
536870683, 536870657, 536870641, 536870627, 536870611, 536870603, 536870599, 536870573,
536870569, 536870563, 536870561, 536870513, 536870501, 536870497, 536870473, 536870401,
536870363, 536870317, 536870303, 536870297, 536870273, 536870267, 536870239, 536870233,
536870219, 536870171, 536870167, 536870153, 536870123, 536870063, 536870057, 536870041,
536870027, 536869999, 536869951, 536869943, 536869937, 536869919, 536869901, 536869891,
];
const PRIMES30: &'static [u64] = &[1073741789, 1073741783, 1073741741, 1073741723, 1073741719,
1073741717, 1073741689, 1073741671, 1073741663, 1073741651,
1073741621, 1073741567, 1073741561, 1073741527, 1073741503,
1073741477, 1073741467, 1073741441, 1073741419, 1073741399,
1073741387, 1073741381, 1073741371, 1073741329, 1073741311,
1073741309, 1073741287, 1073741237, 1073741213, 1073741197,
1073741189, 1073741173, 1073741101, 1073741077, 1073741047,
1073740963, 1073740951, 1073740933, 1073740909, 1073740879,
1073740853, 1073740847, 1073740819, 1073740807];
const PRIMES30: &'static [u64] = &[
1073741789, 1073741783, 1073741741, 1073741723, 1073741719, 1073741717, 1073741689, 1073741671,
1073741663, 1073741651, 1073741621, 1073741567, 1073741561, 1073741527, 1073741503, 1073741477,
1073741467, 1073741441, 1073741419, 1073741399, 1073741387, 1073741381, 1073741371, 1073741329,
1073741311, 1073741309, 1073741287, 1073741237, 1073741213, 1073741197, 1073741189, 1073741173,
1073741101, 1073741077, 1073741047, 1073740963, 1073740951, 1073740933, 1073740909, 1073740879,
1073740853, 1073740847, 1073740819, 1073740807,
];
const PRIMES31: &'static [u64] = &[2147483647, 2147483629, 2147483587, 2147483579, 2147483563,
2147483549, 2147483543, 2147483497, 2147483489, 2147483477,
2147483423, 2147483399, 2147483353, 2147483323, 2147483269,
2147483249, 2147483237, 2147483179, 2147483171, 2147483137,
2147483123, 2147483077, 2147483069, 2147483059, 2147483053,
2147483033, 2147483029, 2147482951, 2147482949, 2147482943,
2147482937, 2147482921, 2147482877, 2147482873, 2147482867,
2147482859, 2147482819, 2147482817, 2147482811, 2147482801,
2147482763, 2147482739, 2147482697, 2147482693, 2147482681,
2147482663, 2147482661];
const PRIMES31: &'static [u64] = &[
2147483647, 2147483629, 2147483587, 2147483579, 2147483563, 2147483549, 2147483543, 2147483497,
2147483489, 2147483477, 2147483423, 2147483399, 2147483353, 2147483323, 2147483269, 2147483249,
2147483237, 2147483179, 2147483171, 2147483137, 2147483123, 2147483077, 2147483069, 2147483059,
2147483053, 2147483033, 2147483029, 2147482951, 2147482949, 2147482943, 2147482937, 2147482921,
2147482877, 2147482873, 2147482867, 2147482859, 2147482819, 2147482817, 2147482811, 2147482801,
2147482763, 2147482739, 2147482697, 2147482693, 2147482681, 2147482663, 2147482661,
];
const PRIMES32: &'static [u64] = &[4294967291, 4294967279, 4294967231, 4294967197, 4294967189,
4294967161, 4294967143, 4294967111, 4294967087, 4294967029,
4294966997, 4294966981, 4294966943, 4294966927, 4294966909,
4294966877, 4294966829, 4294966813, 4294966769, 4294966667,
4294966661, 4294966657, 4294966651, 4294966639, 4294966619,
4294966591, 4294966583, 4294966553, 4294966477, 4294966447,
4294966441, 4294966427, 4294966373, 4294966367, 4294966337,
4294966297];
const PRIMES32: &'static [u64] = &[
4294967291, 4294967279, 4294967231, 4294967197, 4294967189, 4294967161, 4294967143, 4294967111,
4294967087, 4294967029, 4294966997, 4294966981, 4294966943, 4294966927, 4294966909, 4294966877,
4294966829, 4294966813, 4294966769, 4294966667, 4294966661, 4294966657, 4294966651, 4294966639,
4294966619, 4294966591, 4294966583, 4294966553, 4294966477, 4294966447, 4294966441, 4294966427,
4294966373, 4294966367, 4294966337, 4294966297,
];
const PRIMES33: &'static [u64] = &[8589934583, 8589934567, 8589934543, 8589934513, 8589934487,
8589934307, 8589934291, 8589934289, 8589934271, 8589934237,
8589934211, 8589934207, 8589934201, 8589934187, 8589934151,
8589934141, 8589934139, 8589934117, 8589934103, 8589934099,
8589934091, 8589934069, 8589934049, 8589934027, 8589934007,
8589933973, 8589933971, 8589933967, 8589933931, 8589933917,
8589933907, 8589933853, 8589933827, 8589933823, 8589933787,
8589933773, 8589933733, 8589933731, 8589933721, 8589933683,
8589933647, 8589933641, 8589933637, 8589933631, 8589933629,
8589933619, 8589933601, 8589933581];
const PRIMES33: &'static [u64] = &[
8589934583, 8589934567, 8589934543, 8589934513, 8589934487, 8589934307, 8589934291, 8589934289,
8589934271, 8589934237, 8589934211, 8589934207, 8589934201, 8589934187, 8589934151, 8589934141,
8589934139, 8589934117, 8589934103, 8589934099, 8589934091, 8589934069, 8589934049, 8589934027,
8589934007, 8589933973, 8589933971, 8589933967, 8589933931, 8589933917, 8589933907, 8589933853,
8589933827, 8589933823, 8589933787, 8589933773, 8589933733, 8589933731, 8589933721, 8589933683,
8589933647, 8589933641, 8589933637, 8589933631, 8589933629, 8589933619, 8589933601, 8589933581,
];
const PRIMES34: &'static [u64] = &[17179869143,
const PRIMES34: &'static [u64] = &[
17179869143,
17179869107,
17179869071,
17179869053,
@ -499,9 +477,11 @@ const PRIMES34: &'static [u64] = &[17179869143,
17179868287,
17179868249,
17179868243,
17179868183];
17179868183,
];
const PRIMES35: &'static [u64] = &[34359738337,
const PRIMES35: &'static [u64] = &[
34359738337,
34359738319,
34359738307,
34359738299,
@ -530,9 +510,11 @@ const PRIMES35: &'static [u64] = &[34359738337,
34359737479,
34359737407,
34359737393,
34359737371];
34359737371,
];
const PRIMES36: &'static [u64] = &[68719476731,
const PRIMES36: &'static [u64] = &[
68719476731,
68719476719,
68719476713,
68719476671,
@ -580,9 +562,11 @@ const PRIMES36: &'static [u64] = &[68719476731,
68719475771,
68719475767,
68719475731,
68719475729];
68719475729,
];
const PRIMES37: &'static [u64] = &[137438953447,
const PRIMES37: &'static [u64] = &[
137438953447,
137438953441,
137438953427,
137438953403,
@ -604,9 +588,11 @@ const PRIMES37: &'static [u64] = &[137438953447,
137438952611,
137438952529,
137438952503,
137438952491];
137438952491,
];
const PRIMES38: &'static [u64] = &[274877906899,
const PRIMES38: &'static [u64] = &[
274877906899,
274877906857,
274877906837,
274877906813,
@ -642,9 +628,11 @@ const PRIMES38: &'static [u64] = &[274877906899,
274877906063,
274877906053,
274877906021,
274877905931];
274877905931,
];
const PRIMES39: &'static [u64] = &[549755813881,
const PRIMES39: &'static [u64] = &[
549755813881,
549755813869,
549755813821,
549755813797,
@ -686,9 +674,11 @@ const PRIMES39: &'static [u64] = &[549755813881,
549755812937,
549755812933,
549755812889,
549755812867];
549755812867,
];
const PRIMES40: &'static [u64] = &[1099511627689,
const PRIMES40: &'static [u64] = &[
1099511627689,
1099511627609,
1099511627581,
1099511627573,
@ -714,9 +704,11 @@ const PRIMES40: &'static [u64] = &[1099511627689,
1099511626937,
1099511626793,
1099511626781,
1099511626771];
1099511626771,
];
const PRIMES41: &'static [u64] = &[2199023255531,
const PRIMES41: &'static [u64] = &[
2199023255531,
2199023255521,
2199023255497,
2199023255489,
@ -751,9 +743,11 @@ const PRIMES41: &'static [u64] = &[2199023255531,
2199023254699,
2199023254693,
2199023254657,
2199023254567];
2199023254567,
];
const PRIMES42: &'static [u64] = &[4398046511093,
const PRIMES42: &'static [u64] = &[
4398046511093,
4398046511087,
4398046511071,
4398046511051,
@ -789,9 +783,11 @@ const PRIMES42: &'static [u64] = &[4398046511093,
4398046510141,
4398046510133,
4398046510103,
4398046510093];
4398046510093,
];
const PRIMES43: &'static [u64] = &[8796093022151,
const PRIMES43: &'static [u64] = &[
8796093022151,
8796093022141,
8796093022091,
8796093022033,
@ -822,9 +818,11 @@ const PRIMES43: &'static [u64] = &[8796093022151,
8796093021347,
8796093021337,
8796093021281,
8796093021269];
8796093021269,
];
const PRIMES44: &'static [u64] = &[17592186044399,
const PRIMES44: &'static [u64] = &[
17592186044399,
17592186044299,
17592186044297,
17592186044287,
@ -853,9 +851,11 @@ const PRIMES44: &'static [u64] = &[17592186044399,
17592186043483,
17592186043451,
17592186043433,
17592186043409];
17592186043409,
];
const PRIMES45: &'static [u64] = &[35184372088777,
const PRIMES45: &'static [u64] = &[
35184372088777,
35184372088763,
35184372088751,
35184372088739,
@ -892,9 +892,11 @@ const PRIMES45: &'static [u64] = &[35184372088777,
35184372087923,
35184372087881,
35184372087877,
35184372087869];
35184372087869,
];
const PRIMES46: &'static [u64] = &[70368744177643,
const PRIMES46: &'static [u64] = &[
70368744177643,
70368744177607,
70368744177601,
70368744177587,
@ -925,9 +927,11 @@ const PRIMES46: &'static [u64] = &[70368744177643,
70368744176777,
70368744176729,
70368744176719,
70368744176711];
70368744176711,
];
const PRIMES47: &'static [u64] = &[140737488355213,
const PRIMES47: &'static [u64] = &[
140737488355213,
140737488355201,
140737488355181,
140737488355049,
@ -945,9 +949,11 @@ const PRIMES47: &'static [u64] = &[140737488355213,
140737488354409,
140737488354373,
140737488354347,
140737488354329];
140737488354329,
];
const PRIMES48: &'static [u64] = &[281474976710597,
const PRIMES48: &'static [u64] = &[
281474976710597,
281474976710591,
281474976710567,
281474976710563,
@ -976,9 +982,11 @@ const PRIMES48: &'static [u64] = &[281474976710597,
281474976709741,
281474976709711,
281474976709649,
281474976709637];
281474976709637,
];
const PRIMES49: &'static [u64] = &[562949953421231,
const PRIMES49: &'static [u64] = &[
562949953421231,
562949953421201,
562949953421189,
562949953421173,
@ -1008,9 +1016,11 @@ const PRIMES49: &'static [u64] = &[562949953421231,
562949953420369,
562949953420343,
562949953420303,
562949953420297];
562949953420297,
];
const PRIMES50: &'static [u64] = &[1125899906842597,
const PRIMES50: &'static [u64] = &[
1125899906842597,
1125899906842589,
1125899906842573,
1125899906842553,
@ -1046,4 +1056,5 @@ const PRIMES50: &'static [u64] = &[1125899906842597,
1125899906841673,
1125899906841653,
1125899906841623,
1125899906841613];
1125899906841613,
];

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,5 @@
use common::util::*;
#[test]
fn test_link_existing_file() {
let (at, mut ucmd) = at_and_ucmd!();
@ -22,7 +21,8 @@ fn test_link_no_circular() {
let (at, mut ucmd) = at_and_ucmd!();
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");
assert!(!at.file_exists(link));
}
@ -33,7 +33,8 @@ fn test_link_nonexistent_file() {
let file = "test_link_nonexistent_file";
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");
assert!(!at.file_exists(file));
assert!(!at.file_exists(link));

View file

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

View file

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

View file

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

View file

@ -2,7 +2,6 @@ use common::util::*;
extern crate tempdir;
use self::tempdir::TempDir;
static TEST_TEMPLATE1: &'static str = "tempXXXXXX";
static TEST_TEMPLATE2: &'static str = "temp";
static TEST_TEMPLATE3: &'static str = "tempX";
@ -23,14 +22,46 @@ fn test_mktemp_mktemp() {
let pathname = scene.fixtures.as_string();
scene.ucmd().env(TMPDIR, &pathname).arg(TEST_TEMPLATE1).succeeds();
scene.ucmd().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();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg(TEST_TEMPLATE1)
.succeeds();
scene
.ucmd()
.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]
@ -39,14 +70,54 @@ fn test_mktemp_make_temp_dir() {
let pathname = scene.fixtures.as_string();
scene.ucmd().env(TMPDIR, &pathname).arg("-d").arg(TEST_TEMPLATE1).succeeds();
scene.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();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-d")
.arg(TEST_TEMPLATE1)
.succeeds();
scene
.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]
@ -55,25 +126,77 @@ fn test_mktemp_dry_run() {
let pathname = scene.fixtures.as_string();
scene.ucmd().env(TMPDIR, &pathname).arg("-u").arg(TEST_TEMPLATE1).succeeds();
scene.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();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("-u")
.arg(TEST_TEMPLATE1)
.succeeds();
scene
.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]
fn test_mktemp_quiet() {
let scene = TestScenario::new(util_name!());
scene.ucmd().arg("-p").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();
scene
.ucmd()
.arg("-p")
.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]
@ -82,14 +205,62 @@ fn test_mktemp_suffix() {
let pathname = scene.fixtures.as_string();
scene.ucmd().env(TMPDIR, &pathname).arg("--suffix").arg("suf").arg(TEST_TEMPLATE1).succeeds();
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();
scene
.ucmd()
.env(TMPDIR, &pathname)
.arg("--suffix")
.arg("suf")
.arg(TEST_TEMPLATE1)
.succeeds();
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]
@ -99,12 +270,52 @@ fn test_mktemp_tmpdir() {
let path = TempDir::new_in(scene.fixtures.as_string(), util_name!()).unwrap();
let pathname = path.path().as_os_str();
scene.ucmd().arg("-p").arg(pathname).arg(TEST_TEMPLATE1).succeeds();
scene.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();
scene
.ucmd()
.arg("-p")
.arg(pathname)
.arg(TEST_TEMPLATE1)
.succeeds();
scene
.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 time;
use self::filetime::*;
use common::util::*;
#[test]
fn test_mv_rename_dir() {
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)));
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!("{}/{}", dir2, file)));
@ -79,7 +81,13 @@ fn test_mv_strip_slashes() {
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)));
}
@ -95,7 +103,11 @@ fn test_mv_multiple_files() {
at.touch(file_a);
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_b)));
@ -112,7 +124,11 @@ fn test_mv_multiple_folders() {
at.mkdir(dir_a);
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_b)));
@ -128,14 +144,26 @@ fn test_mv_interactive() {
at.touch(file_a);
at.touch(file_b);
scene.ucmd().arg("-i").arg(file_a).arg(file_b).pipe_in("n").succeeds().no_stderr();
scene
.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_b));
scene.ucmd().arg("-i").arg(file_a).arg(file_b).pipe_in("Yesh").succeeds().no_stderr();
scene
.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_b));
@ -150,7 +178,11 @@ fn test_mv_no_clobber() {
at.touch(file_a);
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_b));
@ -180,7 +212,11 @@ fn test_mv_force_replace_file() {
at.touch(file_a);
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_b));
@ -194,7 +230,11 @@ fn test_mv_simple_backup() {
at.touch(file_a);
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_b));
@ -214,7 +254,8 @@ fn test_mv_custom_backup_suffix() {
.arg(format!("--suffix={}", suffix))
.arg(file_a)
.arg(file_b)
.succeeds().no_stderr();
.succeeds()
.no_stderr();
assert!(!at.file_exists(file_a));
assert!(at.file_exists(file_b));
@ -233,7 +274,8 @@ fn test_mv_custom_backup_suffix_via_env() {
.env("SIMPLE_BACKUP_SUFFIX", suffix)
.arg(file_a)
.arg(file_b)
.succeeds().no_stderr();
.succeeds()
.no_stderr();
assert!(!at.file_exists(file_a));
assert!(at.file_exists(file_b));
@ -248,7 +290,11 @@ fn test_mv_backup_numbering() {
at.touch(file_a);
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_b));
@ -266,7 +312,11 @@ fn test_mv_existing_backup() {
at.touch(file_a);
at.touch(file_b);
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_b));
@ -294,7 +344,13 @@ fn test_mv_update_option() {
assert!(at.file_exists(file_a));
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_b));
@ -310,7 +366,12 @@ fn test_mv_target_dir() {
at.touch(file_a);
at.touch(file_b);
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_b));
@ -348,7 +409,16 @@ fn test_mv_overwrite_nonempty_dir() {
// GNU: "mv: cannot move a to b: Directory not empty"
// 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_b));
@ -362,11 +432,14 @@ fn test_mv_backup_dir() {
at.mkdir(dir_a);
at.mkdir(dir_b);
ucmd.arg("-vbT").arg(dir_a).arg(dir_b).succeeds()
.stdout_only(format!("{} -> {} (backup: {}~)\n",
dir_a,
dir_b,
dir_b));
ucmd.arg("-vbT")
.arg(dir_a)
.arg(dir_b)
.succeeds()
.stdout_only(format!(
"{} -> {} (backup: {}~)\n",
dir_a, dir_b, dir_b
));
assert!(!at.dir_exists(dir_a));
assert!(at.dir_exists(dir_b));
@ -386,15 +459,31 @@ fn test_mv_errors() {
// $ mv -T -t a b
// 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()
.stderr_is("mv: error: cannot combine --target-directory (-t) and --no-target-directory (-T)\n");
scene
.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
// $ mv -T file dir
// err == mv: cannot overwrite directory dir with non-directory
scene.ucmd().arg("-T").arg(file_a).arg(dir).fails()
.stderr_is(format!("mv: error: cannot overwrite directory {} with non-directory\n",
dir));
scene
.ucmd()
.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
// $ mv dir file
@ -413,15 +502,25 @@ fn test_mv_verbose() {
at.touch(file_a);
at.touch(file_b);
scene.ucmd().arg("-v").arg(file_a).arg(file_b).succeeds()
scene
.ucmd()
.arg("-v")
.arg(file_a)
.arg(file_b)
.succeeds()
.stdout_only(format!("{} -> {}\n", file_a, file_b));
at.touch(file_a);
scene.ucmd().arg("-vb").arg(file_a).arg(file_b).succeeds()
.stdout_only(format!("{} -> {} (backup: {}~)\n",
file_a,
file_b,
file_b));
scene
.ucmd()
.arg("-vb")
.arg(file_a)
.arg(file_b)
.succeeds()
.stdout_only(format!(
"{} -> {} (backup: {}~)\n",
file_a, file_b, file_b
));
}
// Todo:

View file

@ -1,9 +1,11 @@
use common::util::*;
#[test]
fn test_stdin_nonewline() {
new_ucmd!().pipe_in("No Newline").run().stdout_is(" 1\tNo Newline\n");
new_ucmd!()
.pipe_in("No Newline")
.run()
.stdout_is(" 1\tNo Newline\n");
}
#[test]
fn test_stdin_newline() {
@ -17,36 +19,47 @@ fn test_stdin_newline() {
#[test]
fn test_padding_without_overflow() {
new_ucmd!()
.args(&["-i", "1000", "-s", "x", "-n", "rz", "simple.txt"]).run()
.args(&["-i", "1000", "-s", "x", "-n", "rz", "simple.txt"])
.run()
.stdout_is(
"000001xL1\n001001xL2\n002001xL3\n003001xL4\n004001xL5\n005001xL6\n006001xL7\n0070\
01xL8\n008001xL9\n009001xL10\n010001xL11\n011001xL12\n012001xL13\n013001xL14\n014\
001xL15\n");
001xL15\n",
);
}
#[test]
fn test_padding_with_overflow() {
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(
"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]
fn test_sections_and_styles() {
for &(fixture, output) in &[("section.txt",
for &(fixture, output) in &[
(
"section.txt",
"\nHEADER1\nHEADER2\n\n1 |BODY1\n2 \
|BODY2\n\nFOOTER1\nFOOTER2\n\nNEXTHEADER1\nNEXTHEADER2\n\n1 \
|NEXTBODY1\n2 |NEXTBODY2\n\nNEXTFOOTER1\nNEXTFOOTER2\n"),
("joinblanklines.txt",
|NEXTBODY1\n2 |NEXTBODY2\n\nNEXTFOOTER1\nNEXTFOOTER2\n",
),
(
"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 \
|Followed by 4x empty\n\n\n\n\n9 |Nonempty\n10 |Nonempty\n11 \
|Nonempty.\n")]
{
|Nonempty.\n",
),
] {
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()
.stdout_is(output);
}

View file

@ -1,13 +1,12 @@
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 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'
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!(result.success);
@ -51,18 +53,22 @@ fn test_2files() {
let file1 = tmpdir.join("test1");
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);
}
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();
if f.write_all(data.as_bytes()).is_err() {
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!(result.success);
@ -88,7 +94,9 @@ fn test_no_file() {
#[test]
fn test_from_stdin() {
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!(result.success);
@ -103,15 +111,20 @@ fn test_from_mixed() {
let file1 = tmpdir.join("test-1");
let file3 = tmpdir.join("test-3");
let (data1, data2, data3) = ("abcdefg","hijklmnop","qrstuvwxyz\n");
for &(path,data)in &[(&file1, data1),(&file3, data3)] {
let (data1, data2, data3) = ("abcdefg", "hijklmnop", "qrstuvwxyz\n");
for &(path, data) in &[(&file1, data1), (&file3, data3)] {
let mut f = File::create(&path).unwrap();
if f.write_all(data.as_bytes()).is_err() {
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!(result.success);
@ -121,34 +134,42 @@ fn test_from_mixed() {
#[test]
fn test_multiple_formats() {
let input = "abcdefghijklmnopqrstuvwxyz\n";
let result = new_ucmd!().arg("-c").arg("-b").run_piped_stdin(input.as_bytes());
let result = new_ucmd!()
.arg("-c")
.arg("-b")
.run_piped_stdin(input.as_bytes());
assert_empty_stderr!(result);
assert!(result.success);
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
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
161 162 163 164 165 166 167 170 171 172 012
0000033
"));
"
)
);
}
#[test]
fn test_dec() {
let input = [
0u8, 0u8,
1u8, 0u8,
2u8, 0u8,
3u8, 0u8,
0xffu8,0x7fu8,
0x00u8,0x80u8,
0x01u8,0x80u8,];
let expected_output = unindent("
0u8, 0u8, 1u8, 0u8, 2u8, 0u8, 3u8, 0u8, 0xffu8, 0x7fu8, 0x00u8, 0x80u8, 0x01u8, 0x80u8,
];
let expected_output = unindent(
"
0000000 0 1 2 3 32767 -32768 -32767
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!(result.success);
@ -156,14 +177,18 @@ fn test_dec() {
}
#[test]
fn test_hex16(){
let input: [u8; 9] = [
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xff];
let expected_output = unindent("
fn test_hex16() {
let input: [u8; 9] = [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xff];
let expected_output = unindent(
"
0000000 2301 6745 ab89 efcd 00ff
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!(result.success);
@ -171,14 +196,18 @@ fn test_hex16(){
}
#[test]
fn test_hex32(){
let input: [u8; 9] = [
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xff];
let expected_output = unindent("
fn test_hex32() {
let input: [u8; 9] = [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xff];
let expected_output = unindent(
"
0000000 67452301 efcdab89 000000ff
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!(result.success);
@ -186,7 +215,7 @@ fn test_hex32(){
}
#[test]
fn test_f16(){
fn test_f16() {
let input: [u8; 14] = [
0x00, 0x3c, // 0x3C00 1.0
0x00, 0x00, // 0x0000 0.0
@ -194,13 +223,20 @@ fn test_f16(){
0x00, 0x7c, // 0x7C00 Inf
0x00, 0xfc, // 0xFC00 -Inf
0x00, 0xfe, // 0xFE00 NaN
0x00, 0x84];// 0x8400 -6.104e-5
let expected_output = unindent("
0x00, 0x84,
]; // 0x8400 -6.104e-5
let expected_output = unindent(
"
0000000 1.000 0 -0 inf
0000010 -inf NaN -6.104e-5
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!(result.success);
@ -208,7 +244,7 @@ fn test_f16(){
}
#[test]
fn test_f32(){
fn test_f32() {
let input: [u8; 28] = [
0x52, 0x06, 0x9e, 0xbf, // 0xbf9e0652 -1.2345679
0x4e, 0x61, 0x3c, 0x4b, // 0x4b3c614e 12345678
@ -216,13 +252,19 @@ fn test_f32(){
0x00, 0x00, 0x00, 0x80, // 0x80000000 -0.0
0xff, 0xff, 0xff, 0x7f, // 0x7fffffff NaN
0xc2, 0x16, 0x01, 0x00, // 0x000116c2 1e-40
0x00, 0x00, 0x7f, 0x80];// 0x807f0000 -1.1663108E-38
let expected_output = unindent("
0x00, 0x00, 0x7f, 0x80,
]; // 0x807f0000 -1.1663108E-38
let expected_output = unindent(
"
0000000 -1.2345679 12345678 -9.8765427e37 -0
0000020 NaN 1e-40 -1.1663108e-38
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!(result.success);
@ -230,20 +272,29 @@ fn test_f32(){
}
#[test]
fn test_f64(){
fn test_f64() {
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, 0x10, 0x80, // 0x8010000000000000 -2.2250738585072014e-308
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0000000000000001 5e-324 (subnormal)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0];// 0xc000000000000000 -2
let expected_output = unindent("
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
0x80, // 0x8010000000000000 -2.2250738585072014e-308
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 0x0000000000000001 5e-324 (subnormal)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
]; // 0xc000000000000000 -2
let expected_output = unindent(
"
0000000 12345678912345678 0
0000020 -2.2250738585072014e-308 5e-324
0000040 -2.0000000000000000
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!(result.success);
@ -252,26 +303,36 @@ fn test_f64(){
#[test]
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!(result.success);
assert_eq!(result.stdout, unindent("
assert_eq!(
result.stdout,
unindent(
"
0000000 U n i v e r s i t ä ** t
0000014 T ü ** b i n g e n \u{1B000}
0000030 ** ** **
0000033
"));
"
)
);
}
#[test]
fn test_width(){
fn test_width() {
let input: [u8; 8] = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
let expected_output = unindent("
let expected_output = unindent(
"
0000000 000000 000000
0000004 000000 000000
0000010
");
",
);
let result = new_ucmd!().arg("-w4").arg("-v").run_piped_stdin(&input[..]);
@ -281,40 +342,50 @@ fn test_width(){
}
#[test]
fn test_invalid_width(){
fn test_invalid_width() {
let input: [u8; 4] = [0x00, 0x00, 0x00, 0x00];
let expected_output = unindent("
let expected_output = unindent(
"
0000000 000000
0000002 000000
0000004
");
",
);
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_eq!(result.stdout, expected_output);
}
#[test]
fn test_zero_width(){
fn test_zero_width() {
let input: [u8; 4] = [0x00, 0x00, 0x00, 0x00];
let expected_output = unindent("
let expected_output = unindent(
"
0000000 000000
0000002 000000
0000004
");
",
);
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_eq!(result.stdout, expected_output);
}
#[test]
fn test_width_without_value(){
let input: [u8; 40] = [0 ; 40];
fn test_width_without_value() {
let input: [u8; 40] = [0; 40];
let expected_output = unindent("
0000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000
0000040 000000 000000 000000 000000
@ -329,20 +400,13 @@ fn test_width_without_value(){
}
#[test]
fn test_suppress_duplicates(){
fn test_suppress_duplicates() {
let input: [u8; 41] = [
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];
let expected_output = unindent("
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,
];
let expected_output = unindent(
"
0000000 00000000000
0000 0000
*
@ -354,9 +418,14 @@ fn test_suppress_duplicates(){
0000050 00000000000
0000
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!(result.success);
@ -365,18 +434,25 @@ fn test_suppress_duplicates(){
#[test]
fn test_big_endian() {
let input: [u8; 8] = [
0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];// 0xc000000000000000 -2
let input: [u8; 8] = [0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; // 0xc000000000000000 -2
let expected_output = unindent("
let expected_output = unindent(
"
0000000 -2.0000000000000000
-2.0000000 0
c0000000 00000000
c000 0000 0000 0000
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!(result.success);
@ -386,18 +462,24 @@ fn test_big_endian() {
#[test]
#[allow(non_snake_case)]
fn test_alignment_Xxa() {
let input: [u8; 8] = [
0x0A, 0x0D, 0x65, 0x66, 0x67, 0x00, 0x9e, 0x9f];
let input: [u8; 8] = [0x0A, 0x0D, 0x65, 0x66, 0x67, 0x00, 0x9e, 0x9f];
let expected_output = unindent("
let expected_output = unindent(
"
0000000 66650d0a 9f9e0067
0d0a 6665 0067 9f9e
nl cr e f g nul rs us
0000010
");
",
);
// 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!(result.success);
@ -407,17 +489,22 @@ fn test_alignment_Xxa() {
#[test]
#[allow(non_snake_case)]
fn test_alignment_Fx() {
let input: [u8; 8] = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0];// 0xc000000000000000 -2
let input: [u8; 8] = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0]; // 0xc000000000000000 -2
let expected_output = unindent("
let expected_output = unindent(
"
0000000 -2.0000000000000000
0000 0000 0000 c000
0000010
");
",
);
// 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!(result.success);
@ -425,9 +512,10 @@ fn test_alignment_Fx() {
}
#[test]
fn test_maxuint(){
let input = [0xFFu8 ; 8];
let expected_output = unindent("
fn test_maxuint() {
let input = [0xFFu8; 8];
let expected_output = unindent(
"
0000000 1777777777777777777777
37777777777 37777777777
177777 177777 177777 177777
@ -437,9 +525,15 @@ fn test_maxuint(){
65535 65535 65535 65535
255 255 255 255 255 255 255 255
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!(result.success);
@ -447,17 +541,23 @@ fn test_maxuint(){
}
#[test]
fn test_hex_offset(){
let input = [0u8 ; 0x1F];
let expected_output = unindent("
fn test_hex_offset() {
let input = [0u8; 0x1F];
let expected_output = unindent(
"
000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000
000010 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000
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!(result.success);
@ -465,17 +565,23 @@ fn test_hex_offset(){
}
#[test]
fn test_dec_offset(){
let input = [0u8 ; 19];
let expected_output = unindent("
fn test_dec_offset() {
let input = [0u8; 19];
let expected_output = unindent(
"
0000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000
0000016 00000000
00000000
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!(result.success);
@ -483,12 +589,16 @@ fn test_dec_offset(){
}
#[test]
fn test_no_offset(){
let input = [0u8 ; 31];
fn test_no_offset() {
let input = [0u8; 31];
const LINE: &'static str = " 00000000 00000000 00000000 00000000\n";
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!(result.success);
@ -496,37 +606,50 @@ fn test_no_offset(){
}
#[test]
fn test_invalid_offset(){
fn test_invalid_offset() {
let result = new_ucmd!().arg("-Ab").run();
assert!(!result.success);
}
#[test]
fn test_skip_bytes(){
fn test_skip_bytes() {
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!(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
0000021
"));
"
)
);
}
#[test]
fn test_skip_bytes_error(){
fn test_skip_bytes_error() {
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);
}
#[test]
fn test_read_bytes(){
fn test_read_bytes() {
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!(result.success);
@ -534,15 +657,19 @@ fn test_read_bytes(){
}
#[test]
fn test_ascii_dump(){
fn test_ascii_dump() {
let input: [u8; 22] = [
0x00, 0x01, 0x0a, 0x0d, 0x10, 0x1f, 0x20, 0x61, 0x62, 0x63, 0x7d,
0x7e, 0x7f, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0xff];
0x00, 0x01, 0x0a, 0x0d, 0x10, 0x1f, 0x20, 0x61, 0x62, 0x63, 0x7d, 0x7e, 0x7f, 0x80, 0x90,
0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0xff,
];
let result = new_ucmd!().arg("-tx1zacz").run_piped_stdin(&input[..]);
assert_empty_stderr!(result);
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}~....<
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}~....<
@ -550,113 +677,190 @@ fn test_ascii_dump(){
0 @ P ` p del
** 300 320 340 360 377 >......<
0000026
"));
"
)
);
}
#[test]
fn test_filename_parsing(){
fn test_filename_parsing() {
// 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
// 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!(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
000010 f nl
000012
"));
"
)
);
}
#[test]
fn test_stdin_offset(){
fn test_stdin_offset() {
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!(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
0000021
"));
"
)
);
}
#[test]
fn test_file_offset(){
fn test_file_offset() {
let result = new_ucmd!().arg("-c").arg("--").arg("-f").arg("10").run();
assert_empty_stderr!(result);
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
0000022
"));
"
)
);
}
#[test]
fn test_traditional(){
fn test_traditional() {
// note gnu od does not align both lines
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!(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
i j k l m n o p q
0000021 (0000011)
"));
"
)
);
}
#[test]
fn test_traditional_with_skip_bytes_override(){
fn test_traditional_with_skip_bytes_override() {
// --skip-bytes is ignored in this case
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!(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
0000020
"));
"
)
);
}
#[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
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!(result.success);
assert_eq!(result.stdout, unindent(r"
assert_eq!(
result.stdout,
unindent(
r"
0000012 k l m n o p
0000020
"));
"
)
);
}
#[test]
fn test_traditional_error(){
fn test_traditional_error() {
// 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);
}
#[test]
fn test_traditional_only_label(){
fn test_traditional_only_label() {
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!(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
i j k l m n o p q r s t u v w x
(0000040) y z
y z
(0000042)
"));
"
)
);
}

View file

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

View file

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

View file

@ -20,18 +20,18 @@ fn test_long_format() {
let ulogin = "root";
let pw: Passwd = Passwd::locate(ulogin).unwrap();
let real_name = pw.user_info().replace("&", &pw.name().capitalize());
new_ucmd!()
.arg("-l").arg(ulogin)
.run()
.stdout_is(format!("Login name: {:<28}In real life: {}\nDirectory: {:<29}Shell: {}\n\n",
ulogin, real_name, pw.user_dir(), pw.user_shell()));
new_ucmd!().arg("-l").arg(ulogin).run().stdout_is(format!(
"Login name: {:<28}In real life: {}\nDirectory: {:<29}Shell: {}\n\n",
ulogin,
real_name,
pw.user_dir(),
pw.user_shell()
));
new_ucmd!()
.arg("-lb")
.arg(ulogin)
.run()
.stdout_is(format!("Login name: {:<28}In real life: {1}\n\n",
ulogin, real_name));
new_ucmd!().arg("-lb").arg(ulogin).run().stdout_is(format!(
"Login name: {:<28}In real life: {1}\n\n",
ulogin, real_name
));
}
#[cfg(target_os = "linux")]
@ -40,7 +40,11 @@ fn test_short_format_i() {
// allow whitespace variation
// * minor whitespace differences occur between platform built-in outputs; specifically, the number of trailing TABs may be variant
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);
println!("actual: {:?}", actual);
println!("expect: {:?}", expect);
@ -55,7 +59,11 @@ fn test_short_format_q() {
// allow whitespace variation
// * minor whitespace differences occur between platform built-in outputs; specifically, the number of trailing TABs may be variant
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);
println!("actual: {:?}", actual);
println!("expect: {:?}", expect);
@ -66,5 +74,10 @@ fn test_short_format_q() {
#[cfg(target_os = "linux")]
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::*;
#[test]
fn basic_literal() {
new_ucmd!().args(&["hello world"]).succeeds().stdout_only("hello world");
new_ucmd!()
.args(&["hello world"])
.succeeds()
.stdout_only("hello world");
}
#[test]
fn escaped_tab() {
new_ucmd!().args(&["hello\\t world"]).succeeds().stdout_only("hello\t world");
new_ucmd!()
.args(&["hello\\t world"])
.succeeds()
.stdout_only("hello\t world");
}
#[test]
fn escaped_newline() {
new_ucmd!().args(&["hello\\n world"]).succeeds().stdout_only("hello\n world");
new_ucmd!()
.args(&["hello\\n world"])
.succeeds()
.stdout_only("hello\n world");
}
#[test]
fn escaped_slash() {
new_ucmd!().args(&["hello\\\\ world"]).succeeds().stdout_only("hello\\ world");
new_ucmd!()
.args(&["hello\\\\ world"])
.succeeds()
.stdout_only("hello\\ world");
}
#[test]
@ -38,12 +49,18 @@ fn escaped_unicode_fourdigit() {
#[test]
fn escaped_unicode_eightdigit() {
new_ucmd!().args(&["\\U00000125"]).succeeds().stdout_only("ĥ");
new_ucmd!()
.args(&["\\U00000125"])
.succeeds()
.stdout_only("ĥ");
}
#[test]
fn escaped_percent_sign() {
new_ucmd!().args(&["hello%% world"]).succeeds().stdout_only("hello% world");
new_ucmd!()
.args(&["hello%% world"])
.succeeds()
.stdout_only("hello% world");
}
#[test]
@ -53,227 +70,362 @@ fn escaped_unrecognized() {
#[test]
fn sub_string() {
new_ucmd!().args(&["hello %s", "world"]).succeeds().stdout_only("hello world");
new_ucmd!()
.args(&["hello %s", "world"])
.succeeds()
.stdout_only("hello world");
}
#[test]
fn sub_multifield() {
new_ucmd!().args(&["%s %s", "hello", "world"]).succeeds().stdout_only("hello world");
new_ucmd!()
.args(&["%s %s", "hello", "world"])
.succeeds()
.stdout_only("hello world");
}
#[test]
fn sub_repeat_formatstr() {
new_ucmd!().args(&["%s.", "hello", "world"]).succeeds().stdout_only("hello.world.");
new_ucmd!()
.args(&["%s.", "hello", "world"])
.succeeds()
.stdout_only("hello.world.");
}
#[test]
fn sub_string_ignore_escapes() {
new_ucmd!().args(&["hello %s", "\\tworld"]).succeeds().stdout_only("hello \\tworld");
new_ucmd!()
.args(&["hello %s", "\\tworld"])
.succeeds()
.stdout_only("hello \\tworld");
}
#[test]
fn sub_bstring_handle_escapes() {
new_ucmd!().args(&["hello %b", "\\tworld"]).succeeds().stdout_only("hello \tworld");
new_ucmd!()
.args(&["hello %b", "\\tworld"])
.succeeds()
.stdout_only("hello \tworld");
}
#[test]
fn sub_bstring_ignore_subs() {
new_ucmd!().args(&["hello %b", "world %% %i"]).succeeds().stdout_only("hello world %% %i");
new_ucmd!()
.args(&["hello %b", "world %% %i"])
.succeeds()
.stdout_only("hello world %% %i");
}
#[test]
fn sub_char() {
new_ucmd!().args(&["the letter %c", "A"]).succeeds().stdout_only("the letter A");
new_ucmd!()
.args(&["the letter %c", "A"])
.succeeds()
.stdout_only("the letter A");
}
#[test]
fn sub_num_int() {
new_ucmd!().args(&["twenty is %i", "20"]).succeeds().stdout_only("twenty is 20");
new_ucmd!()
.args(&["twenty is %i", "20"])
.succeeds()
.stdout_only("twenty is 20");
}
#[test]
fn sub_num_int_minwidth() {
new_ucmd!().args(&["twenty is %1i", "20"]).succeeds().stdout_only("twenty is 20");
new_ucmd!()
.args(&["twenty is %1i", "20"])
.succeeds()
.stdout_only("twenty is 20");
}
#[test]
fn sub_num_int_neg() {
new_ucmd!().args(&["neg. twenty is %i", "-20"]).succeeds().stdout_only("neg. twenty is -20");
new_ucmd!()
.args(&["neg. twenty is %i", "-20"])
.succeeds()
.stdout_only("neg. twenty is -20");
}
#[test]
fn sub_num_int_oct_in() {
new_ucmd!().args(&["twenty is %i", "024"]).succeeds().stdout_only("twenty is 20");
new_ucmd!()
.args(&["twenty is %i", "024"])
.succeeds()
.stdout_only("twenty is 20");
}
#[test]
fn sub_num_int_oct_in_neg() {
new_ucmd!().args(&["neg. twenty is %i", "-024"]).succeeds().stdout_only("neg. twenty is -20");
new_ucmd!()
.args(&["neg. twenty is %i", "-024"])
.succeeds()
.stdout_only("neg. twenty is -20");
}
#[test]
fn sub_num_int_hex_in() {
new_ucmd!().args(&["twenty is %i", "0x14"]).succeeds().stdout_only("twenty is 20");
new_ucmd!()
.args(&["twenty is %i", "0x14"])
.succeeds()
.stdout_only("twenty is 20");
}
#[test]
fn sub_num_int_hex_in_neg() {
new_ucmd!().args(&["neg. twenty is %i", "-0x14"]).succeeds().stdout_only("neg. twenty is -20");
new_ucmd!()
.args(&["neg. twenty is %i", "-0x14"])
.succeeds()
.stdout_only("neg. twenty is -20");
}
#[test]
fn sub_num_int_charconst_in() {
new_ucmd!().args(&["ninetyseven is %i", "'a"]).succeeds().stdout_only("ninetyseven is 97");
new_ucmd!()
.args(&["ninetyseven is %i", "'a"])
.succeeds()
.stdout_only("ninetyseven is 97");
}
#[test]
fn sub_num_uint() {
new_ucmd!().args(&["twenty is %u", "20"]).succeeds().stdout_only("twenty is 20");
new_ucmd!()
.args(&["twenty is %u", "20"])
.succeeds()
.stdout_only("twenty is 20");
}
#[test]
fn sub_num_octal() {
new_ucmd!().args(&["twenty in octal is %o", "20"]).succeeds().stdout_only("twenty in octal is 24");
new_ucmd!()
.args(&["twenty in octal is %o", "20"])
.succeeds()
.stdout_only("twenty in octal is 24");
}
#[test]
fn sub_num_hex_lower() {
new_ucmd!().args(&["thirty in hex is %x", "30"]).succeeds().stdout_only("thirty in hex is 1e");
new_ucmd!()
.args(&["thirty in hex is %x", "30"])
.succeeds()
.stdout_only("thirty in hex is 1e");
}
#[test]
fn sub_num_hex_upper() {
new_ucmd!().args(&["thirty in hex is %X", "30"]).succeeds().stdout_only("thirty in hex is 1E");
new_ucmd!()
.args(&["thirty in hex is %X", "30"])
.succeeds()
.stdout_only("thirty in hex is 1E");
}
#[test]
fn sub_num_float() {
new_ucmd!().args(&["twenty is %f", "20"]).succeeds().stdout_only("twenty is 20.000000");
new_ucmd!()
.args(&["twenty is %f", "20"])
.succeeds()
.stdout_only("twenty is 20.000000");
}
#[test]
fn sub_num_float_round() {
new_ucmd!().args(&["two is %f", "1.9999995"]).succeeds().stdout_only("two is 2.000000");
new_ucmd!()
.args(&["two is %f", "1.9999995"])
.succeeds()
.stdout_only("two is 2.000000");
}
#[test]
fn sub_num_sci_lower() {
new_ucmd!().args(&["twenty is %e", "20"]).succeeds().stdout_only("twenty is 2.000000e+01");
new_ucmd!()
.args(&["twenty is %e", "20"])
.succeeds()
.stdout_only("twenty is 2.000000e+01");
}
#[test]
fn sub_num_sci_upper() {
new_ucmd!().args(&["twenty is %E", "20"]).succeeds().stdout_only("twenty is 2.000000E+01");
new_ucmd!()
.args(&["twenty is %E", "20"])
.succeeds()
.stdout_only("twenty is 2.000000E+01");
}
#[test]
fn sub_num_sci_trunc() {
new_ucmd!().args(&["pi is ~ %e", "3.1415926535"]).succeeds().stdout_only("pi is ~ 3.141593e+00");
new_ucmd!()
.args(&["pi is ~ %e", "3.1415926535"])
.succeeds()
.stdout_only("pi is ~ 3.141593e+00");
}
#[test]
fn sub_num_dec_trunc() {
new_ucmd!().args(&["pi is ~ %g", "3.1415926535"]).succeeds().stdout_only("pi is ~ 3.141593");
new_ucmd!()
.args(&["pi is ~ %g", "3.1415926535"])
.succeeds()
.stdout_only("pi is ~ 3.141593");
}
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test]
fn sub_num_hex_float_lower() {
new_ucmd!().args(&["%a", ".875"]).succeeds().stdout_only("0xep-4");
new_ucmd!()
.args(&["%a", ".875"])
.succeeds()
.stdout_only("0xep-4");
}
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test]
fn sub_num_hex_float_upper() {
new_ucmd!().args(&["%A", ".875"]).succeeds().stdout_only("0XEP-4");
new_ucmd!()
.args(&["%A", ".875"])
.succeeds()
.stdout_only("0XEP-4");
}
#[test]
fn sub_minwidth() {
new_ucmd!().args(&["hello %7s", "world"]).succeeds().stdout_only("hello world");
new_ucmd!()
.args(&["hello %7s", "world"])
.succeeds()
.stdout_only("hello world");
}
#[test]
fn sub_minwidth_negative() {
new_ucmd!().args(&["hello %-7s", "world"]).succeeds().stdout_only("hello world ");
new_ucmd!()
.args(&["hello %-7s", "world"])
.succeeds()
.stdout_only("hello world ");
}
#[test]
fn sub_str_max_chars_input() {
new_ucmd!().args(&["hello %7.2s", "world"]).succeeds().stdout_only("hello wo");
new_ucmd!()
.args(&["hello %7.2s", "world"])
.succeeds()
.stdout_only("hello wo");
}
#[test]
fn sub_int_decimal() {
new_ucmd!().args(&["%0.i", "11"]).succeeds().stdout_only("11");
new_ucmd!()
.args(&["%0.i", "11"])
.succeeds()
.stdout_only("11");
}
#[test]
fn sub_int_leading_zeroes() {
new_ucmd!().args(&["%.4i", "11"]).succeeds().stdout_only("0011");
new_ucmd!()
.args(&["%.4i", "11"])
.succeeds()
.stdout_only("0011");
}
#[test]
fn sub_int_leading_zeroes_prio() {
new_ucmd!().args(&["%5.4i", "11"]).succeeds().stdout_only(" 0011");
new_ucmd!()
.args(&["%5.4i", "11"])
.succeeds()
.stdout_only(" 0011");
}
#[test]
fn sub_float_dec_places() {
new_ucmd!().args(&["pi is ~ %.11f", "3.1415926535"]).succeeds().stdout_only("pi is ~ 3.14159265350");
new_ucmd!()
.args(&["pi is ~ %.11f", "3.1415926535"])
.succeeds()
.stdout_only("pi is ~ 3.14159265350");
}
#[test]
fn sub_float_hex_in() {
new_ucmd!().args(&["%f", "0xF1.1F"]).succeeds().stdout_only("241.121094");
new_ucmd!()
.args(&["%f", "0xF1.1F"])
.succeeds()
.stdout_only("241.121094");
}
#[test]
fn sub_float_no_octal_in() {
new_ucmd!().args(&["%f", "077"]).succeeds().stdout_only("77.000000");
new_ucmd!()
.args(&["%f", "077"])
.succeeds()
.stdout_only("77.000000");
}
#[test]
fn sub_any_asterisk_firstparam() {
new_ucmd!().args(&["%*i", "3", "11", "4", "12"]).succeeds().stdout_only(" 11 12");
new_ucmd!()
.args(&["%*i", "3", "11", "4", "12"])
.succeeds()
.stdout_only(" 11 12");
}
#[test]
fn sub_any_asterisk_second_param() {
new_ucmd!().args(&["%.*i", "3", "11", "4", "12"]).succeeds().stdout_only("0110012");
new_ucmd!()
.args(&["%.*i", "3", "11", "4", "12"])
.succeeds()
.stdout_only("0110012");
}
#[test]
fn sub_any_asterisk_both_params() {
new_ucmd!().args(&["%*.*i", "4", "3", "11", "5", "4", "12"]).succeeds().stdout_only(" 011 0012");
new_ucmd!()
.args(&["%*.*i", "4", "3", "11", "5", "4", "12"])
.succeeds()
.stdout_only(" 011 0012");
}
#[test]
fn sub_any_asterisk_octal_arg() {
new_ucmd!().args(&["%.*i", "011", "12345678"]).succeeds().stdout_only("012345678");
new_ucmd!()
.args(&["%.*i", "011", "12345678"])
.succeeds()
.stdout_only("012345678");
}
#[test]
fn sub_any_asterisk_hex_arg() {
new_ucmd!().args(&["%.*i", "0xA", "123456789"]).succeeds().stdout_only("0123456789");
new_ucmd!()
.args(&["%.*i", "0xA", "123456789"])
.succeeds()
.stdout_only("0123456789");
}
#[test]
fn sub_any_specifiers_no_params() {
new_ucmd!().args(&["%ztlhLji", "3"]).succeeds().stdout_only("3");
new_ucmd!()
.args(&["%ztlhLji", "3"])
.succeeds()
.stdout_only("3");
}
#[test]
fn sub_any_specifiers_after_first_param() {
new_ucmd!().args(&["%0ztlhLji", "3"]).succeeds().stdout_only("3");
new_ucmd!()
.args(&["%0ztlhLji", "3"])
.succeeds()
.stdout_only("3");
}
#[test]
fn sub_any_specifiers_after_period() {
new_ucmd!().args(&["%0.ztlhLji", "3"]).succeeds().stdout_only("3");
new_ucmd!()
.args(&["%0.ztlhLji", "3"])
.succeeds()
.stdout_only("3");
}
#[test]
fn sub_any_specifiers_after_second_param() {
new_ucmd!().args(&["%0.0ztlhLji", "3"]).succeeds().stdout_only("3");
new_ucmd!()
.args(&["%0.0ztlhLji", "3"])
.succeeds()
.stdout_only("3");
}

View file

@ -1,44 +1,57 @@
use common::util::*;
#[test]
fn gnu_ext_disabled_roff_no_ref() {
new_ucmd!().args(&["-G", "-R", "input"])
.succeeds().stdout_only_fixture("gnu_ext_disabled_roff_no_ref.expected");
new_ucmd!()
.args(&["-G", "-R", "input"])
.succeeds()
.stdout_only_fixture("gnu_ext_disabled_roff_no_ref.expected");
}
#[test]
fn gnu_ext_disabled_roff_input_ref() {
new_ucmd!().args(&["-G", "-r", "-R", "input"])
.succeeds().stdout_only_fixture("gnu_ext_disabled_roff_input_ref.expected");
new_ucmd!()
.args(&["-G", "-r", "-R", "input"])
.succeeds()
.stdout_only_fixture("gnu_ext_disabled_roff_input_ref.expected");
}
#[test]
fn gnu_ext_disabled_roff_auto_ref() {
new_ucmd!().args(&["-G", "-A", "-R", "input"])
.succeeds().stdout_only_fixture("gnu_ext_disabled_roff_auto_ref.expected");
new_ucmd!()
.args(&["-G", "-A", "-R", "input"])
.succeeds()
.stdout_only_fixture("gnu_ext_disabled_roff_auto_ref.expected");
}
#[test]
fn gnu_ext_disabled_tex_no_ref() {
new_ucmd!().args(&["-G", "-T", "-R", "input"])
.succeeds().stdout_only_fixture("gnu_ext_disabled_tex_no_ref.expected");
new_ucmd!()
.args(&["-G", "-T", "-R", "input"])
.succeeds()
.stdout_only_fixture("gnu_ext_disabled_tex_no_ref.expected");
}
#[test]
fn gnu_ext_disabled_tex_input_ref() {
new_ucmd!().args(&["-G", "-T", "-r", "-R", "input"])
.succeeds().stdout_only_fixture("gnu_ext_disabled_tex_input_ref.expected");
new_ucmd!()
.args(&["-G", "-T", "-r", "-R", "input"])
.succeeds()
.stdout_only_fixture("gnu_ext_disabled_tex_input_ref.expected");
}
#[test]
fn gnu_ext_disabled_tex_auto_ref() {
new_ucmd!().args(&["-G", "-T", "-A", "-R", "input"])
.succeeds().stdout_only_fixture("gnu_ext_disabled_tex_auto_ref.expected");
new_ucmd!()
.args(&["-G", "-T", "-A", "-R", "input"])
.succeeds()
.stdout_only_fixture("gnu_ext_disabled_tex_auto_ref.expected");
}
#[test]
fn gnu_ext_disabled_ignore_and_only_file() {
new_ucmd!().args(&["-G", "-o", "only", "-i", "ignore", "input"])
.succeeds().stdout_only_fixture("gnu_ext_disabled_ignore_and_only_file.expected");
new_ucmd!()
.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::*;
#[test]
fn test_default() {
let (at, mut ucmd) = at_and_ucmd!();

View file

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

View file

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

View file

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

View file

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

View file

@ -1,26 +1,33 @@
use common::util::*;
#[test]
fn test_count_up() {
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]
fn test_count_down() {
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]
fn test_separator_and_terminator() {
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]
fn test_equalize_widths() {
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::*;
#[test]
fn test_numeric_floats_and_ints() {
test_helper("numeric_floats_and_ints", "-n");
@ -73,7 +71,8 @@ fn test_multiple_files() {
.arg("-n")
.arg("multiple_files1.txt")
.arg("multiple_files2.txt")
.succeeds().stdout_only_fixture("multiple_files.expected");
.succeeds()
.stdout_only_fixture("multiple_files.expected");
}
#[test]
@ -83,7 +82,8 @@ fn test_merge_interleaved() {
.arg("merge_ints_interleaved_1.txt")
.arg("merge_ints_interleaved_2.txt")
.arg("merge_ints_interleaved_3.txt")
.succeeds().stdout_only_fixture("merge_ints_interleaved.expected");
.succeeds()
.stdout_only_fixture("merge_ints_interleaved.expected");
}
#[test]
@ -97,7 +97,8 @@ fn test_merge_unique() {
.arg("merge_ints_interleaved_3.txt")
.arg("merge_ints_interleaved_2.txt")
.arg("merge_ints_interleaved_1.txt")
.succeeds().stdout_only_fixture("merge_ints_interleaved.expected");
.succeeds()
.stdout_only_fixture("merge_ints_interleaved.expected");
}
#[test]
@ -108,7 +109,8 @@ fn test_merge_reversed() {
.arg("merge_ints_reversed_1.txt")
.arg("merge_ints_reversed_2.txt")
.arg("merge_ints_reversed_3.txt")
.succeeds().stdout_only_fixture("merge_ints_reversed.expected");
.succeeds()
.stdout_only_fixture("merge_ints_reversed.expected");
}
#[test]
@ -116,15 +118,20 @@ fn test_check() {
new_ucmd!()
.arg("-c")
.arg("check_fail.txt")
.fails().stdout_is("sort: disorder in line 4\n");
.fails()
.stdout_is("sort: disorder in line 4\n");
new_ucmd!()
.arg("-c")
.arg("multiple_files.expected")
.succeeds().stdout_is("");
.succeeds()
.stdout_is("");
}
fn test_helper(file_name: &str, args: &str) {
new_ucmd!().arg(args).arg(format!("{}{}", file_name, ".txt"))
.succeeds().stdout_is_fixture(format!("{}{}", file_name, ".expected"));
new_ucmd!()
.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 regex;
use std::fs::{File, read_dir};
use std::io::Write;
use std::path::Path;
use self::rand::{Rng, thread_rng};
use self::rand::{thread_rng, Rng};
use self::regex::Regex;
use common::util::*;
use std::fs::{read_dir, File};
use std::io::Write;
use std::path::Path;
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 {
@ -35,7 +37,9 @@ impl Glob {
.unwrap()
.filter_map(|entry| {
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) {
Some(name)
} else {
@ -62,15 +66,13 @@ struct RandomFile {
impl 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) {
let chunk_size: usize = if bytes >= 1024 {
1024
} else {
bytes
};
let chunk_size: usize = if bytes >= 1024 { 1024 } else { bytes };
let mut n = bytes;
while n > chunk_size {
let _ = write!(self.inner, "{}", random_chars(chunk_size));

View file

@ -5,7 +5,6 @@ use common::util::*;
extern crate uu_stat;
pub use self::uu_stat::*;
#[cfg(test)]
mod test_fsext {
use super::*;
@ -18,20 +17,32 @@ mod test_fsext {
assert_eq!("lrw-r-xr-x", pretty_access(S_IFLNK | 0o655));
assert_eq!("?rw-r-xr-x", pretty_access(0o655));
assert_eq!("brwSr-xr-x",
pretty_access(S_IFBLK | S_ISUID as mode_t | 0o655));
assert_eq!("brwsr-xr-x",
pretty_access(S_IFBLK | S_ISUID as mode_t | 0o755));
assert_eq!(
"brwSr-xr-x",
pretty_access(S_IFBLK | S_ISUID as mode_t | 0o655)
);
assert_eq!(
"brwsr-xr-x",
pretty_access(S_IFBLK | S_ISUID as mode_t | 0o755)
);
assert_eq!("prw---sr--",
pretty_access(S_IFIFO | S_ISGID as mode_t | 0o614));
assert_eq!("prw---Sr--",
pretty_access(S_IFIFO | S_ISGID as mode_t | 0o604));
assert_eq!(
"prw---sr--",
pretty_access(S_IFIFO | S_ISGID as mode_t | 0o614)
);
assert_eq!(
"prw---Sr--",
pretty_access(S_IFIFO | S_ISGID as mode_t | 0o604)
);
assert_eq!("c---r-xr-t",
pretty_access(S_IFCHR | S_ISVTX as mode_t | 0o055));
assert_eq!("c---r-xr-T",
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 | 0o055)
);
assert_eq!(
"c---r-xr-T",
pretty_access(S_IFCHR | S_ISVTX as mode_t | 0o054)
);
}
#[test]
@ -90,7 +101,8 @@ mod test_generate_tokens {
#[test]
fn normal_format() {
let s = "%'010.2ac%-#5.w\n";
let expected = vec![Token::Directive {
let expected = vec![
Token::Directive {
flag: F_GROUP | F_ZERO,
width: 10,
precision: 2,
@ -103,14 +115,16 @@ mod test_generate_tokens {
precision: 0,
format: 'w',
},
Token::Char('\n')];
Token::Char('\n'),
];
assert_eq!(&expected, &Stater::generate_tokens(s, false).unwrap());
}
#[test]
fn printf_format() {
let s = "%-# 15a\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.-23w\\x12\\167\\132\\112\\n";
let expected = vec![Token::Directive {
let expected = vec![
Token::Directive {
flag: F_LEFT | F_ALTER | F_SPACE,
width: 15,
precision: -1,
@ -134,21 +148,23 @@ mod test_generate_tokens {
Token::Char('w'),
Token::Char('Z'),
Token::Char('J'),
Token::Char('\n')];
Token::Char('\n'),
];
assert_eq!(&expected, &Stater::generate_tokens(s, true).unwrap());
}
}
#[test]
fn test_invalid_option() {
new_ucmd!()
.arg("-w").arg("-q").arg("/").fails();
new_ucmd!().arg("-w").arg("-q").arg("/").fails();
}
#[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")]
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")]
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")]
fn test_terse_fs_format() {
let args = ["-f", "-t", "/proc"];
new_ucmd!().args(&args)
new_ucmd!()
.args(&args)
.run()
.stdout_is(expected_result(&args));
}
@ -165,7 +182,8 @@ fn test_terse_fs_format() {
#[cfg(target_os = "linux")]
fn test_fs_format() {
let args = ["-f", "-c", FS_FMTSTR, "/dev/shm"];
new_ucmd!().args(&args)
new_ucmd!()
.args(&args)
.run()
.stdout_is(expected_result(&args));
}
@ -183,7 +201,10 @@ fn test_terse_normal_format() {
let v_actual: Vec<&str> = actual.split(' ').collect();
let v_expect: Vec<&str> = expect.split(' ').collect();
// * 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]
@ -199,7 +220,10 @@ fn test_format_created_time() {
let v_actual: Vec<&str> = re.split(&actual).collect();
let v_expect: Vec<&str> = re.split(&expect).collect();
// * 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]
@ -215,14 +239,18 @@ fn test_format_created_seconds() {
let v_actual: Vec<&str> = re.split(&actual).collect();
let v_expect: Vec<&str> = re.split(&expect).collect();
// * 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]
#[cfg(target_os = "linux")]
fn test_normal_format() {
let args = ["-c", NORMAL_FMTSTR, "/boot"];
new_ucmd!().args(&args)
new_ucmd!()
.args(&args)
.run()
.stdout_is(expected_result(&args));
}
@ -231,7 +259,8 @@ fn test_normal_format() {
#[cfg(target_os = "linux")]
fn test_follow_symlink() {
let args = ["-L", "-c", DEV_FMTSTR, "/dev/cdrom"];
new_ucmd!().args(&args)
new_ucmd!()
.args(&args)
.run()
.stdout_is(expected_result(&args));
}
@ -240,7 +269,8 @@ fn test_follow_symlink() {
#[cfg(target_os = "linux")]
fn test_symlink() {
let args = ["-c", DEV_FMTSTR, "/dev/cdrom"];
new_ucmd!().args(&args)
new_ucmd!()
.args(&args)
.run()
.stdout_is(expected_result(&args));
}
@ -249,7 +279,8 @@ fn test_symlink() {
#[cfg(target_os = "linux")]
fn test_char() {
let args = ["-c", DEV_FMTSTR, "/dev/pts/ptmx"];
new_ucmd!().args(&args)
new_ucmd!()
.args(&args)
.run()
.stdout_is(expected_result(&args));
}
@ -257,8 +288,16 @@ fn test_char() {
#[test]
#[cfg(target_os = "linux")]
fn test_multi_files() {
let args = ["-c", NORMAL_FMTSTR, "/dev", "/usr/lib", "/etc/fstab", "/var"];
new_ucmd!().args(&args)
let args = [
"-c",
NORMAL_FMTSTR,
"/dev",
"/usr/lib",
"/etc/fstab",
"/var",
];
new_ucmd!()
.args(&args)
.run()
.stdout_is(expected_result(&args));
}
@ -266,13 +305,22 @@ fn test_multi_files() {
#[test]
#[cfg(target_os = "linux")]
fn test_printf() {
let args = ["--printf=123%-# 15q\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.23m\\x12\\167\\132\\112\\n", "/"];
new_ucmd!().args(&args)
let args = [
"--printf=123%-# 15q\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.23m\\x12\\167\\132\\112\\n",
"/",
];
new_ucmd!()
.args(&args)
.run()
.stdout_is(expected_result(&args));
}
#[cfg(target_os = "linux")]
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::*;
#[test]
fn test_stdbuf_unbuffered_stdout() {
if cfg!(target_os="linux") {
if cfg!(target_os = "linux") {
// This is a basic smoke test
new_ucmd!().args(&["-o0", "head"])
.pipe_in("The quick brown fox jumps over the lazy dog.").run()
new_ucmd!()
.args(&["-o0", "head"])
.pipe_in("The quick brown fox jumps over the lazy dog.")
.run()
.stdout_is("The quick brown fox jumps over the lazy dog.");
}
}

View file

@ -1,11 +1,11 @@
use common::util::*;
#[test]
fn test_bsd_single_file() {
new_ucmd!()
.arg("lorem_ipsum.txt")
.succeeds().stdout_only_fixture("bsd_single_file.expected");
.succeeds()
.stdout_only_fixture("bsd_single_file.expected");
}
#[test]
@ -13,21 +13,25 @@ fn test_bsd_multiple_files() {
new_ucmd!()
.arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt")
.succeeds().stdout_only_fixture("bsd_multiple_files.expected");
.succeeds()
.stdout_only_fixture("bsd_multiple_files.expected");
}
#[test]
fn test_bsd_stdin() {
new_ucmd!()
.pipe_in_fixture("lorem_ipsum.txt")
.succeeds().stdout_only_fixture("bsd_stdin.expected");
.succeeds()
.stdout_only_fixture("bsd_stdin.expected");
}
#[test]
fn test_sysv_single_file() {
new_ucmd!()
.arg("-s").arg("lorem_ipsum.txt")
.succeeds().stdout_only_fixture("sysv_single_file.expected");
.arg("-s")
.arg("lorem_ipsum.txt")
.succeeds()
.stdout_only_fixture("sysv_single_file.expected");
}
#[test]
@ -36,7 +40,8 @@ fn test_sysv_multiple_files() {
.arg("-s")
.arg("lorem_ipsum.txt")
.arg("alice_in_wonderland.txt")
.succeeds().stdout_only_fixture("sysv_multiple_files.expected");
.succeeds()
.stdout_only_fixture("sysv_multiple_files.expected");
}
#[test]
@ -44,5 +49,6 @@ fn test_sysv_stdin() {
new_ucmd!()
.arg("-s")
.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::*;
#[test]
fn test_stdin_default() {
new_ucmd!()
@ -29,18 +28,24 @@ fn test_stdin_non_newline_separator_before() {
#[test]
fn test_single_default() {
new_ucmd!().arg("prime_per_line.txt")
.run().stdout_is_fixture("prime_per_line.expected");
new_ucmd!()
.arg("prime_per_line.txt")
.run()
.stdout_is_fixture("prime_per_line.expected");
}
#[test]
fn test_single_non_newline_separator() {
new_ucmd!().args(&["-s", ":", "delimited_primes.txt"])
.run().stdout_is_fixture("delimited_primes.expected");
new_ucmd!()
.args(&["-s", ":", "delimited_primes.txt"])
.run()
.stdout_is_fixture("delimited_primes.expected");
}
#[test]
fn test_single_non_newline_separator_before() {
new_ucmd!().args(&["-b", "-s", ":", "delimited_primes.txt"])
.run().stdout_is_fixture("delimited_primes_before.expected");
new_ucmd!()
.args(&["-b", "-s", ":", "delimited_primes.txt"])
.run()
.stdout_is_fixture("delimited_primes_before.expected");
}

View file

@ -1,37 +1,50 @@
extern crate uu_tail;
use self::uu_tail::parse_size;
use common::util::*;
use std::char::from_digit;
use self::uu_tail::parse_size;
use std::io::Write;
use std::process::{Command, Stdio};
use std::thread::sleep;
use std::time::Duration;
static FOOBAR_TXT: &'static str = "foobar.txt";
static FOOBAR_2_TXT: &'static str = "foobar2.txt";
static FOOBAR_WITH_NULL_TXT: &'static str = "foobar_with_null.txt";
#[test]
fn test_stdin_default() {
new_ucmd!().pipe_in_fixture(FOOBAR_TXT).run().stdout_is_fixture("foobar_stdin_default.expected");
new_ucmd!()
.pipe_in_fixture(FOOBAR_TXT)
.run()
.stdout_is_fixture("foobar_stdin_default.expected");
}
#[test]
fn test_single_default() {
new_ucmd!().arg(FOOBAR_TXT).run().stdout_is_fixture("foobar_single_default.expected");
new_ucmd!()
.arg(FOOBAR_TXT)
.run()
.stdout_is_fixture("foobar_single_default.expected");
}
#[test]
fn test_n_greater_than_number_of_lines() {
new_ucmd!().arg("-n").arg("99999999").arg(FOOBAR_TXT).run()
new_ucmd!()
.arg("-n")
.arg("99999999")
.arg(FOOBAR_TXT)
.run()
.stdout_is_fixture(FOOBAR_TXT);
}
#[test]
fn test_null_default() {
new_ucmd!().arg("-z").arg(FOOBAR_WITH_NULL_TXT).run().stdout_is_fixture("foobar_with_null_default.expected");
new_ucmd!()
.arg("-z")
.arg(FOOBAR_WITH_NULL_TXT)
.run()
.stdout_is_fixture("foobar_with_null_default.expected");
}
#[test]
@ -55,7 +68,11 @@ fn test_follow() {
#[test]
fn test_follow_multiple() {
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");
assert_eq!(read_size(&mut child, expected.len()), expected);
@ -74,7 +91,11 @@ fn test_follow_multiple() {
#[test]
fn test_follow_stdin() {
new_ucmd!().arg("-f").pipe_in_fixture(FOOBAR_TXT).run().stdout_is_fixture("follow_stdin.expected");
new_ucmd!()
.arg("-f")
.pipe_in_fixture(FOOBAR_TXT)
.run()
.stdout_is_fixture("follow_stdin.expected");
}
#[test]
@ -86,10 +107,18 @@ fn test_follow_with_pid() {
#[cfg(windows)]
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 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");
assert_eq!(read_size(&mut child, expected.len()), expected);
@ -140,18 +169,30 @@ fn test_single_big_args() {
}
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]
fn test_bytes_single() {
new_ucmd!().arg("-c").arg("10").arg(FOOBAR_TXT).run()
new_ucmd!()
.arg("-c")
.arg("10")
.arg(FOOBAR_TXT)
.run()
.stdout_is_fixture("foobar_bytes_single.expected");
}
#[test]
fn test_bytes_stdin() {
new_ucmd!().arg("-c").arg("13").pipe_in_fixture(FOOBAR_TXT).run()
new_ucmd!()
.arg("-c")
.arg("13")
.pipe_in_fixture(FOOBAR_TXT)
.run()
.stdout_is_fixture("foobar_bytes_stdin.expected");
}
@ -178,7 +219,12 @@ fn test_bytes_big() {
}
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);
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");
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]
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]
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]
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
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::*;
#[test]
fn test_op_prec_and_or_1() {
new_ucmd!()
.args(&[" ", "-o", "", "-a", ""])
.succeeds();
new_ucmd!().args(&[" ", "-o", "", "-a", ""]).succeeds();
}
#[test]
@ -26,7 +23,5 @@ fn test_op_prec_and_or_2() {
#[test]
fn test_or_as_filename() {
new_ucmd!()
.args(&["x", "-a", "-z", "-o"])
.fails();
new_ucmd!().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) {
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) {
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) {
@ -36,7 +40,6 @@ fn test_touch_default() {
ucmd.arg(file).succeeds().no_stderr();
assert!(at.file_exists(file));
}
@ -72,13 +75,14 @@ fn test_touch_set_mdhm_time() {
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);
assert_eq!(atime, mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(),
45240);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45240);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45240);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45240);
}
#[test]
@ -86,17 +90,20 @@ fn test_touch_set_mdhms_time() {
let (at, mut ucmd) = at_and_ucmd!();
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));
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);
assert_eq!(atime, mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(),
45296);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45296);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45296);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45296);
}
#[test]
@ -104,17 +111,17 @@ fn test_touch_set_ymdhm_time() {
let (at, mut ucmd) = at_and_ucmd!();
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));
let start_of_year = str_to_filetime("%y%m%d%H%M", "1501010000");
let (atime, mtime) = get_file_times(&at, file);
assert_eq!(atime, mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(),
45240);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45240);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45240);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45240);
}
#[test]
@ -122,17 +129,17 @@ fn test_touch_set_ymdhms_time() {
let (at, mut ucmd) = at_and_ucmd!();
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));
let start_of_year = str_to_filetime("%y%m%d%H%M.%S", "1501010000.00");
let (atime, mtime) = get_file_times(&at, file);
assert_eq!(atime, mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(),
45296);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45296);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45296);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45296);
}
#[test]
@ -140,17 +147,17 @@ fn test_touch_set_cymdhm_time() {
let (at, mut ucmd) = at_and_ucmd!();
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));
let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000");
let (atime, mtime) = get_file_times(&at, file);
assert_eq!(atime, mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(),
45240);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45240);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45240);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45240);
}
#[test]
@ -158,17 +165,17 @@ fn test_touch_set_cymdhms_time() {
let (at, mut ucmd) = at_and_ucmd!();
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));
let start_of_year = str_to_filetime("%Y%m%d%H%M.%S", "201501010000.00");
let (atime, mtime) = get_file_times(&at, file);
assert_eq!(atime, mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(),
45296);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45296);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45296);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45296);
}
#[test]
@ -176,15 +183,16 @@ fn test_touch_set_only_atime() {
let (at, mut ucmd) = at_and_ucmd!();
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));
let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000");
let (atime, mtime) = get_file_times(&at, file);
assert!(atime != mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(),
45240);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45240);
}
#[test]
@ -192,15 +200,16 @@ fn test_touch_set_only_mtime() {
let (at, mut ucmd) = at_and_ucmd!();
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));
let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000");
let (atime, mtime) = get_file_times(&at, file);
assert!(atime != mtime);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45240);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45240);
}
#[test]
@ -208,17 +217,17 @@ fn test_touch_set_both() {
let (at, mut ucmd) = at_and_ucmd!();
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));
let start_of_year = str_to_filetime("%Y%m%d%H%M", "201501010000");
let (atime, mtime) = get_file_times(&at, file);
assert_eq!(atime, mtime);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(),
45240);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(),
45240);
assert_eq!(atime.unix_seconds() - start_of_year.unix_seconds(), 45240);
assert_eq!(mtime.unix_seconds() - start_of_year.unix_seconds(), 45240);
}
#[test]
@ -235,7 +244,9 @@ fn test_touch_no_dereference() {
assert!(at.file_exists(file_a));
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);
assert_eq!(atime, mtime);
@ -274,7 +285,9 @@ fn test_touch_set_date() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_touch_set_date";
ucmd.args(&["-d", "Thu Jan 01 12:34:00 2015", file]).succeeds().no_stderr();
ucmd.args(&["-d", "Thu Jan 01 12:34:00 2015", file])
.succeeds()
.no_stderr();
assert!(at.file_exists(file));

View file

@ -1,83 +1,118 @@
use common::util::*;
#[test]
fn test_toupper() {
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]
fn test_small_set2() {
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]
fn test_unicode() {
new_ucmd!()
.args(&[", ┬─┬", "╯︵┻━┻"])
.pipe_in("(,°□°), ┬─┬").run()
.pipe_in("(,°□°), ┬─┬")
.run()
.stdout_is("(╯°□°)╯︵┻━┻");
}
#[test]
fn test_delete() {
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]
fn test_delete_complement() {
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]
fn test_squeeze() {
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]
fn test_squeeze_complement() {
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]
fn test_delete_and_squeeze() {
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]
fn test_delete_and_squeeze_complement() {
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]
fn test_set1_longer_than_set2() {
new_ucmd!()
.args(&["abc", "xy"]).pipe_in("abcde").run().stdout_is("xyyde");
.args(&["abc", "xy"])
.pipe_in("abcde")
.run()
.stdout_is("xyyde");
}
#[test]
fn test_set1_shorter_than_set2() {
new_ucmd!()
.args(&["ab", "xyz"]).pipe_in("abcde").run().stdout_is("xycde");
.args(&["ab", "xyz"])
.pipe_in("abcde")
.run()
.stdout_is("xycde");
}
#[test]
fn test_truncate() {
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]
fn test_truncate_with_set1_shorter_than_set2() {
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::*;
#[test]
fn test_exit_code() {
new_ucmd!().succeeds();

View file

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

View file

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

View file

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

View file

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

View file

@ -1,21 +1,26 @@
use common::util::*;
#[test]
fn test_stdin_default() {
new_ucmd!().pipe_in_fixture("lorem_ipsum.txt")
.run().stdout_is(" 13 109 772\n");
new_ucmd!()
.pipe_in_fixture("lorem_ipsum.txt")
.run()
.stdout_is(" 13 109 772\n");
}
#[test]
fn test_stdin_only_bytes() {
new_ucmd!().args(&["-c"]).pipe_in_fixture("lorem_ipsum.txt")
.run().stdout_is(" 772\n");
new_ucmd!()
.args(&["-c"])
.pipe_in_fixture("lorem_ipsum.txt")
.run()
.stdout_is(" 772\n");
}
#[test]
fn test_stdin_all_counts() {
new_ucmd!().args(&["-c", "-m", "-l", "-L", "-w"])
new_ucmd!()
.args(&["-c", "-m", "-l", "-L", "-w"])
.pipe_in_fixture("alice_in_wonderland.txt")
.run()
.stdout_is(" 5 57 302 302 66\n");
@ -24,27 +29,38 @@ fn test_stdin_all_counts() {
#[test]
fn test_single_default() {
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]
fn test_single_only_lines() {
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]
fn test_single_all_counts() {
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");
}
#[test]
fn test_multiple_default() {
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(
" 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")]
use common::util::*;
#[cfg(target_os = "linux")]
#[test]
fn test_count() {
@ -76,5 +75,10 @@ fn test_all() {
#[cfg(target_os = "linux")]
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
}