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 Apr 27, 2024
1 parent b6f0c66 commit 29ab4d5
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 32 deletions.
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 swift(<6.0)
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
#endif
}
61 changes: 61 additions & 0 deletions Sources/SPMTestSupport/XCTSkipHelpers.swift
@@ -0,0 +1,61 @@
//===----------------------------------------------------------------------===//
//
// 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 RegexBuilder
import XCTest

import class TSCBasic.Process
import struct TSCBasic.StringError

extension Toolchain {
package func skipUnlessSwiftVersion(
major: Int,
minor: Int,
file: StaticString = #file,
line: UInt = #line
) async throws {
let currentVersion = try await getSwiftVersion(swiftCompilerPath)
guard let currentVersion else {
throw StringError("Failed to fine Swift version for '\(swiftCompilerPath)'")
}

if currentVersion.major < major || currentVersion.minor < minor {
throw XCTSkip("""
Skipping because toolchain has Swift version \(currentVersion.major).\(currentVersion.minor) \
but test requires at least \(major).\(minor)
""", file: file, line: line)
}
}
}

/// Return the major and minor version of Swift for a `swiftc` compiler at `swiftcPath`.
fileprivate func getSwiftVersion(_ swiftcPath: AbsolutePath) async throws -> (major: Int, minor: Int)? {
let process = Process(args: swiftcPath.pathString, "--version")
try process.launch()
let result = try await process.waitUntilExit()
let output = String(bytes: try result.output.get(), encoding: .utf8)
let regex = Regex {
"Swift version "
Capture { OneOrMore(.digit) }
"."
Capture { OneOrMore(.digit) }
}
guard let match = output?.firstMatch(of: regex) else {
return nil
}
guard let major = Int(match.1), let minor = Int(match.2) else {
return nil
}
return (major, minor)
}
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.skipUnlessSwiftVersion(major: 6, minor: 0)
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.skipUnlessSwiftVersion(major: 6, minor: 0)

// 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.skipUnlessSwiftVersion(major: 6, minor: 0)

// 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.skipUnlessSwiftVersion(major: 6, minor: 0)

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.skipUnlessSwiftVersion(major: 6, minor: 0)

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.skipUnlessSwiftVersion(major: 6, minor: 0)

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.skipUnlessSwiftVersion(major: 6, minor: 0)

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.skipUnlessSwiftVersion(major: 6, minor: 0)

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.skipUnlessSwiftVersion(major: 6, minor: 0)

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.skipUnlessSwiftVersion(major: 6, minor: 0)

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.skipUnlessSwiftVersion(major: 6, minor: 0)

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.skipUnlessSwiftVersion(major: 6, minor: 0)

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.skipUnlessSwiftVersion(major: 6, minor: 0)

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.skipUnlessSwiftVersion(major: 6, minor: 0)

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.skipUnlessSwiftVersion(major: 6, minor: 0)

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.skipUnlessSwiftVersion(major: 6, minor: 0)

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.skipUnlessSwiftVersion(major: 6, minor: 0)

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.skipUnlessSwiftVersion(major: 6, minor: 0)
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.skipUnlessSwiftVersion(major: 6, minor: 0)

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

Expand Down

0 comments on commit 29ab4d5

Please sign in to comment.