mirror of
https://github.com/Llewellynvdm/zoxide.git
synced 2024-12-29 12:32:40 +00:00
Reuse values in shell tests
This commit is contained in:
parent
6307146fbb
commit
dc64d912ab
44
Cargo.lock
generated
44
Cargo.lock
generated
@ -47,9 +47,9 @@ checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341"
|
||||
|
||||
[[package]]
|
||||
name = "askama_shared"
|
||||
version = "0.12.1"
|
||||
version = "0.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3d372b233d121e841b4cc5dc716538755e338ca902b3e12ac131ffb6b9d5fbf"
|
||||
checksum = "bf722b94118a07fcbc6640190f247334027685d4e218b794dbfe17c32bf38ed0"
|
||||
dependencies = [
|
||||
"askama_escape",
|
||||
"mime",
|
||||
@ -125,9 +125,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.1.2"
|
||||
version = "3.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5177fac1ab67102d8989464efd043c6ff44191b1557ec1ddd489b4f7e1447e77"
|
||||
checksum = "ced1892c55c910c1219e98d6fc8d71f6bddba7905866ce740066d8bfea859312"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
@ -142,9 +142,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete"
|
||||
version = "3.1.0"
|
||||
version = "3.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23eec4dd324308f49d8bf86a2732078c34d57955fec1e1d865554fc37c15d420"
|
||||
checksum = "df6f3613c0a3cddfd78b41b10203eb322cb29b600cbdf808a7d3db95691b8e25"
|
||||
dependencies = [
|
||||
"clap",
|
||||
]
|
||||
@ -161,9 +161,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "3.1.2"
|
||||
version = "3.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "01d42c94ce7c2252681b5fed4d3627cc807b13dfc033246bd05d5b252399000e"
|
||||
checksum = "da95d038ede1a964ce99f49cbe27a7fb538d1da595e4b4f70b8c8f338d17bf16"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
@ -409,9 +409,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.9.0"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
|
||||
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
|
||||
|
||||
[[package]]
|
||||
name = "ordered-float"
|
||||
@ -520,9 +520,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.2.10"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff"
|
||||
checksum = "8380fe0152551244f0747b1bf41737e0f8a74f97a14ccefd1148187271634f3c"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
@ -582,6 +582,17 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rstest_reuse"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b29d3117bce27ea307d1fb7ce12c64ba11b3fd04311a42d32bc5f0072e6e3d4d"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"rustc_version",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.4.0"
|
||||
@ -665,9 +676,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.2"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
|
||||
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
@ -680,9 +691,9 @@ checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b"
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.14.2"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
|
||||
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
@ -818,6 +829,7 @@ dependencies = [
|
||||
"ordered-float",
|
||||
"rand",
|
||||
"rstest",
|
||||
"rstest_reuse",
|
||||
"serde",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
|
@ -43,6 +43,7 @@ clap_complete_fig = "3.1.0"
|
||||
[dev-dependencies]
|
||||
assert_cmd = "2.0.0"
|
||||
rstest = "0.12.0"
|
||||
rstest_reuse = "0.3.0"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
4
contrib/completions/zoxide.bash
generated
4
contrib/completions/zoxide.bash
generated
@ -69,7 +69,7 @@ _zoxide() {
|
||||
fi
|
||||
case "${prev}" in
|
||||
--from)
|
||||
COMPREPLY=($(compgen -W "autojump z" -- "${cur}"))
|
||||
COMPREPLY=($(compgen -W "" -- "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
@ -91,7 +91,7 @@ _zoxide() {
|
||||
return 0
|
||||
;;
|
||||
--hook)
|
||||
COMPREPLY=($(compgen -W "none prompt pwd" -- "${cur}"))
|
||||
COMPREPLY=($(compgen -W "" -- "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
|
@ -1,3 +1,9 @@
|
||||
#![allow(clippy::single_component_path_imports)]
|
||||
|
||||
// rstest_reuse must be imported at the top of the crate.
|
||||
#[cfg(test)]
|
||||
use rstest_reuse;
|
||||
|
||||
mod cmd;
|
||||
mod config;
|
||||
mod db;
|
||||
|
161
src/shell.rs
161
src/shell.rs
@ -38,16 +38,22 @@ mod tests {
|
||||
use askama::Template;
|
||||
use assert_cmd::Command;
|
||||
use rstest::rstest;
|
||||
use rstest_reuse::{apply, template};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[template]
|
||||
#[rstest]
|
||||
fn bash_bash(
|
||||
fn opts(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
}
|
||||
|
||||
#[apply(opts)]
|
||||
fn bash_bash(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let source = Bash(&opts).render().unwrap();
|
||||
Command::new("bash")
|
||||
@ -58,13 +64,8 @@ mod tests {
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn bash_shellcheck(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn bash_shellcheck(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let source = Bash(&opts).render().unwrap();
|
||||
|
||||
@ -77,13 +78,8 @@ mod tests {
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn bash_shfmt(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn bash_shfmt(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let mut source = Bash(&opts).render().unwrap();
|
||||
source.push('\n');
|
||||
@ -97,13 +93,8 @@ mod tests {
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn elvish_elvish(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn elvish_elvish(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let mut source = String::new();
|
||||
|
||||
@ -117,13 +108,8 @@ mod tests {
|
||||
Command::new("elvish").args(&["-c", &source, "-norc"]).assert().success().stdout("").stderr("");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn fish_fish(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn fish_fish(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let source = Fish(&opts).render().unwrap();
|
||||
|
||||
@ -139,13 +125,8 @@ mod tests {
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn fish_fishindent(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn fish_fishindent(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let mut source = Fish(&opts).render().unwrap();
|
||||
source.push('\n');
|
||||
@ -162,13 +143,8 @@ mod tests {
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn nushell_nushell(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn nushell_nushell(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let source = Nushell(&opts).render().unwrap();
|
||||
|
||||
@ -183,13 +159,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn posix_bash(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn posix_bash(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let source = Posix(&opts).render().unwrap();
|
||||
|
||||
@ -203,13 +174,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn posix_dash(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn posix_dash(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let source = Posix(&opts).render().unwrap();
|
||||
|
||||
@ -219,13 +185,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn posix_shellcheck_(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn posix_shellcheck_(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let source = Posix(&opts).render().unwrap();
|
||||
|
||||
@ -238,13 +199,8 @@ mod tests {
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn posix_shfmt(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn posix_shfmt(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let mut source = Posix(&opts).render().unwrap();
|
||||
source.push('\n');
|
||||
@ -258,13 +214,8 @@ mod tests {
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn powershell_pwsh(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn powershell_pwsh(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let mut source = "Set-StrictMode -Version latest\n".to_string();
|
||||
Powershell(&opts).render_into(&mut source).unwrap();
|
||||
@ -277,13 +228,8 @@ mod tests {
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn xonsh_black(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn xonsh_black(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let mut source = Xonsh(&opts).render().unwrap();
|
||||
source.push('\n');
|
||||
@ -291,26 +237,16 @@ mod tests {
|
||||
Command::new("black").args(&["--check", "--diff", "-"]).write_stdin(source).assert().success().stdout("");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn xonsh_mypy(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn xonsh_mypy(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let source = Xonsh(&opts).render().unwrap();
|
||||
|
||||
Command::new("mypy").args(&["--command", &source, "--strict"]).assert().success().stderr("");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn xonsh_pylint(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn xonsh_pylint(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let mut source = Xonsh(&opts).render().unwrap();
|
||||
source.push('\n');
|
||||
@ -323,13 +259,8 @@ mod tests {
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn xonsh_xonsh(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn xonsh_xonsh(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let source = Xonsh(&opts).render().unwrap();
|
||||
|
||||
@ -345,13 +276,8 @@ mod tests {
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn zsh_shellcheck(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn zsh_shellcheck(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let source = Zsh(&opts).render().unwrap();
|
||||
|
||||
@ -365,13 +291,8 @@ mod tests {
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn zsh_zsh(
|
||||
#[values(None, Some("z"))] cmd: Option<&str>,
|
||||
#[values(InitHook::None, InitHook::Prompt, InitHook::Pwd)] hook: InitHook,
|
||||
#[values(false, true)] echo: bool,
|
||||
#[values(false, true)] resolve_symlinks: bool,
|
||||
) {
|
||||
#[apply(opts)]
|
||||
fn zsh_zsh(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||
let source = Zsh(&opts).render().unwrap();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user