swift-syntax icon indicating copy to clipboard operation
swift-syntax copied to clipboard

feat: warn when SwiftSyntaxMacrosTestSupport is used with Swift Testing (#3190)

Open DPrakashhh opened this issue 11 months ago • 2 comments

Description: This PR addresses #3190 by adding a runtime safety guard to SwiftSyntaxMacrosTestSupport. This is a stop-gap measure until full Swift Testing support (#2720) is implemented.

The Problem SwiftSyntaxMacrosTestSupport is XCTest-based. When used with the new Swift Testing framework, assertions may fail silently or produce false positives, leading to developer confusion.

The Solution I have added a thread-safe, once-per-process runtime check in _SwiftTestingDetection.swift.

Key Features:

  • Smart Detection: Identifies Swift Testing via environment variables (SWIFT_TESTING_) and command-line arguments.
  • XCTest Safety: Automatically detects standard XCTest environments to prevent false warnings for existing tests.
  • Swift 6 Ready: Uses NSLock and nonisolated(unsafe) to satisfy strict concurrency requirements.
  • High Visibility: Prints a distinct ASCII banner to stderr that is "hard to miss."
  • Configuration: - SWIFTSYNTAX_TESTSUPPORT_SILENCE=1: Suppresses the warning.
    • SWIFTSYNTAX_TESTSUPPORT_STRICT=1: Triggers a preconditionFailure for strict enforcement.

Verification

  • Regression Testing: Verified with the full test suite (3,470 tests passed).

DPrakashhh avatar Dec 25 '25 10:12 DPrakashhh

@ahoppen Sir, kindly check this PR, I have opened this few time ago :)

DPrakashhh avatar Jan 07 '26 17:01 DPrakashhh

I’ll leave this PR to @rintaro and @hamishknight to review who have more context here at the moment.

ahoppen avatar Jan 07 '26 20:01 ahoppen