@@ -234,24 +234,17 @@ func _withKnownIssue(
234234 await withKnownIssue( message, isIntermittent, fileID, filePath, line, column, body)
235235}
236236@usableFromInline
237- func _currentTestIsNotNil ( ) - > Bool {
238- guard let function = function ( for: " $s25IssueReportingTestSupport08_currentC8IsNotNilypyF " )
237+ func _currentTestID ( ) - > AnyHashable ? {
238+ guard let function = function ( for: " $s25IssueReportingTestSupport08_currentC2IDypyF " )
239239 else {
240240 #if DEBUG
241- return Test . current != nil
241+ return Test . current? . id
242242 #else
243- printError (
244- """
245- 'Test.current' was accessed without linking the Testing framework.
246-
247- To fix this, add " IssueReportingTestSupport " as a dependency to your test target.
248- """
249- )
250- return false
243+ return nil
251244 #endif
252245 }
253246
254- return ( function as! @Sendable ( ) -> Bool ) ( )
247+ return ( function as! @Sendable ( ) -> AnyHashable ? ) ( )
255248}
256249
257250#if DEBUG
@@ -348,11 +341,15 @@ func _currentTestIsNotNil() -> Bool {
348341 var sourceLocation : SourceLocation ?
349342 }
350343
351- private struct SourceLocation: Sendable {
344+ private struct SourceLocation: Hashable , Sendable {
352345 var fileID : String
353346 var _filePath : String
354347 var line : Int
355348 var column : Int
349+ var moduleName : String {
350+ let firstSlash = fileID. firstIndex ( of: " / " ) !
351+ return String ( fileID [ ..< firstSlash] )
352+ }
356353 }
357354
358355 struct Test: @unchecked Sendable {
@@ -388,6 +385,42 @@ func _currentTestIsNotNil() -> Bool {
388385 var typeInfo : TypeInfo
389386 }
390387 private var isSynthesized = false
388+
389+ private var isSuite : Bool {
390+ containingTypeInfo != nil && testCasesState == nil
391+ }
392+ fileprivate var id : ID {
393+ var result = containingTypeInfo. map ( ID . init)
394+ ?? ID ( moduleName: sourceLocation. moduleName, nameComponents: [ ] , sourceLocation: nil )
395+
396+ if !isSuite {
397+ result. nameComponents. append ( name)
398+ result. sourceLocation = sourceLocation
399+ }
400+
401+ return result
402+ }
403+ fileprivate struct ID : Hashable {
404+ var moduleName : String
405+ var nameComponents : [ String ]
406+ var sourceLocation : SourceLocation ?
407+ init ( moduleName: String , nameComponents: [ String ] , sourceLocation: SourceLocation ? ) {
408+ self . moduleName = moduleName
409+ self . nameComponents = nameComponents
410+ self . sourceLocation = sourceLocation
411+ }
412+ init ( _ fullyQualifiedNameComponents: some Collection < String > ) {
413+ moduleName = fullyQualifiedNameComponents. first ?? " "
414+ if fullyQualifiedNameComponents. count > 0 {
415+ nameComponents = Array ( fullyQualifiedNameComponents. dropFirst ( ) )
416+ } else {
417+ nameComponents = [ ]
418+ }
419+ }
420+ init ( typeInfo: TypeInfo ) {
421+ self . init ( typeInfo. fullyQualifiedNameComponents)
422+ }
423+ }
391424 }
392425
393426 private protocol Trait: Sendable { }
@@ -398,6 +431,34 @@ func _currentTestIsNotNil() -> Bool {
398431 case nameOnly( fullyQualifiedComponents: [ String ] , unqualified: String , mangled: String ? )
399432 }
400433 var _kind : _Kind
434+
435+ static let _fullyQualifiedNameComponentsCache : LockIsolated <
436+ [ ObjectIdentifier : [ String ] ]
437+ > = LockIsolated ( [ : ] )
438+ var fullyQualifiedNameComponents : [ String ] {
439+ switch _kind {
440+ case let . type( type) :
441+ if let cachedResult = Self
442+ . _fullyQualifiedNameComponentsCache. withLock ( { $0 [ ObjectIdentifier ( type) ] } )
443+ {
444+ return cachedResult
445+ }
446+ var result = String ( reflecting: type)
447+ . split ( separator: " . " )
448+ . map ( String . init)
449+ if let firstComponent = result. first, firstComponent. starts ( with: " (extension in " ) {
450+ result [ 0 ] = String ( firstComponent. split ( separator: " : " , maxSplits: 1 ) . last!)
451+ }
452+ result = result. filter { !$0. starts ( with: " (unknown context at " ) }
453+ Self . _fullyQualifiedNameComponentsCache. withLock { [ result] in
454+ $0 [ ObjectIdentifier ( type) ] = result
455+ }
456+ return result
457+
458+ case let . nameOnly( fullyQualifiedComponents, _, _) :
459+ return fullyQualifiedComponents
460+ }
461+ }
401462 }
402463#endif
403464
0 commit comments