use assert_cmd::Command; const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane"); fn script(shell: &str) -> String { let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); let assert = cmd.arg("completions").arg(shell).assert().success(); String::from_utf8(assert.get_output().stdout.clone()).unwrap() } /// Every shell clap can generate for, since the README names all five. #[test] fn completions_prints_a_script_for_every_shell() { for shell in ["fish", "bash", "zsh", "elvish", "powershell"] { let out = script(shell); assert!(out.contains("worklane"), "the {shell} script never names the command"); // Long enough to be a script rather than an empty file with a comment in it. assert!(out.len() > 500, "the {shell} script is {} bytes", out.len()); } } /// No board is looked for, the way `install-skill` looks for none: the script comes off /// the clap definition and is the same wherever it is run. Run from a temp directory /// with no `.worklane` above it, which every other command refuses. #[test] fn completions_needs_no_board() { let temp = assert_fs::TempDir::new().unwrap(); let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); cmd.current_dir(temp.path()) .arg("completions") .arg("fish") .assert() .success(); } #[test] fn fish_gets_both_halves() { let out = script("fish"); // clap's, which is where the subcommands and the flags come from. assert!(out.contains("__fish_worklane_needs_command")); assert!(out.contains("install-skill")); // Ours, which is where the tickets come from. assert!(out.contains("__worklane_first_arg_of")); assert!(out.contains("worklane ls --ids")); } /// The fish half is fish syntax, so it must not reach any other shell's output. #[test] fn no_other_shell_gets_the_fish_half() { for shell in ["bash", "zsh", "elvish", "powershell"] { let out = script(shell); assert!( !out.contains("__worklane_first_arg_of"), "fish-only helpers leaked into {shell}" ); assert!(!out.contains("worklane ls --ids"), "the dynamic half leaked into {shell}"); } } /// The four statuses reach fish twice over, from clap for the `mv` option and from the /// appended half for the `ls` positional, which clap emits nothing for. #[test] fn fish_is_offered_every_status() { let out = script("fish"); for status in ["backlog", "committed", "reviewing", "done", "discarded"] { assert!(out.contains(status), "fish is never offered {status}"); } assert!(out.contains("-a 'backlog committed reviewing done discarded' -d status")); } #[test] fn an_unknown_shell_is_a_usage_error() { let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); let assert = cmd.arg("completions").arg("tcsh").assert().code(2); let stderr = String::from_utf8(assert.get_output().stderr.clone()).unwrap(); assert!(stderr.contains("invalid value 'tcsh'"), "{stderr}"); }