Files
worklane/tests/cmd_completions.rs
T
Ansho ReiandClaude Opus 5 73ffcad733 Reformat with cargo fmt, and nothing else
Layout only, no behaviour and no wording. 161 hunks across 22 files, 98 of them
rustfmt joining a call or a message onto the one line it fits on. The config it
formats to, and how its four numbers were arrived at, is the commit before this
one.

Separate so that it is reviewable by not being read: nothing here is a decision,
and every decision is next door.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-23 00:23:04 +02:00

78 lines
2.9 KiB
Rust

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"] {
assert!(out.contains(status), "fish is never offered {status}");
}
assert!(out.contains("-a 'backlog committed reviewing done' -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}");
}