Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
22 changes: 19 additions & 3 deletions libexec/bats-core/bats-exec-test
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ skip() {
exit 0
}

todo() {
BATS_TEST_TODO="${1:-1}"
}

bats_test_begin() {
BATS_TEST_DESCRIPTION="$1"
if [[ -n "$BATS_EXTENDED_SYNTAX" ]]; then
Expand Down Expand Up @@ -272,6 +276,8 @@ bats_exit_trap() {
local line
local status
local skipped=''
local todo=''
local done_=''
trap - ERR EXIT

if [[ -n "$BATS_TEST_SKIPPED" ]]; then
Expand All @@ -281,6 +287,15 @@ bats_exit_trap() {
fi
fi

if [[ -n "$BATS_TEST_TODO" ]]; then
todo=" # todo"
done_=" # done"
if [[ "$BATS_TEST_TODO" != '1' ]]; then
todo+=" $BATS_TEST_TODO"
done_+=" $BATS_TEST_TODO"
fi
fi

if [[ -z "$BATS_TEST_COMPLETED" || -z "$BATS_TEARDOWN_COMPLETED" ]]; then
if [[ "$BATS_ERROR_STATUS" -eq 0 ]]; then
# For some versions of bash, `$?` may not be set properly for some error
Expand All @@ -295,7 +310,8 @@ bats_exit_trap() {
BATS_STACK_TRACE=( "${BATS_CURRENT_STACK_TRACE[@]}" )
BATS_ERROR_STATUS=1
fi
printf 'not ok %d %s\n' "$BATS_TEST_NUMBER" "$BATS_TEST_DESCRIPTION" >&3
printf 'not ok %d %s%s\n' "$BATS_TEST_NUMBER" "$BATS_TEST_DESCRIPTION" \
"$todo" >&3
bats_print_stack_trace "${BATS_STACK_TRACE[@]}" >&3
bats_print_failed_command >&3

Expand All @@ -307,8 +323,8 @@ bats_exit_trap() {
fi
status=1
else
printf 'ok %d %s%s\n' "$BATS_TEST_NUMBER" "$BATS_TEST_DESCRIPTION" \
"$skipped" >&3
printf 'ok %d %s%s%s\n' "$BATS_TEST_NUMBER" "$BATS_TEST_DESCRIPTION" \
"$skipped" "$done_" >&3
status=0
fi

Expand Down
44 changes: 42 additions & 2 deletions libexec/bats-core/bats-format-tap-stream
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ if [[ "$header" =~ $header_pattern ]]; then
passed=0
failures=0
skipped=0
done_=0
todo=0
name=
count_column_width=$(( ${#count} * 2 + 2 ))
else
Expand Down Expand Up @@ -51,6 +53,26 @@ skip() {
advance
}

todo_print() {
local reason="$1"
if [[ -n "$reason" ]]; then
reason=": $reason"
fi
go_to_column 0
buffer " - %s (todo%s)" "$name" "$reason"
advance
}

done_print() {
local reason="$1"
if [[ -n "$reason" ]]; then
reason=": $reason"
fi
go_to_column 0
buffer " ✓ %s (done%s)" "$name" "$reason"
advance
}

fail() {
go_to_column 0
set_color 1 bold
Expand Down Expand Up @@ -79,6 +101,14 @@ summary() {
buffer ', %d skipped' "$skipped"
fi

if [[ "$todo" -gt 0 ]]; then
buffer ", %d todo" "$todo"
fi

if [[ "$done_" -gt 0 ]]; then
buffer ", %d done" "$done_"
fi

not_run=$((count - passed - failures - skipped))
if [[ "$not_run" -gt 0 ]]; then
buffer ', %d not run' "$not_run"
Expand Down Expand Up @@ -162,17 +192,27 @@ while IFS= read -r line; do
;;
'ok '* )
skip_expr="ok $index (.*) # skip ?(([[:print:]]*))?"
done_expr="ok $index (.*) # done ?(([[:print:]]*))?"
if [[ "$line" =~ $skip_expr ]]; then
((++skipped))
skip "${BASH_REMATCH[2]}"
elif [[ "$line" =~ $done_expr ]]; then
((++done_))
done_print "${BASH_REMATCH[2]}"
else
((++passed))
pass
fi
;;
'not ok '* )
((++failures))
fail
todo_expr="not ok $index (.*) # todo ?(([[:print:]]*))?"
if [[ "$line" =~ $todo_expr ]]; then
((++todo))
todo_print "${BASH_REMATCH[2]}"
else
((++failures))
fail
fi
;;
'# '* )
log "${line:2}"
Expand Down
19 changes: 19 additions & 0 deletions test/fixtures/todo.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@test "a test marked todo that fails" {
todo
false
}

@test "a test marked todo with a reason that fails" {
todo "a reason"
false
}

@test "a test marked todo that passes" {
todo
true
}

@test "a test marked todo with a reason that passes" {
todo "a reason"
true
}