-
Notifications
You must be signed in to change notification settings - Fork 21
Use duct internally? #32
Comments
@hniksic also launched https://github.com/hniksic/rust-subprocess recently, which uses the style of the Python standard library. It might be worth looking into both. |
Thanks for the mention, @oconnor663. The initial goal of |
Since creating this issue, I've used duct in a few more projects and really liked it (I still have to use subprocess, but duct seems more popular overall). At the same time, we added a bunch of cool new stuff to assert_cli. Thus, I want to get back to the original question here, but also add this: Would it make sense to add duct not only as a private dependency to assert_cli, but also extend our API to implement our assertions on I imagine this might work (uses current API): #[macro_use] extern crate duct;
extern crate assert_cli;
use assert_cli::CliAsserts; // trait that extends duct::Expression
#[test]
fn foo() {
cmd!("echo", "hi").pipe(cmd!("sed", "s/h/p/"))
.assert().fails().stderr().contains("foo-bar-foo")
} What do you think? @epage |
Can I abuse this thread for feedback? I so rarely get any :)
|
@oconnor663 looks like most of that feedback is targetted at
So
That does seem like some overlap that we can reduce. Some counter points
We could make pub enum OutputAssert {
output: process::Output
}
impl OutputAssert {
pub fn new(output: process::Output) -> Self {
...
}
...
}
trait CommandAssert {
fn assert(self) -> Result<OutputAssert> {
...
}
}
#[cfg(duct)]
impl CommandAssert for duct::Expression {
... call run...
}
impl CommandAssert for process::Command {
... setup stdout/stderr for reading and call spawn / wait_with_output...
} Going a step further, we could make our asserts be extension traits to |
On the surface, Granted, that last part might be a reason not to extend |
Another question to consider along these lines. We'll probably need to define this so that when the user starts adding assertions, the process has already run (because we don't have a way to track our extra state otherwise). Options
|
I just saw this announcement of duct, which seems to handle a bunch of weird edge cases in relation to
std::process::Command
.It looks like we can use it to:
sh
fn. Internally it actually calls/bin/sh
/cmd.exe
, so it doesn't have to do crazy string splitting (it also has a macro). Deprecate macro in favor of cleverAssert::command(&str)
? #25I really like our fluent API, and would suggest adding methods that internally handle
duct::Expression
.cc @nathanross @colin-kiegel @epage who are the authors of the linked issues
cc @oconnor663 who is the author of duct
The text was updated successfully, but these errors were encountered: