Skip to content

Commit

Permalink
fix(stdin): Provide a Command wrapper
Browse files Browse the repository at this point in the history
Many of our problems with `stdin` are derived from using extension
traits. By moving away from them, we fix the API problems and make it
easier to add other features like timeout (assert-rs#10) or signalling (assert-rs#84).

So the new philosphy if:
- Core functionality is provided by extension traits
- Provide a convinience API that makes `Command` friendlier. These do
  not need to be generalized.  Other abstractions can provide their own
  (like `duct`).

Fixes assert-rs#73
  • Loading branch information
Ed Page committed Dec 5, 2019
1 parent 15e40f6 commit d159e87
Show file tree
Hide file tree
Showing 6 changed files with 557 additions and 287 deletions.
11 changes: 3 additions & 8 deletions README.md
Expand Up @@ -21,15 +21,10 @@ assert_cmd = "0.11"
Here's a trivial example:

```rust,no_run
extern crate assert_cmd;
use assert_cmd::Command;
use std::process::Command;
use assert_cmd::prelude::*;
Command::cargo_bin("bin_fixture")
.unwrap()
.assert()
.success();
let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
cmd.assert().success();
```

## Relevant crates
Expand Down
22 changes: 16 additions & 6 deletions src/cargo.rs
Expand Up @@ -124,14 +124,24 @@ where
fn cargo_bin<S: AsRef<str>>(name: S) -> Result<Self, CargoError>;
}

impl CommandCargoExt for crate::cmd::Command {
fn cargo_bin<S: AsRef<str>>(name: S) -> Result<Self, CargoError> {
crate::cmd::Command::cargo_bin(name)
}
}

impl CommandCargoExt for process::Command {
fn cargo_bin<S: AsRef<str>>(name: S) -> Result<Self, CargoError> {
let path = cargo_bin(name);
if path.is_file() {
Ok(process::Command::new(path))
} else {
Err(CargoError::with_cause(NotFoundError { path }))
}
cargo_bin_cmd(name)
}
}

pub(crate) fn cargo_bin_cmd<S: AsRef<str>>(name: S) -> Result<process::Command, CargoError> {
let path = cargo_bin(name);
if path.is_file() {
Ok(process::Command::new(path))
} else {
Err(CargoError::with_cause(NotFoundError { path }))
}
}

Expand Down

0 comments on commit d159e87

Please sign in to comment.