Skip to content

Commit

Permalink
Gate 6.0 dependent tests with a 6.0 compiler check
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxDesiatov authored and bnbarham committed May 7, 2024
1 parent 7c20a13 commit e834159
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 36 deletions.
7 changes: 4 additions & 3 deletions Fixtures/Miscellaneous/Plugins/DependentPlugins/Package.swift
Expand Up @@ -10,15 +10,15 @@ let package = Package(
targets: [
.executableTarget(name: "MyExecutable"),
.executableTarget(name: "MyExecutable2"),

.plugin(
name: "MyPlugin",
capability: .buildTool(),
dependencies: [
"MyExecutable"
]
),

.plugin(
name: "MyPlugin2",
capability: .buildTool(),
Expand All @@ -34,5 +34,6 @@ let package = Package(
"MyPlugin2",
]
),
]
],
swiftLanguageVersions: [.v5]
)
25 changes: 16 additions & 9 deletions IntegrationTests/Tests/IntegrationTests/BasicTests.swift
Expand Up @@ -19,6 +19,7 @@ final class BasicTests: XCTestCase {

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

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

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

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

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

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

Expand All @@ -149,6 +146,8 @@ final class BasicTests: XCTestCase {
}

func testSwiftPackageInitLib() throws {
try skipUnlessAtLeastSwift6()

try withTemporaryDirectory { tempDir in
// Create a new package with an executable target.
let packagePath = tempDir.appending(component: "Project")
Expand All @@ -167,6 +166,8 @@ final class BasicTests: XCTestCase {
}

func testSwiftPackageLibsTests() throws {
try skipUnlessAtLeastSwift6()

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

try withTemporaryDirectory { tempDir in
Expand Down Expand Up @@ -225,9 +226,7 @@ final class BasicTests: XCTestCase {
}

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

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

func testSwiftTest() throws {
try skipUnlessAtLeastSwift6()

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

try withTemporaryDirectory { tempDir in
Expand Down Expand Up @@ -377,3 +378,9 @@ private extension Character {
}
}
}

private func skipUnlessAtLeastSwift6() throws {
#if compiler(<6.0)
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
#endif
}
3 changes: 3 additions & 0 deletions IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift
Expand Up @@ -53,6 +53,9 @@ final class SwiftPMTests: XCTestCase {
#if !os(macOS)
try XCTSkip("Test requires macOS")
#endif
#if swift(<6.0)
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
#endif

try withTemporaryDirectory { tmpDir in
let packagePath = tmpDir.appending(component: "foo")
Expand Down
29 changes: 29 additions & 0 deletions Sources/SPMTestSupport/XCTSkipHelpers.swift
@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Basics
import PackageModel
import XCTest

import class TSCBasic.Process
import struct TSCBasic.StringError

extension Toolchain {
package func skipUnlessAtLeastSwift6(
file: StaticString = #file,
line: UInt = #line
) async throws {
#if compiler(<6.0)
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
#endif
}
}
3 changes: 2 additions & 1 deletion Tests/BuildTests/BuildSystemDelegateTests.swift
Expand Up @@ -17,7 +17,8 @@ import XCTest
import var TSCBasic.localFileSystem

final class BuildSystemDelegateTests: XCTestCase {
func testDoNotFilterLinkerDiagnostics() throws {
func testDoNotFilterLinkerDiagnostics() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()
try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test")
try fixture(name: "Miscellaneous/DoNotFilterLinkerDiagnostics") { fixturePath in
#if !os(macOS)
Expand Down
12 changes: 9 additions & 3 deletions Tests/FunctionalTests/PluginTests.swift
Expand Up @@ -178,7 +178,9 @@ final class PluginTests: XCTestCase {
}
}

func testBuildToolWithoutOutputs() throws {
func testBuildToolWithoutOutputs() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")

Expand Down Expand Up @@ -1155,7 +1157,9 @@ final class PluginTests: XCTestCase {
}
}

func testURLBasedPluginAPI() throws {
func testURLBasedPluginAPI() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")

Expand All @@ -1165,7 +1169,9 @@ final class PluginTests: XCTestCase {
}
}

func testDependentPlugins() throws {
func testDependentPlugins() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")

try fixture(name: "Miscellaneous/Plugins/DependentPlugins") { fixturePath in
Expand Down
5 changes: 4 additions & 1 deletion Tests/FunctionalTests/ResourcesTests.swift
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

import Basics
import PackageModel
import SPMTestSupport
import XCTest

Expand Down Expand Up @@ -126,7 +127,9 @@ class ResourcesTests: XCTestCase {
}
}

func testResourcesOutsideOfTargetCanBeIncluded() throws {
func testResourcesOutsideOfTargetCanBeIncluded() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

try testWithTemporaryDirectory { tmpPath in
let packageDir = tmpPath.appending(components: "MyPackage")

Expand Down
15 changes: 14 additions & 1 deletion Tests/PackageLoadingTests/ManifestLoaderCacheTests.swift
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand All @@ -22,7 +22,10 @@ import func TSCTestSupport.withCustomEnv

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
final class ManifestLoaderCacheTests: XCTestCase {

func testDBCaching() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

try await testWithTemporaryDirectory { path in
let fileSystem = localFileSystem
let observability = ObservabilitySystem.makeForTesting()
Expand Down Expand Up @@ -117,6 +120,8 @@ final class ManifestLoaderCacheTests: XCTestCase {
}

func testInMemoryCaching() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

let fileSystem = InMemoryFileSystem()
let observability = ObservabilitySystem.makeForTesting()

Expand Down Expand Up @@ -206,6 +211,8 @@ final class ManifestLoaderCacheTests: XCTestCase {
}

func testContentBasedCaching() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

try await testWithTemporaryDirectory { path in
let manifest = """
import PackageDescription
Expand Down Expand Up @@ -265,6 +272,8 @@ final class ManifestLoaderCacheTests: XCTestCase {
}

func testCacheInvalidationOnEnv() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

try await testWithTemporaryDirectory { path in
let fileSystem = InMemoryFileSystem()
let observability = ObservabilitySystem.makeForTesting()
Expand Down Expand Up @@ -330,6 +339,8 @@ final class ManifestLoaderCacheTests: XCTestCase {
}

func testCacheDoNotInvalidationExpectedEnv() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

try await testWithTemporaryDirectory { path in
let fileSystem = InMemoryFileSystem()
let observability = ObservabilitySystem.makeForTesting()
Expand Down Expand Up @@ -415,6 +426,8 @@ final class ManifestLoaderCacheTests: XCTestCase {
}

func testInMemoryCacheHappyCase() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

let content = """
import PackageDescription
let package = Package(
Expand Down
10 changes: 8 additions & 2 deletions Tests/PackageLoadingTests/PD_6_0_LoadingTests.swift
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Copyright (c) 2023-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand All @@ -16,12 +16,14 @@ import SourceControl
import SPMTestSupport
import XCTest

class PackageDescription6_0LoadingTests: PackageDescriptionLoadingTests {
final class PackageDescription6_0LoadingTests: PackageDescriptionLoadingTests {
override var toolsVersion: ToolsVersion {
.v6_0
}

func testPackageContextGitStatus() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

let content = """
import PackageDescription
let package = Package(name: "\\(Context.gitInformation?.hasUncommittedChanges == true)")
Expand All @@ -34,6 +36,8 @@ class PackageDescription6_0LoadingTests: PackageDescriptionLoadingTests {
}

func testPackageContextGitTag() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

let content = """
import PackageDescription
let package = Package(name: "\\(Context.gitInformation?.currentTag ?? "")")
Expand All @@ -46,6 +50,8 @@ class PackageDescription6_0LoadingTests: PackageDescriptionLoadingTests {
}

func testPackageContextGitCommit() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

let content = """
import PackageDescription
let package = Package(name: "\\(Context.gitInformation?.currentCommit ?? "")")
Expand Down
29 changes: 19 additions & 10 deletions Tests/WorkspaceTests/InitTests.swift
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand All @@ -16,7 +16,7 @@ import PackageModel
import Workspace
import XCTest

class InitTests: XCTestCase {
final class InitTests: XCTestCase {

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

Expand Down Expand Up @@ -53,8 +53,10 @@ class InitTests: XCTestCase {
XCTAssertMatch(manifestContents, .contains(packageWithNameOnly(named: name)))
}
}

func testInitPackageExecutable() throws {

func testInitPackageExecutable() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

try testWithTemporaryDirectory { tmpPath in
let fs = localFileSystem
let path = tmpPath.appending("Foo")
Expand Down Expand Up @@ -98,7 +100,9 @@ class InitTests: XCTestCase {
}
}

func testInitPackageLibraryWithXCTestOnly() throws {
func testInitPackageLibraryWithXCTestOnly() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

try testWithTemporaryDirectory { tmpPath in
let fs = localFileSystem
let path = tmpPath.appending("Foo")
Expand Down Expand Up @@ -148,7 +152,7 @@ class InitTests: XCTestCase {
XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "Foo.swiftmodule"))
}
}

func testInitPackageLibraryWithSwiftTestingOnly() throws {
try testWithTemporaryDirectory { tmpPath in
let fs = localFileSystem
Expand Down Expand Up @@ -235,7 +239,9 @@ class InitTests: XCTestCase {
}
}

func testInitPackageLibraryWithNoTests() throws {
func testInitPackageLibraryWithNoTests() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

try testWithTemporaryDirectory { tmpPath in
let fs = localFileSystem
let path = tmpPath.appending("Foo")
Expand Down Expand Up @@ -339,8 +345,9 @@ class InitTests: XCTestCase {
}

// MARK: Special case testing

func testInitPackageNonc99Directory() throws {

func testInitPackageNonc99Directory() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()
try withTemporaryDirectory(removeTreeOnDeinit: true) { tempDirPath in
XCTAssertDirectoryExists(tempDirPath)

Expand All @@ -367,7 +374,9 @@ class InitTests: XCTestCase {
}
}

func testNonC99NameExecutablePackage() throws {
func testNonC99NameExecutablePackage() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

try withTemporaryDirectory(removeTreeOnDeinit: true) { tempDirPath in
XCTAssertDirectoryExists(tempDirPath)

Expand Down

0 comments on commit e834159

Please sign in to comment.