Skip to content

Commit 6662ead

Browse files
authored
Merge pull request swiftlang#36673 from lorentey/stdlib-test-availability
[test] Add missing version guards to tests for new stdlib behavior
2 parents b6ae499 + f7f4476 commit 6662ead

File tree

4 files changed

+165
-145
lines changed

4 files changed

+165
-145
lines changed

test/stdlib/FloatingPoint.swift.gyb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,20 @@ FloatingPoint.test("BinaryFloatingPoint/genericFloatingPointConversion") {
243243
from: Double._convert(from: Float.leastNonzeroMagnitude).value).value,
244244
Float.leastNonzeroMagnitude)
245245

246-
// Let's make sure that the correct value is returned when two representable
247-
// values are equally close to the original value.
248-
let bitPattern: UInt64 = 0b01111111111_0000000000000000000000110000000000000000000000000000
249-
var z = Double(bitPattern: bitPattern)
250-
expectEqual(Float._convert(from: z).value, Float(z))
251-
252-
z = Double(Float.greatestFiniteMagnitude) +
253-
Double(Float.greatestFiniteMagnitude.ulp / 2)
254-
expectEqual(Float._convert(from: z).value, Float(z))
246+
if #available(macOS 11, iOS 14, watchOS 7, tvOS 14, *) {
247+
// The behavior tested here was introduced in
248+
// https://github.com/apple/swift/pull/30194
249+
250+
// Let's make sure that the correct value is returned when two representable
251+
// values are equally close to the original value.
252+
let bitPattern: UInt64 = 0b01111111111_0000000000000000000000110000000000000000000000000000
253+
var z = Double(bitPattern: bitPattern)
254+
expectEqual(Float._convert(from: z).value, Float(z))
255+
256+
z = Double(Float.greatestFiniteMagnitude) +
257+
Double(Float.greatestFiniteMagnitude.ulp / 2)
258+
expectEqual(Float._convert(from: z).value, Float(z))
259+
}
255260
}
256261

257262
func positiveOne<T: ExpressibleByIntegerLiteral>() -> T {

test/stdlib/objc-array-slice.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88

99
import Foundation
1010

11-
let array = NSMutableArray()
12-
for _ in 0..<1000 {
13-
array.insert(NSObject(), at: 0)
14-
}
11+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
12+
// This tests behavior that was fixed in
13+
// https://github.com/apple/swift/pull/36355
14+
15+
let array = NSMutableArray()
16+
for _ in 0..<1000 {
17+
array.insert(NSObject(), at: 0)
18+
}
1519

16-
// Check that this does not crash because of an over-release of the array content.
17-
_ = (array as! [NSObject]).prefix(3)
18-
_ = (array as! [NSObject]).prefix(3)
20+
// Check that this does not crash because of an over-release of the array content.
21+
_ = (array as! [NSObject]).prefix(3)
22+
_ = (array as! [NSObject]).prefix(3)
23+
}
1924

2025
// CHECK: done
2126
print("done")
22-

validation-test/stdlib/DictionaryTrapsObjC.swift

Lines changed: 129 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -141,170 +141,175 @@ DictionaryTraps.test("BridgedKeyIsNotNSCopyable2")
141141
nsd.mutableCopy()
142142
}
143143

144-
DictionaryTraps.test("ForcedNonverbatimBridge.StringKey")
144+
if #available(macOS 15, iOS 13, watchOS 6, tvOS 13, *) {
145+
// The behavior tested here was introduced in
146+
// https://github.com/apple/swift/pull/23174
147+
148+
DictionaryTraps.test("ForcedNonverbatimBridge.StringKey")
145149
.skip(.custom(
146-
{ _isFastAssertConfiguration() },
147-
reason: "this trap is not guaranteed to happen in -Ounchecked"))
150+
{ _isFastAssertConfiguration() },
151+
reason: "this trap is not guaranteed to happen in -Ounchecked"))
148152
.crashOutputMatches("Could not cast value of type")
149153
.code {
150-
let d1: NSDictionary = [
151-
"Gordon" as NSString: NSObject(),
152-
"William" as NSString: NSObject(),
153-
"Katherine" as NSString: NSObject(),
154-
"Lynn" as NSString: NSObject(),
155-
"Brian" as NSString: NSObject(),
156-
1756 as NSNumber: NSObject()]
157-
158-
expectCrashLater()
159-
_ = d1 as! Dictionary<String, Any>
160-
}
154+
let d1: NSDictionary = [
155+
"Gordon" as NSString: NSObject(),
156+
"William" as NSString: NSObject(),
157+
"Katherine" as NSString: NSObject(),
158+
"Lynn" as NSString: NSObject(),
159+
"Brian" as NSString: NSObject(),
160+
1756 as NSNumber: NSObject()]
161+
162+
expectCrashLater()
163+
_ = d1 as! Dictionary<String, Any>
164+
}
161165

162-
DictionaryTraps.test("ForcedNonverbatimBridge.IntKey")
166+
DictionaryTraps.test("ForcedNonverbatimBridge.IntKey")
163167
.skip(.custom(
164-
{ _isFastAssertConfiguration() },
165-
reason: "this trap is not guaranteed to happen in -Ounchecked"))
168+
{ _isFastAssertConfiguration() },
169+
reason: "this trap is not guaranteed to happen in -Ounchecked"))
166170
.crashOutputMatches("Could not cast value of type")
167171
.code {
168172

169-
let d1: NSDictionary = [
170-
4 as NSNumber: NSObject(),
171-
8 as NSNumber: NSObject(),
172-
15 as NSNumber: NSObject(),
173-
16 as NSNumber: NSObject(),
174-
23 as NSNumber: NSObject(),
175-
42 as NSNumber: NSObject(),
176-
"John" as NSString: NSObject()]
177-
178-
expectCrashLater()
179-
_ = d1 as! Dictionary<Int, Any>
180-
}
173+
let d1: NSDictionary = [
174+
4 as NSNumber: NSObject(),
175+
8 as NSNumber: NSObject(),
176+
15 as NSNumber: NSObject(),
177+
16 as NSNumber: NSObject(),
178+
23 as NSNumber: NSObject(),
179+
42 as NSNumber: NSObject(),
180+
"John" as NSString: NSObject()]
181+
182+
expectCrashLater()
183+
_ = d1 as! Dictionary<Int, Any>
184+
}
181185

182-
DictionaryTraps.test("ForcedNonverbatimBridge.Value")
186+
DictionaryTraps.test("ForcedNonverbatimBridge.Value")
183187
.skip(.custom(
184-
{ _isFastAssertConfiguration() },
185-
reason: "this trap is not guaranteed to happen in -Ounchecked"))
188+
{ _isFastAssertConfiguration() },
189+
reason: "this trap is not guaranteed to happen in -Ounchecked"))
186190
.crashOutputMatches("Could not cast value of type")
187191
.code {
188192

189-
let d1: NSDictionary = [
190-
4 as NSNumber: "Jack" as NSString,
191-
8 as NSNumber: "Kate" as NSString,
192-
15 as NSNumber: "Hurley" as NSString,
193-
16 as NSNumber: "Sawyer" as NSString,
194-
23 as NSNumber: "John" as NSString,
195-
42 as NSNumber: NSObject()]
193+
let d1: NSDictionary = [
194+
4 as NSNumber: "Jack" as NSString,
195+
8 as NSNumber: "Kate" as NSString,
196+
15 as NSNumber: "Hurley" as NSString,
197+
16 as NSNumber: "Sawyer" as NSString,
198+
23 as NSNumber: "John" as NSString,
199+
42 as NSNumber: NSObject()]
196200

197-
expectCrashLater()
198-
_ = d1 as! Dictionary<NSObject, String>
199-
}
201+
expectCrashLater()
202+
_ = d1 as! Dictionary<NSObject, String>
203+
}
200204

201-
DictionaryTraps.test("ForcedVerbatimBridge.StringKey")
205+
DictionaryTraps.test("ForcedVerbatimBridge.StringKey")
202206
.skip(.custom(
203-
{ _isFastAssertConfiguration() },
204-
reason: "this trap is not guaranteed to happen in -Ounchecked"))
207+
{ _isFastAssertConfiguration() },
208+
reason: "this trap is not guaranteed to happen in -Ounchecked"))
205209
.crashOutputMatches("Could not cast value of type")
206210
.code {
207-
let d1: NSDictionary = [
208-
"Gordon" as NSString: NSObject(),
209-
"William" as NSString: NSObject(),
210-
"Katherine" as NSString: NSObject(),
211-
"Lynn" as NSString: NSObject(),
212-
"Brian" as NSString: NSObject(),
213-
1756 as NSNumber: NSObject()]
214-
215-
// With the ObjC runtime, the verbatim downcast is O(1); it performs no
216-
// runtime checks.
217-
let d2 = d1 as! Dictionary<NSString, NSObject>
218-
// Element access goes through the bridged path and performs forced downcasts.
219-
// This is where the odd numeric value is caught.
220-
expectCrashLater()
221-
for (key, value) in d2 {
222-
_ = (key, value)
211+
let d1: NSDictionary = [
212+
"Gordon" as NSString: NSObject(),
213+
"William" as NSString: NSObject(),
214+
"Katherine" as NSString: NSObject(),
215+
"Lynn" as NSString: NSObject(),
216+
"Brian" as NSString: NSObject(),
217+
1756 as NSNumber: NSObject()]
218+
219+
// With the ObjC runtime, the verbatim downcast is O(1); it performs no
220+
// runtime checks.
221+
let d2 = d1 as! Dictionary<NSString, NSObject>
222+
// Element access goes through the bridged path and performs forced downcasts.
223+
// This is where the odd numeric value is caught.
224+
expectCrashLater()
225+
for (key, value) in d2 {
226+
_ = (key, value)
227+
}
223228
}
224-
}
225229

226-
DictionaryTraps.test("ForcedVerbatimBridge.IntKey")
230+
DictionaryTraps.test("ForcedVerbatimBridge.IntKey")
227231
.skip(.custom(
228-
{ _isFastAssertConfiguration() },
229-
reason: "this trap is not guaranteed to happen in -Ounchecked"))
232+
{ _isFastAssertConfiguration() },
233+
reason: "this trap is not guaranteed to happen in -Ounchecked"))
230234
.crashOutputMatches("Could not cast value of type")
231235
.code {
232236

233-
let d1: NSDictionary = [
234-
4 as NSNumber: NSObject(),
235-
8 as NSNumber: NSObject(),
236-
15 as NSNumber: NSObject(),
237-
16 as NSNumber: NSObject(),
238-
23 as NSNumber: NSObject(),
239-
42 as NSNumber: NSObject(),
240-
"John" as NSString: NSObject()]
241-
242-
// With the ObjC runtime, the verbatim downcast is O(1); it performs no
243-
// runtime checks.
244-
let d2 = d1 as! Dictionary<NSNumber, NSObject>
245-
// Element access goes through the bridged path and performs forced downcasts.
246-
// This is where the odd numeric value is caught.
247-
expectCrashLater()
248-
for (key, value) in d2 {
249-
_ = (key, value)
237+
let d1: NSDictionary = [
238+
4 as NSNumber: NSObject(),
239+
8 as NSNumber: NSObject(),
240+
15 as NSNumber: NSObject(),
241+
16 as NSNumber: NSObject(),
242+
23 as NSNumber: NSObject(),
243+
42 as NSNumber: NSObject(),
244+
"John" as NSString: NSObject()]
245+
246+
// With the ObjC runtime, the verbatim downcast is O(1); it performs no
247+
// runtime checks.
248+
let d2 = d1 as! Dictionary<NSNumber, NSObject>
249+
// Element access goes through the bridged path and performs forced downcasts.
250+
// This is where the odd numeric value is caught.
251+
expectCrashLater()
252+
for (key, value) in d2 {
253+
_ = (key, value)
254+
}
250255
}
251-
}
252256

253-
DictionaryTraps.test("ForcedVerbatimBridge.Value")
257+
DictionaryTraps.test("ForcedVerbatimBridge.Value")
254258
.skip(.custom(
255-
{ _isFastAssertConfiguration() },
256-
reason: "this trap is not guaranteed to happen in -Ounchecked"))
259+
{ _isFastAssertConfiguration() },
260+
reason: "this trap is not guaranteed to happen in -Ounchecked"))
257261
.crashOutputMatches("Could not cast value of type")
258262
.code {
259263

260-
let d1: NSDictionary = [
261-
4 as NSNumber: "Jack" as NSString,
262-
8 as NSNumber: "Kate" as NSString,
263-
15 as NSNumber: "Hurley" as NSString,
264-
16 as NSNumber: "Sawyer" as NSString,
265-
23 as NSNumber: "John" as NSString,
266-
42 as NSNumber: NSObject()]
267-
268-
// With the ObjC runtime, the verbatim downcast is O(1); it performs no
269-
// runtime checks.
270-
let d2 = d1 as! Dictionary<NSObject, NSString>
271-
// Element access goes through the bridged path and performs forced downcasts.
272-
// This is where the odd numeric value is caught.
273-
expectCrashLater()
274-
for (key, value) in d2 {
275-
_ = (key, value)
264+
let d1: NSDictionary = [
265+
4 as NSNumber: "Jack" as NSString,
266+
8 as NSNumber: "Kate" as NSString,
267+
15 as NSNumber: "Hurley" as NSString,
268+
16 as NSNumber: "Sawyer" as NSString,
269+
23 as NSNumber: "John" as NSString,
270+
42 as NSNumber: NSObject()]
271+
272+
// With the ObjC runtime, the verbatim downcast is O(1); it performs no
273+
// runtime checks.
274+
let d2 = d1 as! Dictionary<NSObject, NSString>
275+
// Element access goes through the bridged path and performs forced downcasts.
276+
// This is where the odd numeric value is caught.
277+
expectCrashLater()
278+
for (key, value) in d2 {
279+
_ = (key, value)
280+
}
276281
}
277-
}
278282

279-
DictionaryTraps.test("Downcast.Verbatim")
283+
DictionaryTraps.test("Downcast.Verbatim")
280284
.skip(.custom(
281-
{ _isFastAssertConfiguration() },
282-
reason: "this trap is not guaranteed to happen in -Ounchecked"))
285+
{ _isFastAssertConfiguration() },
286+
reason: "this trap is not guaranteed to happen in -Ounchecked"))
283287
.crashOutputMatches("Could not cast value of type")
284288
.code {
285-
let d: Dictionary<NSObject, NSObject> = [ TestObjCKeyTy(10): NSObject(),
286-
NSObject() : NSObject() ]
287-
let d2: Dictionary<TestObjCKeyTy, NSObject> = _dictionaryDownCast(d)
288-
expectCrashLater()
289-
_ = d2[TestObjCKeyTy(10)]
290-
_ = d2[TestObjCKeyTy(20)]
291-
292-
// This triggers failure.
293-
for (_, _) in d2 { }
294-
}
289+
let d: Dictionary<NSObject, NSObject> = [ TestObjCKeyTy(10): NSObject(),
290+
NSObject() : NSObject() ]
291+
let d2: Dictionary<TestObjCKeyTy, NSObject> = _dictionaryDownCast(d)
292+
expectCrashLater()
293+
_ = d2[TestObjCKeyTy(10)]
294+
_ = d2[TestObjCKeyTy(20)]
295+
296+
// This triggers failure.
297+
for (_, _) in d2 { }
298+
}
295299

296-
DictionaryTraps.test("Downcast.NonVerbatimBridged")
300+
DictionaryTraps.test("Downcast.NonVerbatimBridged")
297301
.skip(.custom(
298-
{ _isFastAssertConfiguration() },
299-
reason: "this trap is not guaranteed to happen in -Ounchecked"))
302+
{ _isFastAssertConfiguration() },
303+
reason: "this trap is not guaranteed to happen in -Ounchecked"))
300304
.crashOutputMatches("Could not cast value of type")
301305
.code {
302-
let d: Dictionary<NSObject, NSObject> = [ TestObjCKeyTy(10): NSObject(),
303-
NSObject() : NSObject() ]
306+
let d: Dictionary<NSObject, NSObject> = [ TestObjCKeyTy(10): NSObject(),
307+
NSObject() : NSObject() ]
304308

305-
expectCrashLater()
306-
let d2 = d as! Dictionary<TestBridgedKeyTy, NSObject>
307-
_ = d2[TestBridgedKeyTy(10)]
309+
expectCrashLater()
310+
let d2 = d as! Dictionary<TestBridgedKeyTy, NSObject>
311+
_ = d2[TestBridgedKeyTy(10)]
312+
}
308313
}
309314

310315
runAllTests()

validation-test/stdlib/Stride.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@ var StrideTestSuite = TestSuite("Stride")
99
StrideTestSuite.test("to") {
1010
checkSequence(Array(0...4), stride(from: 0, to: 5, by: 1))
1111
checkSequence(Array(1...5).reversed(), stride(from: 5, to: 0, by: -1))
12-
checkSequence(stride(from: 0, to: 127, by: 3).map { Int8($0) },
13-
stride(from: 0, to: 127 as Int8, by: 3))
12+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
13+
// This used to crash before https://github.com/apple/swift/pull/34860
14+
checkSequence(stride(from: 0, to: 127, by: 3).map { Int8($0) },
15+
stride(from: 0, to: 127 as Int8, by: 3))
16+
}
1417
}
1518

1619
StrideTestSuite.test("through") {
1720
checkSequence(Array(0...5), stride(from: 0, through: 5, by: 1))
1821
checkSequence(Array(0...5).reversed(), stride(from: 5, through: 0, by: -1))
19-
checkSequence(stride(from: 0, through: 127, by: 3).map { Int8($0) },
20-
stride(from: 0, through: 127 as Int8, by: 3))
22+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
23+
// This used to crash before https://github.com/apple/swift/pull/34860
24+
checkSequence(stride(from: 0, through: 127, by: 3).map { Int8($0) },
25+
stride(from: 0, through: 127 as Int8, by: 3))
26+
}
2127
}
2228

2329
runAllTests()

0 commit comments

Comments
 (0)