mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 15:22:38 +00:00
tests/tail: Add system tests for ---presume-input-pipe
This commit is contained in:
parent
fa8eaf3080
commit
c32d61dcfb
2 changed files with 75 additions and 7 deletions
|
@ -380,9 +380,9 @@ fn backwards_thru_file(file: &mut File, num_delimiters: u64, delimiter: u8) {
|
|||
/// `BLOCK_SIZE` until we find the location of the first line/byte. This ends up
|
||||
/// being a nice performance win for very large files.
|
||||
fn bounded_tail(file: &mut File, settings: &Settings) {
|
||||
debug_assert!(!settings.presume_input_pipe);
|
||||
|
||||
// Find the position in the file to start printing from.
|
||||
// dbg!("bounded");
|
||||
// dbg!(&settings.mode);
|
||||
match &settings.mode {
|
||||
FilterMode::Lines(Signum::Negative(count), delimiter) => {
|
||||
backwards_thru_file(file, *count, *delimiter);
|
||||
|
@ -419,8 +419,6 @@ fn bounded_tail(file: &mut File, settings: &Settings) {
|
|||
fn unbounded_tail<T: Read>(reader: &mut BufReader<T>, settings: &Settings) -> UResult<()> {
|
||||
let stdout = stdout();
|
||||
let mut writer = BufWriter::new(stdout.lock());
|
||||
// dbg!("unbounded");
|
||||
// dbg!(&settings.mode);
|
||||
match &settings.mode {
|
||||
FilterMode::Lines(Signum::Negative(count), sep) => {
|
||||
let mut chunks = chunks::LinesChunkBuffer::new(*sep, *count);
|
||||
|
|
|
@ -7,10 +7,9 @@
|
|||
// spell-checker:ignore (libs) kqueue
|
||||
// spell-checker:ignore (jargon) tailable untailable
|
||||
|
||||
// TODO: add tests for presume_input_pipe
|
||||
|
||||
extern crate tail;
|
||||
|
||||
use crate::common::random::*;
|
||||
use crate::common::util::*;
|
||||
use std::char::from_digit;
|
||||
#[cfg(unix)]
|
||||
|
@ -2516,7 +2515,6 @@ fn test_illegal_seek() {
|
|||
#[cfg(all(not(target_os = "android"), not(target_os = "windows")))] // FIXME: See https://github.com/uutils/coreutils/issues/3881
|
||||
mod pipe_tests {
|
||||
use super::*;
|
||||
use crate::common::random::*;
|
||||
use rand::distributions::Alphanumeric;
|
||||
use tail::chunks::BUFFER_SIZE as CHUNK_BUFFER_SIZE;
|
||||
|
||||
|
@ -3251,3 +3249,75 @@ fn test_seek_bytes_forward_outside_file() {
|
|||
.run()
|
||||
.stdout_is("");
|
||||
}
|
||||
|
||||
// Some basic tests for ---presume-input-pipe. These tests build upon the
|
||||
// debug_assert in bounded tail to detect that we're using the bounded_tail in
|
||||
// case the option is given on command line.
|
||||
#[cfg(all(not(target_os = "android"), not(target_os = "windows")))] // FIXME:
|
||||
#[test]
|
||||
fn test_args_when_presume_input_pipe_given_input_is_pipe() {
|
||||
let random_string = RandomString::generate(AlphanumericNewline, 1000);
|
||||
let random_string = random_string.as_str();
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["---presume-input-pipe", "-c", "-0"])
|
||||
.pipe_in(random_string)
|
||||
.ignore_stdin_write_error()
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.no_stderr();
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["---presume-input-pipe", "-c", "+0"])
|
||||
.pipe_in(random_string)
|
||||
.ignore_stdin_write_error()
|
||||
.succeeds()
|
||||
.stdout_only(random_string);
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["---presume-input-pipe", "-n", "-0"])
|
||||
.pipe_in(random_string)
|
||||
.ignore_stdin_write_error()
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.no_stderr();
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["---presume-input-pipe", "-n", "+0"])
|
||||
.pipe_in(random_string)
|
||||
.ignore_stdin_write_error()
|
||||
.succeeds()
|
||||
.stdout_only(random_string);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_args_when_presume_input_pipe_given_input_is_file() {
|
||||
let random_string = RandomString::generate(AlphanumericNewline, 1000);
|
||||
let random_string = random_string.as_str();
|
||||
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
at.write("data", random_string);
|
||||
|
||||
ts.ucmd()
|
||||
.args(&["---presume-input-pipe", "-c", "-0", "data"])
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.no_stderr();
|
||||
|
||||
ts.ucmd()
|
||||
.args(&["---presume-input-pipe", "-c", "+0", "data"])
|
||||
.succeeds()
|
||||
.stdout_only(random_string);
|
||||
|
||||
ts.ucmd()
|
||||
.args(&["---presume-input-pipe", "-n", "-0", "data"])
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.no_stderr();
|
||||
|
||||
ts.ucmd()
|
||||
.args(&["---presume-input-pipe", "-n", "+0", "data"])
|
||||
.succeeds()
|
||||
.stdout_only(random_string);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue