diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index 88f309d95..7f7d0d9a3 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -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(reader: &mut BufReader, 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); diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index 8e2e177c8..5460df554 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -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); +}