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:
parent
bc72b85871
commit
93d6a43dae
|
@ -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" ] || {
|
||||
|
|
|
@ -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
6
test/fixtures/bats/debug.bats
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
@test "this test contains decho call" {
|
||||
decho "testing decho"
|
||||
[[ 1 -eq 1 ]]
|
||||
}
|
Loading…
Reference in New Issue
Block a user