mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 17:58:06 +00:00
Merge pull request #173 from ebfe/fix-make-test
Update tests to use std::process:Command
This commit is contained in:
commit
d6c15a7f0c
4 changed files with 52 additions and 43 deletions
37
cat/test.rs
37
cat/test.rs
|
@ -1,32 +1,41 @@
|
|||
use std::io::process::Process;
|
||||
use std::io::process::Command;
|
||||
use std::str;
|
||||
|
||||
#[test]
|
||||
fn test_output_multi_files_print_all_chars() {
|
||||
let prog = Process::output("build/cat",
|
||||
["cat/fixtures/alpha.txt".to_owned(), "cat/fixtures/256.txt".to_owned(),
|
||||
"-A".to_owned(), "-n".to_owned()]).unwrap();
|
||||
let out = str::from_utf8_owned(prog.output.as_slice().to_owned()).unwrap();
|
||||
let po = match Command::new("build/cat")
|
||||
.arg("cat/fixtures/alpha.txt")
|
||||
.arg("cat/fixtures/256.txt")
|
||||
.arg("-A")
|
||||
.arg("-n").output() {
|
||||
|
||||
Ok(p) => p,
|
||||
Err(err) => fail!("{}", err),
|
||||
};
|
||||
|
||||
let out = str::from_utf8(po.output.as_slice()).unwrap();
|
||||
assert_eq!(out,
|
||||
" 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:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~^?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-^_M- 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-UM-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-^?".to_owned());
|
||||
" 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:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~^?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-^_M- 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-UM-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-^?");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin_squeeze() {
|
||||
let mut prog = Process::new("build/cat", ["-A".to_owned()]).unwrap();
|
||||
let mut process= Command::new("build/cat").arg("-A").spawn().unwrap();
|
||||
|
||||
prog.stdin.take_unwrap().write(bytes!("\x00\x01\x02"));
|
||||
process.stdin.take_unwrap().write(bytes!("\x00\x01\x02")).unwrap();
|
||||
let po = process.wait_with_output().unwrap();
|
||||
let out = str::from_utf8(po.output.as_slice()).unwrap();
|
||||
|
||||
let out = str::from_utf8_owned(prog.wait_with_output().output.as_slice().to_owned()).unwrap();
|
||||
assert_eq!(out, "^@^A^B".to_owned());
|
||||
assert_eq!(out, "^@^A^B");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin_number_non_blank() {
|
||||
let mut prog = Process::new("build/cat", ["-b".to_owned(), "-".to_owned()]).unwrap();
|
||||
let mut process = Command::new("build/cat").arg("-b").arg("-").spawn().unwrap();
|
||||
|
||||
prog.stdin.take_unwrap().write(bytes!("\na\nb\n\n\nc"));
|
||||
process.stdin.take_unwrap().write(bytes!("\na\nb\n\n\nc")).unwrap();
|
||||
let po = process.wait_with_output().unwrap();
|
||||
let out = str::from_utf8(po.output.as_slice()).unwrap();
|
||||
|
||||
let out = str::from_utf8_owned(prog.wait_with_output().output.as_slice().to_owned()).unwrap();
|
||||
assert_eq!(out, "\n 1\ta\n 2\tb\n\n\n 3\tc".to_owned());
|
||||
assert_eq!(out, "\n 1\ta\n 2\tb\n\n\n 3\tc");
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::process::Process;
|
||||
use std::io::process::Command;
|
||||
use std::io::fs::rmdir;
|
||||
|
||||
static exe: &'static str = "build/mkdir";
|
||||
|
@ -12,14 +12,14 @@ fn cleanup(dir: &'static str) {
|
|||
let d = dir.into_owned();
|
||||
let p = Path::new(d.into_owned());
|
||||
if p.exists() {
|
||||
rmdir(&p);
|
||||
rmdir(&p).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mkdir_mkdir() {
|
||||
cleanup(test_dir1);
|
||||
let prog = Process::status(exe.into_owned(), [test_dir1.into_owned()]);
|
||||
let prog = Command::new(exe).arg(test_dir1).status();
|
||||
let exit_success = prog.unwrap().success();
|
||||
cleanup(test_dir1);
|
||||
assert_eq!(exit_success, true);
|
||||
|
@ -28,13 +28,13 @@ fn test_mkdir_mkdir() {
|
|||
#[test]
|
||||
fn test_mkdir_dup_dir() {
|
||||
cleanup(test_dir2);
|
||||
let prog = Process::status(exe.into_owned(), [test_dir2.into_owned()]);
|
||||
let prog = Command::new(exe).arg(test_dir2).status();
|
||||
let exit_success = prog.unwrap().success();
|
||||
if !exit_success {
|
||||
cleanup(test_dir2);
|
||||
fail!();
|
||||
}
|
||||
let prog2 = Process::status(exe.into_owned(), [test_dir2.into_owned()]);
|
||||
let prog2 = Command::new(exe).arg(test_dir2).status();
|
||||
let exit_success2 = prog2.unwrap().success();
|
||||
cleanup(test_dir2);
|
||||
assert_eq!(exit_success2, false);
|
||||
|
@ -43,7 +43,7 @@ fn test_mkdir_dup_dir() {
|
|||
#[test]
|
||||
fn test_mkdir_mode() {
|
||||
cleanup(test_dir3);
|
||||
let prog = Process::status(exe.into_owned(), ["-m".to_owned(), "755".to_owned(), test_dir3.into_owned()]);
|
||||
let prog = Command::new(exe).arg("-m").arg("755").arg(test_dir3).status();
|
||||
let exit_success = prog.unwrap().success();
|
||||
cleanup(test_dir3);
|
||||
assert_eq!(exit_success, true);
|
||||
|
@ -52,7 +52,7 @@ fn test_mkdir_mode() {
|
|||
#[test]
|
||||
fn test_mkdir_parent() {
|
||||
cleanup(test_dir4);
|
||||
let prog = Process::status(exe.into_owned(), ["-p".to_owned(), test_dir4.into_owned()]);
|
||||
let prog = Command::new(exe).arg("-p").arg(test_dir4).status();
|
||||
let exit_success = prog.unwrap().success();
|
||||
cleanup(test_dir4);
|
||||
assert_eq!(exit_success, true);
|
||||
|
@ -61,7 +61,7 @@ fn test_mkdir_parent() {
|
|||
#[test]
|
||||
fn test_mkdir_no_parent() {
|
||||
cleanup(test_dir5);
|
||||
let prog = Process::status(exe.into_owned(), [test_dir5.into_owned()]);
|
||||
let prog = Command::new(exe).arg(test_dir5).status();
|
||||
let exit_success = prog.unwrap().success();
|
||||
cleanup(test_dir5);
|
||||
assert_eq!(exit_success, false);
|
||||
|
|
26
seq/test.rs
26
seq/test.rs
|
@ -1,30 +1,30 @@
|
|||
use std::io::process::Process;
|
||||
use std::io::process::Command;
|
||||
use std::str;
|
||||
|
||||
#[test]
|
||||
fn test_count_up() {
|
||||
let p = Process::output("build/seq", ["10".to_owned()]).unwrap();
|
||||
let out = str::from_utf8(p.output.as_slice().to_owned()).unwrap().into_owned();
|
||||
assert_eq!(out, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n".to_owned());
|
||||
let p = Command::new("build/seq").args(["10"]).output().unwrap();
|
||||
let out = str::from_utf8(p.output.as_slice()).unwrap();
|
||||
assert_eq!(out, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_count_down() {
|
||||
let p = Process::output("build/seq", ["--".to_owned(), "5".to_owned(), "-1".to_owned(), "1".to_owned()]).unwrap();
|
||||
let out = str::from_utf8(p.output.as_slice().to_owned()).unwrap().into_owned();
|
||||
assert_eq!(out, "5\n4\n3\n2\n1\n".to_owned());
|
||||
let p = Command::new("build/seq").args(["--", "5", "-1", "1"]).output().unwrap();
|
||||
let out = str::from_utf8(p.output.as_slice()).unwrap();
|
||||
assert_eq!(out, "5\n4\n3\n2\n1\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_separator_and_terminator() {
|
||||
let p = Process::output("build/seq", ["-s".to_owned(), ",".to_owned(), "-t".to_owned(), "!".to_owned(), "2".to_owned(), "6".to_owned()]).unwrap();
|
||||
let out = str::from_utf8(p.output.as_slice().to_owned()).unwrap().into_owned();
|
||||
assert_eq!(out, "2,3,4,5,6!".to_owned());
|
||||
let p = Command::new("build/seq").args(["-s", ",", "-t", "!", "2", "6"]).output().unwrap();
|
||||
let out = str::from_utf8(p.output.as_slice()).unwrap();
|
||||
assert_eq!(out, "2,3,4,5,6!");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_equalize_widths() {
|
||||
let p = Process::output("build/seq", ["-w".to_owned(), "5".to_owned(), "10".to_owned()]).unwrap();
|
||||
let out = str::from_utf8(p.output.as_slice().to_owned()).unwrap().into_owned();
|
||||
assert_eq!(out, "05\n06\n07\n08\n09\n10\n".to_owned());
|
||||
let p = Command::new("build/seq").args(["-w", "5", "10"]).output().unwrap();
|
||||
let out = str::from_utf8(p.output.as_slice()).unwrap();
|
||||
assert_eq!(out, "05\n06\n07\n08\n09\n10\n");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::io;
|
||||
use std::io::process::Process;
|
||||
use std::io::process::Command;
|
||||
|
||||
static PROG: &'static str = "build/truncate";
|
||||
static TFILE1: &'static str = "truncate_test_1";
|
||||
|
@ -15,27 +15,27 @@ fn make_file(name: &str) -> io::File {
|
|||
#[test]
|
||||
fn test_increase_file_size() {
|
||||
let mut file = make_file(TFILE1);
|
||||
if !Process::status(PROG, ["-s".to_owned(), "+5K".to_owned(), TFILE1.to_owned()]).unwrap().success() {
|
||||
if !Command::new(PROG).args(["-s", "+5K", TFILE1]).status().unwrap().success() {
|
||||
fail!();
|
||||
}
|
||||
file.seek(0, io::SeekEnd);
|
||||
file.seek(0, io::SeekEnd).unwrap();
|
||||
if file.tell().unwrap() != 5 * 1024 {
|
||||
fail!();
|
||||
}
|
||||
io::fs::unlink(&Path::new(TFILE1));
|
||||
io::fs::unlink(&Path::new(TFILE1)).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_decrease_file_size() {
|
||||
let mut file = make_file(TFILE2);
|
||||
file.write(bytes!("1234567890"));
|
||||
if !Process::status(PROG, ["--size=-4".to_owned(), TFILE2.to_owned()]).unwrap().success() {
|
||||
file.write(bytes!("1234567890")).unwrap();
|
||||
if !Command::new(PROG).args(["--size=-4", TFILE2]).status().unwrap().success() {
|
||||
fail!();
|
||||
}
|
||||
file.seek(0, io::SeekEnd);
|
||||
file.seek(0, io::SeekEnd).unwrap();
|
||||
if file.tell().unwrap() != 6 {
|
||||
println!("{}", file.tell());
|
||||
fail!();
|
||||
}
|
||||
io::fs::unlink(&Path::new(TFILE2));
|
||||
io::fs::unlink(&Path::new(TFILE2)).unwrap();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue