ios_xctestrun_runner rejects passing assertion tests because it scans the entire log for `Fatal error:`

Open
#3,139 0 comments 0 reactions 0 assignees View on GitHub

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
Tech stack
shell, swift

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 real fatalError, 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bazelbuild/rules_apple

All issues in bazelbuild/rules_apple

Similar issues

More Build System issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.