Skip to content

Commit

Permalink
Add --debug flag to test driver
Browse files Browse the repository at this point in the history
This is easier than the old method of adding `DEBUG=true` to the top of
test files.
  • Loading branch information
anishathalye committed Feb 25, 2021
1 parent 43b62ed commit dac7a9b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ edits on your host machine). You can run the test suite by `cd /dotbot/test`
and then running `./test`. Selected tests can be run by passing paths to the
tests as arguments, e.g. `./test tests/create.bash tests/defaults.bash`.

To debug tests, you can prepend the line `DEBUG=true` as the first line to any
individual test (a `.bash` file inside `test/tests`). This will enable printing
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
Expand Down
2 changes: 1 addition & 1 deletion test/driver-lib.bash
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ 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 DOTBOT_TEST=true bash "${1}"); then
if (cd "${BASEDIR}/test/tests" && HOME=~/fakehome DEBUG=${2} DOTBOT_TEST=true bash "${1}"); then
pass
else
fail
Expand Down
21 changes: 19 additions & 2 deletions test/test
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ 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
Expand All @@ -20,10 +37,10 @@ else
tests=("$@")
fi

initialize "${#tests[@]}" "${VERSION}"
initialize "${#tests[@]}"

for file in "${tests[@]}"; do
run_test "$(basename "${file}")" "${VERSION}"
run_test "$(basename "${file}")" "${DEBUG}"
done

if report; then
Expand Down
1 change: 0 additions & 1 deletion test/test-lib.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
DEBUG=${DEBUG:-false}
DOTBOT_EXEC="${BASEDIR}/bin/dotbot"
DOTFILES="${HOME}/dotfiles"
INSTALL_CONF='install.conf.yaml'
Expand Down

0 comments on commit dac7a9b

Please sign in to comment.