From fafab00cd8a374b85275418956304edaa7ccc0b9 Mon Sep 17 00:00:00 2001 From: Mariano Casco Date: Mon, 30 May 2016 19:12:01 -0300 Subject: [PATCH 1/3] tail: remove extra println --- src/tail/tail.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tail/tail.rs b/src/tail/tail.rs index a806af722..d4d17003c 100755 --- a/src/tail/tail.rs +++ b/src/tail/tail.rs @@ -319,8 +319,7 @@ fn follow(mut readers: Vec>, filenames: &Vec, sett Ok(0) => break, Ok(_) => { if i != last { - println!(""); - println!("==> {} <==", filenames[i]); + println!("\n==> {} <==", filenames[i]); last = i; } print!("{}", datum); From 79d281394f70fd0fdc9e981c8c482160f5d87e28 Mon Sep 17 00:00:00 2001 From: Mariano Casco Date: Tue, 31 May 2016 12:36:45 -0300 Subject: [PATCH 2/3] tail: -f option on stdin The follow() function takes slices instead of the actual vectors, and in the case of unbounded_tail the single bufReader is on stdin. --- src/tail/tail.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/tail/tail.rs b/src/tail/tail.rs index d4d17003c..05651a25d 100755 --- a/src/tail/tail.rs +++ b/src/tail/tail.rs @@ -172,7 +172,7 @@ pub fn uumain(args: Vec) -> i32 { } if settings.follow { - follow(readers, &files, &settings); + follow(&mut readers[..], &files[..], &settings); } } @@ -304,7 +304,7 @@ fn obsolete(options: &[String]) -> (Vec, Option) { /// block read at a time. const BLOCK_SIZE: u64 = 1 << 16; -fn follow(mut readers: Vec>, filenames: &Vec, settings: &Settings) { +fn follow(readers: &mut [BufReader], filenames: &[String], settings: &Settings) { assert!(settings.follow); let mut last = readers.len() - 1; @@ -482,10 +482,8 @@ fn unbounded_tail(mut reader: BufReader, settings: &Settings) { } } - // TODO: make following stdin work with the new follow() signature - // maybe wrap stdin in a 1-element vec? if settings.follow { - //follow(reader, settings); + follow(&mut [reader], &["stdin".to_string()], settings); } } From abb95018940b02b2b6317b8523dc3556645098a8 Mon Sep 17 00:00:00 2001 From: Mariano Casco Date: Tue, 31 May 2016 17:40:06 -0300 Subject: [PATCH 3/3] tail: test -f with no files --- tests/fixtures/tail/follow_stdin.expected | 10 ++++++++++ tests/test_tail.rs | 13 ++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/tail/follow_stdin.expected diff --git a/tests/fixtures/tail/follow_stdin.expected b/tests/fixtures/tail/follow_stdin.expected new file mode 100644 index 000000000..8eacac3b5 --- /dev/null +++ b/tests/fixtures/tail/follow_stdin.expected @@ -0,0 +1,10 @@ +dos +tres +quattro +cinco +seis +siette +ocho +nueve +diez +once diff --git a/tests/test_tail.rs b/tests/test_tail.rs index c842354d1..4f5f117bd 100644 --- a/tests/test_tail.rs +++ b/tests/test_tail.rs @@ -2,7 +2,7 @@ extern crate uu_tail; use common::util::*; use std::char::from_digit; -use std::io::{Read, Write}; +use std::io::Write; use uu_tail::parse_size; static UTIL_NAME: &'static str = "tail"; @@ -77,6 +77,17 @@ fn test_follow_multiple() { child.kill().unwrap(); } +#[test] +fn test_follow_stdin() { + let (at, mut ucmd) = testing(UTIL_NAME); + let mut child = ucmd.arg("-f").pipe_in(at.read(FOOBAR_TXT)).run_no_wait(); + + let expected = at.read("follow_stdin.expected"); + assert_eq!(read_size(&mut child, expected.len()), expected); + + child.kill().unwrap(); +} + #[test] fn test_single_big_args() { const FILE: &'static str = "single_big_args.txt";