Skip to content

Commit 57e63c2

Browse files
committed
Address test availability for current and older OSes
1 parent b91b9aa commit 57e63c2

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let availabilityTags: [_Availability] = [
1010
_Availability("FoundationPreview"), // Default FoundationPreview availability,
1111
_Availability("FoundationPredicate"), // Predicate relies on pack parameter runtime support
1212
_Availability("FoundationPredicateRegex"), // Predicate regexes rely on new stdlib APIs
13-
_Availability("FoundationSpan"), // Availability of Span types
13+
_Availability("FoundationSpan", availability: .future), // Availability of Span types
1414
]
1515
let versionNumbers = ["0.1", "0.2", "0.3", "0.4", "6.0.2", "6.1", "6.2"]
1616

Tests/FoundationEssentialsTests/DataTests.swift

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,9 @@ class DataTests : XCTestCase {
16361636

16371637
@available(FoundationSpan 6.2, *)
16381638
func test_InlineDataSpan() throws {
1639+
#if compiler(<6.2)
1640+
throw XCTSkip("Span not available")
1641+
#else
16391642
var source = Data()
16401643
var span = source.span
16411644
XCTAssertTrue(span.isEmpty)
@@ -1645,18 +1648,26 @@ class DataTests : XCTestCase {
16451648
XCTAssertFalse(span.isEmpty)
16461649
XCTAssertEqual(span.count, source.count)
16471650
XCTAssertEqual(span[0], 1)
1651+
#endif
16481652
}
16491653

16501654
@available(FoundationSpan 6.2, *)
16511655
func test_InlineSliceDataSpan() throws {
1656+
#if compiler(<6.2)
1657+
throw XCTSkip("Span not available")
1658+
#else
16521659
let source = Data(0 ... .max)
16531660
let span = source.span
16541661
XCTAssertEqual(span.count, source.count)
16551662
XCTAssertEqual(span[span.indices.last!], .max)
1663+
#endif
16561664
}
16571665

16581666
@available(FoundationSpan 6.2, *)
16591667
func test_LargeSliceDataSpan() throws {
1668+
#if compiler(<6.2)
1669+
throw XCTSkip("Span not available")
1670+
#else
16601671
#if _pointerBitWidth(_64)
16611672
let count = Int(Int32.max)
16621673
#elseif _pointerBitWidth(_32)
@@ -1669,10 +1680,14 @@ class DataTests : XCTestCase {
16691680
XCTAssertNotEqual(source.startIndex, 0)
16701681
let span = source.span
16711682
XCTAssertFalse(span.isEmpty)
1683+
#endif
16721684
}
16731685

16741686
@available(FoundationSpan 6.2, *)
16751687
func test_InlineDataMutableSpan() throws {
1688+
#if compiler(<6.2)
1689+
throw XCTSkip("Span not available")
1690+
#else
16761691
var source = Data()
16771692
var span = source.mutableSpan
16781693
XCTAssertTrue(span.isEmpty)
@@ -1686,28 +1701,36 @@ class DataTests : XCTestCase {
16861701
let v = UInt8.random(in: 10..<100)
16871702
span[i] = v
16881703
XCTAssertEqual(source[i], v)
1704+
#endif
16891705
}
16901706

16911707
@available(FoundationSpan 6.2, *)
16921708
func test_InlineSliceDataMutableSpan() throws {
1709+
#if compiler(<6.2)
1710+
throw XCTSkip("Span not available")
1711+
#else
16931712
var source = Data(0..<100)
16941713
let count = source.count
16951714
var span = source.mutableSpan
16961715
XCTAssertEqual(span.count, count)
16971716
let i = try XCTUnwrap(span.indices.randomElement())
16981717
span[i] = .max
16991718
XCTAssertEqual(source[i], .max)
1719+
#endif
17001720
}
17011721

17021722
@available(FoundationSpan 6.2, *)
17031723
func test_LargeSliceDataMutableSpan() throws {
1704-
#if _pointerBitWidth(_64)
1724+
#if compiler(<6.2)
1725+
throw XCTSkip("Span not available")
1726+
#else
1727+
#if _pointerBitWidth(_64)
17051728
var count = Int(Int32.max)
1706-
#elseif _pointerBitWidth(_32)
1729+
#elseif _pointerBitWidth(_32)
17071730
var count = Int(Int16.max)
1708-
#else
1731+
#else
17091732
#error("This test needs updating")
1710-
#endif
1733+
#endif
17111734

17121735
var source = Data(repeating: 0, count: count).dropFirst()
17131736
XCTAssertNotEqual(source.startIndex, 0)
@@ -1718,10 +1741,14 @@ class DataTests : XCTestCase {
17181741
span[i] = .max
17191742
XCTAssertEqual(source[i], 0)
17201743
XCTAssertEqual(source[i+1], .max)
1744+
#endif
17211745
}
17221746

17231747
@available(FoundationSpan 6.2, *)
17241748
func test_InlineDataMutableRawSpan() throws {
1749+
#if compiler(<6.2)
1750+
throw XCTSkip("Span not available")
1751+
#else
17251752
var source = Data()
17261753
var span = source.mutableBytes
17271754
XCTAssertTrue(span.isEmpty)
@@ -1735,21 +1762,29 @@ class DataTests : XCTestCase {
17351762
let v = UInt8.random(in: 10..<100)
17361763
span.storeBytes(of: v, toByteOffset: i, as: UInt8.self)
17371764
XCTAssertEqual(source[i], v)
1765+
#endif
17381766
}
17391767

17401768
@available(FoundationSpan 6.2, *)
17411769
func test_InlineSliceDataMutableRawSpan() throws {
1770+
#if compiler(<6.2)
1771+
throw XCTSkip("Span not available")
1772+
#else
17421773
var source = Data(0..<100)
17431774
let count = source.count
17441775
var span = source.mutableBytes
17451776
XCTAssertEqual(span.byteCount, count)
17461777
let i = try XCTUnwrap(span.byteOffsets.randomElement())
17471778
span.storeBytes(of: -1, toByteOffset: i, as: Int8.self)
17481779
XCTAssertEqual(source[i], .max)
1780+
#endif
17491781
}
17501782

17511783
@available(FoundationSpan 6.2, *)
17521784
func test_LargeSliceDataMutableRawSpan() throws {
1785+
#if compiler(<6.2)
1786+
throw XCTSkip("Span not available")
1787+
#else
17531788
#if _pointerBitWidth(_64)
17541789
var count = Int(Int32.max)
17551790
#elseif _pointerBitWidth(_32)
@@ -1767,6 +1802,7 @@ class DataTests : XCTestCase {
17671802
span.storeBytes(of: -1, toByteOffset: i, as: Int8.self)
17681803
XCTAssertEqual(source[i], 0)
17691804
XCTAssertEqual(source[i+1], .max)
1805+
#endif
17701806
}
17711807

17721808
#if false // FIXME: XCTest doesn't support crash tests yet rdar://20195010&22387653

0 commit comments

Comments
 (0)