2015-11-16 05:25:01 +00:00
|
|
|
use common::util::*;
|
2016-05-22 07:46:54 +00:00
|
|
|
use std::io::{Seek, SeekFrom, Write};
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
static UTIL_NAME: &'static str = "truncate";
|
2016-07-29 21:26:32 +00:00
|
|
|
fn at_and_ucmd() -> (AtPath, UCommand) {
|
|
|
|
let ts = TestScenario::new(UTIL_NAME);
|
|
|
|
let ucmd = ts.ucmd();
|
|
|
|
(ts.fixtures, ucmd)
|
|
|
|
}
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
static TFILE1: &'static str = "truncate_test_1";
|
|
|
|
static TFILE2: &'static str = "truncate_test_2";
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_increase_file_size() {
|
2016-07-29 21:26:32 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd();
|
2015-11-16 05:25:01 +00:00
|
|
|
let mut file = at.make_file(TFILE1);
|
|
|
|
assert!(ucmd.args(&["-s", "+5K", TFILE1]).run().success);
|
|
|
|
|
|
|
|
file.seek(SeekFrom::End(0)).unwrap();
|
|
|
|
assert!(file.seek(SeekFrom::Current(0)).unwrap() == 5 * 1024);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_decrease_file_size() {
|
2016-07-29 21:26:32 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd();
|
2015-11-16 05:25:01 +00:00
|
|
|
let mut file = at.make_file(TFILE2);
|
|
|
|
file.write_all(b"1234567890").unwrap();
|
|
|
|
assert!(ucmd.args(&["--size=-4", TFILE2]).run().success);
|
|
|
|
file.seek(SeekFrom::End(0)).unwrap();
|
|
|
|
assert!(file.seek(SeekFrom::Current(0)).unwrap() == 6);
|
|
|
|
}
|