diff --git a/libexec/bats-exec-test b/libexec/bats-exec-test index d4c21b3..20d10f8 100755 --- a/libexec/bats-exec-test +++ b/libexec/bats-exec-test @@ -23,6 +23,13 @@ fi BATS_TEST_DIRNAME="$(dirname "$BATS_TEST_FILENAME")" BATS_TEST_NAMES=() +# if DEBUG is set, write the given string to the console. +decho() { + if [[ -n "$DEBUG" ]]; then + echo "# DEBUG: " $@ >&3 + fi +} + load() { local filename="$BATS_TEST_DIRNAME/$1.bash" [ -f "$filename" ] || { diff --git a/test/bats.bats b/test/bats.bats index fe24cd7..f6ec532 100755 --- a/test/bats.bats +++ b/test/bats.bats @@ -110,3 +110,16 @@ fixtures bats run bats "$FIXTURE_ROOT/dos_line.bats" [ $status -eq 0 ] } + +@test "test should not output DEBUG line if DEBUG is not set" { + run bats "$FIXTURE_ROOT/debug.bats" + [ $status -eq 0 ] + [[ ! $(echo $output | grep DEBUG) ]] +} + +@test "test should output DEBUG line if DEBUG is set" { + export DEBUG=1 + run bats "$FIXTURE_ROOT/debug.bats" + [ $status -eq 0 ] + echo $output | grep DEBUG +} diff --git a/test/fixtures/bats/debug.bats b/test/fixtures/bats/debug.bats new file mode 100644 index 0000000..d32d3a4 --- /dev/null +++ b/test/fixtures/bats/debug.bats @@ -0,0 +1,6 @@ +#!/usr/bin/env bats + +@test "this test contains decho call" { + decho "testing decho" + [[ 1 -eq 1 ]] +}