1
0
mirror of https://github.com/sstephenson/bats.git synced 2024-11-17 11:42:33 +01:00

added decho function for debugging output

if DEBUG is defined, then when decho is called, it will output the given
string to the console, prefixed with '# DEBUG: '

This allows easier debugging of tests but still will conditionally
output said output.
This commit is contained in:
Spike Grobstein 2013-08-31 10:08:59 -04:00
parent bc72b85871
commit 93d6a43dae
3 changed files with 26 additions and 0 deletions

View File

@ -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" ] || {

View File

@ -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
}

6
test/fixtures/bats/debug.bats vendored Normal file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bats
@test "this test contains decho call" {
decho "testing decho"
[[ 1 -eq 1 ]]
}