feat: warn when SwiftSyntaxMacrosTestSupport is used with Swift Testing (#3190)
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
NSLockandnonisolated(unsafe)to satisfy strict concurrency requirements. - High Visibility: Prints a distinct ASCII banner to
stderrthat is "hard to miss." - Configuration: -
SWIFTSYNTAX_TESTSUPPORT_SILENCE=1: Suppresses the warning.SWIFTSYNTAX_TESTSUPPORT_STRICT=1: Triggers apreconditionFailurefor strict enforcement.
Verification
- Regression Testing: Verified with the full test suite (3,470 tests passed).
@ahoppen Sir, kindly check this PR, I have opened this few time ago :)
I’ll leave this PR to @rintaro and @hamishknight to review who have more context here at the moment.