Skip to content

Commit 458abfd

Browse files
MaxDesiatovbnbarham
authored andcommitted
Gate 6.0 dependent tests with a 6.0 compiler check
1 parent 5f4278c commit 458abfd

File tree

10 files changed

+128
-25
lines changed

10 files changed

+128
-25
lines changed

IntegrationTests/Tests/IntegrationTests/BasicTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ final class BasicTests: XCTestCase {
225225
}
226226

227227
func testSwiftRun() throws {
228-
#if swift(<5.5)
229-
try XCTSkipIf(true, "skipping because host compiler doesn't support '-entry-point-function-name'")
228+
#if swift(<6.0)
229+
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
230230
#endif
231231

232232
try withTemporaryDirectory { tempDir in
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

@@ -1159,7 +1161,9 @@ final class PluginTests: XCTestCase {
11591161
}
11601162
}
11611163

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

@@ -1169,7 +1173,9 @@ final class PluginTests: XCTestCase {
11691173
}
11701174
}
11711175

1172-
func testDependentPlugins() throws {
1176+
func testDependentPlugins() async throws {
1177+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
1178+
11731179
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")
11741180

11751181
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 ?? "")")

Tests/WorkspaceTests/InitTests.swift

Lines changed: 19 additions & 10 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) 2014-2023 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014-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,7 +16,7 @@ import PackageModel
1616
import Workspace
1717
import XCTest
1818

19-
class InitTests: XCTestCase {
19+
final class InitTests: XCTestCase {
2020

2121
// MARK: TSCBasic package creation for each package type.
2222

@@ -53,8 +53,10 @@ class InitTests: XCTestCase {
5353
XCTAssertMatch(manifestContents, .contains(packageWithNameOnly(named: name)))
5454
}
5555
}
56-
57-
func testInitPackageExecutable() throws {
56+
57+
func testInitPackageExecutable() async throws {
58+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
59+
5860
try testWithTemporaryDirectory { tmpPath in
5961
let fs = localFileSystem
6062
let path = tmpPath.appending("Foo")
@@ -98,7 +100,9 @@ class InitTests: XCTestCase {
98100
}
99101
}
100102

101-
func testInitPackageLibraryWithXCTestOnly() throws {
103+
func testInitPackageLibraryWithXCTestOnly() async throws {
104+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
105+
102106
try testWithTemporaryDirectory { tmpPath in
103107
let fs = localFileSystem
104108
let path = tmpPath.appending("Foo")
@@ -148,7 +152,7 @@ class InitTests: XCTestCase {
148152
XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "Foo.swiftmodule"))
149153
}
150154
}
151-
155+
152156
func testInitPackageLibraryWithSwiftTestingOnly() throws {
153157
try testWithTemporaryDirectory { tmpPath in
154158
let fs = localFileSystem
@@ -235,7 +239,9 @@ class InitTests: XCTestCase {
235239
}
236240
}
237241

238-
func testInitPackageLibraryWithNoTests() throws {
242+
func testInitPackageLibraryWithNoTests() async throws {
243+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
244+
239245
try testWithTemporaryDirectory { tmpPath in
240246
let fs = localFileSystem
241247
let path = tmpPath.appending("Foo")
@@ -339,8 +345,9 @@ class InitTests: XCTestCase {
339345
}
340346

341347
// MARK: Special case testing
342-
343-
func testInitPackageNonc99Directory() throws {
348+
349+
func testInitPackageNonc99Directory() async throws {
350+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
344351
try withTemporaryDirectory(removeTreeOnDeinit: true) { tempDirPath in
345352
XCTAssertDirectoryExists(tempDirPath)
346353

@@ -367,7 +374,9 @@ class InitTests: XCTestCase {
367374
}
368375
}
369376

370-
func testNonC99NameExecutablePackage() throws {
377+
func testNonC99NameExecutablePackage() async throws {
378+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
379+
371380
try withTemporaryDirectory(removeTreeOnDeinit: true) { tempDirPath in
372381
XCTAssertDirectoryExists(tempDirPath)
373382

Tests/WorkspaceTests/ManifestSourceGenerationTests.swift

Lines changed: 3 additions & 3 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) 2020-2021 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
@@ -33,8 +33,7 @@ extension String {
3333
}
3434
}
3535

36-
class ManifestSourceGenerationTests: XCTestCase {
37-
36+
final class ManifestSourceGenerationTests: XCTestCase {
3837
/// Private function that writes the contents of a package manifest to a temporary package directory and then loads it, then serializes the loaded manifest back out again and loads it once again, after which it compares that no information was lost. Return the source of the newly generated manifest.
3938
@discardableResult
4039
private func testManifestWritingRoundTrip(
@@ -591,6 +590,7 @@ class ManifestSourceGenerationTests: XCTestCase {
591590
}
592591

593592
func testManifestGenerationWithSwiftLanguageVersion() async throws {
593+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
594594
let manifest = Manifest.createRootManifest(
595595
displayName: "pkg",
596596
path: "/pkg",

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 6 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) 2014-2023 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014-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
@@ -155,7 +155,9 @@ final class WorkspaceTests: XCTestCase {
155155
}
156156
}
157157

158-
func testInterpreterFlags() throws {
158+
func testInterpreterFlags() async throws {
159+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
160+
159161
let fs = localFileSystem
160162

161163
try testWithTemporaryDirectory { path in
@@ -5252,6 +5254,8 @@ final class WorkspaceTests: XCTestCase {
52525254

52535255
// This verifies that the simplest possible loading APIs are available for package clients.
52545256
func testSimpleAPI() async throws {
5257+
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
5258+
52555259
try await testWithTemporaryDirectory { path in
52565260
// Create a temporary package as a test case.
52575261
let packagePath = path.appending("MyPkg")

0 commit comments

Comments
 (0)