From dac7a9bc888f807a8ce579bdc22abb3716958f00 Mon Sep 17 00:00:00 2001 From: Anish Athalye Date: Thu, 25 Feb 2021 08:14:34 -0500 Subject: [PATCH] Add --debug flag to test driver This is easier than the old method of adding `DEBUG=true` to the top of test files. --- test/README.md | 4 ++-- test/driver-lib.bash | 2 +- test/test | 21 +++++++++++++++++++-- test/test-lib.bash | 1 - 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/test/README.md b/test/README.md index 9ec79f5..a4d8208 100644 --- a/test/README.md +++ b/test/README.md @@ -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 diff --git a/test/driver-lib.bash b/test/driver-lib.bash index ab59240..b7b314e 100644 --- a/test/driver-lib.bash +++ b/test/driver-lib.bash @@ -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 diff --git a/test/test b/test/test index f944512..c52932b 100755 --- a/test/test +++ b/test/test @@ -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 @@ -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 diff --git a/test/test-lib.bash b/test/test-lib.bash index 5472e46..1fa72cb 100644 --- a/test/test-lib.bash +++ b/test/test-lib.bash @@ -1,4 +1,3 @@ -DEBUG=${DEBUG:-false} DOTBOT_EXEC="${BASEDIR}/bin/dotbot" DOTFILES="${HOME}/dotfiles" INSTALL_CONF='install.conf.yaml'