-
Notifications
You must be signed in to change notification settings - Fork 21
WIP: Holistic CLI test harness experiments #98
Conversation
btw, |
This is an experiment in trying to use extension traits rather than wrapping `process::Command`. This both makes it more extensible (can interop with other crates) and able to be adapted to other "Command" crates like `duct`. `cli_test_dir` has something like `CommandStdInExt` called `CommandExt`. Differences include: - Scoped name since traits generally are pulled out of any namespace they are in. - Preserves the command and `stdin` to for richer error reporting.
This is an experiment in what kind of tempdir operations a holistic CLI testing framework might provide, following on the previous experiments with extension traits. The exact structure in this crate or across crates is TBD. This crate extends `TempDir` with the following - In TempDir or a child path, run a command. - On child path, touch a file. - On child path, write a binary blob or str to file. - Copy to a TempDir or a child path some files. Some other potential operations include - `write_yml(serde)` - `write_json(serde)` - `write_toml(serde)` In contrast, `cli_test_dir` can: - Run a single pre-defined program within the tempdir - Write binary files to tempdir - Offer a absolute path to a child file within the crate source (so its safe to pass to the program running in the tempdir).
Another common use case in basic assertions.
fyi @nikomatsakis just told me he used assert_cli and manually added a tempdir wrapper because that was missing |
|
||
impl CommandCargoExt for process::Command { | ||
fn main_binary() -> Self { | ||
let mut cmd = process::Command::new("carg"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
carg
-> cargo
?
Same in line 51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Obviously very little testing has been done which might be clear considering this is here :). This is a rough sketch to get high level feedback before actually getting the details right.
My current thought on crate organization
Couple questions from that
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool! Sorry it took me so long to around to this, @epage.
I've long been in favor of splitting assert_cli up into smaller pieces. What we should also offer in the long run, though, is a way to easily extend this, e.g., to make shortcut methods to set a bunch of env vars.
/// ``` | ||
fn main_binary() -> Self; | ||
|
||
/// Create a `Command` Run a specific binary of the current crate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Run/to run
/// `std::process::Output` represented as a `Result`. | ||
pub type OutputResult = Result<process::Output, OutputError>; | ||
|
||
/// Extends `std::process::Output` with methods to to convert it to an `OutputResult`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/to to/to
/// | ||
/// By default, stdin, stdout and stderr are inherited from the parent. | ||
/// | ||
/// *(mirrors `std::process::Command::spawn`** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/**/)*
|
||
/// Extend `TempDir` to run commands in it. | ||
pub trait TempDirCommandExt { | ||
/// Constructs a new Command for launching the program at path program, with the following |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/path program/path
/// temp.command("pwd").output().unwrap(); | ||
/// temp.close().unwrap(); | ||
/// ``` | ||
fn command<S>(&self, program: S) -> process::Command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd probably call this exec?
This is now implemented as |
This includes
cli_test_dir
, another holistic harness that is more rigid in its APISee commit messages for more details
Work to do
Assert
s ability to run commands with traits