diff --git a/libexec/bats b/libexec/bats index 71f392f7..5f551d9c 100755 --- a/libexec/bats +++ b/libexec/bats @@ -16,11 +16,12 @@ help() { echo " 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 @@ -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" ;; diff --git a/libexec/bats-exec-test b/libexec/bats-exec-test index 5a076650..c6316921 100755 --- a/libexec/bats-exec-test +++ b/libexec/bats-exec-test @@ -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 } @@ -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"