use pretty_assertions::assert_eq;
use std::{io::Write, process::Stdio};
#[test]
fn test1653483581_demo_example() {
let mut std_io_iterators_demo = escargot::CargoBuild::new()
.example("demo")
.run()
.expect("1653483983 - Failed to link to cargo binary")
.command()
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.expect("1653483903 - Failed to spawn child process");
let mut stdin = std_io_iterators_demo
.stdin
.take()
.expect("1653485873 - Failed to open stdin");
std::thread::spawn(move || {
stdin
.write_all("Hello, world!".as_bytes())
.expect("1653484109 - Failed to write to stdin");
});
let output = std_io_iterators_demo
.wait_with_output()
.expect("1653484120 - Failed to read stdout");
assert_eq!(
String::from_utf8_lossy(&output.stdout),
"Prepend-Hello, world!\ntest1\ntest2\ntest3\n"
);
}
#[test]
fn test1669403991_pipe_in_and_pipe_out_examples() {
let mut pipe_out = escargot::CargoBuild::new()
.example("pipe_out")
.run()
.expect("1669404035 - Failed to link to pipe_out")
.command()
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.expect("1669404297 - Failed to spawn pipe_out");
let std_out = pipe_out.stdout.take().unwrap();
let pipe_in = escargot::CargoBuild::new()
.example("pipe_in")
.run()
.expect("1669404314 - Failed to link to pipe_in")
.command()
.stdin(std_out)
.stdout(Stdio::piped())
.spawn()
.expect("1669404321 - Failed to spawn pipe_in");
let output = pipe_in
.wait_with_output()
.expect("1669404902 - Failed to read stdout");
pipe_out
.wait()
.expect("1750805401 - Should be done since pipe_in is done");
assert_eq!(
String::from_utf8_lossy(&output.stdout),
"1669234324 - Test Passed\n"
);
}