diff --git a/test/.editorconfig b/test/.editorconfig deleted file mode 100644 index b490228..0000000 --- a/test/.editorconfig +++ /dev/null @@ -1,5 +0,0 @@ -[Vagrantfile] -indent_size = 2 - -[{test,test_travis}] -indent_size = 4 diff --git a/test/.gitignore b/test/.gitignore deleted file mode 100644 index 73ab2cf..0000000 --- a/test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.vagrant/ -*.log diff --git a/test/README.md b/test/README.md deleted file mode 100644 index 459981e..0000000 --- a/test/README.md +++ /dev/null @@ -1,86 +0,0 @@ -Testing -======= - -Dotbot testing code uses [Vagrant] to run all tests inside a virtual machine to -have tests be completely isolated from the host machine. Specifically, you -will need both: - - - [VirtualBox] - - [Vagrant] - -Install Dotbot dependencies ---------------------------- - -Ensure you have updated the `dotbot` submodule dependencies, on the host machine: - -```bash -git submodule sync --quiet --recursive -git submodule update --init --recursive -``` -Install Vagrant ---------------- - -### Debian-based distributions - -```bash -sudo apt install vagrant virtualbox -``` - -### macOS - -You can download those directly from the above URLs, or via some MacOS package managers. -e.g. using [HomeBrew](https://brew.sh/): - -```bash -brew cask install virtualbox -brew cask install vagrant -# optional, adding menu-bar support: -brew cask install vagrant-manager -``` - -Running the Tests ------------------ - -Before running the tests, you must start and `ssh` into the VM: - -```bash -vagrant up -vagrant ssh -``` - -All remaining commands are run inside the VM. - -First, you must install a version of Python to test against, using: - - pyenv install -s {version} - -You can choose any version you like, e.g. `3.8.1`. It isn't particularly -important to test against all supported versions of Python in the VM, because -they will be tested by CI. Once you've installed a specific version of Python, -activate it with: - - pyenv global {version} - -The VM mounts your host's Dotbot directory in `/dotbot` as read-only, allowing -you to make edits on your host machine. Run the entire test suite by: - -```bash -cd /dotbot/test -./test -``` - -Selected tests can be run by passing paths to the tests as arguments, e.g.: - -```bash -./test tests/create.bash tests/defaults.bash -``` - -To debug tests, you can run the test driver with the `--debug` (or `-d` short -form) flag, e.g. `./test --debug tests/link-if.bash`. This will enable printing -stdout/stderr. - -When finished with testing, it is good to shut down the virtual machine by -running `vagrant halt`. - -[VirtualBox]: https://www.virtualbox.org/ -[Vagrant]: https://www.vagrantup.com/ diff --git a/test/Vagrantfile b/test/Vagrantfile deleted file mode 100644 index ad79ef1..0000000 --- a/test/Vagrantfile +++ /dev/null @@ -1,28 +0,0 @@ -Vagrant.configure(2) do |config| - config.vm.box = 'ubuntu/jammy64' - - config.vm.synced_folder "..", "/dotbot", mount_options: ["ro"] - - # disable default synced folder - config.vm.synced_folder ".", "/vagrant", disabled: true - - # install packages - config.vm.provision "shell", inline: <<-EOS - apt-get -y update - apt-get install -y git make build-essential libssl-dev zlib1g-dev \ - libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \ - libncurses5-dev - EOS - - # install pyenv - config.vm.provision "shell", privileged: false, inline: <<-EOS - rm -rf ~/.pyenv - git clone https://github.com/pyenv/pyenv.git ~/.pyenv - cat <<-'PYENV' > ~/.bashrc - export PYENV_ROOT="$HOME/.pyenv" - export PATH="$PYENV_ROOT/bin:$PATH" - eval "$(pyenv init --path)" - eval "$(pyenv init -)" -PYENV - EOS -end diff --git a/test/driver-lib.bash b/test/driver-lib.bash deleted file mode 100644 index 09ad303..0000000 --- a/test/driver-lib.bash +++ /dev/null @@ -1,99 +0,0 @@ -red() { - if [ -t 1 ]; then - printf "\033[31m%s\033[0m\n" "$*" - else - printf "%s\n" "$*" - fi -} - -green() { - if [ -t 1 ]; then - printf "\033[32m%s\033[0m\n" "$*" - else - printf "%s\n" "$*" - fi -} - -yellow() { - if [ -t 1 ]; then - printf "\033[33m%s\033[0m\n" "$*" - else - printf "%s\n" "$*" - fi -} - - -check_env() { - if [[ "$(whoami)" != "vagrant" && "${CI}" != true ]]; then - die "tests must be run inside Vagrant or CI" - fi -} - -cleanup() { - rm -rf ~/fakehome - mkdir -p ~/fakehome -} - -initialize() { - echo "initializing." - tests_run=0 - tests_passed=0 - tests_failed=0 - tests_skipped=0 - tests_total="${1}" - local plural="" && [ "${tests_total}" -gt 1 ] && plural="s" - printf -- "running %d test%s...\n\n" "${tests_total}" "${plural}" -} - -pass() { - tests_passed=$((tests_passed + 1)) - green "-> ok." - echo -} - -fail() { - tests_failed=$((tests_failed + 1)) - red "-> fail!" - echo -} - -skip() { - tests_skipped=$((tests_skipped + 1)) - yellow "-> skipped." - echo -} - -run_test() { - tests_run=$((tests_run + 1)) - printf '[%d/%d] (%s)\n' "${tests_run}" "${tests_total}" "${1}" - cleanup - if (cd "${BASEDIR}/test/tests" && HOME=~/fakehome DEBUG=${2} DOTBOT_TEST=true bash "${1}"); then - pass - elif [ $? -eq 42 ]; then - skip - else - fail - fi -} - -report() { - printf -- "test report\n" - printf -- "-----------\n" - printf -- "- %3d run\n" ${tests_run} - printf -- "- %3d passed\n" ${tests_passed} - printf -- "- %3d skipped\n" ${tests_skipped} - printf -- "- %3d failed\n" ${tests_failed} - if [ ${tests_failed} -gt 0 ]; then - red "==> FAIL! " - return 1 - else - green "==> PASS. " - return 0 - fi -} - -die() { - >&2 echo $@ - >&2 echo "terminating..." - exit 1 -} diff --git a/test/test b/test/test deleted file mode 100755 index c52932b..0000000 --- a/test/test +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash -set -e - -export BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -cd "${BASEDIR}/test" -. "./driver-lib.bash" - -date_stamp="$(date --rfc-3339=ns)" -start="$(date +%s)" - -check_env - -# parse flags; must come before positional arguments -POSITIONAL=() -DEBUG=false -while [[ $# -gt 0 ]]; do - case $1 in - -d|--debug) - DEBUG=true - shift - ;; - *) - POSITIONAL+=("$1") - shift - ;; - esac -done -set -- "${POSITIONAL[@]}" # restore positional arguments - -declare -a tests=() - -if [ $# -eq 0 ]; then - while read file; do - tests+=("${file}") - done < <(find tests -type f -name '*.bash' | sort) -else - tests=("$@") -fi - -initialize "${#tests[@]}" - -for file in "${tests[@]}"; do - run_test "$(basename "${file}")" "${DEBUG}" -done - -if report; then - ret=0 -else - ret=1 -fi - -echo "(tests run in $(($(date +%s) - start)) seconds)" -exit ${ret} diff --git a/test/test-lib.bash b/test/test-lib.bash deleted file mode 100644 index d1028cf..0000000 --- a/test/test-lib.bash +++ /dev/null @@ -1,76 +0,0 @@ -DOTBOT_EXEC="${BASEDIR}/bin/dotbot" -DOTFILES="${HOME}/dotfiles" -INSTALL_CONF='install.conf.yaml' -INSTALL_CONF_JSON='install.conf.json' - -test_run_() { - if ! ${DEBUG}; then - (eval "$*") >/dev/null 2>&1 - else - (eval "$*") - fi -} - -test_expect_success() { - local tag=${1} && shift - if ! test_run_ "$@"; then - >&2 echo "- ${tag} failed." - exit 1 - fi -} - -test_expect_failure() { - local tag=${1} && shift - if test_run_ "$@"; then - >&2 echo "- ${tag} failed." - exit 1 - fi -} - -skip_tests() { - # exit with special exit code picked up by driver-lib.bash - exit 42 -} - -check_env() { - if [ "${DOTBOT_TEST}" != "true" ]; then - >&2 echo "test must be run by test driver" - exit 1 - fi -} - -# run comparison check on python version; args: -# $1 - comparison operator (e.g. '>=') -# $2 - version number, to be passed to python (e.g. '3', '3.5', '3.6.4') -# status code will reflect if comparison is true/false -# e.g. `check_python_version '>=' 3.5` -check_python_version() { - check="$1" - version="$(echo "$2" | tr . , )" - # this call to just `python` will work in the Vagrant-based testing VM - # because `pyenv` will always create a link to the "right" version. - python -c "import sys; exit( not (sys.version_info ${check} (${version})) )" -} - -initialize() { - check_env - echo "${test_description}" - mkdir -p "${DOTFILES}" - cd -} - -run_dotbot() { - ( - cat > "${DOTFILES}/${INSTALL_CONF}" - ${DOTBOT_EXEC} -c "${DOTFILES}/${INSTALL_CONF}" "${@}" - ) -} - -run_dotbot_json() { - ( - cat > "${DOTFILES}/${INSTALL_CONF_JSON}" - ${DOTBOT_EXEC} -c "${DOTFILES}/${INSTALL_CONF_JSON}" "${@}" - ) -} - -initialize diff --git a/test/tests/clean-default.bash b/test/tests/clean-default.bash deleted file mode 100644 index 8bb405d..0000000 --- a/test/tests/clean-default.bash +++ /dev/null @@ -1,19 +0,0 @@ -test_description='clean uses default unless overridden' -. '../test-lib.bash' - -test_expect_success 'setup' ' -ln -s /nowhere ~/.g -' - -test_expect_success 'run' ' -run_dotbot < ${DOTFILES}/h -' - -test_expect_success 'run' ' -run_dotbot_json < ${DOTFILES}/h -' - -test_expect_success 'run' ' -run_dotbot_json < ${DOTFILES}/f && -echo "grape" > ~/f && -ln -s ~/f ~/.f && -ln -s /nowhere ~/.g -' - -test_expect_failure 'run-fail' ' -run_dotbot < ~/x -- link: - ~/y: y -EOF -' - -test_expect_success 'test' ' -[ "$(readlink ~/bad | cut -d/ -f5-)" = "dotfiles/nonexistent" ] && - ! test -f ~/x && test -f ~/y -' diff --git a/test/tests/except.bash b/test/tests/except.bash deleted file mode 100644 index 2973ad9..0000000 --- a/test/tests/except.bash +++ /dev/null @@ -1,32 +0,0 @@ -test_description='--except' -. '../test-lib.bash' - -test_expect_success 'setup' ' -echo "apple" > ${DOTFILES}/x -' - -test_expect_success 'run' ' -run_dotbot --except link < ~/y -- link: - ~/x: x -EOF -' - -test_expect_success 'test' ' -grep "pear" ~/y && ! test -f ~/x -' - -test_expect_success 'run 2' ' -run_dotbot --except shell < ~/z -- link: - ~/x: x -EOF -' - -test_expect_success 'test' ' -grep "apple" ~/x && ! test -f ~/z -' diff --git a/test/tests/exit-on-failure.bash b/test/tests/exit-on-failure.bash deleted file mode 100644 index aead77b..0000000 --- a/test/tests/exit-on-failure.bash +++ /dev/null @@ -1,32 +0,0 @@ -test_description='test exit on failure' -. '../test-lib.bash' - -test_expect_success 'setup' ' -echo "apple" > ${DOTFILES}/f1 && -echo "orange" > ${DOTFILES}/f2 && -echo "pineapple" > ${DOTFILES}/f3 -' - -test_expect_failure 'run_case1' ' -run_dotbot -x <> ~/tmp_bin/python < ${DOTFILES}/f && -ln -s dotfiles dotfiles-symlink -' - -test_expect_success 'run' ' -cat > "${DOTFILES}/${INSTALL_CONF}" < ${DOTFILES}/f && -echo "grape" > ${DOTFILES}/fd -' - -test_expect_success 'run' ' -run_dotbot < ~/f -' - -test_expect_success 'run' ' -run_dotbot < ${DOTFILES}/h -' - -test_expect_success 'run' ' -export APPLE="h" && -run_dotbot < ${DOTFILES}/h -' - -test_expect_success 'run' ' -export APPLE="h" && -run_dotbot < ${DOTFILES}/f && -echo "grape" > ${DOTFILES}/h -' - -test_expect_success 'run' ' -export ORANGE=".config" && -export BANANA="g" && -unset PEAR && -run_dotbot < ${DOTFILES}/\$ORANGE -' - -test_expect_success 'run' ' -unset ORANGE && -run_dotbot < ${DOTFILES}/config/foo/a && -echo "banana" > ${DOTFILES}/config/bar/b && -echo "cherry" > ${DOTFILES}/config/bar/c && -echo "donut" > ${DOTFILES}/config/baz/d -' - -test_expect_success 'run 1' ' -run_dotbot -v < ${DOTFILES}/config/baz/buzz/e -' - -test_expect_success 'run 2' ' -run_dotbot -v < ${DOTFILES}/config/baz/bizz/g -' - -test_expect_success 'run 3' ' -run_dotbot -v < ${DOTFILES}/config/fiz/f -' - -test_expect_success 'run 4' ' -run_dotbot -v < ${DOTFILES}/config/foo/a && -echo "banana" > ${DOTFILES}/config/bar/b && -echo "cherry" > ${DOTFILES}/config/bar/c -' - -test_expect_success 'run' ' -run_dotbot -v < ${DOTFILES}/conf/${fruit} - echo "dot-${fruit}" > ${DOTFILES}/conf/.${fruit} -done -' - -test_expect_success 'glob patterns: "conf/*"' ' -run_dotbot -v <=" 3.5 \ - || test_expect_failure 'expect-fail' ' -run_dotbot -v <=" 3.5 \ - || skip_tests - -test_expect_success 'setup' ' -mkdir -p ${DOTFILES}/config/foo/bar && -echo "apple" > ${DOTFILES}/config/foo/bar/a && -echo "banana" > ${DOTFILES}/config/foo/bar/b && -echo "cherry" > ${DOTFILES}/config/foo/bar/c -' - -test_expect_success 'run' ' -run_dotbot -v < ${DOTFILES}/bin/a && -echo "banana" > ${DOTFILES}/bin/b && -echo "cherry" > ${DOTFILES}/bin/c -' - -test_expect_success 'run 1' ' -run_dotbot -v < ${DOTFILES}/bin/.a && -echo "dot_banana" > ${DOTFILES}/bin/.b && -echo "dot_cherry" > ${DOTFILES}/bin/.c -' - -test_expect_success 'run 3' ' -run_dotbot -v < ${DOTFILES}/.a && -echo "dot_banana" > ${DOTFILES}/.b && -echo "dot_cherry" > ${DOTFILES}/.c -' - -test_expect_success 'run 4' ' -run_dotbot -v < ${DOTFILES}/f -' - -test_expect_success 'run' ' -run_dotbot < ${DOTFILES}/f && -echo "grape" > ~/.f -' - -test_expect_failure 'run' ' -run_dotbot < ${DOTFILES}/f && -echo "grape" > ${DOTFILES}/g && -ln -s dotfiles dotfiles-symlink -' - -test_expect_success 'run' ' -cat > "${DOTFILES}/${INSTALL_CONF}" < "${DOTFILES}/${INSTALL_CONF}" < ${DOTFILES}/conf/a && -echo "banana" > ${DOTFILES}/conf/b && -echo "cherry" > ${DOTFILES}/conf/c -' - -test_expect_success 'test glob w/ prefix' ' -run_dotbot -v < ${DOTFILES}/f && -mkdir ${DOTFILES}/d && -echo "grape" > ${DOTFILES}/d/e -' - -test_expect_success 'run' ' -run_dotbot < ${DOTFILES}/f && -echo "grape" > ~/.f -' - -test_expect_failure 'run' ' -run_dotbot < ${DOTFILES}/f && -echo "grape" > ~/f && -ln -s ~/f ~/.f -' - -test_expect_success 'run' ' -run_dotbot < ${DOTFILES}/f && -echo "grape" > ~/.f -' - -test_expect_success 'run' ' -run_dotbot < ${DOTFILES}/x -' - -test_expect_success 'run' ' -run_dotbot --only link < ~/z -- link: - ~/d/x: x -EOF -' - -test_expect_success 'test' ' -grep "apple" ~/d/x && ! test -f ~/z -' diff --git a/test/tests/only-multi.bash b/test/tests/only-multi.bash deleted file mode 100644 index e8d8362..0000000 --- a/test/tests/only-multi.bash +++ /dev/null @@ -1,20 +0,0 @@ -test_description='--only with multiple arguments' -. '../test-lib.bash' - -test_expect_success 'setup' ' -ln -s ${DOTFILES}/nonexistent ~/bad && touch ${DOTFILES}/y -' - -test_expect_success 'run' ' -run_dotbot --only clean shell < ~/x -- link: - ~/y: y -EOF -' - -test_expect_success 'test' ' -! test -f ~/bad && grep "x" ~/x && ! test -f ~/y -' diff --git a/test/tests/only.bash b/test/tests/only.bash deleted file mode 100644 index 1f74441..0000000 --- a/test/tests/only.bash +++ /dev/null @@ -1,32 +0,0 @@ -test_description='--only' -. '../test-lib.bash' - -test_expect_success 'setup' ' -echo "apple" > ${DOTFILES}/x -' - -test_expect_success 'run' ' -run_dotbot --only shell < ~/y -- link: - ~/x: x -EOF -' - -test_expect_success 'test' ' -grep "pear" ~/y && ! test -f ~/x -' - -test_expect_success 'run 2' ' -run_dotbot --only link < ~/z -- link: - ~/x: x -EOF -' - -test_expect_success 'test' ' -grep "apple" ~/x && ! test -f ~/z -' diff --git a/test/tests/plugin-dir.bash b/test/tests/plugin-dir.bash deleted file mode 100644 index f3a5e94..0000000 --- a/test/tests/plugin-dir.bash +++ /dev/null @@ -1,29 +0,0 @@ -test_description='directory-based plugin loading works' -. '../test-lib.bash' - -test_expect_success 'setup' ' -mkdir ${DOTFILES}/plugins -cat > ${DOTFILES}/plugins/test.py < ${DOTFILES}/f -' - -test_expect_failure 'run' ' -run_dotbot --disable-built-in-plugins < ${DOTFILES}/test.py < ${DOTFILES}/test.py <&2 -EOF -' - -test_expect_success 'run 5' ' -(run_dotbot -vv 2>&1 | (grep "^apple")) <&2 -EOF -' - -test_expect_success 'run 6' ' -(run_dotbot -vv 2>&1 | (grep "^apple")) <&2 - stdout: false -EOF -' - -test_expect_success 'run 7' ' -(run_dotbot -vv 2>&1 | (grep "^apple")) <&2 -EOF -' - -# Make sure that we must use verbose level 2 -# This preserves backwards compatability -test_expect_failure 'run 8' ' -(run_dotbot -v | (grep "^apple")) <&2 -EOF -' diff --git a/test/tests/shell-compact-stdout.bash b/test/tests/shell-compact-stdout.bash deleted file mode 100644 index dc55d52..0000000 --- a/test/tests/shell-compact-stdout.bash +++ /dev/null @@ -1,22 +0,0 @@ -test_description='shell command stdout works in compact form' -. '../test-lib.bash' - -test_expect_success 'run' ' -(run_dotbot | grep "^apple") < ${DOTFILES}/foo -' - -test_expect_success 'run' ' -cat > ${DOTFILES}/install.conf.yaml <