Skip to content

Commit f2cea3f

Browse files
committed
Merge branch 'main' into jgrynspan/promote-windows-image-attachments-to-api
2 parents 3e259ae + 992cd27 commit f2cea3f

14 files changed

+73
-32
lines changed

Sources/Testing/ExitTests/ExitTest.CapturedValue.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
private import _TestingInternals
1212

13-
@_spi(Experimental) @_spi(ForToolsIntegrationOnly)
13+
@_spi(ForToolsIntegrationOnly)
1414
#if SWT_NO_EXIT_TESTS
15+
@_unavailableInEmbedded
1516
@available(*, unavailable, message: "Exit tests are not available on this platform.")
1617
#endif
1718
extension ExitTest {

Sources/Testing/ExitTests/ExitTest.Condition.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
private import _TestingInternals
1212

1313
#if SWT_NO_EXIT_TESTS
14+
@_unavailableInEmbedded
1415
@available(*, unavailable, message: "Exit tests are not available on this platform.")
1516
#endif
1617
extension ExitTest {
@@ -58,6 +59,7 @@ extension ExitTest {
5859
// MARK: -
5960

6061
#if SWT_NO_EXIT_TESTS
62+
@_unavailableInEmbedded
6163
@available(*, unavailable, message: "Exit tests are not available on this platform.")
6264
#endif
6365
extension ExitTest.Condition {
@@ -176,8 +178,8 @@ extension ExitTest.Condition {
176178

177179
// MARK: - CustomStringConvertible
178180

179-
@_spi(Experimental)
180181
#if SWT_NO_EXIT_TESTS
182+
@_unavailableInEmbedded
181183
@available(*, unavailable, message: "Exit tests are not available on this platform.")
182184
#endif
183185
extension ExitTest.Condition: CustomStringConvertible {
@@ -200,6 +202,7 @@ extension ExitTest.Condition: CustomStringConvertible {
200202
// MARK: - Comparison
201203

202204
#if SWT_NO_EXIT_TESTS
205+
@_unavailableInEmbedded
203206
@available(*, unavailable, message: "Exit tests are not available on this platform.")
204207
#endif
205208
extension ExitTest.Condition {

Sources/Testing/ExitTests/ExitTest.Result.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//
1010

1111
#if SWT_NO_EXIT_TESTS
12+
@_unavailableInEmbedded
1213
@available(*, unavailable, message: "Exit tests are not available on this platform.")
1314
#endif
1415
extension ExitTest {

Sources/Testing/ExitTests/ExitTest.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ private import _TestingInternals
3535
/// @Available(Xcode, introduced: 26.0)
3636
/// }
3737
#if SWT_NO_EXIT_TESTS
38+
@_unavailableInEmbedded
3839
@available(*, unavailable, message: "Exit tests are not available on this platform.")
3940
#endif
4041
public struct ExitTest: Sendable, ~Copyable {
@@ -128,7 +129,7 @@ public struct ExitTest: Sendable, ~Copyable {
128129
///
129130
/// The order of values in this array must be the same between the parent and
130131
/// child processes.
131-
@_spi(Experimental) @_spi(ForToolsIntegrationOnly)
132+
@_spi(ForToolsIntegrationOnly)
132133
public var capturedValues = [CapturedValue]()
133134

134135
/// Make a copy of this instance.

Sources/Testing/Expectations/Expectation+Macro.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ public macro require<R>(
877877
@freestanding(expression)
878878
@discardableResult
879879
#if SWT_NO_EXIT_TESTS
880+
@_unavailableInEmbedded
880881
@available(*, unavailable, message: "Exit tests are not available on this platform.")
881882
#endif
882883
public macro expect(
@@ -924,6 +925,7 @@ public macro expect(
924925
@freestanding(expression)
925926
@discardableResult
926927
#if SWT_NO_EXIT_TESTS
928+
@_unavailableInEmbedded
927929
@available(*, unavailable, message: "Exit tests are not available on this platform.")
928930
#endif
929931
public macro require(

Sources/Testing/Expectations/ExpectationChecking+Macro.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,6 @@ public func __checkClosureCall(
11751175
///
11761176
/// - Warning: This function is used to implement the `#expect()` and
11771177
/// `#require()` macros. Do not call it directly.
1178-
@_spi(Experimental)
11791178
public func __checkClosureCall<each T>(
11801179
identifiedBy exitTestID: (UInt64, UInt64, UInt64, UInt64),
11811180
encodingCapturedValues capturedValues: (repeat each T),

Sources/Testing/Parameterization/TypeInfo.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public struct TypeInfo: Sendable {
7979
///
8080
/// - Parameters:
8181
/// - type: The type which this instance should describe.
82-
init(describing type: any ~Copyable.Type) {
82+
init(describing type: (some ~Copyable).Type) {
8383
_kind = .type(type)
8484
}
8585

@@ -88,8 +88,21 @@ public struct TypeInfo: Sendable {
8888
///
8989
/// - Parameters:
9090
/// - value: The value whose type this instance should describe.
91-
init(describingTypeOf value: Any) {
92-
self.init(describing: Swift.type(of: value))
91+
init(describingTypeOf value: some Any) {
92+
#if !hasFeature(Embedded)
93+
let value = value as Any
94+
#endif
95+
let type = Swift.type(of: value)
96+
self.init(describing: type)
97+
}
98+
99+
/// Initialize an instance of this type describing the type of the specified
100+
/// value.
101+
///
102+
/// - Parameters:
103+
/// - value: The value whose type this instance should describe.
104+
init<T>(describingTypeOf value: borrowing T) where T: ~Copyable {
105+
self.init(describing: T.self)
93106
}
94107
}
95108

Sources/Testing/SourceAttribution/Backtrace.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ extension Backtrace: Codable {
119119
// MARK: - Backtraces for thrown errors
120120

121121
extension Backtrace {
122+
#if !hasFeature(Embedded)
122123
// MARK: - Error cache keys
123124

124125
/// A type used as a cache key that uniquely identifies error existential
@@ -321,6 +322,7 @@ extension Backtrace {
321322
}
322323
forward(errorType)
323324
}
325+
#endif
324326

325327
/// Whether or not Foundation provides a function that triggers the capture of
326328
/// backtaces when instances of `NSError` or `CFError` are created.
@@ -336,7 +338,7 @@ extension Backtrace {
336338
/// - Note: The underlying Foundation function is called (if present) the
337339
/// first time the value of this property is read.
338340
static let isFoundationCaptureEnabled = {
339-
#if _runtime(_ObjC) && !SWT_NO_DYNAMIC_LINKING
341+
#if !hasFeature(Embedded) && _runtime(_ObjC) && !SWT_NO_DYNAMIC_LINKING
340342
if Environment.flag(named: "SWT_FOUNDATION_ERROR_BACKTRACING_ENABLED") == true {
341343
let _CFErrorSetCallStackCaptureEnabled = symbol(named: "_CFErrorSetCallStackCaptureEnabled").map {
342344
castCFunction(at: $0, to: (@convention(c) (DarwinBoolean) -> DarwinBoolean).self)
@@ -348,6 +350,7 @@ extension Backtrace {
348350
return false
349351
}()
350352

353+
#if !hasFeature(Embedded)
351354
/// The implementation of ``Backtrace/startCachingForThrownErrors()``, run
352355
/// only once.
353356
///
@@ -373,6 +376,7 @@ extension Backtrace {
373376
}
374377
}
375378
}()
379+
#endif
376380

377381
/// Configure the Swift runtime to allow capturing backtraces when errors are
378382
/// thrown.
@@ -381,17 +385,21 @@ extension Backtrace {
381385
/// developer-supplied code to ensure that thrown errors' backtraces are
382386
/// always captured.
383387
static func startCachingForThrownErrors() {
388+
#if !hasFeature(Embedded)
384389
__SWIFT_TESTING_IS_CAPTURING_A_BACKTRACE_FOR_A_THROWN_ERROR__
390+
#endif
385391
}
386392

387393
/// Flush stale entries from the error-mapping cache.
388394
///
389395
/// Call this function periodically to ensure that errors do not continue to
390396
/// take up space in the cache after they have been deinitialized.
391397
static func flushThrownErrorCache() {
398+
#if !hasFeature(Embedded)
392399
_errorMappingCache.withLock { cache in
393400
cache = cache.filter { $0.value.errorObject != nil }
394401
}
402+
#endif
395403
}
396404

397405
/// Initialize an instance of this type with the previously-cached backtrace
@@ -411,6 +419,7 @@ extension Backtrace {
411419
/// initializer cannot be made an instance method or property of `Error`
412420
/// because doing so will cause Swift-native errors to be unboxed into
413421
/// existential containers with different addresses.
422+
#if !hasFeature(Embedded)
414423
@inline(never)
415424
init?(forFirstThrowOf error: any Error, checkFoundation: Bool = true) {
416425
if checkFoundation && Self.isFoundationCaptureEnabled,
@@ -430,4 +439,9 @@ extension Backtrace {
430439
return nil
431440
}
432441
}
442+
#else
443+
init?(forFirstThrowOf error: some Error, checkFoundation: Bool = true) {
444+
return nil
445+
}
446+
#endif
433447
}

Sources/Testing/Test+Macro.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,16 @@ extension Test {
157157
///
158158
/// - Warning: This function is used to implement the `@Test` macro. Do not
159159
/// call it directly.
160-
public static func __function(
160+
public static func __function<S>(
161161
named testFunctionName: String,
162-
in containingType: (any ~Copyable.Type)?,
162+
in containingType: S.Type?,
163163
xcTestCompatibleSelector: __XCTestCompatibleSelector?,
164164
displayName: String? = nil,
165165
traits: [any TestTrait],
166166
sourceLocation: SourceLocation,
167167
parameters: [__Parameter] = [],
168168
testFunction: @escaping @Sendable () async throws -> Void
169-
) -> Self {
169+
) -> Self where S: ~Copyable {
170170
// Don't use Optional.map here due to a miscompile/crash. Expand out to an
171171
// if expression instead. SEE: rdar://134280902
172172
let containingTypeInfo: TypeInfo? = if let containingType {
@@ -241,17 +241,17 @@ extension Test {
241241
///
242242
/// - Warning: This function is used to implement the `@Test` macro. Do not
243243
/// call it directly.
244-
public static func __function<C>(
244+
public static func __function<S, C>(
245245
named testFunctionName: String,
246-
in containingType: (any ~Copyable.Type)?,
246+
in containingType: S.Type?,
247247
xcTestCompatibleSelector: __XCTestCompatibleSelector?,
248248
displayName: String? = nil,
249249
traits: [any TestTrait],
250250
arguments collection: @escaping @Sendable () async throws -> C,
251251
sourceLocation: SourceLocation,
252252
parameters paramTuples: [__Parameter],
253253
testFunction: @escaping @Sendable (C.Element) async throws -> Void
254-
) -> Self where C: Collection & Sendable, C.Element: Sendable {
254+
) -> Self where S: ~Copyable, C: Collection & Sendable, C.Element: Sendable {
255255
let containingTypeInfo: TypeInfo? = if let containingType {
256256
TypeInfo(describing: containingType)
257257
} else {
@@ -388,17 +388,17 @@ extension Test {
388388
///
389389
/// - Warning: This function is used to implement the `@Test` macro. Do not
390390
/// call it directly.
391-
public static func __function<C1, C2>(
391+
public static func __function<S, C1, C2>(
392392
named testFunctionName: String,
393-
in containingType: (any ~Copyable.Type)?,
393+
in containingType: S.Type?,
394394
xcTestCompatibleSelector: __XCTestCompatibleSelector?,
395395
displayName: String? = nil,
396396
traits: [any TestTrait],
397397
arguments collection1: @escaping @Sendable () async throws -> C1, _ collection2: @escaping @Sendable () async throws -> C2,
398398
sourceLocation: SourceLocation,
399399
parameters paramTuples: [__Parameter],
400400
testFunction: @escaping @Sendable (C1.Element, C2.Element) async throws -> Void
401-
) -> Self where C1: Collection & Sendable, C1.Element: Sendable, C2: Collection & Sendable, C2.Element: Sendable {
401+
) -> Self where S: ~Copyable, C1: Collection & Sendable, C1.Element: Sendable, C2: Collection & Sendable, C2.Element: Sendable {
402402
let containingTypeInfo: TypeInfo? = if let containingType {
403403
TypeInfo(describing: containingType)
404404
} else {
@@ -416,17 +416,17 @@ extension Test {
416416
///
417417
/// - Warning: This function is used to implement the `@Test` macro. Do not
418418
/// call it directly.
419-
public static func __function<C, E1, E2>(
419+
public static func __function<S, C, E1, E2>(
420420
named testFunctionName: String,
421-
in containingType: (any ~Copyable.Type)?,
421+
in containingType: S.Type?,
422422
xcTestCompatibleSelector: __XCTestCompatibleSelector?,
423423
displayName: String? = nil,
424424
traits: [any TestTrait],
425425
arguments collection: @escaping @Sendable () async throws -> C,
426426
sourceLocation: SourceLocation,
427427
parameters paramTuples: [__Parameter],
428428
testFunction: @escaping @Sendable ((E1, E2)) async throws -> Void
429-
) -> Self where C: Collection & Sendable, C.Element == (E1, E2), E1: Sendable, E2: Sendable {
429+
) -> Self where S: ~Copyable, C: Collection & Sendable, C.Element == (E1, E2), E1: Sendable, E2: Sendable {
430430
let containingTypeInfo: TypeInfo? = if let containingType {
431431
TypeInfo(describing: containingType)
432432
} else {
@@ -447,17 +447,17 @@ extension Test {
447447
///
448448
/// - Warning: This function is used to implement the `@Test` macro. Do not
449449
/// call it directly.
450-
public static func __function<Key, Value>(
450+
public static func __function<S, Key, Value>(
451451
named testFunctionName: String,
452-
in containingType: (any ~Copyable.Type)?,
452+
in containingType: S.Type?,
453453
xcTestCompatibleSelector: __XCTestCompatibleSelector?,
454454
displayName: String? = nil,
455455
traits: [any TestTrait],
456456
arguments dictionary: @escaping @Sendable () async throws -> Dictionary<Key, Value>,
457457
sourceLocation: SourceLocation,
458458
parameters paramTuples: [__Parameter],
459459
testFunction: @escaping @Sendable ((Key, Value)) async throws -> Void
460-
) -> Self where Key: Sendable, Value: Sendable {
460+
) -> Self where S: ~Copyable, Key: Sendable, Value: Sendable {
461461
let containingTypeInfo: TypeInfo? = if let containingType {
462462
TypeInfo(describing: containingType)
463463
} else {
@@ -472,17 +472,17 @@ extension Test {
472472
///
473473
/// - Warning: This function is used to implement the `@Test` macro. Do not
474474
/// call it directly.
475-
public static func __function<C1, C2>(
475+
public static func __function<S, C1, C2>(
476476
named testFunctionName: String,
477-
in containingType: (any ~Copyable.Type)?,
477+
in containingType: S.Type?,
478478
xcTestCompatibleSelector: __XCTestCompatibleSelector?,
479479
displayName: String? = nil,
480480
traits: [any TestTrait],
481481
arguments zippedCollections: @escaping @Sendable () async throws -> Zip2Sequence<C1, C2>,
482482
sourceLocation: SourceLocation,
483483
parameters paramTuples: [__Parameter],
484484
testFunction: @escaping @Sendable (C1.Element, C2.Element) async throws -> Void
485-
) -> Self where C1: Collection & Sendable, C1.Element: Sendable, C2: Collection & Sendable, C2.Element: Sendable {
485+
) -> Self where S: ~Copyable, C1: Collection & Sendable, C1.Element: Sendable, C2: Collection & Sendable, C2.Element: Sendable {
486486
let containingTypeInfo: TypeInfo? = if let containingType {
487487
TypeInfo(describing: containingType)
488488
} else {
@@ -556,7 +556,7 @@ extension Test {
556556
///
557557
/// - Warning: This function is used to implement the `@Test` macro. Do not use
558558
/// it directly.
559-
@unsafe @inlinable public func __requiringUnsafe<T>(_ value: consuming T) throws -> T where T: ~Copyable {
559+
@unsafe @inlinable public func __requiringUnsafe<T>(_ value: consuming T) -> T where T: ~Copyable {
560560
value
561561
}
562562

Sources/TestingMacros/TestDeclarationMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ public struct TestDeclarationMacro: PeerMacro, Sendable {
382382

383383
// Get the name of the type containing the function for passing to the test
384384
// factory function later.
385-
let typeNameExpr: ExprSyntax = typeName.map { "\($0).self" } ?? "nil"
385+
let typeNameExpr: ExprSyntax = typeName.map { "\($0).self" } ?? "nil as Swift.Never.Type?"
386386

387387
if typeName != nil, let genericGuardDecl = makeGenericGuardDecl(guardingAgainst: functionDecl, in: context) {
388388
result.append(genericGuardDecl)

0 commit comments

Comments
 (0)