2021-10-11 20:05:24 +00:00
|
|
|
//! Test clap generated completions.
|
|
|
|
#![cfg(feature = "nix")]
|
2021-05-07 07:34:44 +00:00
|
|
|
|
|
|
|
use assert_cmd::Command;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn completions_bash() {
|
|
|
|
let source = include_str!("../contrib/completions/zoxide.bash");
|
2021-09-12 21:36:21 +00:00
|
|
|
Command::new("bash").args(&["--noprofile", "--norc", "-c", source]).assert().success().stdout("").stderr("");
|
2021-05-07 07:34:44 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 08:01:58 +00:00
|
|
|
// Elvish: the completions file uses editor commands to add completions to the shell. However,
|
|
|
|
// Elvish does not support running editor commands from a script, so we can't create a test for
|
|
|
|
// this. See: https://github.com/elves/elvish/issues/1299
|
2021-05-07 07:34:44 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn completions_fish() {
|
|
|
|
let source = include_str!("../contrib/completions/zoxide.fish");
|
|
|
|
let tempdir = tempfile::tempdir().unwrap();
|
|
|
|
let tempdir = tempdir.path().to_str().unwrap();
|
|
|
|
|
|
|
|
Command::new("fish")
|
|
|
|
.env("HOME", tempdir)
|
|
|
|
.args(&["--command", source, "--private"])
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("")
|
|
|
|
.stderr("");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn completions_powershell() {
|
|
|
|
let source = include_str!("../contrib/completions/_zoxide.ps1");
|
|
|
|
Command::new("pwsh")
|
2021-05-17 16:16:42 +00:00
|
|
|
.args(&["-NoLogo", "-NonInteractive", "-NoProfile", "-Command", source])
|
2021-05-07 07:34:44 +00:00
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout("")
|
|
|
|
.stderr("");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn completions_zsh() {
|
|
|
|
let source = r#"
|
|
|
|
set -eu
|
|
|
|
completions='./contrib/completions'
|
|
|
|
test -d "$completions"
|
|
|
|
fpath=("$completions" $fpath)
|
|
|
|
autoload -Uz compinit
|
|
|
|
compinit -u
|
|
|
|
"#;
|
|
|
|
|
2021-05-17 16:16:42 +00:00
|
|
|
Command::new("zsh").args(&["-c", source, "--no-rcs"]).assert().success().stdout("").stderr("");
|
2021-05-07 07:34:44 +00:00
|
|
|
}
|