1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

Fix test for cat, add mkdir test

This commit is contained in:
Nick 2014-01-03 22:33:05 -06:00
parent fc1da5a691
commit aac0a46b39
4 changed files with 78 additions and 16 deletions

View file

@ -30,8 +30,8 @@ EXES := \
# Programs with usable tests
TEST_PROGS := \
cat \
mkdir \
cat \
TEST ?= $(TEST_PROGS)
@ -54,7 +54,7 @@ test_$(1): tmp/$(1)_test build build/$(1)
$(call command,tmp/$(1)_test)
tmp/$(1)_test: $(1)/test.rs
$(call command,$(RUSTC) $(RUSTCFLAGS) --test -o tmp/$(1)_test $(1)/test.rs)
$(call command,$(RUSTC) $(RUSTCFLAGS) -o tmp/$(1)_test $(1)/test.rs)
endef
# Main rules

View file

@ -10,14 +10,16 @@ fn test_output_multi_files_print_all_chars() {
let prog = run::process_output("build/cat",
[~"cat/fixtures/alpha.txt", ~"cat/fixtures/256.txt",
~"-A", ~"-n"]);
let out = str::from_utf8_owned(prog.output);
let out = str::from_utf8_owned(prog.unwrap().output);
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() {
let mut prog = run::Process::new("build/cat", [~"-A"], run::ProcessOptions::new());
let program = run::Process::new("build/cat", [~"-A"], run::ProcessOptions::new());
if program.is_none() { fail!("cat: error - process not started"); }
let mut prog = program.unwrap();
prog.input().write(bytes!("\x00\x01\x02"));
prog.close_input();
@ -26,8 +28,10 @@ fn test_stdin_squeeze() {
}
fn test_stdin_number_non_blank() {
let mut prog = run::Process::new("build/cat", [~"-b", ~"-"], run::ProcessOptions::new());
let program = run::Process::new("build/cat", [~"-b", ~"-"], run::ProcessOptions::new());
if program.is_none() { fail!("cat: error - process not started"); }
let mut prog = program.unwrap();
prog.input().write(bytes!("\na\nb\n\n\nc"));
prog.close_input();

View file

@ -141,6 +141,7 @@ fn exec(dirs: ~[~str], mk_parents: bool, mode: u32, verbose: bool) {
}
writeln!(&mut stderr() as &mut Writer,
"{}", error_msg);
os::set_exit_status(1);
}
}
}
@ -159,13 +160,3 @@ fn mkdir(path: &Path, mode: u32) -> bool {
}
}
}
// #[test]
// fn create_dir() {
// let test_dir = "mkdir_test_dir";
// let path: Path = Path::new(test_dir);
// let mode: u32 = 0x755;
// let result = mkdir(&path, mode);
// fs::rmdir(&path);
// assert_eq!(true, result);
// }

View file

@ -1,3 +1,70 @@
fn main() {
use std::{run};
use std::io::fs::rmdir;
static exe: &'static str = "build/mkdir";
static test_dir1: &'static str = "mkdir_test1";
static test_dir2: &'static str = "mkdir_test1/mkdir_test2";
fn main() {
test_mkdir_mkdir();
test_mkdir_dup_dir();
test_mkdir_mode();
test_mkdir_parent();
test_mkdir_no_parent();
}
fn cleanup() {
let dirs = [test_dir2, test_dir1];
for d in dirs.iter() {
let p = Path::new(d.into_owned());
if p.exists() {
rmdir(&p);
}
}
}
fn test_mkdir_mkdir() {
cleanup();
let prog = run::process_status(exe.into_owned(), [test_dir1.into_owned()]);
let exit_success = prog.unwrap().success();
cleanup();
assert_eq!(exit_success, true);
}
fn test_mkdir_dup_dir() {
cleanup();
let prog = run::process_status(exe.into_owned(), [test_dir1.into_owned()]);
let exit_success = prog.unwrap().success();
if !exit_success {
cleanup();
fail!();
}
let prog2 = run::process_status(exe.into_owned(), [test_dir1.into_owned()]);
let exit_success2 = prog2.unwrap().success();
cleanup();
assert_eq!(exit_success2, false);
}
fn test_mkdir_mode() {
cleanup();
let prog = run::process_status(exe.into_owned(), [~"-m", ~"755", test_dir1.into_owned()]);
let exit_success = prog.unwrap().success();
cleanup();
assert_eq!(exit_success, true);
}
fn test_mkdir_parent() {
cleanup();
let prog = run::process_status(exe.into_owned(), [~"-p", test_dir2.into_owned()]);
let exit_success = prog.unwrap().success();
cleanup();
assert_eq!(exit_success, true);
}
fn test_mkdir_no_parent() {
cleanup();
let prog = run::process_status(exe.into_owned(), [test_dir2.into_owned()]);
let exit_success = prog.unwrap().success();
cleanup();
assert_eq!(exit_success, false);
}