Skip to content
This repository was archived by the owner on Dec 29, 2021. It is now read-only.

Feature proposal: Run examples as top level concept, with compilation profile #96

Closed
azriel91 opened this issue Mar 26, 2018 · 6 comments

Comments

@azriel91
Copy link
Contributor

azriel91 commented Mar 26, 2018

Hiya, I really like assert_cli, thanks for making such a useful crate!

Since I'm a fan of "automatically test everything, so I know when I break things", I have automated tests for my examples, and control them through arguments or stdin. For example:

extern crate assert_cli;

#[test]
fn example_01_menu() {
    assert_cli::Assert::command(&["cargo", "run", "--example", "01_menu", "--"])
        .with_args(&["--timeout", "0"])
        .unwrap();
}

Now, because cargo run --example example_name always runs the example in the debug profile, to make sure I don't double compile when I'm testing my release profile build, I can do something like this:

extern crate assert_cli;

#[test]
fn example_01_menu() {
    assert_cli::Assert::command(&(example_command("01_menu")))
        .with_args(&["--timeout", "0"])
        .unwrap();
}

fn example_command(example_name: &'static str) -> Vec<&str> {
    let mut command = vec!["cargo", "run"];
    if !cfg!(debug_assertions) {
        command.push("--release");
    }
    command.extend(&["--example", example_name, "--"]);
    command
}

Since I would be replicating this functionality across a number of crates, I was wondering whether you'd like this to go in assert_cli (is it in line with what this crate is intended to cover), otherwise I can make an intermediate crate.


Edit: just noticed the conditional compilation for the profile is also mentioned in #86.

@epage
Copy link
Collaborator

epage commented Mar 26, 2018

In light of #86, do you see value in keeping this issue open?

@azriel91
Copy link
Contributor Author

Yeap -- even after implementing #86, there's no quick way to run an example and insert the compilation profile. Assert::cargo_binary lets you pick another binary, but not an example.

@epage
Copy link
Collaborator

epage commented Mar 26, 2018

Oh, I missed the part about running examples.

@volks73
Copy link
Contributor

volks73 commented May 14, 2018

I, too, would like to be able to quickly use an example for a command to test. I would like to suggest an Assert::example_binary constructor/method similar to Assert::cargo_binary, but accepts a name of an example defined in the Cargo.toml of the project.

@epage
Copy link
Collaborator

epage commented May 21, 2018

Fixed by #108

@epage epage closed this as completed May 21, 2018
@epage
Copy link
Collaborator

epage commented May 21, 2018

I'm publishing 0.6.1 right now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants