-
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
13 changed files
with
606 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#![cfg(all(unix, feature = "std"))] | ||
#[path = "std_unix/mod.rs"] | ||
mod std_unix; |
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,39 @@ | ||
use super::prelude::*; | ||
|
||
#[test] | ||
fn nowrap() -> Result<()> { | ||
let child = StdCommandWrap::with_new("echo", |command| { | ||
command.stdout(Stdio::null()); | ||
}) | ||
.spawn()?; | ||
|
||
assert_eq!(child.id(), child.inner().id()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn process_group() -> Result<()> { | ||
let child = StdCommandWrap::with_new("echo", |command| { | ||
command.stdout(Stdio::null()); | ||
}) | ||
.wrap(ProcessGroup::leader()) | ||
.spawn()?; | ||
|
||
assert_eq!(child.id(), child.inner().id()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn process_session() -> Result<()> { | ||
let child = StdCommandWrap::with_new("echo", |command| { | ||
command.stdout(Stdio::null()); | ||
}) | ||
.wrap(ProcessSession) | ||
.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,51 @@ | ||
use super::prelude::*; | ||
|
||
#[test] | ||
fn nowrap() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("echo", |command| { | ||
command.arg("hello").stdout(Stdio::piped()); | ||
}) | ||
.spawn()?; | ||
|
||
let mut output = String::new(); | ||
if let Some(mut out) = child.stdout().take() { | ||
out.read_to_string(&mut output)?; | ||
} | ||
|
||
assert_eq!(output.as_str(), "hello\n"); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn process_group() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("echo", |command| { | ||
command.arg("hello").stdout(Stdio::piped()); | ||
}) | ||
.wrap(ProcessGroup::leader()) | ||
.spawn()?; | ||
|
||
let mut output = String::new(); | ||
if let Some(mut out) = child.stdout().take() { | ||
out.read_to_string(&mut output)?; | ||
} | ||
|
||
assert_eq!(output.as_str(), "hello\n"); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn process_session() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("echo", |command| { | ||
command.arg("hello").stdout(Stdio::piped()); | ||
}) | ||
.wrap(ProcessSession) | ||
.spawn()?; | ||
|
||
let mut output = String::new(); | ||
if let Some(mut out) = child.stdout().take() { | ||
out.read_to_string(&mut output)?; | ||
} | ||
|
||
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,66 @@ | ||
use super::prelude::*; | ||
|
||
#[test] | ||
fn nowrap() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("cat", |command| { | ||
command.stdin(Stdio::piped()).stdout(Stdio::piped()); | ||
}) | ||
.spawn()? | ||
.into_inner(); | ||
|
||
if let Some(mut din) = child.stdin.take() { | ||
din.write_all(b"hello")?; | ||
} | ||
|
||
let mut output = String::new(); | ||
if let Some(mut out) = child.stdout.take() { | ||
out.read_to_string(&mut output)?; | ||
} | ||
|
||
assert_eq!(output.as_str(), "hello"); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn process_group() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("cat", |command| { | ||
command.stdin(Stdio::piped()).stdout(Stdio::piped()); | ||
}) | ||
.wrap(ProcessGroup::leader()) | ||
.spawn()? | ||
.into_inner(); | ||
|
||
if let Some(mut din) = child.stdin.take() { | ||
din.write_all(b"hello")?; | ||
} | ||
|
||
let mut output = String::new(); | ||
if let Some(mut out) = child.stdout.take() { | ||
out.read_to_string(&mut output)?; | ||
} | ||
|
||
assert_eq!(output.as_str(), "hello"); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn process_session() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("cat", |command| { | ||
command.stdin(Stdio::piped()).stdout(Stdio::piped()); | ||
}) | ||
.wrap(ProcessSession) | ||
.spawn()? | ||
.into_inner(); | ||
|
||
if let Some(mut din) = child.stdin.take() { | ||
din.write_all(b"hello")?; | ||
} | ||
|
||
let mut output = String::new(); | ||
if let Some(mut out) = child.stdout.take() { | ||
out.read_to_string(&mut output)?; | ||
} | ||
|
||
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,61 @@ | ||
use super::prelude::*; | ||
|
||
#[test] | ||
fn nowrap() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("yes", |command| { | ||
command.stdout(Stdio::null()); | ||
}) | ||
.spawn()?; | ||
assert!(child.try_wait()?.is_none(), "pre kill"); | ||
|
||
child.kill()?; | ||
sleep(DIE_TIME); | ||
assert!(child.try_wait()?.is_some(), "try_wait() one"); | ||
|
||
sleep(DIE_TIME); | ||
assert!(child.try_wait()?.is_some(), "try_wait() two"); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn process_group() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("yes", |command| { | ||
command.stdout(Stdio::null()); | ||
}) | ||
.wrap(ProcessGroup::leader()) | ||
.spawn()?; | ||
assert!(child.try_wait()?.is_none(), "pre kill"); | ||
|
||
child.kill()?; | ||
|
||
let status = (child.wait())?; | ||
assert!(!status.success()); | ||
|
||
sleep(DIE_TIME); | ||
assert!(child.try_wait()?.is_some(), "try_wait() one"); | ||
|
||
sleep(DIE_TIME); | ||
assert!(child.try_wait()?.is_some(), "try_wait() two"); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn process_session() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("yes", |command| { | ||
command.stdout(Stdio::null()); | ||
}) | ||
.wrap(ProcessSession) | ||
.spawn()?; | ||
assert!(child.try_wait()?.is_none(), "pre kill"); | ||
|
||
child.kill()?; | ||
sleep(DIE_TIME); | ||
assert!(child.try_wait()?.is_some(), "try_wait() one"); | ||
|
||
sleep(DIE_TIME); | ||
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,26 @@ | ||
mod prelude { | ||
pub use std::{ | ||
io::{Read, Result, Write}, | ||
os::unix::process::ExitStatusExt, | ||
process::Stdio, | ||
thread::sleep, | ||
time::Duration, | ||
}; | ||
|
||
pub use nix::sys::signal::Signal; | ||
pub use process_wrap::std::*; | ||
|
||
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 signals; | ||
mod try_wait_after_die; | ||
mod try_wait_twice_after_sigterm; | ||
mod wait_after_die; | ||
mod wait_twice; | ||
mod wait_twice_after_sigterm; | ||
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,57 @@ | ||
use super::prelude::*; | ||
|
||
#[test] | ||
fn nowrap() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("yes", |command| { | ||
command.stdout(Stdio::null()); | ||
}) | ||
.spawn()?; | ||
|
||
child.signal(Signal::SIGCONT)?; | ||
sleep(DIE_TIME); | ||
assert!(child.try_wait()?.is_none(), "not exited with sigcont"); | ||
|
||
child.signal(Signal::SIGTERM)?; | ||
sleep(DIE_TIME); | ||
assert!(child.try_wait()?.is_some(), "exited with sigterm"); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn process_group() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("yes", |command| { | ||
command.stdout(Stdio::null()); | ||
}) | ||
.wrap(ProcessGroup::leader()) | ||
.spawn()?; | ||
|
||
child.signal(Signal::SIGCONT)?; | ||
sleep(DIE_TIME); | ||
assert!(child.try_wait()?.is_none(), "not exited with sigcont"); | ||
|
||
child.signal(Signal::SIGTERM)?; | ||
sleep(DIE_TIME); | ||
assert!(child.try_wait()?.is_some(), "exited with sigterm"); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn process_session() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("yes", |command| { | ||
command.stdout(Stdio::null()); | ||
}) | ||
.wrap(ProcessSession) | ||
.spawn()?; | ||
|
||
child.signal(Signal::SIGCONT)?; | ||
sleep(DIE_TIME); | ||
assert!(child.try_wait()?.is_none(), "not exited with sigcont"); | ||
|
||
child.signal(Signal::SIGTERM)?; | ||
sleep(DIE_TIME); | ||
assert!(child.try_wait()?.is_some(), "exited with sigterm"); | ||
|
||
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,45 @@ | ||
use super::prelude::*; | ||
|
||
#[test] | ||
fn nowrap() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("echo", |command| { | ||
command.stdout(Stdio::null()); | ||
}) | ||
.spawn()?; | ||
sleep(DIE_TIME); | ||
let status = child.try_wait()?; | ||
assert!(status.is_some()); | ||
assert!(status.unwrap().success()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn process_group() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("echo", |command| { | ||
command.stdout(Stdio::null()); | ||
}) | ||
.wrap(ProcessGroup::leader()) | ||
.spawn()?; | ||
sleep(DIE_TIME); | ||
let status = child.try_wait()?; | ||
assert!(status.is_some()); | ||
assert!(status.unwrap().success()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn process_session() -> Result<()> { | ||
let mut child = StdCommandWrap::with_new("echo", |command| { | ||
command.stdout(Stdio::null()); | ||
}) | ||
.wrap(ProcessSession) | ||
.spawn()?; | ||
sleep(DIE_TIME); | ||
let status = child.try_wait()?; | ||
assert!(status.is_some()); | ||
assert!(status.unwrap().success()); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.