cargo-cgp 0.1.0-alpha

A cargo subcommand that runs `cargo check` through the cargo-cgp rustc driver.
//! Tests for subcommand dispatch error paths ([`cargo_cgp::run::dispatch`]). The success
//! paths spawn cargo/rustup and are exercised end to end by the UI suite, so only the
//! side-effect-free error branches are unit-tested here.

use cargo_cgp::run::dispatch;

fn args(list: &[&str]) -> Vec<String> {
    list.iter().map(|s| s.to_string()).collect()
}

#[test]
fn unknown_subcommand_errors() {
    let err = dispatch(&args(&["frobnicate"])).unwrap_err().to_string();
    assert!(
        err.contains("frobnicate"),
        "message should name the bad subcommand: {err}"
    );
}

#[test]
fn no_subcommand_shows_help() {
    // A bare `cargo cgp` prints the help and succeeds rather than erroring.
    assert_eq!(dispatch(&[]).unwrap(), 0);
}

#[test]
fn help_flag_shows_help() {
    assert_eq!(dispatch(&args(&["--help"])).unwrap(), 0);
    assert_eq!(dispatch(&args(&["-h"])).unwrap(), 0);
}