-
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
21 changed files
with
301 additions
and
2 deletions.
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
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
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
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
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
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,3 @@ | ||
#![cfg(all(windows, feature = "tokio1"))] | ||
#[path = "tokio_windows/mod.rs"] | ||
mod tokio_windows; |
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,26 @@ | ||
use super::prelude::*; | ||
|
||
#[tokio::test] | ||
async fn nowrap() -> Result<()> { | ||
let child = TokioCommandWrap::with_new("powershell.exe", |command| { | ||
command.arg("/C").arg("echo hello").stdout(Stdio::null()); | ||
}) | ||
.spawn()?; | ||
|
||
assert_eq!(child.id(), child.inner().id()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn process_job_object() -> Result<()> { | ||
let child = TokioCommandWrap::with_new("powershell.exe", |command| { | ||
command.arg("/C").arg("echo hello").stdout(Stdio::null()); | ||
}) | ||
.wrap(JobObject) | ||
.spawn()?; | ||
|
||
assert_eq!(child.id(), child.inner().id()); | ||
|
||
Ok(()) | ||
} |
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,34 @@ | ||
use super::prelude::*; | ||
|
||
#[tokio::test] | ||
async fn nowrap() -> Result<()> { | ||
let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { | ||
command.arg("/C").arg("echo hello").stdout(Stdio::piped()); | ||
}) | ||
.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 process_job_object() -> Result<()> { | ||
let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { | ||
command.arg("/C").arg("echo hello").stdout(Stdio::piped()); | ||
}) | ||
.wrap(JobObject) | ||
.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(()) | ||
} |
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,43 @@ | ||
use super::prelude::*; | ||
|
||
#[tokio::test] | ||
async fn nowrap() -> Result<()> { | ||
let mut child = TokioCommandWrap::with_new("findstr", |command| { | ||
command.arg("^").stdin(Stdio::piped()).stdout(Stdio::piped()); | ||
}) | ||
.spawn()?; | ||
|
||
if let Some(mut din) = child.stdin().take() { | ||
din.write_all(b"hello").await?; | ||
} | ||
|
||
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"); | ||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn job_object() -> Result<()> { | ||
let mut child = TokioCommandWrap::with_new("findstr", |command| { | ||
command.arg("^").stdin(Stdio::piped()).stdout(Stdio::piped()); | ||
}) | ||
.wrap(JobObject) | ||
.spawn()? | ||
.into_inner(); | ||
|
||
if let Some(mut din) = child.stdin().take() { | ||
din.write_all(b"hello").await?; | ||
} | ||
|
||
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"); | ||
Ok(()) | ||
} |
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,38 @@ | ||
use super::prelude::*; | ||
|
||
#[tokio::test] | ||
async fn nowrap() -> Result<()> { | ||
let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { | ||
command.arg("/C").arg("pause").stdout(Stdio::null()); | ||
}) | ||
.spawn()?; | ||
assert!(child.try_wait()?.is_none(), "pre kill"); | ||
|
||
Box::into_pin(child.kill()).await?; | ||
sleep(DIE_TIME).await; | ||
assert!(child.try_wait()?.is_some(), "try_wait() one"); | ||
|
||
sleep(DIE_TIME).await; | ||
assert!(child.try_wait()?.is_some(), "try_wait() two"); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn job_object() -> Result<()> { | ||
let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { | ||
command.arg("/C").arg("pause").stdout(Stdio::null()); | ||
}) | ||
.wrap(JobObject) | ||
.spawn()?; | ||
assert!(child.try_wait()?.is_none(), "pre kill"); | ||
|
||
Box::into_pin(child.kill()).await?; | ||
sleep(DIE_TIME).await; | ||
assert!(child.try_wait()?.is_some(), "try_wait() one"); | ||
|
||
sleep(DIE_TIME).await; | ||
assert!(child.try_wait()?.is_some(), "try_wait() two"); | ||
|
||
Ok(()) | ||
} |
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,20 @@ | ||
mod prelude { | ||
pub use std::{io::Result, process::Stdio, time::Duration}; | ||
|
||
pub use process_wrap::tokio::*; | ||
pub use tokio::{ | ||
io::{AsyncReadExt, AsyncWriteExt}, | ||
time::sleep, | ||
}; | ||
|
||
pub const DIE_TIME: Duration = Duration::from_millis(100); | ||
} | ||
|
||
mod id_same_as_inner; | ||
mod inner_read_stdout; | ||
mod into_inner_write_stdin; | ||
mod kill_and_try_wait; | ||
mod try_wait_after_die; | ||
mod wait_after_die; | ||
mod wait_twice; | ||
mod wait_with_output; |
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,30 @@ | ||
use super::prelude::*; | ||
|
||
#[tokio::test] | ||
async fn nowrap() -> Result<()> { | ||
let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { | ||
command.arg("/C").arg("echo hello").stdout(Stdio::null()); | ||
}) | ||
.spawn()?; | ||
sleep(DIE_TIME).await; | ||
let status = child.try_wait()?; | ||
assert!(status.is_some()); | ||
assert!(status.unwrap().success()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn job_object() -> Result<()> { | ||
let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { | ||
command.arg("/C").arg("echo hello").stdout(Stdio::null()); | ||
}) | ||
.wrap(JobObject) | ||
.spawn()?; | ||
sleep(DIE_TIME).await; | ||
let status = child.try_wait()?; | ||
assert!(status.is_some()); | ||
assert!(status.unwrap().success()); | ||
|
||
Ok(()) | ||
} |
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,30 @@ | ||
use super::prelude::*; | ||
|
||
#[tokio::test] | ||
async fn nowrap() -> Result<()> { | ||
let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { | ||
command.arg("/C").arg("echo hello").stdout(Stdio::null()); | ||
}) | ||
.spawn()?; | ||
sleep(DIE_TIME).await; | ||
|
||
let status = Box::into_pin(child.wait()).await?; | ||
assert!(status.success()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn job_object() -> Result<()> { | ||
let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { | ||
command.arg("/C").arg("echo hello").stdout(Stdio::null()); | ||
}) | ||
.wrap(JobObject) | ||
.spawn()?; | ||
sleep(DIE_TIME).await; | ||
|
||
let status = Box::into_pin(child.wait()).await?; | ||
assert!(status.success()); | ||
|
||
Ok(()) | ||
} |
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,34 @@ | ||
use super::prelude::*; | ||
|
||
#[tokio::test] | ||
async fn nowrap() -> Result<()> { | ||
let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { | ||
command.arg("/C").arg("echo hello").stdout(Stdio::null()); | ||
}) | ||
.spawn()?; | ||
|
||
let status = Box::into_pin(child.wait()).await?; | ||
assert!(status.success()); | ||
|
||
let status = Box::into_pin(child.wait()).await?; | ||
assert!(status.success()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn job_object() -> Result<()> { | ||
let mut child = TokioCommandWrap::with_new("powershell.exe", |command| { | ||
command.arg("/C").arg("echo hello").stdout(Stdio::null()); | ||
}) | ||
.wrap(JobObject) | ||
.spawn()?; | ||
|
||
let status = Box::into_pin(child.wait()).await?; | ||
assert!(status.success()); | ||
|
||
let status = Box::into_pin(child.wait()).await?; | ||
assert!(status.success()); | ||
|
||
Ok(()) | ||
} |
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,30 @@ | ||
use super::prelude::*; | ||
|
||
#[tokio::test] | ||
async fn nowrap() -> Result<()> { | ||
let child = TokioCommandWrap::with_new("powershell.exe", |command| { | ||
command.arg("/C").arg("echo hello").stdout(Stdio::piped()); | ||
}) | ||
.spawn()?; | ||
|
||
let output = Box::into_pin(child.wait_with_output()).await?; | ||
assert!(output.status.success()); | ||
assert_eq!(output.stdout, b"hello\r\n".to_vec()); | ||
assert_eq!(output.stderr, Vec::new()); | ||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn job_object() -> Result<()> { | ||
let child = TokioCommandWrap::with_new("powershell.exe", |command| { | ||
command.arg("/C").arg("echo hello").stdout(Stdio::piped()); | ||
}) | ||
.wrap(JobObject) | ||
.spawn()?; | ||
|
||
let output = Box::into_pin(child.wait_with_output()).await?; | ||
assert!(output.status.success()); | ||
assert_eq!(output.stdout, b"hello\r\n".to_vec()); | ||
assert_eq!(output.stderr, Vec::new()); | ||
Ok(()) | ||
} |