//! Shell completions and man pages come from the command definitions. use std::process::Command; fn oxy(args: &[&str]) -> (bool, String) { let out = Command::new(env!("CARGO_BIN_EXE_oxy")) .args(args) .env("NO_COLOR", "1") .output() .unwrap(); ( out.status.success(), String::from_utf8_lossy(&out.stdout).into_owned(), ) } #[test] fn completions_for_each_shell() { for (shell, marker) in [ ("bash", "_oxy()"), ("zsh", "#compdef oxy"), ("fish", "complete -c oxy"), ("powershell", "Register-ArgumentCompleter"), ] { let (ok, text) = oxy(&["completions", shell]); assert!(ok, "{shell}"); assert!( text.contains(marker), "{shell}: {}", &text[..text.len().min(200)] ); assert!( text.contains("commit") && text.contains("doctor"), "{shell} knows the commands" ); } assert!( !oxy(&["completions", "tcsh"]).0, "an unknown shell is refused" ); } #[test] fn man_pages_for_every_command() { let dir = tempfile::tempdir().unwrap(); let (ok, _) = oxy(&["man", "--dir", &dir.path().to_string_lossy()]); assert!(ok); for page in [ "oxy.1", "oxy-commit.1", "oxy-remote-add.1", "oxy-identity-delegate-add.1", "oxy-doctor.1", ] { let text = std::fs::read_to_string(dir.path().join(page)) .unwrap_or_else(|_| panic!("{page} missing")); assert!( text.starts_with(".ie") || text.contains(".TH"), "{page} is roff" ); } let commit = std::fs::read_to_string(dir.path().join("oxy-commit.1")).unwrap(); assert!( commit.contains("subject line"), "argument help reaches the page" ); let (ok, top) = oxy(&["man"]); assert!(ok && top.contains(".TH oxy"), "oxy man prints the top page"); }