diff --git a/clap_complete/tests/snapshots/home/dynamic/test/bash/.bashrc b/clap_complete/tests/snapshots/home/dynamic/test/bash/.bashrc new file mode 100644 index 00000000..cc6c1be0 --- /dev/null +++ b/clap_complete/tests/snapshots/home/dynamic/test/bash/.bashrc @@ -0,0 +1,22 @@ +PS1='% ' +. /etc/bash_completion + +_clap_complete_test() { + export _CLAP_COMPLETE_INDEX=${COMP_CWORD} + export _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE} + if compopt +o nospace 2> /dev/null; then + export _CLAP_COMPLETE_SPACE=false + else + export _CLAP_COMPLETE_SPACE=true + fi + export _CLAP_COMPLETE_IFS=$'\013' + COMPREPLY=( $("test" complete --shell bash -- "${COMP_WORDS[@]}") ) + if [[ $? != 0 ]]; then + unset COMPREPLY + elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then + compopt -o nospace + fi +} +complete -o nospace -o bashdefault -F _clap_complete_test test + + diff --git a/clap_complete/tests/testsuite/bash.rs b/clap_complete/tests/testsuite/bash.rs index 81c2ea91..e2a57839 100644 --- a/clap_complete/tests/testsuite/bash.rs +++ b/clap_complete/tests/testsuite/bash.rs @@ -161,3 +161,9 @@ fn complete() { let actual = runtime.complete(input, &term).unwrap(); snapbox::assert_eq(expected, actual); } + +#[test] +#[cfg(unix)] +fn register_dynamic_completion() { + common::register_example("dynamic", "test", completest::Shell::Bash); +} diff --git a/clap_complete/tests/testsuite/common.rs b/clap_complete/tests/testsuite/common.rs index 50a58471..2d962dbf 100644 --- a/clap_complete/tests/testsuite/common.rs +++ b/clap_complete/tests/testsuite/common.rs @@ -322,10 +322,17 @@ pub fn register_example(context: &str, name: &str, shell: completest::Shell) { println!("Compiled"); let bin_root = bin_path.parent().unwrap().to_owned(); - let registration = std::process::Command::new(&bin_path) - .arg(format!("--generate={shell_name}")) - .output() - .unwrap(); + let mut registration = std::process::Command::new(&bin_path); + match context { + "static" => registration.args([format!("--generate={shell_name}")]), + "dynamic" => registration.args([ + "complete".to_owned(), + "--register=-".to_owned(), + format!("--shell={shell_name}"), + ]), + _ => unreachable!("unsupported context {}", context), + }; + let registration = registration.output().unwrap(); assert!( registration.status.success(), "{}",