2014-02-27 03:35:50 +00:00
|
|
|
use std::io;
|
2014-05-17 13:47:44 +00:00
|
|
|
use std::io::process::Command;
|
2014-02-04 06:54:57 +00:00
|
|
|
|
|
|
|
static PROG: &'static str = "build/truncate";
|
2014-02-07 06:39:07 +00:00
|
|
|
static TFILE1: &'static str = "truncate_test_1";
|
|
|
|
static TFILE2: &'static str = "truncate_test_2";
|
2014-02-04 06:54:57 +00:00
|
|
|
|
2014-02-07 06:39:07 +00:00
|
|
|
fn make_file(name: &str) -> io::File {
|
|
|
|
match io::File::create(&Path::new(name)) {
|
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() {
|
2014-02-07 06:39:07 +00:00
|
|
|
let mut file = make_file(TFILE1);
|
2014-05-17 13:47:44 +00:00
|
|
|
if !Command::new(PROG).args(["-s", "+5K", TFILE1]).status().unwrap().success() {
|
2014-02-04 06:54:57 +00:00
|
|
|
fail!();
|
|
|
|
}
|
2014-05-17 13:47:44 +00:00
|
|
|
file.seek(0, io::SeekEnd).unwrap();
|
2014-02-05 04:17:36 +00:00
|
|
|
if file.tell().unwrap() != 5 * 1024 {
|
2014-02-04 06:54:57 +00:00
|
|
|
fail!();
|
|
|
|
}
|
2014-05-17 13:47:44 +00:00
|
|
|
io::fs::unlink(&Path::new(TFILE1)).unwrap();
|
2014-02-04 06:54:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_decrease_file_size() {
|
2014-02-07 06:39:07 +00:00
|
|
|
let mut file = make_file(TFILE2);
|
2014-06-20 13:15:44 +00:00
|
|
|
file.write(b"1234567890").unwrap();
|
2014-05-17 13:47:44 +00:00
|
|
|
if !Command::new(PROG).args(["--size=-4", TFILE2]).status().unwrap().success() {
|
2014-02-04 06:54:57 +00:00
|
|
|
fail!();
|
|
|
|
}
|
2014-05-17 13:47:44 +00:00
|
|
|
file.seek(0, io::SeekEnd).unwrap();
|
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!();
|
|
|
|
}
|
2014-05-17 13:47:44 +00:00
|
|
|
io::fs::unlink(&Path::new(TFILE2)).unwrap();
|
2014-02-04 06:54:57 +00:00
|
|
|
}
|