coreutils/test/truncate.rs

42 lines
1.1 KiB
Rust
Raw Normal View History

use std::fs;
2015-04-29 23:20:51 +00:00
use std::io::{Seek, SeekFrom, Write};
use std::path::Path;
use std::process::Command;
use util::*;
2014-02-04 06:54:57 +00:00
2014-07-21 17:08:19 +00:00
static PROGNAME: &'static str = "./truncate";
static TFILE1: &'static str = "truncate_test_1";
static TFILE2: &'static str = "truncate_test_2";
2014-02-04 06:54:57 +00:00
#[path = "common/util.rs"]
#[macro_use]
mod util;
2014-02-04 06:54:57 +00:00
#[test]
fn test_increase_file_size() {
let mut file = make_file(TFILE1);
if !Command::new(PROGNAME).args(&["-s", "+5K", TFILE1]).status().unwrap().success() {
2014-10-30 09:06:47 +00:00
panic!();
2014-02-04 06:54:57 +00:00
}
2015-04-29 23:20:51 +00:00
file.seek(SeekFrom::End(0)).unwrap();
if file.seek(SeekFrom::Current(0)).unwrap() != 5 * 1024 {
2014-10-30 09:06:47 +00:00
panic!();
2014-02-04 06:54:57 +00:00
}
fs::remove_file(Path::new(TFILE1)).unwrap();
2014-02-04 06:54:57 +00:00
}
#[test]
fn test_decrease_file_size() {
let mut file = make_file(TFILE2);
2015-01-29 07:45:08 +00:00
file.write_all(b"1234567890").unwrap();
if !Command::new(PROGNAME).args(&["--size=-4", TFILE2]).status().unwrap().success() {
2014-10-30 09:06:47 +00:00
panic!();
2014-02-04 06:54:57 +00:00
}
2015-04-29 23:20:51 +00:00
file.seek(SeekFrom::End(0)).unwrap();
if file.seek(SeekFrom::Current(0)).unwrap() != 6 {
println!("{:?}", file.seek(SeekFrom::Current(0)));
2014-10-30 09:06:47 +00:00
panic!();
2014-02-04 06:54:57 +00:00
}
fs::remove_file(Path::new(TFILE2)).unwrap();
2014-02-04 06:54:57 +00:00
}