assert-rs / assert_cmd

Assert process::Command - Easy command initialization and assertions
https://docs.rs/assert_cmd
Apache License 2.0
463 stars 34 forks source link

feat: implement `From<assert:cmd::Command>` for `process::Command` #214

Closed mcky closed 1 month ago

mcky commented 1 month ago

Allows conversion with process::Command::from(asserted_cmd)

As mentioned in #212 I was having trouble serializing the value of the inner std::process::Command.

After this PR the following should be possible:

let cmd = Command::cargo_bin(env!("CARGO_PKG_NAME"))
let std_cmd = process::Command::from(cmd)
epage commented 1 month ago

Not sure what I think of this as its a lossy operation.

mcky commented 1 month ago

Would you be open to any API that exposed the underlying std::process::Command?

epage commented 1 month ago

Would you be open to any API that exposed the underlying std::process::Command?

What value is using assert_cmd::Command giving you if you are then immediately wanting a std::prcoess::Command?

mcky commented 1 month ago

Many of my other tests use cargo_bin and the success/fail/stdout/stderr assertions via helpers, but for the odd interactive test I’m having to use rexpect instead, and being able to get at the internal cmd would save reworking them all.

Of course I don’t expect this merger just for my convenience, I just thought it might be generally useful to expose it in some manner (e.g. a getter or marking it public)

epage commented 1 month ago

Considering we provide

it seems like if a std::process::Command is needed, assert_cmd shouldn't be in the way, so I'm not seeing a reason to move forward with this.