Skip to content

Commit 774788a

Browse files
committed
[test] Disable misaligned indices test prior to 5.1
Misaligned indices were fixed in 5.1, but we should disable the test when testing back deployment. Adds a shared helper to StdlibUnittest for the run time check.
1 parent 9e89935 commit 774788a

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

stdlib/private/StdlibUnittest/StdlibCoreExtras.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ public func _isStdlibDebugConfiguration() -> Bool {
268268
#endif
269269
}
270270

271+
// Return true if the Swift runtime available is at least 5.1
272+
public func _hasSwift_5_1() -> Bool {
273+
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
274+
return true
275+
}
276+
return false
277+
}
278+
271279
@frozen
272280
public struct LinearCongruentialGenerator: RandomNumberGenerator {
273281

test/stdlib/StringIndex.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ StringIndexTests.test("String.Index(_:within) / Range<String.Index>(_:in:)") {
242242
}
243243

244244
StringIndexTests.test("Misaligned") {
245+
// Misaligned indices were fixed in 5.1
246+
guard _hasSwift_5_1() else { return }
247+
245248
func doIt(_ str: String) {
246249
let characterIndices = Array(str.indices)
247250
let scalarIndices = Array(str.unicodeScalars.indices) + [str.endIndex]

validation-test/stdlib/String.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,6 @@ StringTests.test("Index/Hashable") {
220220
expectTrue(t.contains(s.startIndex))
221221
}
222222

223-
var Swift_5_1_Available: Bool {
224-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
225-
return true
226-
}
227-
return false
228-
}
229-
230223
StringTests.test("ForeignIndexes/Valid") {
231224
// It is actually unclear what the correct behavior is. This test is just a
232225
// change detector.
@@ -247,7 +240,7 @@ StringTests.test("ForeignIndexes/Valid") {
247240

248241
// Scalar alignment fixes and checks were added in 5.1, so we don't get the
249242
// expected behavior on prior runtimes.
250-
guard Swift_5_1_Available else { return }
243+
guard _hasSwift_5_1() else { return }
251244

252245
// Donor's second index is scalar-aligned in donor, but not acceptor. This
253246
// will trigger a stdlib assertion.
@@ -270,7 +263,7 @@ StringTests.test("ForeignIndexes/UnexpectedCrash") {
270263

271264
// Grapheme stride cache under noop scalar alignment was fixed in 5.1, so we
272265
// get a different answer prior.
273-
guard Swift_5_1_Available else { return }
266+
guard _hasSwift_5_1() else { return }
274267

275268
// `start` has a cached stride greater than 1, so subscript will trigger an
276269
// assertion when it makes a multi-grapheme-cluster Character.

validation-test/stdlib/StringViews.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,9 @@ tests.test("String View Setters") {
821821
}
822822

823823
tests.test("Scalar alignment") {
824+
// Misaligned indices were fixed in 5.1
825+
guard _hasSwift_5_1() else { return }
826+
824827
let str = "😀"
825828
let idx = str.utf8.index(after: str.startIndex)
826829
let substr = str[idx...]

0 commit comments

Comments
 (0)