mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
+43
-39
@@ -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" }
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+27
-15
@@ -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]
|
||||
|
||||
+15
-12
@@ -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!()
|
||||
|
||||
+28
-20
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+203
-71
@@ -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);
|
||||
|
||||
+2
-5
@@ -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();
|
||||
}
|
||||
|
||||
+8
-5
@@ -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");
|
||||
}
|
||||
|
||||
+70
-36
@@ -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?
|
||||
|
||||
+67
-40
@@ -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"
|
||||
);
|
||||
}
|
||||
|
||||
+73
-29
@@ -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");
|
||||
}
|
||||
|
||||
+17
-11
@@ -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]
|
||||
|
||||
+81
-20
@@ -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]
|
||||
|
||||
+57
-41
@@ -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);
|
||||
}
|
||||
|
||||
+19
-6
@@ -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");
|
||||
}
|
||||
|
||||
+868
-857
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!()
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user