mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
tests/install: add tests to install from stdin
This commit is contained in:
parent
200e4b1032
commit
e07cc67b30
1 changed files with 50 additions and 0 deletions
|
@ -1717,3 +1717,53 @@ fn test_install_root_combined() {
|
|||
run_and_check(&["-Cv", "c", "d"], "d", 0, 0);
|
||||
run_and_check(&["-Cv", "c", "d"], "d", 0, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn test_install_from_fifo() {
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
use std::thread;
|
||||
|
||||
let pipe_name = "pipe";
|
||||
let target_name = "target";
|
||||
let test_string = "Hello, world!\n";
|
||||
|
||||
let s = TestScenario::new(util_name!());
|
||||
s.fixtures.mkfifo(pipe_name);
|
||||
assert!(s.fixtures.is_fifo(pipe_name));
|
||||
|
||||
let proc = s.ucmd().arg(pipe_name).arg(target_name).run_no_wait();
|
||||
|
||||
let pipe_path = s.fixtures.plus(pipe_name);
|
||||
let thread = thread::spawn(move || {
|
||||
let mut pipe = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(false)
|
||||
.open(pipe_path)
|
||||
.unwrap();
|
||||
pipe.write_all(test_string.as_bytes()).unwrap();
|
||||
});
|
||||
|
||||
proc.wait().unwrap();
|
||||
thread.join().unwrap();
|
||||
|
||||
assert!(s.fixtures.file_exists(target_name));
|
||||
assert_eq!(s.fixtures.read(target_name), test_string);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn test_install_from_stdin() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let target = "target";
|
||||
let test_string = "Hello, World!\n";
|
||||
|
||||
ucmd.arg("/dev/fd/0")
|
||||
.arg(target)
|
||||
.pipe_in(test_string)
|
||||
.succeeds();
|
||||
|
||||
assert!(at.file_exists(target));
|
||||
assert_eq!(at.read(target), test_string);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue