From a4c6a1aaedf8899512d52ae863d77b54c5b5a764 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH] Added first tests for Bash-it completion script --- test/completion/bash-it.completion.bats | 72 +++++++++++++++++++++++++ test/run | 5 +- 2 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 test/completion/bash-it.completion.bats diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats new file mode 100644 index 00000000..dc528ed9 --- /dev/null +++ b/test/completion/bash-it.completion.bats @@ -0,0 +1,72 @@ +#!/usr/bin/env bats + +load ../test_helper +load ../../lib/composure +load ../../completion/available/bash-it.completion + +function local_setup { + mkdir -p "$BASH_IT" + lib_directory="$(cd "$(dirname "$0")" && pwd)" + # Use rsync to copy Bash-it to the temp folder + # rsync is faster than cp, since we can exclude the large ".git" folder + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" + + rm -rf "$BASH_IT"/enabled + rm -rf "$BASH_IT"/aliases/enabled + rm -rf "$BASH_IT"/completion/enabled + rm -rf "$BASH_IT"/plugins/enabled + + # Don't pollute the user's actual $HOME directory + # Use a test home directory instead + export BASH_IT_TEST_CURRENT_HOME="${HOME}" + export BASH_IT_TEST_HOME="$(cd "${BASH_IT}/.." && pwd)/BASH_IT_TEST_HOME" + mkdir -p "${BASH_IT_TEST_HOME}" + export HOME="${BASH_IT_TEST_HOME}" +} + +function local_teardown { + export HOME="${BASH_IT_TEST_CURRENT_HOME}" + + rm -rf "${BASH_IT_TEST_HOME}" + + assert_equal "${BASH_IT_TEST_CURRENT_HOME}" "${HOME}" +} + +@test "completion bash-it: ensure that the _bash-it-comp function is available" { + type -a _bash-it-comp &> /dev/null + assert_success +} + +@test "completion bash-it: provide the atom aliases when not enabled" { + COMP_WORDS=(bash-it enable alias ato) + + COMP_CWORD=3 + + COMP_LINE='bash-it enable alias ato' + + COMP_POINT=${#COMP_LINE} + + _bash-it-comp + + echo "${COMPREPLY[@]}" + all_results="${COMPREPLY[@]}" + + assert_equal "atom" "$all_results" +} + +@test "completion bash-it: provide the a* aliases when not enabled" { + COMP_WORDS=(bash-it enable alias a) + + COMP_CWORD=3 + + COMP_LINE='bash-it enable alias a' + + COMP_POINT=${#COMP_LINE} + + _bash-it-comp + + echo "${COMPREPLY[@]}" + all_results="${COMPREPLY[@]}" + + assert_equal "all ag ansible apt atom" "$all_results" +} diff --git a/test/run b/test/run index 72d8db4a..9cfa72cd 100755 --- a/test/run +++ b/test/run @@ -9,6 +9,5 @@ if [ -z "${BASH_IT}" ]; then export BASH_IT=$(cd ${test_directory} && dirname $(pwd)) fi -# TODO Add tests for bash-it completion - -exec $bats_executable ${CI:+--tap} ${test_directory}/{bash_it,install,lib,plugins,themes} +#exec $bats_executable ${CI:+--tap} ${test_directory}/completion +exec $bats_executable ${CI:+--tap} ${test_directory}/{bash_it,completion,install,lib,plugins,themes}