Skip to content

Commit d159e87

Browse files
author
Ed Page
committed
fix(stdin): Provide a Command wrapper
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 (#10) or signalling (#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 #73
1 parent 15e40f6 commit d159e87

File tree

6 files changed

+557
-287
lines changed

6 files changed

+557
-287
lines changed

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,10 @@ assert_cmd = "0.11"
2121
Here's a trivial example:
2222

2323
```rust,no_run
24-
extern crate assert_cmd;
24+
use assert_cmd::Command;
2525
26-
use std::process::Command;
27-
use assert_cmd::prelude::*;
28-
29-
Command::cargo_bin("bin_fixture")
30-
.unwrap()
31-
.assert()
32-
.success();
26+
let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
27+
cmd.assert().success();
3328
```
3429

3530
## Relevant crates

src/cargo.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,24 @@ where
124124
fn cargo_bin<S: AsRef<str>>(name: S) -> Result<Self, CargoError>;
125125
}
126126

127+
impl CommandCargoExt for crate::cmd::Command {
128+
fn cargo_bin<S: AsRef<str>>(name: S) -> Result<Self, CargoError> {
129+
crate::cmd::Command::cargo_bin(name)
130+
}
131+
}
132+
127133
impl CommandCargoExt for process::Command {
128134
fn cargo_bin<S: AsRef<str>>(name: S) -> Result<Self, CargoError> {
129-
let path = cargo_bin(name);
130-
if path.is_file() {
131-
Ok(process::Command::new(path))
132-
} else {
133-
Err(CargoError::with_cause(NotFoundError { path }))
134-
}
135+
cargo_bin_cmd(name)
136+
}
137+
}
138+
139+
pub(crate) fn cargo_bin_cmd<S: AsRef<str>>(name: S) -> Result<process::Command, CargoError> {
140+
let path = cargo_bin(name);
141+
if path.is_file() {
142+
Ok(process::Command::new(path))
143+
} else {
144+
Err(CargoError::with_cause(NotFoundError { path }))
135145
}
136146
}
137147

0 commit comments

Comments
 (0)