mirror of
https://github.com/uutils/coreutils
synced 2024-12-18 17:14:42 +00:00
7ef4bb37a8
The main motivation is to move toward running those tests for a specific target, that is, if a test won't run on Windows, then we shouldn't build it. This was previously the default behavior and prevented a successful run on AppVeyor. I borrowed this pattern from the tests in the Cargo project.
27 lines
840 B
Rust
27 lines
840 B
Rust
use common::util::*;
|
|
use std::io::{Seek, SeekFrom, Write};
|
|
|
|
static UTIL_NAME: &'static str = "truncate";
|
|
|
|
static TFILE1: &'static str = "truncate_test_1";
|
|
static TFILE2: &'static str = "truncate_test_2";
|
|
|
|
#[test]
|
|
fn test_increase_file_size() {
|
|
let (at, mut ucmd) = testing(UTIL_NAME);
|
|
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() {
|
|
let (at, mut ucmd) = testing(UTIL_NAME);
|
|
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);
|
|
}
|