-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#![cfg(all(unix, feature = "tokio1"))] | ||
|
||
use std::{ | ||
io::Result, | ||
process::Stdio, | ||
}; | ||
|
||
use process_wrap::tokio::*; | ||
use tokio::{ | ||
io::AsyncReadExt, | ||
process::Command, | ||
}; | ||
|
||
// each test has a _nowrap variant that uses the process-wrap API but doesn't apply any Wrappers for comparison/debugging. | ||
|
||
#[tokio::test] | ||
async fn inner_read_stdout_nowrap() -> Result<()> { | ||
let mut command = Command::new("echo"); | ||
command.arg("hello").stdout(Stdio::piped()); | ||
let mut child = TokioCommandWrap::new(command).spawn()?; | ||
|
||
let mut output = String::new(); | ||
if let Some(mut out) = child.stdout().take() { | ||
out.read_to_string(&mut output).await?; | ||
} | ||
|
||
assert_eq!(output.as_str(), "hello\n"); | ||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn inner_read_stdout_process_group() -> Result<()> { | ||
let mut command = Command::new("echo"); | ||
command.arg("hello").stdout(Stdio::piped()); | ||
let mut command = TokioCommandWrap::new(command); | ||
command.wrap(ProcessGroup::leader()); | ||
|
||
let mut child = command.spawn()?; | ||
let mut output = String::new(); | ||
if let Some(mut out) = child.stdout().take() { | ||
out.read_to_string(&mut output).await?; | ||
} | ||
|
||
assert_eq!(output.as_str(), "hello\n"); | ||
Ok(()) | ||
} |