Skip to content

Commit

Permalink
Compare before-after of config files in functional tests
Browse files Browse the repository at this point in the history
- We check the config files before-after, especially
for the hotfix for #12.
- Make some styling improvements
  • Loading branch information
KAUTH committed Dec 28, 2023
1 parent 4c4b804 commit 2b18a43
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 17 deletions.
61 changes: 44 additions & 17 deletions tests/functional/Dockerfile-ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
17 changes: 17 additions & 0 deletions tests/functional/config_files/.bashrc-test-new
Original file line number Diff line number Diff line change
@@ -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)"
16 changes: 16 additions & 0 deletions tests/functional/config_files/.bashrc-test-old
Original file line number Diff line number Diff line change
@@ -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'
6 changes: 6 additions & 0 deletions tests/functional/config_files/.fish-test-new
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions tests/functional/config_files/.fish-test-old
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Example fish config file

# Shell completion configuration for the Click Python package
_EXAMPLE_2_COMPLETE=fish_source example-2 | source
18 changes: 18 additions & 0 deletions tests/functional/config_files/.zshrc-test-new
Original file line number Diff line number Diff line change
@@ -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)"
17 changes: 17 additions & 0 deletions tests/functional/config_files/.zshrc-test-old
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 2b18a43

Please sign in to comment.