Skip to content

Commit 47d63c2

Browse files
MaxDesiatovbnbarham
authored andcommitted
Gate 6.0 dependent tests with a 6.0 compiler check
1 parent b6f0c66 commit 47d63c2

File tree

11 files changed

+144
-33
lines changed

11 files changed

+144
-33
lines changed

IntegrationTests/Tests/IntegrationTests/BasicTests.swift

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ final class BasicTests: XCTestCase {
1919

2020
func testExamplePackageDealer() throws {
2121
try XCTSkipIf(isSelfHosted, "These packages don't use the latest runtime library, which doesn't work with self-hosted builds.")
22+
try skipUnlessAtLeastSwift6()
2223

2324
try withTemporaryDirectory { tempDir in
2425
let packagePath = tempDir.appending(component: "dealer")
@@ -93,9 +94,7 @@ final class BasicTests: XCTestCase {
9394
}
9495

9596
func testSwiftPackageInitExec() throws {
96-
#if swift(<5.5)
97-
try XCTSkipIf(true, "skipping because host compiler doesn't support '-entry-point-function-name'")
98-
#endif
97+
try skipUnlessAtLeastSwift6()
9998

10099
try withTemporaryDirectory { tempDir in
101100
// Create a new package with an executable target.
@@ -122,9 +121,7 @@ final class BasicTests: XCTestCase {
122121
}
123122

124123
func testSwiftPackageInitExecTests() throws {
125-
#if swift(<5.5)
126-
try XCTSkipIf(true, "skipping because host compiler doesn't support '-entry-point-function-name'")
127-
#endif
124+
try skipUnlessAtLeastSwift6()
128125

129126
try XCTSkip("FIXME: swift-test invocations are timing out in Xcode and self-hosted CI")
130127

@@ -149,6 +146,8 @@ final class BasicTests: XCTestCase {
149146
}
150147

151148
func testSwiftPackageInitLib() throws {
149+
try skipUnlessAtLeastSwift6()
150+
152151
try withTemporaryDirectory { tempDir in
153152
// Create a new package with an executable target.
154153
let packagePath = tempDir.appending(component: "Project")
@@ -167,6 +166,8 @@ final class BasicTests: XCTestCase {
167166
}
168167

169168
func testSwiftPackageLibsTests() throws {
169+
try skipUnlessAtLeastSwift6()
170+
170171
try XCTSkip("FIXME: swift-test invocations are timing out in Xcode and self-hosted CI")
171172

172173
try withTemporaryDirectory { tempDir in
@@ -225,9 +226,7 @@ final class BasicTests: XCTestCase {
225226
}
226227

227228
func testSwiftRun() throws {
228-
#if swift(<5.5)
229-
try XCTSkipIf(true, "skipping because host compiler doesn't support '-entry-point-function-name'")
230-
#endif
229+
try skipUnlessAtLeastSwift6()
231230

232231
try withTemporaryDirectory { tempDir in
233232
let packagePath = tempDir.appending(component: "secho")
@@ -256,6 +255,8 @@ final class BasicTests: XCTestCase {
256255
}
257256

258257
func testSwiftTest() throws {
258+
try skipUnlessAtLeastSwift6()
259+
259260
try XCTSkip("FIXME: swift-test invocations are timing out in Xcode and self-hosted CI")
260261

261262
try withTemporaryDirectory { tempDir in
@@ -377,3 +378,9 @@ private extension Character {
377378
}
378379
}
379380
}
381+
382+
private func skipUnlessAtLeastSwift6() throws {
383+
#if swift(<6.0)
384+
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
385+
#endif
386+
}

IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ final class SwiftPMTests: XCTestCase {
5353
#if !os(macOS)
5454
try XCTSkip("Test requires macOS")
5555
#endif
56+
#if swift(<6.0)
57+
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
58+
#endif
5659

5760
try withTemporaryDirectory { tmpDir in
5861
let packagePath = tmpDir.appending(component: "foo")
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import Basics
14+
import PackageModel
15+
import RegexBuilder
16+
import XCTest
17+
18+
import class TSCBasic.Process
19+
import struct TSCBasic.StringError
20+
21+
extension Toolchain {
22+
package func skipUnlessSwiftVersion(
23+
major: Int,
24+
minor: Int,
25+
file: StaticString = #file,
26+
line: UInt = #line
27+
) async throws {
28+
let currentVersion = try await getSwiftVersion(swiftCompilerPath)
29+
guard let currentVersion else {
30+
throw StringError("Failed to fine Swift version for '\(swiftCompilerPath)'")
31+
}
32+
33+
if currentVersion.major < major || currentVersion.minor < minor {
34+
throw XCTSkip("""
35+
Skipping because toolchain has Swift version \(currentVersion.major).\(currentVersion.minor) \
36+
but test requires at least \(major).\(minor)
37+
""", file: file, line: line)
38+
}
39+
}
40+
}
41+
42+
/// Return the major and minor version of Swift for a `swiftc` compiler at `swiftcPath`.
43+
fileprivate func getSwiftVersion(_ swiftcPath: AbsolutePath) async throws -> (major: Int, minor: Int)? {
44+
let process = Process(args: swiftcPath.pathString, "--version")
45+
try process.launch()
46+
let result = try await process.waitUntilExit()
47+
let output = String(bytes: try result.output.get(), encoding: .utf8)
48+
let regex = Regex {
49+
"Swift version "
50+
Capture { OneOrMore(.digit) }
51+
"."
52+
Capture { OneOrMore(.digit) }
53+
}
54+
guard let match = output?.firstMatch(of: regex) else {
55+
return nil
56+
}
57+
guard let major = Int(match.1), let minor = Int(match.2) else {
58+
return nil
59+
}
60+
return (major, minor)
61+
}

Tests/BuildTests/BuildSystemDelegateTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import XCTest
1717
import var TSCBasic.localFileSystem
1818

1919
final class BuildSystemDelegateTests: XCTestCase {
20-
func testDoNotFilterLinkerDiagnostics() throws {
20+
func testDoNotFilterLinkerDiagnostics() async throws {
21+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
2122
try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test")
2223
try fixture(name: "Miscellaneous/DoNotFilterLinkerDiagnostics") { fixturePath in
2324
#if !os(macOS)

Tests/FunctionalTests/PluginTests.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ final class PluginTests: XCTestCase {
178178
}
179179
}
180180

181-
func testBuildToolWithoutOutputs() throws {
181+
func testBuildToolWithoutOutputs() async throws {
182+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
183+
182184
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
183185
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")
184186

@@ -1155,7 +1157,9 @@ final class PluginTests: XCTestCase {
11551157
}
11561158
}
11571159

1158-
func testURLBasedPluginAPI() throws {
1160+
func testURLBasedPluginAPI() async throws {
1161+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
1162+
11591163
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
11601164
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")
11611165

@@ -1165,7 +1169,9 @@ final class PluginTests: XCTestCase {
11651169
}
11661170
}
11671171

1168-
func testDependentPlugins() throws {
1172+
func testDependentPlugins() async throws {
1173+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
1174+
11691175
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")
11701176

11711177
try fixture(name: "Miscellaneous/Plugins/DependentPlugins") { fixturePath in

Tests/FunctionalTests/ResourcesTests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Basics
14+
import PackageModel
1415
import SPMTestSupport
1516
import XCTest
1617

@@ -126,7 +127,9 @@ class ResourcesTests: XCTestCase {
126127
}
127128
}
128129

129-
func testResourcesOutsideOfTargetCanBeIncluded() throws {
130+
func testResourcesOutsideOfTargetCanBeIncluded() async throws {
131+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
132+
130133
try testWithTemporaryDirectory { tmpPath in
131134
let packageDir = tmpPath.appending(components: "MyPackage")
132135

Tests/PackageLoadingTests/ManifestLoaderCacheTests.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2020-2024 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -22,7 +22,10 @@ import func TSCTestSupport.withCustomEnv
2222

2323
@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
2424
final class ManifestLoaderCacheTests: XCTestCase {
25+
2526
func testDBCaching() async throws {
27+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
28+
2629
try await testWithTemporaryDirectory { path in
2730
let fileSystem = localFileSystem
2831
let observability = ObservabilitySystem.makeForTesting()
@@ -117,6 +120,8 @@ final class ManifestLoaderCacheTests: XCTestCase {
117120
}
118121

119122
func testInMemoryCaching() async throws {
123+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
124+
120125
let fileSystem = InMemoryFileSystem()
121126
let observability = ObservabilitySystem.makeForTesting()
122127

@@ -206,6 +211,8 @@ final class ManifestLoaderCacheTests: XCTestCase {
206211
}
207212

208213
func testContentBasedCaching() async throws {
214+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
215+
209216
try await testWithTemporaryDirectory { path in
210217
let manifest = """
211218
import PackageDescription
@@ -265,6 +272,8 @@ final class ManifestLoaderCacheTests: XCTestCase {
265272
}
266273

267274
func testCacheInvalidationOnEnv() async throws {
275+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
276+
268277
try await testWithTemporaryDirectory { path in
269278
let fileSystem = InMemoryFileSystem()
270279
let observability = ObservabilitySystem.makeForTesting()
@@ -330,6 +339,8 @@ final class ManifestLoaderCacheTests: XCTestCase {
330339
}
331340

332341
func testCacheDoNotInvalidationExpectedEnv() async throws {
342+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
343+
333344
try await testWithTemporaryDirectory { path in
334345
let fileSystem = InMemoryFileSystem()
335346
let observability = ObservabilitySystem.makeForTesting()
@@ -415,6 +426,8 @@ final class ManifestLoaderCacheTests: XCTestCase {
415426
}
416427

417428
func testInMemoryCacheHappyCase() async throws {
429+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
430+
418431
let content = """
419432
import PackageDescription
420433
let package = Package(

Tests/PackageLoadingTests/PD_6_0_LoadingTests.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2023 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2023-2024 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -16,12 +16,14 @@ import SourceControl
1616
import SPMTestSupport
1717
import XCTest
1818

19-
class PackageDescription6_0LoadingTests: PackageDescriptionLoadingTests {
19+
final class PackageDescription6_0LoadingTests: PackageDescriptionLoadingTests {
2020
override var toolsVersion: ToolsVersion {
2121
.v6_0
2222
}
2323

2424
func testPackageContextGitStatus() async throws {
25+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
26+
2527
let content = """
2628
import PackageDescription
2729
let package = Package(name: "\\(Context.gitInformation?.hasUncommittedChanges == true)")
@@ -34,6 +36,8 @@ class PackageDescription6_0LoadingTests: PackageDescriptionLoadingTests {
3436
}
3537

3638
func testPackageContextGitTag() async throws {
39+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
40+
3741
let content = """
3842
import PackageDescription
3943
let package = Package(name: "\\(Context.gitInformation?.currentTag ?? "")")
@@ -46,6 +50,8 @@ class PackageDescription6_0LoadingTests: PackageDescriptionLoadingTests {
4650
}
4751

4852
func testPackageContextGitCommit() async throws {
53+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
54+
4955
let content = """
5056
import PackageDescription
5157
let package = Package(name: "\\(Context.gitInformation?.currentCommit ?? "")")

0 commit comments

Comments
 (0)