Skip to content

Commit 4f49cb1

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

File tree

1 file changed

+18
-45
lines changed

1 file changed

+18
-45
lines changed

Tests/FoundationEssentialsTests/DataTests.swift

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,11 +1634,9 @@ class DataTests : XCTestCase {
16341634
// source.advanced(by: 5)
16351635
}
16361636

1637-
@available(FoundationSpan 6.2, *)
16381637
func test_InlineDataSpan() throws {
1639-
#if compiler(<6.2)
1640-
throw XCTSkip("Span not available")
1641-
#else
1638+
guard #available(FoundationSpan 6.2, *) else { throw XCTSkip("Span not available") }
1639+
16421640
var source = Data()
16431641
var span = source.span
16441642
XCTAssertTrue(span.isEmpty)
@@ -1648,26 +1646,20 @@ class DataTests : XCTestCase {
16481646
XCTAssertFalse(span.isEmpty)
16491647
XCTAssertEqual(span.count, source.count)
16501648
XCTAssertEqual(span[0], 1)
1651-
#endif
16521649
}
16531650

1654-
@available(FoundationSpan 6.2, *)
16551651
func test_InlineSliceDataSpan() throws {
1656-
#if compiler(<6.2)
1657-
throw XCTSkip("Span not available")
1658-
#else
1652+
guard #available(FoundationSpan 6.2, *) else { throw XCTSkip("Span not available") }
1653+
16591654
let source = Data(0 ... .max)
16601655
let span = source.span
16611656
XCTAssertEqual(span.count, source.count)
16621657
XCTAssertEqual(span[span.indices.last!], .max)
1663-
#endif
16641658
}
16651659

1666-
@available(FoundationSpan 6.2, *)
16671660
func test_LargeSliceDataSpan() throws {
1668-
#if compiler(<6.2)
1669-
throw XCTSkip("Span not available")
1670-
#else
1661+
guard #available(FoundationSpan 6.2, *) else { throw XCTSkip("Span not available") }
1662+
16711663
#if _pointerBitWidth(_64)
16721664
let count = Int(Int32.max)
16731665
#elseif _pointerBitWidth(_32)
@@ -1680,14 +1672,11 @@ class DataTests : XCTestCase {
16801672
XCTAssertNotEqual(source.startIndex, 0)
16811673
let span = source.span
16821674
XCTAssertFalse(span.isEmpty)
1683-
#endif
16841675
}
16851676

1686-
@available(FoundationSpan 6.2, *)
16871677
func test_InlineDataMutableSpan() throws {
1688-
#if compiler(<6.2)
1689-
throw XCTSkip("Span not available")
1690-
#else
1678+
guard #available(FoundationSpan 6.2, *) else { throw XCTSkip("Span not available") }
1679+
16911680
var source = Data()
16921681
var span = source.mutableSpan
16931682
XCTAssertTrue(span.isEmpty)
@@ -1701,29 +1690,23 @@ class DataTests : XCTestCase {
17011690
let v = UInt8.random(in: 10..<100)
17021691
span[i] = v
17031692
XCTAssertEqual(source[i], v)
1704-
#endif
17051693
}
17061694

1707-
@available(FoundationSpan 6.2, *)
17081695
func test_InlineSliceDataMutableSpan() throws {
1709-
#if compiler(<6.2)
1710-
throw XCTSkip("Span not available")
1711-
#else
1696+
guard #available(FoundationSpan 6.2, *) else { throw XCTSkip("Span not available") }
1697+
17121698
var source = Data(0..<100)
17131699
let count = source.count
17141700
var span = source.mutableSpan
17151701
XCTAssertEqual(span.count, count)
17161702
let i = try XCTUnwrap(span.indices.randomElement())
17171703
span[i] = .max
17181704
XCTAssertEqual(source[i], .max)
1719-
#endif
17201705
}
17211706

1722-
@available(FoundationSpan 6.2, *)
17231707
func test_LargeSliceDataMutableSpan() throws {
1724-
#if compiler(<6.2)
1725-
throw XCTSkip("Span not available")
1726-
#else
1708+
guard #available(FoundationSpan 6.2, *) else { throw XCTSkip("Span not available") }
1709+
17271710
#if _pointerBitWidth(_64)
17281711
var count = Int(Int32.max)
17291712
#elseif _pointerBitWidth(_32)
@@ -1741,14 +1724,11 @@ class DataTests : XCTestCase {
17411724
span[i] = .max
17421725
XCTAssertEqual(source[i], 0)
17431726
XCTAssertEqual(source[i+1], .max)
1744-
#endif
17451727
}
17461728

1747-
@available(FoundationSpan 6.2, *)
17481729
func test_InlineDataMutableRawSpan() throws {
1749-
#if compiler(<6.2)
1750-
throw XCTSkip("Span not available")
1751-
#else
1730+
guard #available(FoundationSpan 6.2, *) else { throw XCTSkip("Span not available") }
1731+
17521732
var source = Data()
17531733
var span = source.mutableBytes
17541734
XCTAssertTrue(span.isEmpty)
@@ -1762,29 +1742,23 @@ class DataTests : XCTestCase {
17621742
let v = UInt8.random(in: 10..<100)
17631743
span.storeBytes(of: v, toByteOffset: i, as: UInt8.self)
17641744
XCTAssertEqual(source[i], v)
1765-
#endif
17661745
}
17671746

1768-
@available(FoundationSpan 6.2, *)
17691747
func test_InlineSliceDataMutableRawSpan() throws {
1770-
#if compiler(<6.2)
1771-
throw XCTSkip("Span not available")
1772-
#else
1748+
guard #available(FoundationSpan 6.2, *) else { throw XCTSkip("Span not available") }
1749+
17731750
var source = Data(0..<100)
17741751
let count = source.count
17751752
var span = source.mutableBytes
17761753
XCTAssertEqual(span.byteCount, count)
17771754
let i = try XCTUnwrap(span.byteOffsets.randomElement())
17781755
span.storeBytes(of: -1, toByteOffset: i, as: Int8.self)
17791756
XCTAssertEqual(source[i], .max)
1780-
#endif
17811757
}
17821758

1783-
@available(FoundationSpan 6.2, *)
17841759
func test_LargeSliceDataMutableRawSpan() throws {
1785-
#if compiler(<6.2)
1786-
throw XCTSkip("Span not available")
1787-
#else
1760+
guard #available(FoundationSpan 6.2, *) else { throw XCTSkip("Span not available") }
1761+
17881762
#if _pointerBitWidth(_64)
17891763
var count = Int(Int32.max)
17901764
#elseif _pointerBitWidth(_32)
@@ -1802,7 +1776,6 @@ class DataTests : XCTestCase {
18021776
span.storeBytes(of: -1, toByteOffset: i, as: Int8.self)
18031777
XCTAssertEqual(source[i], 0)
18041778
XCTAssertEqual(source[i+1], .max)
1805-
#endif
18061779
}
18071780

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

0 commit comments

Comments
 (0)