mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Update cat/test for std::rt::io changes. Also, use the higher level
std::run over std::rt::io::process.
This commit is contained in:
parent
c4fab4cf67
commit
087cfbd0c6
1 changed files with 19 additions and 62 deletions
81
cat/test.rs
81
cat/test.rs
|
@ -1,7 +1,4 @@
|
||||||
use std::rt::io::process::{Process, ProcessConfig, CreatePipe, Ignored};
|
use std::{run, str};
|
||||||
use std::rt::io::{Reader, Writer};
|
|
||||||
use std::rt::io::pipe::PipeStream;
|
|
||||||
use std::str;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
test_output_multi_files_print_all_chars();
|
test_output_multi_files_print_all_chars();
|
||||||
|
@ -9,71 +6,31 @@ fn main() {
|
||||||
test_stdin_number_non_blank();
|
test_stdin_number_non_blank();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_all(input: &mut Reader) -> ~str {
|
|
||||||
let mut ret = ~"";
|
|
||||||
let mut buf = [0, ..1024];
|
|
||||||
loop {
|
|
||||||
match input.read(buf) {
|
|
||||||
None => { break }
|
|
||||||
Some(n) => { ret = ret + str::from_utf8(buf.slice_to(n)); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test_output_multi_files_print_all_chars() {
|
fn test_output_multi_files_print_all_chars() {
|
||||||
let output = PipeStream::new().unwrap();
|
let prog = run::process_output("build/cat",
|
||||||
let io = ~[Ignored,
|
[~"cat/fixtures/alpha.txt", ~"cat/fixtures/256.txt",
|
||||||
CreatePipe(output, false, true)];
|
~"-A", ~"-n"]);
|
||||||
let args = ProcessConfig {
|
let out = str::from_utf8_owned(prog.output);
|
||||||
program: "build/cat",
|
assert_eq!(out,
|
||||||
args: [~"cat/fixtures/alpha.txt", ~"cat/fixtures/256.txt", ~"-A", ~"-n"],
|
~" 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-^?");
|
||||||
env: None,
|
|
||||||
cwd: None,
|
|
||||||
io: io,
|
|
||||||
};
|
|
||||||
let mut p = Process::new(args).expect("proc fail");
|
|
||||||
let out = read_all(p.io[1].get_mut_ref() as &mut Reader);
|
|
||||||
assert_eq!(p.wait(), 0);
|
|
||||||
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-^?");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_stdin_squeeze() {
|
fn test_stdin_squeeze() {
|
||||||
let input = PipeStream::new().unwrap();
|
let mut prog = run::Process::new("build/cat", [~"-A"], run::ProcessOptions::new());
|
||||||
let output = PipeStream::new().unwrap();
|
|
||||||
let io = ~[CreatePipe(input, true, false),
|
prog.input().write(bytes!("\x00\x01\x02"));
|
||||||
CreatePipe(output, false, true)];
|
prog.close_input();
|
||||||
let args = ProcessConfig {
|
|
||||||
program: "build/cat",
|
let out = str::from_utf8_owned(prog.finish_with_output().output);
|
||||||
args: [~"-A"],
|
|
||||||
env: None,
|
|
||||||
cwd: None,
|
|
||||||
io: io,
|
|
||||||
};
|
|
||||||
let mut p = Process::new(args).expect("proc fail");
|
|
||||||
p.io[0].get_mut_ref().write("\x00\x01\x02".as_bytes());
|
|
||||||
p.io[0] = None; // close stdin;
|
|
||||||
let out = read_all(p.io[1].get_mut_ref() as &mut Reader);
|
|
||||||
assert_eq!(p.wait(), 0);
|
|
||||||
assert_eq!(out, ~"^@^A^B");
|
assert_eq!(out, ~"^@^A^B");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_stdin_number_non_blank() {
|
fn test_stdin_number_non_blank() {
|
||||||
let input = PipeStream::new().unwrap();
|
let mut prog = run::Process::new("build/cat", [~"-b", ~"-"], run::ProcessOptions::new());
|
||||||
let output = PipeStream::new().unwrap();
|
|
||||||
let io = ~[CreatePipe(input, true, false),
|
prog.input().write(bytes!("\na\nb\n\n\nc"));
|
||||||
CreatePipe(output, false, true)];
|
prog.close_input();
|
||||||
let args = ProcessConfig {
|
|
||||||
program: "build/cat",
|
let out = str::from_utf8_owned(prog.finish_with_output().output);
|
||||||
args: [~"-b", ~"-"],
|
|
||||||
env: None,
|
|
||||||
cwd: None,
|
|
||||||
io: io,
|
|
||||||
};
|
|
||||||
let mut p = Process::new(args).expect("proc fail");
|
|
||||||
p.io[0].get_mut_ref().write("\na\nb\n\n\nc".as_bytes());
|
|
||||||
p.io[0] = None; // close stdin;
|
|
||||||
let out = read_all(p.io[1].get_mut_ref() as &mut Reader);
|
|
||||||
assert_eq!(p.wait(), 0);
|
|
||||||
assert_eq!(out, ~"\n 1\ta\n 2\tb\n\n\n 3\tc");
|
assert_eq!(out, ~"\n 1\ta\n 2\tb\n\n\n 3\tc");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue