Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Added one log option (--log) #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions libexec/bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ help() {
echo " <test> is the path to a Bats test file, or the path to a directory"
echo " containing Bats test files."
echo
echo " -c, --count Count the number of test cases without running any tests"
echo " -h, --help Display this help message"
echo " -p, --pretty Show results in pretty format (default for terminals)"
echo " -t, --tap Show results in TAP format"
echo " -v, --version Display the version number"
echo " -c, --count Count the number of test cases without running any tests"
echo " -h, --help Display this help message"
echo " -p, --pretty Show results in pretty format (default for terminals)"
echo " -t, --tap Show results in TAP format"
echo " --log [FILE] Combine output and test logs into FILE"
echo " -v, --version Display the version number"
echo
echo " For more information, see https://github.com/sstephenson/bats"
echo
Expand Down Expand Up @@ -96,6 +97,10 @@ for option in "${options[@]}"; do
"t" | "tap" )
pretty=""
;;
"log" )
export BATS_LOG="/tmp/bats.log"
touch "$BATS_LOG"
;;
"p" | "pretty" )
pretty="1"
;;
Expand Down
10 changes: 10 additions & 0 deletions libexec/bats-exec-test
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ bats_test_begin() {
if [ -n "$BATS_EXTENDED_SYNTAX" ]; then
echo "begin $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3
fi
if [ -w "$BATS_LOG" ]; then
echo "[$$] $BATS_TEST_DESCRIPTION" >> "$BATS_LOG"
fi
setup
}

Expand Down Expand Up @@ -256,9 +259,16 @@ bats_exit_trap() {
bats_print_failed_command "${BATS_ERROR_STACK_TRACE[${#BATS_ERROR_STACK_TRACE[@]}-1]}" "$BATS_ERROR_STATUS" >&3
sed -e "s/^/# /" < "$BATS_OUT" >&3
status=1
to_log="not ok $BATS_TEST_DESCRIPTION"
else
echo "ok ${BATS_TEST_NUMBER}${skipped} ${BATS_TEST_DESCRIPTION}" >&3
status=0
to_log="ok $BATS_TEST_DESCRIPTION"
fi

if [ -w "$BATS_LOG" ]; then
sed -e "s/^/\[$$\] /" "$BATS_OUT" >> "$BATS_LOG"
echo "[$$] $to_log" >> "$BATS_LOG"
fi

rm -f "$BATS_OUT"
Expand Down