mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
truncate: added simple tests
This commit is contained in:
parent
9877f5de19
commit
810936ac42
2 changed files with 41 additions and 0 deletions
1
Makefile
1
Makefile
|
@ -42,6 +42,7 @@ TEST_PROGS := \
|
||||||
cat \
|
cat \
|
||||||
mkdir \
|
mkdir \
|
||||||
seq \
|
seq \
|
||||||
|
truncate \
|
||||||
|
|
||||||
TEST ?= $(TEST_PROGS)
|
TEST ?= $(TEST_PROGS)
|
||||||
|
|
||||||
|
|
40
truncate/test.rs
Normal file
40
truncate/test.rs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
use std::{run, io};
|
||||||
|
|
||||||
|
static PROG: &'static str = "build/truncate";
|
||||||
|
static TESTNAME: &'static str = "THISISARANDOMFILENAME";
|
||||||
|
|
||||||
|
fn make_file() -> io::File {
|
||||||
|
while Path::new(TESTNAME).exists() { io::timer::sleep(1000); }
|
||||||
|
match io::File::create(&Path::new(TESTNAME)) {
|
||||||
|
Some(f) => f,
|
||||||
|
None => fail!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_increase_file_size() {
|
||||||
|
let mut file = make_file();
|
||||||
|
if !run::process_status(PROG, [~"-s", ~"+5K", TESTNAME.to_owned()]).unwrap().success() {
|
||||||
|
fail!();
|
||||||
|
}
|
||||||
|
file.seek(0, io::SeekEnd);
|
||||||
|
if file.tell() != 5 * 1024 {
|
||||||
|
fail!();
|
||||||
|
}
|
||||||
|
io::fs::unlink(&Path::new(TESTNAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_decrease_file_size() {
|
||||||
|
let mut file = make_file();
|
||||||
|
file.write(bytes!("1234567890"));
|
||||||
|
if !run::process_status(PROG, [~"--size=-4", TESTNAME.to_owned()]).unwrap().success() {
|
||||||
|
fail!();
|
||||||
|
}
|
||||||
|
file.seek(0, io::SeekEnd);
|
||||||
|
if file.tell() != 6 {
|
||||||
|
println!("{}", file.tell());
|
||||||
|
fail!();
|
||||||
|
}
|
||||||
|
io::fs::unlink(&Path::new(TESTNAME));
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue