Skip to content

Commit db6e08e

Browse files
authored
Lower Backtrace and SourceContext to SPI. (#539)
`Backtrace` is our implementation of a stack trace type. Xcode 16 uses it to provide richer information about test failures than can be provided by _just_ an instance of `SourceLocation`. The standard library has its own type, `_Backtracing.Backtrace`, but due to our deployment requirements on Apple platforms, we can't use it yet. It would make sense for us to adopt the `Backtrace` type in the standard library as soon as possible. To avoid staging issues in the future, and because our type has not undergone any sort of formal review, I'm lowering it to tools-only SPI. I'm also lowering `SourceContext` because it consists of an instance of `Backtrace` and an instance of `SourceLocation`—but if `Backtrace` is SPI, then the public interface of `SourceContext` is simply a wrapper around `SourceLocation`. This does not eliminate the internal need for the type, but it does make it redundant from an API perspective. If and when we regain `Backtrace` as a public interface, we can look at raising `SourceContext` too. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent d454328 commit db6e08e

File tree

5 files changed

+9
-2
lines changed

5 files changed

+9
-2
lines changed

Sources/Testing/ABI/v0/Encoded/ABIv0.EncodedIssue.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ extension ABIv0 {
2222
/// The location in source where this issue occurred, if available.
2323
var sourceLocation: SourceLocation?
2424

25+
/// The backtrace where this issue occurred, if available.
26+
var _backtrace: [Backtrace.Address]?
27+
2528
init(encoding issue: borrowing Issue) {
2629
isKnown = issue.isKnown
2730
sourceLocation = issue.sourceLocation
31+
_backtrace = issue.sourceContext.backtrace.map(\.addresses)
2832
}
2933
}
3034
}

Sources/Testing/Issues/Issue.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public struct Issue: Sendable {
9494
public var comments: [Comment]
9595

9696
/// A ``SourceContext`` indicating where and how this issue occurred.
97+
@_spi(ForToolsIntegrationOnly)
9798
public var sourceContext: SourceContext
9899

99100
/// Whether or not this issue is known to occur.

Sources/Testing/SourceAttribution/Backtrace.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ private import _TestingInternals
1515
#endif
1616

1717
/// A type representing a backtrace or stack trace.
18+
@_spi(ForToolsIntegrationOnly)
1819
public struct Backtrace: Sendable {
1920
/// A type describing an address in a backtrace.
2021
///

Sources/Testing/SourceAttribution/SourceContext.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/// Most commonly used when recording a failure, in order to indicate the source
1515
/// location where the failure occurred as well as the backtrace of the failing
1616
/// call, since the latter may be useful to understand how it was invoked.
17+
@_spi(ForToolsIntegrationOnly)
1718
public struct SourceContext: Sendable {
1819
/// The backtrace associated with this instance, if available.
1920
public var backtrace: Backtrace?

Sources/Testing/Testing.docc/Expectations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,5 @@ the test when the code doesn't satisfy a requirement, use
9090

9191
- ``SourceLocation``
9292
<!-- - ``_sourceLocation()`` -->
93-
- ``SourceContext``
94-
- ``Backtrace``
93+
<!-- - ``SourceContext`` -->
94+
<!-- - ``Backtrace`` -->

0 commit comments

Comments
 (0)