ios_xctestrun_runner rejects passing assertion tests because it scans the entire log for `Fatal error:`
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Domain
- build-system, testing
Research direction
The false positive comes from the log check in apple/testing/default_runner/ios_xctestrun_runner.template.sh, around lines 851-862, which scans the whole test log for Fatal error:. Start by running the minimal/ reproducer, which only writes that text to stderr, and confirm the runner fails it. Done means that a passing test printing the diagnostic is accepted while a genuine crash after test completion still fails, which needs a design decision on how to tell them apart.
Written by the indexing model from the issue text.
Description
Reproducer: xctest-fatal-error-repro.zip
ios_xctestrun_runner reports otherwise passing XCTest bundles as failed when their logs contain Fatal error:. This affects legitimate tests that use Nimble's throwAssertion() to verify a real Swift fatalError.
Swift prints the diagnostic before trapping. Nimble intercepts the trap, verifies the assertion, and the test continues successfully. The runner subsequently matches the diagnostic and exits with:
error: log contained test false negative
Reproduced with unmodified upstream rules_apple at 7610d32139667a06a77d448e6b24b1a34c3e8d2e, through both the direct xctest and xcodebuild test-without-building execution paths.
Reproducer
The accompanying standalone project contains two independent examples:
nimble/: a realfatalError, intercepted by Nimble 14.0.0 using CwlPreconditionTesting 2.2.2.minimal/: an XCTest method that only writes the diagnostic text to stderr, with no assertion-testing dependencies and no trap. This isolates the log heuristic itself.
The real assertion test is:
import Nimble
import XCTest
final class AssertionTests: XCTestCase {
func testExpectedFatalError() {
expect { () -> Void in
fatalError("This assertion is expected and intercepted by the test.")
}.to(throwAssertion())
print("The test continued normally after the intercepted assertion.")
}
}
From nimble/, run each target separately:
bazel test //:XCTestTests --ios_multi_cpus=sim_arm64 \
--@rules_apple//apple/build_settings:ios_simulator_device="iPhone 17 Pro" \
--@rules_apple//apple/build_settings:ios_simulator_version=27.0
bazel test //:XcodebuildTests --ios_multi_cpus=sim_arm64 \
--@rules_apple//apple/build_settings:ios_simulator_device="iPhone 17 Pro" \
--@rules_apple//apple/build_settings:ios_simulator_version=27.0
Use an installed simulator device type/runtime if these are unavailable. The commands above are for Apple Silicon. The project disables cached test results and prints the test output.
Both targets are hostless ios_unit_test targets using ios_xctestrun_runner. XCTestTests uses the direct backend; XcodebuildTests supplies xcodebuild_args = ["-parallel-testing-enabled", "NO"] to select the Xcode backend. Neither uses a custom observer, application host, or patched runner.
Run the same commands from minimal/ to reproduce without Nimble. Its entire test method is:
func testDiagnosticIsNotACrash() {
FileHandle.standardError.write(Data("Fatal error: expected diagnostic\n".utf8))
print("The test continued normally after the diagnostic.")
}
Expected result
Both targets should pass: the expected assertion is intercepted, the test continues, and XCTest reports one test with zero failures. Genuine unhandled crashes should still fail the run.
Actual result
Relevant direct-backend output, with timestamps omitted:
Test Case '-[AssertionTests.AssertionTests testExpectedFatalError]' started.
AssertionTests/AssertionTests.swift:7: Fatal error: This assertion is expected and intercepted by the test.
Test Case '-[AssertionTests.AssertionTests testExpectedFatalError]' passed (0.002 seconds).
Test Suite 'All tests' passed
Executed 1 test, with 0 failures (0 unexpected)
The test continued normally after the intercepted assertion.
Testing is serialized
error: log contained test false negative
//:XCTestTests FAILED
The Xcode backend also reports ** TEST EXECUTE SUCCEEDED **, with native exit code 0 visible when DEBUG_XCTESTRUNNER=1 is set, before the same log check rejects the run. Bazel exits with code 3; the generated runner exits with code 1.
Cause
The log check in ios_xctestrun_runner.template.sh is intended to catch crashes occurring after tests have reportedly completed. However, it searches the entire test log, including diagnostics from expected assertions inside passing tests. It does not establish that an unhandled crash occurred.
Nimble's throwAssertion() implementation uses CwlPreconditionTesting to catch these traps. The diagnostic already printed by Swift remains in the log.
The safeguard for genuine crashes after test completion should be preserved, while allowing expected assertion diagnostics from successful tests.
Environment
- macOS 27.0.1 (26A434), Apple Silicon / arm64
- Xcode 27.1 (27A9275)
- iOS Simulator 27.0, iPhone 17 Pro
- Bazel 9.3.1
- Upstream
rules_apple:7610d32139667a06a77d448e6b24b1a34c3e8d2e - Nimble 14.0.0; CwlPreconditionTesting 2.2.2
- Verified on 2026-11-12
- Dominant language
- Starlark
- Stars
- 600
- Forks
- 354
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 8
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bazelbuild/rules_apple
-
`ios_xctestrun_runner` skips the simulator cleanup action on early exits and signalsPossibly taken @katre claimed this 2 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 67/100
bazelbuild/rules_apple#3163 ·
Maintainers usually reply within 1 day
-
register_binary_linking_action links with the GCC coverage map format under coveragePossibly taken @TrapsterDK claimed this 6 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 30/100
bazelbuild/rules_apple#3160 ·
Maintainers usually reply within 1 day
-
Registered toolchains load //apple/internal and its dependencies in every buildMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 30/100
bazelbuild/rules_apple#3158 ·
Maintainers usually reply within 1 day
-
Simulator cleanup is skipped when the post-action failsPossibly taken @vakhidbetrakhmadov claimed this 14 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 58/100
bazelbuild/rules_apple#3147 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 47/100
bazelbuild/rules_apple#3133 ·
Maintainers usually reply within 1 day
All issues in bazelbuild/rules_apple
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
bazelbuild/apple_support#707 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
out-of-date
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
CachyOS/CachyOS-PKGBUILDS#2232 ·
Maintainers usually reply within 1 day
-
blast/large refactor risk/low spend-dem
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
chriskelly/MusicWall#87 · 2 comments ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 77/100