From cddbb5689ff83e52e3c8604225aacf30510b2415 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 12 Aug 2024 08:29:11 -0500 Subject: [PATCH] fix(complete): Correct version check --- clap_complete/src/dynamic/command/shells.rs | 2 +- .../home/dynamic/exhaustive/bash/.bashrc | 2 +- .../tests/snapshots/register_minimal.bash | 2 +- clap_complete/tests/testsuite/bash.rs | 32 +++++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/clap_complete/src/dynamic/command/shells.rs b/clap_complete/src/dynamic/command/shells.rs index c7ce3ffd628..d7b8b70fe3a 100644 --- a/clap_complete/src/dynamic/command/shells.rs +++ b/clap_complete/src/dynamic/command/shells.rs @@ -202,7 +202,7 @@ _clap_complete_NAME() { compopt -o nospace fi } -if [[ \"${{BASH_VERSINFO[0]}}\" -eq 4 && \"${{BASH_VERSINFO[1]}}\" -ge 4 || \"${{BASH_VERSINFO[0]}}\" -gt 4 ]]; then +if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then complete -o nospace -o bashdefault -o nosort -F _clap_complete_NAME BIN else complete -o nospace -o bashdefault -F _clap_complete_NAME BIN diff --git a/clap_complete/tests/snapshots/home/dynamic/exhaustive/bash/.bashrc b/clap_complete/tests/snapshots/home/dynamic/exhaustive/bash/.bashrc index b10dc26eac6..668029e8297 100644 --- a/clap_complete/tests/snapshots/home/dynamic/exhaustive/bash/.bashrc +++ b/clap_complete/tests/snapshots/home/dynamic/exhaustive/bash/.bashrc @@ -17,7 +17,7 @@ _clap_complete_exhaustive() { compopt -o nospace fi } -if [[ \"${{BASH_VERSINFO[0]}}\" -eq 4 && \"${{BASH_VERSINFO[1]}}\" -ge 4 || \"${{BASH_VERSINFO[0]}}\" -gt 4 ]]; then +if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then complete -o nospace -o bashdefault -o nosort -F _clap_complete_exhaustive exhaustive else complete -o nospace -o bashdefault -F _clap_complete_exhaustive exhaustive diff --git a/clap_complete/tests/snapshots/register_minimal.bash b/clap_complete/tests/snapshots/register_minimal.bash index a111d3d9935..925c3835b87 100644 --- a/clap_complete/tests/snapshots/register_minimal.bash +++ b/clap_complete/tests/snapshots/register_minimal.bash @@ -15,7 +15,7 @@ _clap_complete_my_app() { compopt -o nospace fi } -if [[ /"${{BASH_VERSINFO[0]}}/" -eq 4 && /"${{BASH_VERSINFO[1]}}/" -ge 4 || /"${{BASH_VERSINFO[0]}}/" -gt 4 ]]; then +if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then complete -o nospace -o bashdefault -o nosort -F _clap_complete_my_app my-app else complete -o nospace -o bashdefault -F _clap_complete_my_app my-app diff --git a/clap_complete/tests/testsuite/bash.rs b/clap_complete/tests/testsuite/bash.rs index b2c50c41bfb..d39debbc4cb 100644 --- a/clap_complete/tests/testsuite/bash.rs +++ b/clap_complete/tests/testsuite/bash.rs @@ -253,3 +253,35 @@ fn complete() { fn register_dynamic_completion() { common::register_example::("dynamic", "exhaustive"); } + +#[test] +#[cfg(all(unix, feature = "unstable-command"))] +fn complete_dynamic() { + if !common::has_command("bash") { + return; + } + + let term = completest::Term::new(); + let mut runtime = + common::load_runtime::("dynamic", "exhaustive"); + + let input = "exhaustive \t\t"; + let expected = snapbox::str![[r#" +% +--global --help -h action help last quote +--generate --version -V alias hint pacman value +"#]]; + let actual = runtime.complete(input, &term).unwrap(); + assert_data_eq!(actual, expected); + + let input = "exhaustive quote \t\t"; + let expected = snapbox::str![[r#" +% +--single-quotes --brackets --help cmd-backslash cmd-expansions +--double-quotes --expansions --version cmd-backticks cmd-single-quotes +--backticks --choice -h cmd-brackets escape-help +--backslash --global -V cmd-double-quotes help +"#]]; + let actual = runtime.complete(input, &term).unwrap(); + assert_data_eq!(actual, expected); +}