Skip to content

Commit f0730c4

Browse files
authored
Simplify failureBreakpoint() and add a unit test. (#557)
This PR simplifies the "unique" action performed by `failureBreakpoint()` to avoid de-duplication and implements a unit test to confirm that action is actually occurring and not being optimized away (at least under the current compiler settings at the time of test.) ### 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 c1df9a9 commit f0730c4

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Sources/Testing/Issues/Issue+Recording.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ extension Issue {
236236

237237
// MARK: - Debugging failures
238238

239+
/// A unique value used by ``failureBreakpoint()``.
240+
@usableFromInline nonisolated(unsafe) var failureBreakpointValue = 0
241+
239242
/// A function called by the testing library when a failure occurs.
240243
///
241244
/// Whenever a test failure (specifically, a non-known ``Issue``) is recorded,
@@ -265,11 +268,7 @@ func failureBreakpoint() {
265268
// behavior can be disabled by passing the `-no_deduplicate` flag described in
266269
// ld(1), but that would disable it module-wide and sacrifice optimization
267270
// opportunities elsewhere. Instead, this function performs a trivial
268-
// function call, passing it a sufficiently unique value to avoid
269-
// de-duplication.
270-
struct NoOp {
271-
nonisolated(unsafe) static var ignored: Int = 0
272-
static func perform(_: inout Int) {}
273-
}
274-
NoOp.perform(&NoOp.ignored)
271+
// operation on a usable-from-inline value, which the compiler must assume
272+
// cannot be optimized away.
273+
failureBreakpointValue = 1
275274
}

Tests/TestingTests/MiscellaneousTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,4 +525,11 @@ struct MiscellaneousTests {
525525
#expect(mappedTests.count == tests.count)
526526
#expect(mappedTests.values.allSatisfy { tests.contains($0) })
527527
}
528+
529+
@Test("failureBreakpoint() call")
530+
func failureBreakpointCall() {
531+
failureBreakpointValue = 0
532+
failureBreakpoint()
533+
#expect(failureBreakpointValue == 1)
534+
}
528535
}

0 commit comments

Comments
 (0)