zoxide/tests/completion.rs

61 lines
1.6 KiB
Rust
Raw Normal View History

2021-05-07 07:34:44 +00:00
//! Syntax checking for auto-generated shell completions.
#![cfg(feature = "shell_tests")]
use assert_cmd::Command;
#[test]
fn completions_bash() {
let source = include_str!("../contrib/completions/zoxide.bash");
Command::new("bash")
.args(&["--noprofile", "--norc", "-c", source])
.assert()
.success()
.stdout("")
.stderr("");
}
// 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.
// <https://github.com/elves/elvish/issues/1299>
#[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")
.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
"#;
Command::new("zsh").args(&["-c", source, "--no-rcs"]).assert().success().stdout("").stderr("");
2021-05-07 07:34:44 +00:00
}