File: completions.rs

package info (click to toggle)
rust-zoxide 0.9.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,508 kB
  • sloc: sh: 586; makefile: 13
file content (59 lines) | stat: -rw-r--r-- 1,603 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Test clap generated completions.
#![cfg(feature = "nix-dev")]

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. See: 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])
        .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("");
}