2014-02-04 06:54:57 +00:00
|
|
|
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)) {
|
2014-02-05 04:17:36 +00:00
|
|
|
Ok(f) => f,
|
|
|
|
Err(_) => fail!()
|
2014-02-04 06:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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);
|
2014-02-05 04:17:36 +00:00
|
|
|
if file.tell().unwrap() != 5 * 1024 {
|
2014-02-04 06:54:57 +00:00
|
|
|
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);
|
2014-02-05 04:17:36 +00:00
|
|
|
if file.tell().unwrap() != 6 {
|
|
|
|
println!("{}", file.tell());
|
2014-02-04 06:54:57 +00:00
|
|
|
fail!();
|
|
|
|
}
|
|
|
|
io::fs::unlink(&Path::new(TESTNAME));
|
|
|
|
}
|