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

Deprecate macro in favor of clever Assert::command(&str)? #25

Open
killercup opened this issue Mar 22, 2017 · 3 comments
Open

Deprecate macro in favor of clever Assert::command(&str)? #25

killercup opened this issue Mar 22, 2017 · 3 comments
Labels

Comments

@killercup
Copy link
Collaborator

What do you think about removing the macro and adding <T: ToCommandWithArgs> Assert::command(T) where ToCommandWithArgs is a trait implemented for &[u8] as well as &str? This way, you could run Assert::command(r#"cargo run --bin whatever -- --input="Lorem ipsum" -f"#).

In the &str case we'd parse it in a clever way to split the string by whitespace while preserving quoted blocks. I'm thinking of some split_args that fulfills

#[test]
fn test_arg_split() {
    assert_eq(split_args("echo 42"), vec!["echo", "42"]);

    assert_eq(split_args(r#"echo "42""#), vec!["echo", "\"42\""]);

    assert_eq(
        split_args(r#"cargo run --bin whatever -- --input="Lorem ipsum" -f"#),
        vec!["cargo", "run", "--bin", "whatever",  "--", "--input=\"Lorem ipsum\"", "-f"]
    );
}

(Copypasta from #22 (comment))

killercup added a commit that referenced this issue Mar 23, 2017
Allow &str and &[&str] as input for `command`

Fixes #25
killercup added a commit that referenced this issue Mar 23, 2017
Allow &str and &[&str] as input for `command`

Fixes #25
This was referenced Sep 25, 2017
@epage
Copy link
Collaborator

epage commented Sep 27, 2017

tl;dr I suggest we keep Assert::command as-is and remove the macro.

The primary use case I see assert_cli being used for is to test someone's crate. At that point they'll be wanting to use main_binary or specify it some other means. This means there is low value for Assert::command accepting a single string. To support this, I just looked through all of the dependent crates on crates.io and none of them use the macro which is the current form of "single string" construction.

The main value I could see with having a macro of some form is to accept variable arguments that can all act as AsRef<str>. We'd then also want versions of the macro for various helpers (main_binary, etc). This is a separate concern and can be safely added to the API later without impact if it seems justified.

If a use case comes along for defining the command in a single string, I recommend we handle it then.

@killercup
Copy link
Collaborator Author

killercup commented Sep 27, 2017 via email

@killercup
Copy link
Collaborator Author

It was PR #29. I think I'd like to revisit that idea but use it for .args(r#"--foo --bar="lol" --yay"#) instead of the ::command()

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

No branches or pull requests

2 participants