//! The command surface parses, and a bad invocation is a usage error rather //! than a panic. mod common; use common::Fixture; #[test] fn the_top_level_help_names_both_command_groups() { let fixture = Fixture::bare(); let output = fixture.cli(&["--help"]); assert!(output.status.success()); let stdout = String::from_utf8_lossy(&output.stdout); assert!(stdout.contains("kernel"), "{stdout}"); assert!(stdout.contains("patch"), "{stdout}"); } #[test] fn every_verb_has_help_of_its_own() { let fixture = Fixture::bare(); for verb in [ &["kernel", "quest"][..], &["kernel", "test"], &["patch", "check"], &["patch", "format"], &["patch", "commit"], &["patch", "create"], &["patch", "submit"], &["patch", "update"], ] { let mut args = verb.to_vec(); args.push("--help"); let output = fixture.cli(&args); assert!( output.status.success(), "{} --help failed: {}", verb.join(" "), String::from_utf8_lossy(&output.stderr) ); assert!( !String::from_utf8_lossy(&output.stdout).is_empty(), "{} --help printed nothing", verb.join(" ") ); } } #[test] fn an_unknown_subcommand_exits_two() { let fixture = Fixture::bare(); let output = fixture.cli(&["frobnicate"]); assert_eq!(output.status.code(), Some(2)); let stderr = String::from_utf8_lossy(&output.stderr); assert!(stderr.contains("Usage"), "{stderr}"); } #[test] fn a_leaf_missing_its_argument_exits_two() { let fixture = Fixture::bare(); let output = fixture.cli(&["patch", "commit"]); assert_eq!(output.status.code(), Some(2)); let stderr = String::from_utf8_lossy(&output.stderr); assert!(stderr.contains("MESSAGE"), "{stderr}"); } #[test] fn a_verb_that_is_still_a_stub_panics_where_it_says_it_does() { // `kernel quest` is P5 and `kernel test` is P6. Until they land, this is // the proof that the dispatch is wired end to end: exit 101 with the // panic's own location in it. let fixture = Fixture::kernel_tree(); let output = fixture.cli(&["kernel", "quest"]); assert_eq!(output.status.code(), Some(101)); let stderr = String::from_utf8_lossy(&output.stderr); assert!(stderr.contains("kernel/quest.rs"), "{stderr}"); }