Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Holistic CLI test harness experiments #98

Closed
wants to merge 4 commits into from

Conversation

Projects
None yet
4 participants
@epage
Copy link
Collaborator

epage commented Mar 27, 2018

This includes

  • Experiments with extension traits, opening the door for duct, see #32
  • API for quickly setting up a file system for testing, mostly inspired by my work on cobalt ("I'd like to test X but that'll be too much work to set up a fixture. Maybe its good enough...").
  • Comparisons with cli_test_dir, another holistic harness that is more rigid in its API

See commit messages for more details

Work to do

  • Replace Asserts ability to run commands with traits
  • Make it easy to setup a tempdir
  • Add assertion predicates
  • Determine crate(s) structure
  • Tests and documentation
@azriel91

This comment has been minimized.

Copy link
Contributor

azriel91 commented Mar 28, 2018

btw, tempdir is now merged into tempfile 3.0.0 and was published 2 days ago.

epage added some commits Mar 24, 2018

feat(cmd): Augment process::Command
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.
feat(tmpdir): Augment tempdir::TempDir
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).

@epage epage force-pushed the epage:trait branch from a211010 to 9767301 Mar 29, 2018

epage added some commits Mar 29, 2018

feat(cmd): Add unwrap_err to commands
Another common use case in basic assertions.
@killercup

This comment has been minimized.

Copy link
Collaborator

killercup commented Apr 3, 2018

fyi @nikomatsakis just told me he used assert_cli and manually added a tempdir wrapper because that was missing

@killercup killercup referenced this pull request Apr 3, 2018

Closed

CLI WG Newsletter #2 #19


impl CommandCargoExt for process::Command {
fn main_binary() -> Self {
let mut cmd = process::Command::new("carg");

This comment has been minimized.

@peddermaster2

peddermaster2 Apr 3, 2018

carg -> cargo?
Same in line 51

This comment has been minimized.

@epage

epage Apr 3, 2018

Author Collaborator

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.

@epage

This comment has been minimized.

Copy link
Collaborator Author

epage commented May 8, 2018

My current thought on crate organization

  • assert_cmd for writing asserts on std::process::Command
  • assert_fs for tempfile / path assertions
  • assert_cli that re-exports both of the above

Couple questions from that

  • I assume some people would appreciate process::Command helpers that this PR provides but aren't interested in assertions. Should we advertise that we provide these or create yet another crate for them?
    • passing in a Vec<u8> for stdin
    • Turning an Command / Output into a Result
  • Currently, the tempfile parts have a distinct struct for playing with files in the tempdir. The cmd parts then support using that to run a command in that directory. This might run afoul of trait rules if we split this into multiple crates.
    • Will it?
    • If it will, should we just switch to attaching these extension traits to Path instead?
@killercup
Copy link
Collaborator

killercup left a comment

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.

This comment has been minimized.

@killercup

killercup May 24, 2018

Collaborator

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`.

This comment has been minimized.

@killercup

killercup May 24, 2018

Collaborator

s/to to/to

///
/// By default, stdin, stdout and stderr are inherited from the parent.
///
/// *(mirrors `std::process::Command::spawn`**

This comment has been minimized.

@killercup

killercup May 24, 2018

Collaborator

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

This comment has been minimized.

@killercup

killercup May 24, 2018

Collaborator

s/path program/path

/// temp.command("pwd").output().unwrap();
/// temp.close().unwrap();
/// ```
fn command<S>(&self, program: S) -> process::Command

This comment has been minimized.

@killercup

killercup May 24, 2018

Collaborator

i'd probably call this exec?

@volks73 volks73 referenced this pull request May 24, 2018

Open

Add optional access to Command's stdin handle #107

4 of 4 tasks complete
@epage

This comment has been minimized.

Copy link
Collaborator Author

epage commented May 29, 2018

@epage epage closed this May 29, 2018

@epage epage deleted the epage:trait branch May 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.