Skip to content

Commit a0aeb79

Browse files
MaxDesiatovbnbarham
authored andcommitted
Gate 6.0 dependent tests with a 6.0 compiler check
1 parent b765937 commit a0aeb79

File tree

13 files changed

+130
-38
lines changed

13 files changed

+130
-38
lines changed

Fixtures/Miscellaneous/Plugins/DependentPlugins/Sources/MyExecutable/tool.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@ import Foundation
44
struct Tool {
55
static func main() async throws {
66
print("warning: Whoops! Coming from the executable", to: &StdErr.shared)
7-
8-
let path = CommandLine.arguments[2]
7+
8+
let path: String
9+
if CommandLine.argc >= 3, let cPath = CommandLine.unsafeArgv[2] {
10+
path = String(cString: cPath)
11+
} else {
12+
path = "<unknown>"
13+
}
14+
915
print("Writing a file to \(path)")
10-
16+
1117
try #"""
1218
public struct MyGeneratedStruct {
13-
public static var message: String = "You got struct'd"
19+
public static let message: String = "You got struct'd"
1420
}
1521
"""#.write(to: URL(fileURLWithPath: path), atomically: true, encoding: .utf8)
1622
}
1723
}
1824

1925
struct StdErr: TextOutputStream {
26+
@MainActor
2027
static var shared: Self = .init()
2128
mutating func write(_ string: String) {
2229
string.withCString { ptr in

Fixtures/Miscellaneous/Plugins/DependentPlugins/Sources/MyExecutable2/tool.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import Foundation
33
@main
44
struct Tool {
55
static func main() async throws {
6-
let path = CommandLine.arguments[2]
6+
let path: String
7+
if CommandLine.argc >= 3, let cPath = CommandLine.unsafeArgv[2] {
8+
path = String(cString: cPath)
9+
} else {
10+
path = "<unknown>"
11+
}
12+
713
print("Printing file at \(path)")
814
print(try String(contentsOfFile: path))
915
}

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 compiler(<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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 XCTest
16+
17+
import class TSCBasic.Process
18+
import struct TSCBasic.StringError
19+
20+
extension Toolchain {
21+
package func skipUnlessAtLeastSwift6(
22+
file: StaticString = #file,
23+
line: UInt = #line
24+
) async throws {
25+
#if compiler(<6.0)
26+
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
27+
#endif
28+
}
29+
}

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.skipUnlessAtLeastSwift6()
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.skipUnlessAtLeastSwift6()
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.skipUnlessAtLeastSwift6()
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.skipUnlessAtLeastSwift6()
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.skipUnlessAtLeastSwift6()
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.skipUnlessAtLeastSwift6()
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.skipUnlessAtLeastSwift6()
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.skipUnlessAtLeastSwift6()
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.skipUnlessAtLeastSwift6()
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.skipUnlessAtLeastSwift6()
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.skipUnlessAtLeastSwift6()
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.skipUnlessAtLeastSwift6()
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.skipUnlessAtLeastSwift6()
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.skipUnlessAtLeastSwift6()
54+
4955
let content = """
5056
import PackageDescription
5157
let package = Package(name: "\\(Context.gitInformation?.currentCommit ?? "")")

0 commit comments

Comments
 (0)