Skip to content

Commit e2cfab4

Browse files
committed
[stdlib][test] Adopt availability macros in tests
1 parent 8ed81ae commit e2cfab4

File tree

90 files changed

+234
-236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+234
-236
lines changed

stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ self.test("\(testNamePrefix).partition/DispatchesThroughDirectStorageAccessors")
982982
withUnsafeMutableBufferPointerIsSupported ? 1 : 0,
983983
actualWUMBPIFNonNil + actualWCMSIAIFNonNil)
984984

985-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
985+
if #available(SwiftStdlib 5.5, *) {
986986
// `partition(by:)` is expected to dispatch to the public API in releases
987987
// that contain https://github.com/apple/swift/pull/36003.
988988
expectEqual(0, actualWUMBPIF)

stdlib/private/StdlibUnittest/OpaqueIdentityFunctions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public func getUInt64(_ x: UInt64) -> UInt64 { return _opaqueIdentity(x) }
6666
public func getUInt(_ x: UInt) -> UInt { return _opaqueIdentity(x) }
6767

6868
#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
69-
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
69+
@available(SwiftStdlib 5.3, *)
7070
@inline(never)
7171
public func getFloat16(_ x: Float16) -> Float16 { return _opaqueIdentity(x) }
7272
#endif

stdlib/private/StdlibUnittest/StdlibCoreExtras.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public func _isStdlibDebugConfiguration() -> Bool {
270270

271271
// Return true if the Swift runtime available is at least 5.1
272272
public func _hasSwift_5_1() -> Bool {
273-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
273+
if #available(SwiftStdlib 5.1, *) {
274274
return true
275275
}
276276
return false

test/Casting/CastTraps.swift.gyb

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ CastTrapsTestSuite.test("${t1}__${t2}")
105105
% end
106106

107107
protocol P2 {}
108-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
108+
if #available(SwiftStdlib 5.5, *) {
109109
CastTrapsTestSuite.test("Unexpected null")
110110
.crashOutputMatches("Found unexpected null pointer value while trying to cast value of type '")
111111
.crashOutputMatches("Foo'")
@@ -125,7 +125,7 @@ CastTrapsTestSuite.test("Unexpected null")
125125

126126

127127
#if _runtime(_ObjC)
128-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
128+
if #available(SwiftStdlib 5.5, *) {
129129
CastTrapsTestSuite.test("Unexpected Obj-C null")
130130
.crashOutputMatches("Found unexpected null pointer value while trying to cast value of type '")
131131
.crashOutputMatches("NSObject'")

test/Casting/Casts.swift

+9-9
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ CastsTests.test("Optional<T>.none can be casted to Optional<U>.none in generic c
102102
#if _runtime(_ObjC)
103103
protocol P2 {}
104104
CastsTests.test("Cast from ObjC existential to Protocol (SR-3871)") {
105-
if #available(macOS 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *) {
105+
if #available(SwiftStdlib 5.3, *) {
106106
struct S: P2 {}
107107

108108
class ObjCWrapper {
@@ -167,7 +167,7 @@ CastsTests.test("Dynamic casts of CF types to protocol existentials (SR-2289)")
167167
reason: "This test behaves unpredictably in optimized mode."))
168168
.code {
169169
expectTrue(isP(10 as Int))
170-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
170+
if #available(SwiftStdlib 5.5, *) {
171171
expectTrue(isP(CFBitVector.makeImmutable(from: [10, 20])))
172172
expectTrue(isP(CFMutableBitVector.makeMutable(from: [10, 20])))
173173
}
@@ -195,7 +195,7 @@ CastsTests.test("Casting struct -> Obj-C -> Protocol fails (SR-3871, SR-5590, SR
195195

196196

197197
protocol P4552 {}
198-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
198+
if #available(SwiftStdlib 5.5, *) {
199199
CastsTests.test("Casting Any(Optional(T)) -> Protocol fails (SR-4552)") {
200200
struct S: P4552 {
201201
let tracker = LifetimeTracked(13)
@@ -257,7 +257,7 @@ CastsTests.test("Store Swift metatype in ObjC property and cast back to Any.Type
257257
let sValue2 = a.sVar as? Any.Type
258258
let objcValue2 = a.objcVar as? Any.Type
259259
expectTrue(sValue2 == b)
260-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
260+
if #available(SwiftStdlib 5.5, *) {
261261
expectTrue(sValue2 == objcValue2)
262262
expectTrue(objcValue2 == b)
263263
}
@@ -303,7 +303,7 @@ CastsTests.test("Casts from @objc Type") {
303303
let user = User(name: "Kermit")
304304
let exporter: Exporter = UserExporter()
305305

306-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
306+
if #available(SwiftStdlib 5.5, *) {
307307
expectTrue(exporter.type is User.Type)
308308
}
309309
expectNotNil(exporter.export(item: user))
@@ -319,7 +319,7 @@ CastsTests.test("Conditional NSNumber -> Bool casts") {
319319
#endif
320320

321321
// rdar://45217461 ([dynamic casting] [SR-8964]: Type check operator (is) fails for Any! variable holding an Error (struct) value)
322-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
322+
if #available(SwiftStdlib 5.5, *) {
323323
CastsTests.test("Casts from Any(struct) to Error (SR-8964)") {
324324
struct MyError: Error { }
325325

@@ -393,7 +393,7 @@ CastsTests.test("Swift Protocol Metatypes don't self-conform") {
393393
let a = SwiftProtocol.self
394394
// `is P.Protocol` tests whether the argument is a subtype of P.
395395
// In particular, the protocol identifier `P.self` is such a subtype.
396-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
396+
if #available(SwiftStdlib 5.5, *) {
397397
expectNotNil(runtimeCast(a, to: SwiftProtocol.Protocol.self)) // Fixed by rdar://58991956
398398
}
399399
expectNotNil(a as? SwiftProtocol.Protocol)
@@ -446,7 +446,7 @@ CastsTests.test("Self-conformance for Error.self")
446446
@objc protocol ObjCProtocol {}
447447
CastsTests.test("ObjC Protocol Metatypes self-conform") {
448448
let a = ObjCProtocol.self
449-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
449+
if #available(SwiftStdlib 5.5, *) {
450450
expectNotNil(runtimeCast(a, to: ObjCProtocol.Protocol.self))
451451
}
452452
expectNotNil(a as? ObjCProtocol.Protocol)
@@ -472,7 +472,7 @@ CastsTests.test("String/NSString extension compat") {
472472
#endif
473473

474474
protocol P1999 {}
475-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
475+
if #available(SwiftStdlib 5.5, *) {
476476
CastsTests.test("Cast Any(Optional(class)) to Protocol type (SR-1999)") {
477477
class Foo: P1999 { }
478478

test/Concurrency/Runtime/async_stream.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var tests = TestSuite("AsyncStream")
2626

2727
@main struct Main {
2828
static func main() async {
29-
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
29+
if #available(SwiftStdlib 5.5, *) {
3030
final class Expectation: UnsafeSendable {
3131
var fulfilled = false
3232
}

test/Constraints/async.swift

+20-20
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,38 @@
22

33
// REQUIRES: concurrency
44

5-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
5+
@available(SwiftStdlib 5.5, *)
66
func doAsynchronously() async { }
7-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
7+
@available(SwiftStdlib 5.5, *)
88
func doSynchronously() { }
99

10-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
10+
@available(SwiftStdlib 5.5, *)
1111
func testConversions() async {
1212
let _: () -> Void = doAsynchronously // expected-error{{invalid conversion from 'async' function of type '() async -> ()' to synchronous function type '() -> Void'}}
1313
let _: () async -> Void = doSynchronously // okay
1414
}
1515

1616
// Overloading
17-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
17+
@available(SwiftStdlib 5.5, *)
1818
@available(swift, deprecated: 4.0, message: "synchronous is no fun")
1919
func overloadedSame(_: Int = 0) -> String { "synchronous" }
2020

21-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
21+
@available(SwiftStdlib 5.5, *)
2222
func overloadedSame() async -> String { "asynchronous" }
2323

24-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
24+
@available(SwiftStdlib 5.5, *)
2525
func overloaded() -> String { "synchronous" }
26-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
26+
@available(SwiftStdlib 5.5, *)
2727
func overloaded() async -> Double { 3.14159 }
2828

29-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
29+
@available(SwiftStdlib 5.5, *)
3030
@available(swift, deprecated: 4.0, message: "synchronous is no fun")
3131
func overloadedOptDifference() -> String { "synchronous" }
3232

33-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
33+
@available(SwiftStdlib 5.5, *)
3434
func overloadedOptDifference() async -> String? { nil }
3535

36-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
36+
@available(SwiftStdlib 5.5, *)
3737
func testOverloadedSync() {
3838
_ = overloadedSame() // expected-warning{{synchronous is no fun}}
3939

@@ -63,7 +63,7 @@ func testOverloadedSync() {
6363
let _: Int = fn4 // expected-error{{value of type '() async -> ()'}}
6464
}
6565

66-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
66+
@available(SwiftStdlib 5.5, *)
6767
func testOverloadedAsync() async {
6868
_ = await overloadedSame() // no warning
6969

@@ -98,12 +98,12 @@ func testOverloadedAsync() async {
9898
let _: Int = fn4 // expected-error{{value of type '() async -> ()'}}
9999
}
100100

101-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
101+
@available(SwiftStdlib 5.5, *)
102102
func takesAsyncClosure(_ closure: () async -> String) -> Int { 0 }
103-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
103+
@available(SwiftStdlib 5.5, *)
104104
func takesAsyncClosure(_ closure: () -> String) -> String { "" }
105105

106-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
106+
@available(SwiftStdlib 5.5, *)
107107
func testPassAsyncClosure() {
108108
let a = takesAsyncClosure { await overloadedSame() }
109109
let _: Double = a // expected-error{{convert value of type 'Int'}}
@@ -112,7 +112,7 @@ func testPassAsyncClosure() {
112112
let _: Double = b // expected-error{{convert value of type 'String'}}
113113
}
114114

115-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
115+
@available(SwiftStdlib 5.5, *)
116116
struct FunctionTypes {
117117
var syncNonThrowing: () -> Void
118118
var syncThrowing: () throws -> Void
@@ -135,27 +135,27 @@ struct FunctionTypes {
135135
}
136136

137137
// Overloading when there is conversion from sync to async.
138-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
138+
@available(SwiftStdlib 5.5, *)
139139
func bar(_ f: (Int) -> Int) -> Int {
140140
return f(2)
141141
}
142142

143-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
143+
@available(SwiftStdlib 5.5, *)
144144
func bar(_ f: (Int) async -> Int) async -> Int {
145145
return await f(2)
146146
}
147147

148-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
148+
@available(SwiftStdlib 5.5, *)
149149
func incrementSync(_ x: Int) -> Int {
150150
return x + 1
151151
}
152152

153-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
153+
@available(SwiftStdlib 5.5, *)
154154
func incrementAsync(_ x: Int) async -> Int {
155155
return x + 1
156156
}
157157

158-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
158+
@available(SwiftStdlib 5.5, *)
159159
func testAsyncWithConversions() async {
160160
_ = bar(incrementSync)
161161
_ = bar { -$0 }

test/Constraints/diagnostics.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -1219,22 +1219,22 @@ func voidFuncWithEffects1() throws {
12191219
// expected-note@-2 {{did you mean to add a return type?}}{{35-35= -> <#Return Type#>}}
12201220
}
12211221

1222-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
1222+
@available(SwiftStdlib 5.5, *)
12231223
func voidFuncWithEffects2() async throws {
12241224
return 1
12251225
// expected-error@-1 {{unexpected non-void return value in void function}}
12261226
// expected-note@-2 {{did you mean to add a return type?}}{{41-41= -> <#Return Type#>}}
12271227
}
12281228

1229-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
1229+
@available(SwiftStdlib 5.5, *)
12301230
// expected-error@+1 {{'async' must precede 'throws'}}
12311231
func voidFuncWithEffects3() throws async {
12321232
return 1
12331233
// expected-error@-1 {{unexpected non-void return value in void function}}
12341234
// expected-note@-2 {{did you mean to add a return type?}}{{41-41= -> <#Return Type#>}}
12351235
}
12361236

1237-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
1237+
@available(SwiftStdlib 5.5, *)
12381238
func voidFuncWithEffects4() async {
12391239
return 1
12401240
// expected-error@-1 {{unexpected non-void return value in void function}}
@@ -1247,7 +1247,7 @@ func voidFuncWithEffects5(_ closure: () throws -> Void) rethrows {
12471247
// expected-note@-2 {{did you mean to add a return type?}}{{65-65= -> <#Return Type#>}}
12481248
}
12491249

1250-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
1250+
@available(SwiftStdlib 5.5, *)
12511251
func voidGenericFuncWithEffects<T>(arg: T) async where T: CustomStringConvertible {
12521252
return 1
12531253
// expected-error@-1 {{unexpected non-void return value in void function}}

test/IRGen/opaque_result_type_access_path.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ extension X : P where T : P {
3131
}
3232
}
3333

34-
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
34+
@available(SwiftStdlib 5.1, *)
3535
func bar() -> some P {
3636
return 27
3737
}
3838

39-
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
39+
@available(SwiftStdlib 5.1, *)
4040
func foo() -> some P {
4141
return X(bar())
4242
}
4343

4444
// CHECK: 27
45-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
45+
if #available(SwiftStdlib 5.1, *) {
4646
print(foo().get())
4747
} else {
4848
print(27)

test/Interpreter/SDK/check_class_for_archiving.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ suite.test("NSKeyedUnarchiver") {
6464
}
6565

6666
// Disable negative tests on older OSes because of rdar://problem/50504765
67-
if #available(macOS 12, iOS 15, watchOS 8, tvOS 15, *) {
67+
if #available(SwiftStdlib 5.5, *) {
6868
suite.test("PrivateClass") {
6969
expectNotEqual(0, NSKeyedUnarchiver._swift_checkClassAndWarnForKeyedArchiving(PrivateClass.self, operation: op))
7070
}
7171
}
7272

73-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
73+
if #available(SwiftStdlib 5.5, *) {
7474
// Generic classes and nested classes were considered to have unstable names
7575
// in earlier releases.
7676
suite.test("GenericClass") {

test/Interpreter/SDK/check_class_for_archiving_log.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Foundation
1414

1515
// A tricky way to make the FileCheck tests conditional on the OS version.
16-
if #available(macOS 12, iOS 15, watchOS 8, tvOS 15, *) {
16+
if #available(SwiftStdlib 5.5, *) {
1717
print("-check-prefix=CHECK")
1818
} else {
1919
// Disable the checks for older OSes because of rdar://problem/50504765

test/Interpreter/SDK/protocol_lookup_foreign.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ProtocolLookupForeign.test("NSPoint") {
4242
}
4343

4444
ProtocolLookupForeign.test("CFSet") {
45-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
45+
if #available(SwiftStdlib 5.5, *) {
4646
expectEqual("CFSet", fooify(CFSetCreate(kCFAllocatorDefault, nil, 0, nil)!))
4747
}
4848
}

0 commit comments

Comments
 (0)