Skip to content

Commit

Permalink
Merge pull request #85 from epage/10
Browse files Browse the repository at this point in the history
fix(stdin): Provide a Command wrapper
  • Loading branch information
epage committed Dec 5, 2019
2 parents 028b0df + d159e87 commit fdf9cd3
Show file tree
Hide file tree
Showing 8 changed files with 818 additions and 548 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
4 changes: 2 additions & 2 deletions src/assert.rs
Expand Up @@ -11,8 +11,8 @@ use predicates::str::PredicateStrExt;
use predicates_core;
use predicates_tree::CaseTreeExt;

use crate::cmd::dump_buffer;
use crate::cmd::output_fmt;
use crate::output::dump_buffer;
use crate::output::output_fmt;

/// Assert the state of an [`Output`].
///
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 fdf9cd3

Please sign in to comment.