1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

tests/tail: Add a test for tail'ing large files

This tests both large files and iterating backwards through the file when we
need to search backwards further than our BUFFER_SIZE.
This commit is contained in:
Nick Fitzgerald 2016-03-19 22:25:53 -07:00
parent 161f96dc8c
commit d7974c56a0

View file

@ -1,3 +1,5 @@
use std::io::Write;
#[macro_use] #[macro_use]
mod common; mod common;
@ -7,6 +9,9 @@ static UTIL_NAME: &'static str = "tail";
static INPUT: &'static str = "foobar.txt"; static INPUT: &'static str = "foobar.txt";
static BIG: &'static str = "big.txt";
static BIG_EXPECTED: &'static str = "big_single_big_args.expected";
#[test] #[test]
fn test_stdin_default() { fn test_stdin_default() {
@ -21,3 +26,34 @@ fn test_single_default() {
let result = ucmd.arg(INPUT).run(); let result = ucmd.arg(INPUT).run();
assert_eq!(result.stdout, at.read("foobar_single_default.expected")); assert_eq!(result.stdout, at.read("foobar_single_default.expected"));
} }
const BIG_LINES: usize = 1_000_000;
const BIG_N_ARG: usize = 100_000;
fn generate_big_test_files(at: &AtPath) {
let mut big_input = at.make_file(BIG);
for i in 0..BIG_LINES {
write!(&mut big_input, "Line {}\n", i).expect("Could not write to BIG file");
}
big_input.flush().expect("Could not flush BIG file");
let mut big_expected = at.make_file(BIG_EXPECTED);
for i in (BIG_LINES - BIG_N_ARG)..BIG_LINES {
write!(&mut big_expected, "Line {}\n", i).expect("Could not write to BIG_EXPECTED file");
}
big_expected.flush().expect("Could not flush BIG_EXPECTED file");
}
fn cleanup_big_test_files(at: &AtPath) {
at.cleanup(BIG);
at.cleanup(BIG_EXPECTED);
}
#[test]
fn test_single_big_args() {
let (at, mut ucmd) = testing(UTIL_NAME);
generate_big_test_files(&at);
let result = ucmd.arg(BIG).arg("-n").arg(format!("{}", BIG_N_ARG)).run();
assert_eq!(result.stdout, at.read(BIG_EXPECTED));
cleanup_big_test_files(&at);
}