2020-05-25 17:05:26 +00:00
|
|
|
use crate::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 TFILE1: &'static str = "truncate_test_1";
|
|
|
|
static TFILE2: &'static str = "truncate_test_2";
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_increase_file_size() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2015-11-16 05:25:01 +00:00
|
|
|
let mut file = at.make_file(TFILE1);
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.args(&["-s", "+5K", TFILE1]).succeeds();
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
file.seek(SeekFrom::End(0)).unwrap();
|
|
|
|
assert!(file.seek(SeekFrom::Current(0)).unwrap() == 5 * 1024);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_decrease_file_size() {
|
2016-08-23 11:52:43 +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();
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.args(&["--size=-4", TFILE2]).succeeds();
|
2015-11-16 05:25:01 +00:00
|
|
|
file.seek(SeekFrom::End(0)).unwrap();
|
|
|
|
assert!(file.seek(SeekFrom::Current(0)).unwrap() == 6);
|
|
|
|
}
|