mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
rustfmt the tests
This commit is contained in:
parent
78624a53ee
commit
cf35d75491
61 changed files with 3414 additions and 1975 deletions
|
@ -20,51 +20,55 @@ mod test_generate_tokens {
|
|||
#[test]
|
||||
fn test_normal_format() {
|
||||
let s = "%10.2ac%-5.w\n";
|
||||
let expected = vec![Token::Directive {
|
||||
flag: 0,
|
||||
width: 10,
|
||||
precision: 2,
|
||||
format: 'a',
|
||||
},
|
||||
Token::Char('c'),
|
||||
Token::Directive {
|
||||
flag: F_LEFT,
|
||||
width: 5,
|
||||
precision: 0,
|
||||
format: 'w',
|
||||
},
|
||||
Token::Char('\n')];
|
||||
let expected = vec![
|
||||
Token::Directive {
|
||||
flag: 0,
|
||||
width: 10,
|
||||
precision: 2,
|
||||
format: 'a',
|
||||
},
|
||||
Token::Char('c'),
|
||||
Token::Directive {
|
||||
flag: F_LEFT,
|
||||
width: 5,
|
||||
precision: 0,
|
||||
format: 'w',
|
||||
},
|
||||
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 {
|
||||
flag: F_LEFT | F_ALTER | F_SPACE,
|
||||
width: 15,
|
||||
precision: -1,
|
||||
format: 'a',
|
||||
},
|
||||
Token::Char('\r'),
|
||||
Token::Char('"'),
|
||||
Token::Char('\\'),
|
||||
Token::Char('\x07'),
|
||||
Token::Char('\x08'),
|
||||
Token::Char('\x1B'),
|
||||
Token::Char('\x0C'),
|
||||
Token::Char('\x0B'),
|
||||
Token::Directive {
|
||||
flag: F_SIGN | F_ZERO,
|
||||
width: 20,
|
||||
precision: -1,
|
||||
format: 'w',
|
||||
},
|
||||
Token::Char('\x12'),
|
||||
Token::Char('w'),
|
||||
Token::Char('Z'),
|
||||
Token::Char('J'),
|
||||
Token::Char('\n')];
|
||||
let expected = vec![
|
||||
Token::Directive {
|
||||
flag: F_LEFT | F_ALTER | F_SPACE,
|
||||
width: 15,
|
||||
precision: -1,
|
||||
format: 'a',
|
||||
},
|
||||
Token::Char('\r'),
|
||||
Token::Char('"'),
|
||||
Token::Char('\\'),
|
||||
Token::Char('\x07'),
|
||||
Token::Char('\x08'),
|
||||
Token::Char('\x1B'),
|
||||
Token::Char('\x0C'),
|
||||
Token::Char('\x0B'),
|
||||
Token::Directive {
|
||||
flag: F_SIGN | F_ZERO,
|
||||
width: 20,
|
||||
precision: -1,
|
||||
format: 'w',
|
||||
},
|
||||
Token::Char('\x12'),
|
||||
Token::Char('w'),
|
||||
Token::Char('Z'),
|
||||
Token::Char('J'),
|
||||
Token::Char('\n'),
|
||||
];
|
||||
assert_eq!(&expected, &Stater::generate_tokens(s, true).unwrap());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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" }
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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!()
|
||||
|
|
|
@ -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!()
|
||||
.arg("-RH")
|
||||
.arg("bin")
|
||||
.arg("/proc/self/fd")
|
||||
.fails()
|
||||
.stderr
|
||||
.lines()
|
||||
.fold(0, |acc, _| acc + 1) > 1);
|
||||
assert!(
|
||||
new_ucmd!()
|
||||
.arg("-RH")
|
||||
.arg("bin")
|
||||
.arg("/proc/self/fd")
|
||||
.fails()
|
||||
.stderr
|
||||
.lines()
|
||||
.fold(0, |acc, _| acc + 1)
|
||||
> 1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,36 +16,47 @@ 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();
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
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
|
||||
));
|
||||
}
|
||||
|
||||
for arg in &test.args {
|
||||
ucmd.arg(arg);
|
||||
}
|
||||
let r = ucmd.run();
|
||||
if !r.success {
|
||||
println!("{}", r.stderr);
|
||||
panic!(format!("{:?}: failed", ucmd.raw));
|
||||
}
|
||||
for arg in &test.args {
|
||||
ucmd.arg(arg);
|
||||
}
|
||||
let r = ucmd.run();
|
||||
if !r.success {
|
||||
println!("{}", r.stderr);
|
||||
panic!(format!("{:?}: failed", ucmd.raw));
|
||||
}
|
||||
|
||||
let perms = at.metadata(TEST_FILE).permissions().mode();
|
||||
if perms != test.after {
|
||||
panic!(format!("{:?}: expected: {:o} got: {:o}", ucmd.raw, test.after, perms));
|
||||
}
|
||||
let perms = at.metadata(TEST_FILE).permissions().mode();
|
||||
if perms != test.after {
|
||||
panic!(format!(
|
||||
"{:?}: expected: {:o} got: {:o}",
|
||||
ucmd.raw, test.after, perms
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn run_tests(tests: Vec<TestCase>) {
|
||||
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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,38 +71,46 @@ 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"])
|
||||
.fails()
|
||||
.stdout_is_fixture("bad_order12.check_order.expected")
|
||||
.stderr_is("error to be defined");
|
||||
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"])
|
||||
.succeeds()
|
||||
.stdout_only_fixture("bad_order12.nocheck_order.expected");
|
||||
new_ucmd!()
|
||||
.args(&["--nocheck-order", "bad_order_1", "bad_order_2"])
|
||||
.succeeds()
|
||||
.stdout_only_fixture("bad_order12.nocheck_order.expected");
|
||||
}
|
||||
|
||||
// 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,17 +122,20 @@ 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"])
|
||||
.fails()
|
||||
.stdout_is_fixture("bad_order12.nocheck_order.expected")
|
||||
.stderr_is("error to be defined");
|
||||
new_ucmd!()
|
||||
.args(&["bad_order_1", "bad_order_2"])
|
||||
.fails()
|
||||
.stdout_is_fixture("bad_order12.nocheck_order.expected")
|
||||
.stderr_is("error to be defined");
|
||||
}
|
||||
|
||||
// * the third: (it is not know whether this is a bug or not)
|
||||
|
@ -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?
|
||||
|
|
107
tests/test_cp.rs
107
tests/test_cp.rs
|
@ -2,25 +2,26 @@ use common::util::*;
|
|||
#[cfg(not(windows))]
|
||||
use std::fs::set_permissions;
|
||||
|
||||
static TEST_EXISTING_FILE: &str = "existing_file.txt";
|
||||
static TEST_HELLO_WORLD_SOURCE: &str = "hello_world.txt";
|
||||
static TEST_HELLO_WORLD_DEST: &str = "copy_of_hello_world.txt";
|
||||
static TEST_HOW_ARE_YOU_SOURCE: &str = "how_are_you.txt";
|
||||
static TEST_HOW_ARE_YOU_DEST: &str = "hello_dir/how_are_you.txt";
|
||||
static TEST_COPY_TO_FOLDER: &str = "hello_dir/";
|
||||
static TEST_COPY_TO_FOLDER_FILE: &str = "hello_dir/hello_world.txt";
|
||||
static TEST_COPY_FROM_FOLDER: &str = "hello_dir_with_file/";
|
||||
static TEST_COPY_FROM_FOLDER_FILE: &str = "hello_dir_with_file/hello_world.txt";
|
||||
static TEST_COPY_TO_FOLDER_NEW: &str = "hello_dir_new/";
|
||||
static TEST_EXISTING_FILE: &str = "existing_file.txt";
|
||||
static TEST_HELLO_WORLD_SOURCE: &str = "hello_world.txt";
|
||||
static TEST_HELLO_WORLD_DEST: &str = "copy_of_hello_world.txt";
|
||||
static TEST_HOW_ARE_YOU_SOURCE: &str = "how_are_you.txt";
|
||||
static TEST_HOW_ARE_YOU_DEST: &str = "hello_dir/how_are_you.txt";
|
||||
static TEST_COPY_TO_FOLDER: &str = "hello_dir/";
|
||||
static TEST_COPY_TO_FOLDER_FILE: &str = "hello_dir/hello_world.txt";
|
||||
static TEST_COPY_FROM_FOLDER: &str = "hello_dir_with_file/";
|
||||
static TEST_COPY_FROM_FOLDER_FILE: &str = "hello_dir_with_file/hello_world.txt";
|
||||
static TEST_COPY_TO_FOLDER_NEW: &str = "hello_dir_new/";
|
||||
static TEST_COPY_TO_FOLDER_NEW_FILE: &str = "hello_dir_new/hello_world.txt";
|
||||
|
||||
#[test]
|
||||
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)
|
||||
.arg(TEST_HELLO_WORLD_DEST)
|
||||
.run();
|
||||
let result = ucmd
|
||||
.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_HELLO_WORLD_DEST)
|
||||
.run();
|
||||
|
||||
// Check that the exit code represents a successful copy.
|
||||
let exit_success = result.success;
|
||||
|
@ -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"
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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,45 +79,63 @@ 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");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_output_delimiter() {
|
||||
// we use -d here to ensure output delimiter
|
||||
// we use -d here to ensure output delimiter
|
||||
// is applied to the current, and not just the default, input delimiter
|
||||
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");
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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, "");
|
||||
}
|
||||
|
@ -100,14 +116,14 @@ fn test_ignore_environment() {
|
|||
#[test]
|
||||
fn test_null_delimiter() {
|
||||
let out = new_ucmd!()
|
||||
.arg("-i")
|
||||
.arg("--null")
|
||||
.arg("FOO=bar")
|
||||
.arg("ABC=xyz")
|
||||
.run()
|
||||
.stdout;
|
||||
.arg("-i")
|
||||
.arg("--null")
|
||||
.arg("FOO=bar")
|
||||
.arg("ABC=xyz")
|
||||
.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], "");
|
||||
|
@ -120,11 +136,11 @@ fn test_unset_variable() {
|
|||
// This test depends on the HOME variable being pre-defined by the
|
||||
// default shell
|
||||
let out = TestScenario::new(util_name!())
|
||||
.ucmd_keepenv()
|
||||
.arg("-u")
|
||||
.arg("HOME")
|
||||
.run()
|
||||
.stdout;
|
||||
.ucmd_keepenv()
|
||||
.arg("-u")
|
||||
.arg("HOME")
|
||||
.run()
|
||||
.stdout;
|
||||
|
||||
assert_eq!(out.lines().any(|line| line.starts_with("HOME=")), false);
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
1725
tests/test_factor.rs
1725
tests/test_factor.rs
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,5 @@
|
|||
use common::util::*;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_exit_code() {
|
||||
new_ucmd!().fails();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use common::util::*;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_default_80_column_wrap() {
|
||||
new_ucmd!()
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use common::util::*;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_ls_ls() {
|
||||
new_ucmd!().succeeds();
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
173
tests/test_mv.rs
173
tests/test_mv.rs
|
@ -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()
|
||||
.stdout_only(format!("‘{}’ -> ‘{}’\n", file_a, file_b));
|
||||
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:
|
||||
|
|
|
@ -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\
|
||||
"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");
|
||||
"0001xL1\n1001xL2\n2001xL3\n3001xL4\n4001xL5\n5001xL6\n6001xL7\n7001xL8\n8001xL9\n\
|
||||
9001xL10\n10001xL11\n11001xL12\n12001xL13\n13001xL14\n14001xL15\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sections_and_styles() {
|
||||
for &(fixture, output) in &[("section.txt",
|
||||
"\nHEADER1\nHEADER2\n\n1 |BODY1\n2 \
|
||||
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",
|
||||
"1 |Nonempty\n2 |Nonempty\n3 |Followed by 10x empty\n\n\n\n\n4 \
|
||||
|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);
|
||||
}
|
||||
|
|
538
tests/test_od.rs
538
tests/test_od.rs
|
@ -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(){
|
||||
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("
|
||||
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(
|
||||
"
|
||||
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)
|
||||
"));
|
||||
"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use common::util::*;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_combine_pairs_of_lines() {
|
||||
new_ucmd!()
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use common::util::*;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_default() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use common::util::*;
|
||||
|
||||
|
||||
static GIBBERISH: &'static str = "supercalifragilisticexpialidocious";
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use common::util::*;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_current_directory() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
"rmdir: error: failed to remove 'test_rmdir_nonempty/with/parents': Directory not \
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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,65 +101,70 @@ mod test_generate_tokens {
|
|||
#[test]
|
||||
fn normal_format() {
|
||||
let s = "%'010.2ac%-#5.w\n";
|
||||
let expected = vec![Token::Directive {
|
||||
flag: F_GROUP | F_ZERO,
|
||||
width: 10,
|
||||
precision: 2,
|
||||
format: 'a',
|
||||
},
|
||||
Token::Char('c'),
|
||||
Token::Directive {
|
||||
flag: F_LEFT | F_ALTER,
|
||||
width: 5,
|
||||
precision: 0,
|
||||
format: 'w',
|
||||
},
|
||||
Token::Char('\n')];
|
||||
let expected = vec![
|
||||
Token::Directive {
|
||||
flag: F_GROUP | F_ZERO,
|
||||
width: 10,
|
||||
precision: 2,
|
||||
format: 'a',
|
||||
},
|
||||
Token::Char('c'),
|
||||
Token::Directive {
|
||||
flag: F_LEFT | F_ALTER,
|
||||
width: 5,
|
||||
precision: 0,
|
||||
format: 'w',
|
||||
},
|
||||
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 {
|
||||
flag: F_LEFT | F_ALTER | F_SPACE,
|
||||
width: 15,
|
||||
precision: -1,
|
||||
format: 'a',
|
||||
},
|
||||
Token::Char('\r'),
|
||||
Token::Char('"'),
|
||||
Token::Char('\\'),
|
||||
Token::Char('\x07'),
|
||||
Token::Char('\x08'),
|
||||
Token::Char('\x1B'),
|
||||
Token::Char('\x0C'),
|
||||
Token::Char('\x0B'),
|
||||
Token::Directive {
|
||||
flag: F_SIGN | F_ZERO,
|
||||
width: 20,
|
||||
precision: -1,
|
||||
format: 'w',
|
||||
},
|
||||
Token::Char('\x12'),
|
||||
Token::Char('w'),
|
||||
Token::Char('Z'),
|
||||
Token::Char('J'),
|
||||
Token::Char('\n')];
|
||||
let expected = vec![
|
||||
Token::Directive {
|
||||
flag: F_LEFT | F_ALTER | F_SPACE,
|
||||
width: 15,
|
||||
precision: -1,
|
||||
format: 'a',
|
||||
},
|
||||
Token::Char('\r'),
|
||||
Token::Char('"'),
|
||||
Token::Char('\\'),
|
||||
Token::Char('\x07'),
|
||||
Token::Char('\x08'),
|
||||
Token::Char('\x1B'),
|
||||
Token::Char('\x0C'),
|
||||
Token::Char('\x0B'),
|
||||
Token::Directive {
|
||||
flag: F_SIGN | F_ZERO,
|
||||
width: 20,
|
||||
precision: -1,
|
||||
format: 'w',
|
||||
},
|
||||
Token::Char('\x12'),
|
||||
Token::Char('w'),
|
||||
Token::Char('Z'),
|
||||
Token::Char('J'),
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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,19 +169,31 @@ 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()
|
||||
.stdout_is_fixture("foobar_bytes_stdin.expected");
|
||||
new_ucmd!()
|
||||
.arg("-c")
|
||||
.arg("13")
|
||||
.pipe_in_fixture(FOOBAR_TXT)
|
||||
.run()
|
||||
.stdout_is_fixture("foobar_bytes_stdin.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use common::util::*;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_exit_code() {
|
||||
new_ucmd!().succeeds();
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
" 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",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue