1
0
Fork 0
mirror of synced 2024-11-22 16:25:34 -05:00
dotbot/test/test-lib.bash
Anish Athalye a517c4c5d0 Fix bug in test harness
Because 'bin/dotbot' is a hybrid sh/Python script that finds the
appropriate Python binary and then runs, the test code should not invoke
it as an sh script when sh does not source the pyenv initialization
script.

The fix implemented in this patch is to directly run 'bin/dotbot' as a
Python script using 'python', which when called from bash, will run with
the correct Python version (because bash is set up to source the pyenv
initialization script).
2018-03-27 21:50:31 -04:00

68 lines
1.2 KiB
Bash

DEBUG=${DEBUG:-false}
USE_VAGRANT=${USE_VAGRANT:-true}
if ${USE_VAGRANT}; then
DOTBOT_EXEC=${DOTBOT_EXEC:-"python /dotbot/bin/dotbot"}
else
DOTBOT_EXEC=${DOTBOT_EXEC:-"/dotbot/bin/dotbot"}
fi
DOTFILES="/home/$(whoami)/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
}
check_vm() {
if [ "$(whoami)" != "vagrant" ]; then
>&2 echo "test can't run outside vm!"
exit 1
fi
}
initialize() {
if ${USE_VAGRANT}; then
check_vm
fi
echo "${test_description}"
mkdir -p "${DOTFILES}"
cd
}
run_dotbot() {
(
cd "${DOTFILES}"
cat > "${INSTALL_CONF}"
${DOTBOT_EXEC} -d . -c "${INSTALL_CONF}" "${@}"
)
}
run_dotbot_json() {
(
cd "${DOTFILES}"
cat > "${INSTALL_CONF_JSON}"
${DOTBOT_EXEC} -d . -c "${INSTALL_CONF_JSON}" "${@}"
)
}
initialize