Skip to content

Testing complex command structures without repeating App construction #1945

Answered by kbknapp
jburnett asked this question in Q&A
Discussion options

You must be logged in to vote

To test your CLI I would look into something like assert_cli or assert_cmd.

If you're wanting to do something closer to your example then I usually use a non-test function to setup the App instance each time. This is because setting up the App instance is very fast (ns fast), and during the parsing phase, it'll get mutated so it's best to start clean for each test. It would look something like:

fn build() -> App<'static, 'static> {
    App::new("prog")
        .arg(Arg::with_name("first"))
        .arg(Arg::with_name("second"))
        .arg(Arg::with_name("third").last(true))
}

#[test]
fn verify_three_params() {
    let res = build().get_matches_from_safe(vec![
            "prog", "one", "…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jburnett
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants