Skip to content

Add a StdlibUnitTest modifier for requiring a stdlib version #79838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2112,6 +2112,11 @@ public final class TestSuite {
return self
}

public func require(_ stdlibVersion: StdLibVersion) -> _TestBuilder {
_data._skip.append(.minimumStdlib(stdlibVersion))
return self
}

public func stdin(_ stdinText: String, eof: Bool = false) -> _TestBuilder {
_data._stdinText = stdinText
_data._stdinEndsWithEOF = eof
Expand Down Expand Up @@ -2203,6 +2208,35 @@ func _getSystemVersionPlistProperty(_ propertyName: String) -> String? {
#endif
#endif

public enum StdLibVersion: String {
case stdlib_5_7 = "5.7"
case stdlib_5_8 = "5.8"
case stdlib_5_9 = "5.9"
case stdlib_5_10 = "5.10"
case stdlib_6_0 = "6.0"
case stdlib_6_1 = "6.1"
case stdlib_6_2 = "6.2"

var isAvailable: Bool {
switch self {
case .stdlib_5_7:
return if #available(SwiftStdlib 5.7, *) { true } else { false }
case .stdlib_5_8:
return if #available(SwiftStdlib 5.8, *) { true } else { false }
case .stdlib_5_9:
return if #available(SwiftStdlib 5.9, *) { true } else { false }
case .stdlib_5_10:
return if #available(SwiftStdlib 5.10, *) { true } else { false }
case .stdlib_6_0:
return if #available(SwiftStdlib 6.0, *) { true } else { false }
case .stdlib_6_1:
return if #available(SwiftStdlib 6.1, *) { true } else { false }
case .stdlib_6_2:
return if #available(SwiftStdlib 6.2, *) { true } else { false }
}
}
}

public enum OSVersion : CustomStringConvertible {
case osx(major: Int, minor: Int, bugFix: Int)
case iOS(major: Int, minor: Int, bugFix: Int)
Expand Down Expand Up @@ -2413,6 +2447,8 @@ public enum TestRunPredicate : CustomStringConvertible {
case objCRuntime(/*reason:*/ String)
case nativeRuntime(/*reason:*/ String)

case minimumStdlib(StdLibVersion)

public var description: String {
switch self {
case .custom(_, let reason):
Expand Down Expand Up @@ -2533,6 +2569,9 @@ public enum TestRunPredicate : CustomStringConvertible {
return "Objective-C runtime, reason: \(reason))"
case .nativeRuntime(let reason):
return "Native runtime (no ObjC), reason: \(reason))"

case .minimumStdlib(let version):
return "Requires Swift \(version.rawValue)'s standard library"
}
}

Expand Down Expand Up @@ -2921,6 +2960,9 @@ public enum TestRunPredicate : CustomStringConvertible {
#else
return true
#endif

case .minimumStdlib(let version):
return !version.isAvailable
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions test/Casting/Casts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,7 @@ CastsTests.test("Recursive AnyHashable") {
// https://github.com/apple/swift/issues/56987
#if _runtime(_ObjC)
CastsTests.test("Do not overuse __SwiftValue")
.skip(.custom({
if #available(SwiftStdlib 5.9, *) { return false } else { return true }
}, reason: "Requires stdlib from Swift 5.9 or later"))
.require(.stdlib_5_9)
.code {
struct Bar {}
// This used to succeed because of overeager __SwiftValue
Expand Down
25 changes: 5 additions & 20 deletions test/stdlib/StringCreate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ let s1 = "Long string containing the characters é, ß, 🦆, and 👨‍👧‍
let s2 = "Long ascii string with no accented characters (obviously)."

StringCreateTests.test("Validating.utf8")
.skip(.custom(
{ if #available(SwiftStdlib 6.0, *) { false } else { true } },
reason: "Requires Swift 6.0's standard library"
))
.require(.stdlib_6_0)
.code {
guard #available(SwiftStdlib 6.0, *) else { return }

Expand Down Expand Up @@ -182,10 +179,7 @@ StringCreateTests.test("Validating.utf8")
}

StringCreateTests.test("Validating.utf8.from.int8")
.skip(.custom(
{ if #available(SwiftStdlib 6.0, *) { false } else { true } },
reason: "Requires Swift 6.0's standard library"
))
.require(.stdlib_6_0)
.code {
guard #available(SwiftStdlib 6.0, *) else { return }

Expand All @@ -209,10 +203,7 @@ StringCreateTests.test("Validating.utf8.from.int8")
}

StringCreateTests.test("Validating.ascii")
.skip(.custom(
{ if #available(SwiftStdlib 6.0, *) { false } else { true } },
reason: "Requires Swift 6.0's standard library"
))
.require(.stdlib_6_0)
.code {
guard #available(SwiftStdlib 6.0, *) else { return }

Expand All @@ -236,10 +227,7 @@ StringCreateTests.test("Validating.ascii")
}

StringCreateTests.test("Validating.utf16")
.skip(.custom(
{ if #available(SwiftStdlib 6.0, *) { false } else { true } },
reason: "Requires Swift 6.0's standard library"
))
.require(.stdlib_6_0)
.code {
guard #available(SwiftStdlib 6.0, *) else { return }

Expand All @@ -263,10 +251,7 @@ StringCreateTests.test("Validating.utf16")
}

StringCreateTests.test("Validating.utf32")
.skip(.custom(
{ if #available(SwiftStdlib 6.0, *) { false } else { true } },
reason: "Requires Swift 6.0's standard library"
))
.require(.stdlib_6_0)
.code {
guard #available(SwiftStdlib 6.0, *) else { return }

Expand Down
13 changes: 3 additions & 10 deletions test/stdlib/UnsafeRawBufferPointer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,7 @@ UnsafeRawBufferPointerTestSuite.test("load.invalid")
}

UnsafeRawBufferPointerTestSuite.test("load.unaligned")
.skip(.custom({ // require SwiftStdlib 5.7
if #available(SwiftStdlib 5.7, *) { return false } else { return true }
}, reason: "Requires stdlib from Swift 5.7"))
.require(.stdlib_5_7)
.code {
guard #available(SwiftStdlib 5.7, *) else { return }
var data: [UInt8] = [0, 0, 0, .max, .max, .max, .max, 0]
Expand Down Expand Up @@ -619,10 +617,7 @@ UnsafeRawBufferPointerTestSuite.test("store.after")
}

UnsafeRawBufferPointerTestSuite.test("store.unaligned")
.skip(.custom({
if #available(SwiftStdlib 5.7, *) { return false }
return true
}, reason: "Requires Swift 5.7's stdlib"))
.require(.stdlib_5_7)
.code {
let count = MemoryLayout<UInt>.stride * 2
let p1 = UnsafeMutableRawBufferPointer.allocate(
Expand All @@ -648,9 +643,7 @@ UnsafeRawBufferPointerTestSuite.test("store.unaligned")
UnsafeRawBufferPointerTestSuite.test("store.invalid")
.skip(.custom({ !_isDebugAssertConfiguration() }, // require debugAssert
reason: "This tests a debug precondition.."))
.skip(.custom({ // require SwiftStdlib 5.7
if #available(SwiftStdlib 5.7, *) { return false } else { return true }
}, reason: "Requires stdlib from Swift 5.7"))
.require(.stdlib_5_7)
.code {
let t = "Text that is longer than fits in a small String."
let p1 = UnsafeMutableRawPointer.allocate(
Expand Down
19 changes: 4 additions & 15 deletions test/stdlib/UnsafeRawPointer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ UnsafeMutableRawPointerExtraTestSuite.test("initializeMemory") {
}

UnsafeMutableRawPointerExtraTestSuite.test("initializeMemorySingleElement")
.skip(.custom({
if #available(SwiftStdlib 5.8, *) { return false } else { return true }
}, reason: "Requires standard library from Swift 5.8"))
.require(.stdlib_5_8)
.code {
Missile.missilesLaunched = 0
let p1 = UnsafeMutableRawPointer.allocate(
Expand Down Expand Up @@ -112,10 +110,7 @@ UnsafeMutableRawPointerExtraTestSuite.test("load/store") {
}

UnsafeMutableRawPointerExtraTestSuite.test("load.unaligned")
.skip(.custom({
if #available(SwiftStdlib 5.7, *) { return false }
return true
}, reason: "Requires Swift 5.7's stdlib"))
.require(.stdlib_5_7)
.code {
guard #available(SwiftStdlib 5.7, *) else { return }
var data: [UInt8] = [0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0x0]
Expand Down Expand Up @@ -158,10 +153,7 @@ UnsafeMutableRawPointerExtraTestSuite.test("load.invalid.mutable")
#endif

UnsafeMutableRawPointerExtraTestSuite.test("store.unaligned")
.skip(.custom({
if #available(SwiftStdlib 5.7, *) { return false }
return true
}, reason: "Requires Swift 5.7's stdlib"))
.require(.stdlib_5_7)
.code {
let count = MemoryLayout<UInt>.stride * 2
let p1 = UnsafeMutableRawPointer.allocate(
Expand Down Expand Up @@ -190,10 +182,7 @@ UnsafeMutableRawPointerExtraTestSuite.test("store.unaligned")
UnsafeMutableRawPointerExtraTestSuite.test("store.invalid")
.skip(.custom({ !_isDebugAssertConfiguration() },
reason: "This tests a debug precondition.."))
.skip(.custom({
if #available(SwiftStdlib 5.7, *) { return false }
return true
}, reason: "Requires Swift 5.7's stdlib"))
.require(.stdlib_5_7)
.code {
Missile.missilesLaunched = 0
let m = Missile(0)
Expand Down