Skip to content

Commit

Permalink
fix: exit 0 despite focus test when filtered out
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-schulze-vireso committed Jan 21, 2025
1 parent 3cad1df commit 8ed578d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
27 changes: 16 additions & 11 deletions libexec/bats-core/bats-exec-suite
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,26 @@ if [[ -n "$focus_mode" ]]; then
printf "WARNING: This test run only contains tests tagged \`bats:focus\`!\n"
fi

bats_exit_suite() {
if [[ "$focus_mode" == 1 && $bats_exec_suite_status -eq 0 ]]; then
if [[ ${BATS_NO_FAIL_FOCUS_RUN-} == 1 ]]; then
printf "WARNING: This test run only contains tests tagged \`bats:focus\`!\n"
else
printf "Marking test run as failed due to \`bats:focus\` tag. (Set \`BATS_NO_FAIL_FOCUS_RUN=1\` to disable.)\n" >&2
bats_exec_suite_status=1
fi
fi

exit "$bats_exec_suite_status" # the actual exit code will be set by the exit trap using bats_exec_suite_status
}

bats_exec_suite_status=0
printf '1..%d\n' "${test_count}"

# No point on continuing if there's no tests.
if [[ "${test_count}" == 0 ]]; then
exit
bats_exec_suite_status=0
bats_exit_suite
fi

export BATS_SUITE_TMPDIR="${BATS_RUN_TMPDIR}/suite"
Expand Down Expand Up @@ -299,13 +313,4 @@ fi
set -eET
bats_run_teardown_suite

if [[ "$focus_mode" == 1 && $bats_exec_suite_status -eq 0 ]]; then
if [[ ${BATS_NO_FAIL_FOCUS_RUN-} == 1 ]]; then
printf "WARNING: This test run only contains tests tagged \`bats:focus\`!\n"
else
printf "Marking test run as failed due to \`bats:focus\` tag. (Set \`BATS_NO_FAIL_FOCUS_RUN=1\` to disable.)\n" >&2
bats_exec_suite_status=1
fi
fi

exit "$bats_exec_suite_status" # the actual exit code will be set by the exit trap using bats_exec_suite_status
bats_exit_suite
5 changes: 5 additions & 0 deletions test/bats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,11 @@ END_OF_ERR_MSG
[ "${#lines[@]}" == 4 ]
}

@test "Fail with focus, even if all tests are filtered out (#1044)" {
bats_require_minimum_version 1.5.0
reentrant_run -1 bats --filter-tags filter "$FIXTURE_ROOT/focused_filtered_out.bats"
}

@test "Bats waits for report formatter to finish" {
REPORT_FORMATTER=$FIXTURE_ROOT/gobble_up_stdin_sleep_and_print_finish.bash
bats_require_minimum_version 1.5.0
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/bats/focused_filtered_out.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# bats test_tags=bats:focus
@test "focused test" {
true
}

# bats test_tags=filter
@test "unfocused tests" {
true
}

0 comments on commit 8ed578d

Please sign in to comment.