mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
tail: Add test for tail -f
.
This commit is contained in:
parent
4ba6ea7aad
commit
e673a102b6
2 changed files with 36 additions and 1 deletions
|
@ -3,7 +3,7 @@
|
|||
extern crate tempdir;
|
||||
|
||||
use std::env;
|
||||
use std::fs::{self, File};
|
||||
use std::fs::{self, File, OpenOptions};
|
||||
use std::io::{Read, Write, Result};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
#[cfg(unix)]
|
||||
|
@ -16,6 +16,8 @@ use std::str::from_utf8;
|
|||
use std::ffi::OsStr;
|
||||
use self::tempdir::TempDir;
|
||||
use std::rc::Rc;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
#[cfg(windows)]
|
||||
static PROGNAME: &'static str = "target\\debug\\uutils.exe";
|
||||
|
@ -242,6 +244,12 @@ impl AtPath {
|
|||
let _ = f.write(contents.as_bytes());
|
||||
}
|
||||
|
||||
pub fn append(&self, name: &str, contents: &str) {
|
||||
log_info("open(append)", self.plus_as_string(name));
|
||||
let mut f = OpenOptions::new().append(true).open(self.plus(name)).unwrap();
|
||||
let _ = f.write(contents.as_bytes());
|
||||
}
|
||||
|
||||
pub fn mkdir(&self, dir: &str) {
|
||||
log_info("mkdir", self.plus_as_string(dir));
|
||||
fs::create_dir(&self.plus(dir)).unwrap();
|
||||
|
@ -544,6 +552,14 @@ impl UCommand {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn read_size(child: &mut Child, size: usize) -> String {
|
||||
let mut output = Vec::new();
|
||||
output.resize(size, 0);
|
||||
sleep(Duration::from_millis(100));
|
||||
child.stdout.as_mut().unwrap().read(output.as_mut_slice()).unwrap();
|
||||
String::from_utf8(output).unwrap()
|
||||
}
|
||||
|
||||
// returns a testSet and a ucommand initialized to the utility binary
|
||||
// operating in the fixtures directory with a cleared environment
|
||||
pub fn testset_and_ucommand(utilname: &str) -> (TestSet, UCommand) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
extern crate uu_tail;
|
||||
use uu_tail::parse_size;
|
||||
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
|
||||
#[macro_use]
|
||||
|
@ -41,6 +42,24 @@ fn test_null_default() {
|
|||
assert_eq!(result.stdout, at.read("foobar_with_null_default.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_follow() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
|
||||
let mut child = ucmd.arg("-f").arg(FOOBAR_TXT).run_no_wait();
|
||||
|
||||
let expected = at.read("foobar_single_default.expected");
|
||||
assert_eq!(read_size(&mut child, expected.len()), expected);
|
||||
|
||||
// We write in a temporary copy of foobar.txt
|
||||
let expected = "line1\nline2\n";
|
||||
at.append(FOOBAR_TXT, 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";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue