diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/README.md | 41 | ||||
-rw-r--r-- | test/Vagrantfile | 5 | ||||
-rw-r--r-- | test/driver-lib.bash | 25 | ||||
-rwxr-xr-x | test/test | 2 | ||||
-rw-r--r-- | test/test-lib.bash | 12 | ||||
-rwxr-xr-x | test/test_travis | 2 | ||||
-rw-r--r-- | test/tests/clean-environment-variable-expansion.bash | 16 | ||||
-rw-r--r-- | test/tests/find-python-executable.bash | 6 | ||||
-rw-r--r-- | test/tests/link-glob-ambiguous.bash | 45 | ||||
-rw-r--r-- | test/tests/link-glob-multi-star.bash | 31 | ||||
-rw-r--r-- | test/tests/link-glob.bash | 47 | ||||
-rw-r--r-- | test/tests/link-if.bash | 51 | ||||
-rw-r--r-- | test/tests/plugin-dir.bash | 2 | ||||
-rw-r--r-- | test/tests/plugin-disable-builtin.bash | 17 | ||||
-rw-r--r-- | test/tests/plugin.bash | 2 | ||||
-rw-r--r-- | test/tests/shim.bash | 29 |
16 files changed, 297 insertions, 36 deletions
diff --git a/test/README.md b/test/README.md index c4abddc..993a753 100644 --- a/test/README.md +++ b/test/README.md @@ -1,12 +1,37 @@ Testing ======= -Dotbot testing code uses [Vagrant][vagrant] to run all tests inside a virtual -machine to have tests be completely isolated from the host machine. The test -driver relies on the [Sahara][sahara] plugin to snapshot and roll back virtual -machine state. The tests are deterministic, and each test is run in a virtual -machine with fresh state, ensuring that tests that modify system state are -easily repeatable. +Dotbot testing code uses [Vagrant] to run all tests inside a virtual machine to +have tests be completely isolated from the host machine. + +Installing the Test environnement +--------------------------------- + +### Debian-based distributions + +- Install the test requirements + +```bash +sudo apt install vagrant virtualbox +``` + +- Install Dotbot dependencies + +```bash +git submodule update --init --recursive +``` + +### macOS + +- Install the test requirements + - [VirtualBox] + - [Vagrant] + +- Install Dotbot dependencies + +```bash +git submodule update --init --recursive +``` Running the Tests ----------------- @@ -23,5 +48,5 @@ Tests can be run with a specific Python version by running `./test --version When finished with testing, it is good to shut down the virtual machine by running `vagrant halt`. -[vagrant]: https://www.vagrantup.com/ -[sahara]: https://github.com/jedi4ever/sahara +[VirtualBox]: https://www.virtualbox.org/wiki/Downloads +[Vagrant]: https://www.vagrantup.com/ diff --git a/test/Vagrantfile b/test/Vagrantfile index 6d3feb0..05d6747 100644 --- a/test/Vagrantfile +++ b/test/Vagrantfile @@ -1,9 +1,8 @@ Vagrant.configure(2) do |config| - config.vm.box = 'debian/jessie64' + config.vm.box = 'debian/stretch64' # sync by copying for isolation - config.vm.synced_folder "..", "/dotbot", type: "rsync", - rsync__exclude: ".git/" + config.vm.synced_folder "..", "/dotbot", type: "rsync" # disable default synced folder config.vm.synced_folder ".", "/vagrant", disabled: true diff --git a/test/driver-lib.bash b/test/driver-lib.bash index 56a0740..02a71a5 100644 --- a/test/driver-lib.bash +++ b/test/driver-lib.bash @@ -31,10 +31,6 @@ check_prereqs() { >&2 echo "vagrant vm must be running." return 1 fi - if ! (vagrant plugin list | grep '^sahara\s\+') >/dev/null 2>&1; then - >&2 echo "vagrant plugin 'sahara' is not installed." - return 1 - fi } until_success() { @@ -56,23 +52,26 @@ wait_for_vagrant() { until_success vagrant ssh -c 'exit' } -rollback() { - vagrant sandbox rollback >/dev/null 2>&1 && - wait_for_vagrant && - vagrant rsync >/dev/null 2>&1 +cleanup() { + vagrant ssh -c " + find . -not \\( \ + -path './.pyenv' -o \ + -path './.pyenv/*' -o \ + -path './.bashrc' -o \ + -path './.profile' -o \ + -path './.ssh' -o \ + -path './.ssh/*' \ + \\) -delete" >/dev/null 2>&1 } initialize() { echo "initializing." - vagrant sandbox on >/dev/null 2>&1 if ! vagrant ssh -c "pyenv local ${2}" >/dev/null 2>&1; then - wait_for_vagrant && vagrant sandbox rollback >/dev/null 2>&1 - wait_for_vagrant if ! vagrant ssh -c "pyenv install -s ${2} && pyenv local ${2}" >/dev/null 2>&1; then die "could not install python ${2}" fi - vagrant sandbox commit >/dev/null 2>&1 fi + vagrant rsync >/dev/null 2>&1 tests_run=0 tests_passed=0 tests_failed=0 @@ -96,7 +95,7 @@ fail() { run_test() { tests_run=$((tests_run + 1)) printf '[%d/%d] (%s)\n' "${tests_run}" "${tests_total}" "${1}" - rollback || die "unable to rollback vm." # start with a clean slate + cleanup vagrant ssh -c "pyenv local ${2}" >/dev/null 2>&1 if vagrant ssh -c "cd /dotbot/test/tests && bash ${1}" 2>/dev/null; then pass @@ -24,7 +24,7 @@ do ;; esac done -VERSION="${VERSION:-2.7.9}" +VERSION="${VERSION:-3.6.4}" declare -a tests=() diff --git a/test/test-lib.bash b/test/test-lib.bash index affb5c9..e4d9a4e 100644 --- a/test/test-lib.bash +++ b/test/test-lib.bash @@ -1,6 +1,6 @@ DEBUG=${DEBUG:-false} USE_VAGRANT=${USE_VAGRANT:-true} -DOTBOT_EXEC=${DOTBOT_EXEC:-"/dotbot/bin/dotbot"} +DOTBOT_EXEC=${DOTBOT_EXEC:-"python /dotbot/bin/dotbot"} DOTFILES="/home/$(whoami)/dotfiles" INSTALL_CONF='install.conf.yaml' INSTALL_CONF_JSON='install.conf.json' @@ -47,17 +47,15 @@ initialize() { run_dotbot() { ( - cd "${DOTFILES}" - cat > "${INSTALL_CONF}" - ${DOTBOT_EXEC} -d . -c "${INSTALL_CONF}" "${@}" + cat > "${DOTFILES}/${INSTALL_CONF}" + ${DOTBOT_EXEC} -c "${DOTFILES}/${INSTALL_CONF}" "${@}" ) } run_dotbot_json() { ( - cd "${DOTFILES}" - cat > "${INSTALL_CONF_JSON}" - ${DOTBOT_EXEC} -d . -c "${INSTALL_CONF_JSON}" "${@}" + cat > "${DOTFILES}/${INSTALL_CONF_JSON}" + ${DOTBOT_EXEC} -c "${DOTFILES}/${INSTALL_CONF_JSON}" "${@}" ) } diff --git a/test/test_travis b/test/test_travis index 20ec1ae..79439e1 100755 --- a/test/test_travis +++ b/test/test_travis @@ -6,7 +6,7 @@ set -e # set -x # set -v -BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +export BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # Prevent execution outside of Travis CI builds if [[ "${TRAVIS}" != true || "${CI}" != true ]]; then diff --git a/test/tests/clean-environment-variable-expansion.bash b/test/tests/clean-environment-variable-expansion.bash new file mode 100644 index 0000000..fedab45 --- /dev/null +++ b/test/tests/clean-environment-variable-expansion.bash @@ -0,0 +1,16 @@ +test_description='clean expands environment variables' +. '../test-lib.bash' + +test_expect_success 'setup' ' +ln -s ${DOTFILES}/f ~/.f +' + +test_expect_success 'run' ' +run_dotbot <<EOF +- clean: ["\$HOME"] +EOF +' + +test_expect_success 'test' ' +! test -h ~/.f +' diff --git a/test/tests/find-python-executable.bash b/test/tests/find-python-executable.bash index cc46724..d4fa7eb 100644 --- a/test/tests/find-python-executable.bash +++ b/test/tests/find-python-executable.bash @@ -1,6 +1,10 @@ test_description='can find python executable with different names' . '../test-lib.bash' +if ${USE_VAGRANT}; then + DOTBOT_EXEC="/dotbot/bin/dotbot" # revert to calling it as a shell script +fi + # the test machine needs to have a binary named `python` test_expect_success 'setup' ' mkdir ~/tmp_bin && @@ -26,7 +30,7 @@ test_expect_success 'setup 2' ' touch ~/tmp_bin/python && chmod +x ~/tmp_bin/python && cat >> ~/tmp_bin/python <<EOF -#!$HOME/tmp_bin/sh +#!$HOME/tmp_bin/bash exec $(which python) EOF ' diff --git a/test/tests/link-glob-ambiguous.bash b/test/tests/link-glob-ambiguous.bash new file mode 100644 index 0000000..7e23348 --- /dev/null +++ b/test/tests/link-glob-ambiguous.bash @@ -0,0 +1,45 @@ +test_description='link glob ambiguous' +. '../test-lib.bash' + +test_expect_success 'setup' ' +mkdir ${DOTFILES}/foo +' + +test_expect_failure 'run 1' ' +run_dotbot <<EOF +- link: + ~/foo/: + path: foo + glob: true +EOF +' + +test_expect_failure 'test 1' ' +test -d ~/foo +' + +test_expect_failure 'run 2' ' +run_dotbot <<EOF +- link: + ~/foo/: + path: foo/ + glob: true +EOF +' + +test_expect_failure 'test 2' ' +test -d ~/foo +' + +test_expect_success 'run 3' ' +run_dotbot <<EOF +- link: + ~/foo: + path: foo + glob: true +EOF +' + +test_expect_success 'test 3' ' +test -d ~/foo +' diff --git a/test/tests/link-glob-multi-star.bash b/test/tests/link-glob-multi-star.bash new file mode 100644 index 0000000..11ae740 --- /dev/null +++ b/test/tests/link-glob-multi-star.bash @@ -0,0 +1,31 @@ +test_description='link glob' +. '../test-lib.bash' + +test_expect_success 'setup' ' +mkdir ${DOTFILES}/config && +mkdir ${DOTFILES}/config/foo && +mkdir ${DOTFILES}/config/bar && +echo "apple" > ${DOTFILES}/config/foo/a && +echo "banana" > ${DOTFILES}/config/bar/b && +echo "cherry" > ${DOTFILES}/config/bar/c +' + +test_expect_success 'run' ' +run_dotbot -v <<EOF +- defaults: + link: + glob: true + create: true +- link: + ~/.config/: config/*/* +EOF +' + +test_expect_success 'test' ' +! readlink ~/.config/ && +! readlink ~/.config/foo && +readlink ~/.config/foo/a && +grep "apple" ~/.config/foo/a && +grep "banana" ~/.config/bar/b && +grep "cherry" ~/.config/bar/c +' diff --git a/test/tests/link-glob.bash b/test/tests/link-glob.bash new file mode 100644 index 0000000..f1c813d --- /dev/null +++ b/test/tests/link-glob.bash @@ -0,0 +1,47 @@ +test_description='link glob' +. '../test-lib.bash' + +test_expect_success 'setup 1' ' +mkdir ${DOTFILES}/bin && +echo "apple" > ${DOTFILES}/bin/a && +echo "banana" > ${DOTFILES}/bin/b && +echo "cherry" > ${DOTFILES}/bin/c +' + +test_expect_success 'run 1' ' +run_dotbot -v <<EOF +- defaults: + link: + glob: true + create: true +- link: + ~/bin: bin/* +EOF +' + +test_expect_success 'test 1' ' +grep "apple" ~/bin/a && +grep "banana" ~/bin/b && +grep "cherry" ~/bin/c +' + +test_expect_success 'setup 2' ' +rm -rf ~/bin +' + +test_expect_success 'run 2' ' +run_dotbot -v <<EOF +- defaults: + link: + glob: true + create: true +- link: + ~/bin/: bin/* +EOF +' + +test_expect_success 'test 2' ' +grep "apple" ~/bin/a && +grep "banana" ~/bin/b && +grep "cherry" ~/bin/c +' diff --git a/test/tests/link-if.bash b/test/tests/link-if.bash new file mode 100644 index 0000000..1ea7709 --- /dev/null +++ b/test/tests/link-if.bash @@ -0,0 +1,51 @@ +test_description='link if' +. '../test-lib.bash' + +test_expect_success 'setup' ' +mkdir ~/d +echo "apple" > ${DOTFILES}/f +' + +test_expect_success 'run' ' +run_dotbot <<EOF +- link: + ~/.f: + path: f + if: "true" + ~/.g: + path: f + if: "false" + ~/.h: + path: f + if: "[[ -d ~/d ]]" + ~/.i: + path: f + if: "badcommand" +EOF +' + +test_expect_success 'test' ' +grep "apple" ~/.f && +! test -f ~/.g && +grep "apple" ~/.h && +! test -f ~/.i +' + +test_expect_success 'run 2' ' +run_dotbot <<EOF +- defaults: + link: + if: "false" +- link: + ~/.j: + path: f + if: "true" + ~/.k: + path: f +EOF +' + +test_expect_success 'test 2' ' +grep "apple" ~/.j && +! test -f ~/.k +' diff --git a/test/tests/plugin-dir.bash b/test/tests/plugin-dir.bash index 299f144..f3a5e94 100644 --- a/test/tests/plugin-dir.bash +++ b/test/tests/plugin-dir.bash @@ -19,7 +19,7 @@ EOF ' test_expect_success 'run' ' -run_dotbot --plugin-dir plugins <<EOF +run_dotbot --plugin-dir ${DOTFILES}/plugins <<EOF - test: ~ EOF ' diff --git a/test/tests/plugin-disable-builtin.bash b/test/tests/plugin-disable-builtin.bash new file mode 100644 index 0000000..f469b0f --- /dev/null +++ b/test/tests/plugin-disable-builtin.bash @@ -0,0 +1,17 @@ +test_description='can disable built-in plugins' +. '../test-lib.bash' + +test_expect_success 'setup' ' +echo "apple" > ${DOTFILES}/f +' + +test_expect_failure 'run' ' +run_dotbot --disable-built-in-plugins <<EOF +- link: + ~/.f: f +EOF +' + +test_expect_failure 'test' ' +test -f ~/.f +' diff --git a/test/tests/plugin.bash b/test/tests/plugin.bash index 960e9ce..bdf0c7f 100644 --- a/test/tests/plugin.bash +++ b/test/tests/plugin.bash @@ -18,7 +18,7 @@ EOF ' test_expect_success 'run' ' -run_dotbot --plugin test.py <<EOF +run_dotbot --plugin ${DOTFILES}/test.py <<EOF - test: ~ EOF ' diff --git a/test/tests/shim.bash b/test/tests/shim.bash new file mode 100644 index 0000000..2ed7d54 --- /dev/null +++ b/test/tests/shim.bash @@ -0,0 +1,29 @@ +test_description='install shim works' +. '../test-lib.bash' + +test_expect_success 'setup' ' +cd ${DOTFILES} +git init +if ${USE_VAGRANT}; then + git submodule add /dotbot dotbot +else + git submodule add ${BASEDIR} dotbot +fi +cp ./dotbot/tools/git-submodule/install . +echo "pear" > ${DOTFILES}/foo +' + +test_expect_success 'run' ' +cat > ${DOTFILES}/install.conf.yaml <<EOF +- link: + ~/.foo: foo +EOF +if ! ${USE_VAGRANT}; then + sed -i "" "1 s/sh$/python/" ${DOTFILES}/dotbot/bin/dotbot +fi +${DOTFILES}/install +' + +test_expect_success 'test' ' +grep "pear" ~/.foo +' |