diff --git a/tests/functional/Dockerfile-ubuntu b/tests/functional/Dockerfile-ubuntu index cd4cb95..1de87c0 100644 --- a/tests/functional/Dockerfile-ubuntu +++ b/tests/functional/Dockerfile-ubuntu @@ -9,59 +9,86 @@ WORKDIR /opt/auto-click-auto RUN pip install -e . +# Test adding autocompletion for bash and fish FROM base_test_env as test_example_1 RUN echo "Current login shell is $SHELL" \ + && touch ~/.zshrc \ && echo "John Doe" | python3 examples/example_1.py \ - && grep 'eval "\$(_EXAMPLE_1_COMPLETE=bash_source example-1)"' ~/.bashrc \ + # Check that configuration has been added for bash + && grep 'command -v example-1 > /dev/null 2>&1 && eval "\$(_EXAMPLE_1_COMPLETE=bash_source example-1)"' ~/.bashrc \ && echo "~/.bashrc file is correct..." \ - && grep '_EXAMPLE_1_COMPLETE=fish_source example-1 | source' ~/.config/fish/completions/example-1.fish \ + # Check that configuration has been added for fish + && grep 'command -v example-1 > /dev/null 2>&1 && _EXAMPLE_1_COMPLETE=fish_source example-1 | source' ~/.config/fish/completions/example-1.fish \ && echo "fish config file is correct..." \ - && touch ~/.zshrc \ - && ! grep -q 'eval "\$(_EXAMPLE_2_COMPLETE=zsh_source example-2)"' ~/.zshrc || { echo "Completion added"; exit 1; } + # Check that no configuration has been added for zsh + && ! grep -q 'command -v example-1 > /dev/null 2>&1 && eval "\$(_EXAMPLE_1_COMPLETE=zsh_source example-1)"' ~/.zshrc || { echo "Completion should not haven be added"; exit 1; } +# Test adding autocompletion with default option and autodetect with bash FROM base_test_env as test_example_2_bash RUN echo "Current login shell is $SHELL" \ + && touch ~/.zshrc \ # We need to export the env variable otherwise we can't get it with # Python's `os.environ["SHELL"]`. && export SHELL=/bin/bash \ + # Check that configuration has been added for bash + && cp tests/functional/config_files/.bashrc-test-old ~/.bashrc \ && python3 examples/example_2.py --autocomplete \ - && grep 'eval "\$(_EXAMPLE_2_COMPLETE=bash_source example-2)"' ~/.bashrc \ + && grep 'command -v example-2 > /dev/null 2>&1 && eval "\$(_EXAMPLE_2_COMPLETE=bash_source example-2)"' ~/.bashrc \ + && diff ~/.bashrc tests/functional/config_files/.bashrc-test-new \ && echo "~/.bashrc file is correct..." \ - && touch ~/.zshrc \ - && ! grep -q 'eval "\$(_EXAMPLE_2_COMPLETE=zsh_source example-2)"' ~/.zshrc || { echo "Completion added"; exit 1; } \ - && if [ -e "~/.config/fish/completions/example-2.fish" ]; then echo "File exists"; exit 1; fi + # Check that no configuration has been added for zsh + && ! grep -q 'command -v example-2 > /dev/null 2>&1 && eval "\$(_EXAMPLE_2_COMPLETE=zsh_source example-2)"' ~/.zshrc || { echo "Completion should not haven be added"; exit 1; } \ + # Check that no configuration has been added for fish + && if [ -e "~/.config/fish/completions/example-2.fish" ]; then echo "File should not exist"; exit 1; fi +# Test adding autocompletion with default option and autodetect with zsh FROM base_test_env as test_example_2_zsh RUN echo "Current login shell is $SHELL" \ && touch ~/.zshrc \ # We need to export the env variable otherwise we can't get it with # Python's `os.environ["SHELL"]`. && export SHELL=/bin/zsh \ + # Check that configuration has been added for zsh + && cp tests/functional/config_files/.zshrc-test-old ~/.zshrc \ && python3 examples/example_2.py --autocomplete \ - && grep 'eval "\$(_EXAMPLE_2_COMPLETE=zsh_source example-2)"' ~/.zshrc \ + && grep 'command -v example-2 > /dev/null 2>&1 && eval "\$(_EXAMPLE_2_COMPLETE=zsh_source example-2)"' ~/.zshrc \ + && diff ~/.zshrc tests/functional/config_files/.zshrc-test-new \ && echo "~/.zshrc file is correct..." \ - && ! grep -q 'eval "\$(_EXAMPLE_2_COMPLETE=bash_source example-2)"' ~/.bashrc || { echo "Completion added"; exit 1; } \ - && if [ -e "~/.config/fish/completions/example-2.fish" ]; then echo "File exists"; exit 1; fi + # Check that no configuration has been added for bash + && ! grep -q 'command -v example-2 > /dev/null 2>&1 && eval "\$(_EXAMPLE_2_COMPLETE=bash_source example-2)"' ~/.bashrc || { echo "Completion should not haven be added"; exit 1; } \ + # Check that no configuration has been added for fish + && if [ -e "~/.config/fish/completions/example-2.fish" ]; then echo "File should not exist"; exit 1; fi +# Test adding autocompletion with default option and autodetect with fish FROM base_test_env as test_example_2_fish RUN echo "Current login shell is $SHELL" \ && touch ~/.zshrc \ + && mkdir -p ~/.config/fish/completions/ \ # We need to export the env variable otherwise we can't get it with # Python's `os.environ["SHELL"]`. && export SHELL=/usr/bin/fish \ + # Check that configuration has been added for fish + && cp tests/functional/config_files/.fish-test-old ~/.config/fish/completions/example-2.fish \ && python3 examples/example_2.py --autocomplete \ - && grep '_EXAMPLE_2_COMPLETE=fish_source example-2 | source' ~/.config/fish/completions/example-2.fish \ + && diff ~/.config/fish/completions/example-2.fish tests/functional/config_files/.fish-test-new \ + && grep 'command -v example-2 > /dev/null 2>&1 && _EXAMPLE_2_COMPLETE=fish_source example-2 | source' ~/.config/fish/completions/example-2.fish \ && echo "fish config file is correct..." \ - && ! grep -q 'eval "\$(_EXAMPLE_2_COMPLETE=bash_source example-2)"' ~/.bashrc || { echo "Completion added"; exit 1; } \ - && ! grep -q 'eval "\$(_EXAMPLE_2_COMPLETE=zsh_source example-2)"' ~/.zshrc || { echo "Completion added"; exit 1; } + # Check that no configuration has been added for bash + && ! grep -q 'command -v example-2 > /dev/null 2>&1 && eval "\$(_EXAMPLE_2_COMPLETE=bash_source example-2)"' ~/.bashrc || { echo "Completion should not haven be added"; exit 1; } \ + # Check that no configuration has been added for zsh + && ! grep -q 'command -v example-2 > /dev/null 2>&1 && eval "\$(_EXAMPLE_2_COMPLETE=zsh_source example-2)"' ~/.zshrc || { echo "Completion should not haven be added"; exit 1; } +# Test adding autocompletion for bash, zsh, fish FROM base_test_env as test_example_3 RUN echo "Current login shell is $SHELL" \ && touch ~/.zshrc \ && python3 examples/example_3.py config shell-completion \ - && grep 'eval "\$(_EXAMPLE_3_COMPLETE=bash_source example-3)"' ~/.bashrc \ + # Check that configuration has been added for bash + && grep 'command -v example-3 > /dev/null 2>&1 && eval "\$(_EXAMPLE_3_COMPLETE=bash_source example-3)"' ~/.bashrc \ && echo "~/.bashrc file is correct..." \ - && grep 'eval "\$(_EXAMPLE_3_COMPLETE=zsh_source example-3)"' ~/.zshrc \ + # Check that configuration has been added for zsh + && grep 'command -v example-3 > /dev/null 2>&1 && eval "\$(_EXAMPLE_3_COMPLETE=zsh_source example-3)"' ~/.zshrc \ && echo "~/.zshrc file is correct..." \ - && grep '_EXAMPLE_3_COMPLETE=fish_source example-3 | source' ~/.config/fish/completions/example-3.fish \ + # Check that configuration has been added for fish + && grep 'command -v example-3 > /dev/null 2>&1 && _EXAMPLE_3_COMPLETE=fish_source example-3 | source' ~/.config/fish/completions/example-3.fish \ && echo "fish config file is correct..." diff --git a/tests/functional/config_files/.bashrc-test-new b/tests/functional/config_files/.bashrc-test-new new file mode 100644 index 0000000..c465bd6 --- /dev/null +++ b/tests/functional/config_files/.bashrc-test-new @@ -0,0 +1,17 @@ +# Example .bashrc config file + +# If not running interactively, don't do anything +case $- in + *i*) ;; + *) return;; +esac + + + +# Define some colors first: +red='\e[0;31m' +RED='\e[1;31m' +blue='\e[0;34m' + +# Shell completion configuration for the Click Python package +command -v example-2 > /dev/null 2>&1 && eval "$(_EXAMPLE_2_COMPLETE=bash_source example-2)" \ No newline at end of file diff --git a/tests/functional/config_files/.bashrc-test-old b/tests/functional/config_files/.bashrc-test-old new file mode 100644 index 0000000..7d2e5ce --- /dev/null +++ b/tests/functional/config_files/.bashrc-test-old @@ -0,0 +1,16 @@ +# Example .bashrc config file + +# If not running interactively, don't do anything +case $- in + *i*) ;; + *) return;; +esac + + +# Shell completion configuration for the Click Python package +eval "$(_EXAMPLE_2_COMPLETE=bash_source example-2)" + +# Define some colors first: +red='\e[0;31m' +RED='\e[1;31m' +blue='\e[0;34m' \ No newline at end of file diff --git a/tests/functional/config_files/.fish-test-new b/tests/functional/config_files/.fish-test-new new file mode 100644 index 0000000..78c0c52 --- /dev/null +++ b/tests/functional/config_files/.fish-test-new @@ -0,0 +1,6 @@ +# Example fish config file + + + +# Shell completion configuration for the Click Python package +command -v example-2 > /dev/null 2>&1 && _EXAMPLE_2_COMPLETE=fish_source example-2 | source \ No newline at end of file diff --git a/tests/functional/config_files/.fish-test-old b/tests/functional/config_files/.fish-test-old new file mode 100644 index 0000000..2c18b5d --- /dev/null +++ b/tests/functional/config_files/.fish-test-old @@ -0,0 +1,4 @@ +# Example fish config file + +# Shell completion configuration for the Click Python package +_EXAMPLE_2_COMPLETE=fish_source example-2 | source \ No newline at end of file diff --git a/tests/functional/config_files/.zshrc-test-new b/tests/functional/config_files/.zshrc-test-new new file mode 100644 index 0000000..af1a9e6 --- /dev/null +++ b/tests/functional/config_files/.zshrc-test-new @@ -0,0 +1,18 @@ +# Example .zshrc config file + +# If not running interactively, don't do anything +case $- in + *i*) ;; + *) return;; +esac + + + + +# Define some colors first: +red='\e[0;31m' +RED='\e[1;31m' +blue='\e[0;34m' + +# Shell completion configuration for the Click Python package +command -v example-2 > /dev/null 2>&1 && eval "$(_EXAMPLE_2_COMPLETE=zsh_source example-2)" \ No newline at end of file diff --git a/tests/functional/config_files/.zshrc-test-old b/tests/functional/config_files/.zshrc-test-old new file mode 100644 index 0000000..780153d --- /dev/null +++ b/tests/functional/config_files/.zshrc-test-old @@ -0,0 +1,17 @@ +# Example .zshrc config file + +# If not running interactively, don't do anything +case $- in + *i*) ;; + *) return;; +esac + + + +# Shell completion configuration for the Click Python package +eval "$(_EXAMPLE_2_COMPLETE=zsh_source example-2)" + +# Define some colors first: +red='\e[0;31m' +RED='\e[1;31m' +blue='\e[0;34m' \ No newline at end of file