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 26, 2024
1 parent 5f4278c commit 417bfc8
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 24 deletions.
4 changes: 2 additions & 2 deletions IntegrationTests/Tests/IntegrationTests/BasicTests.swift
Expand Up @@ -225,8 +225,8 @@ 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'")
#if swift(<6.0)
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
#endif

try withTemporaryDirectory { tempDir in
Expand Down
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 @@ -1159,7 +1161,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 @@ -1169,7 +1173,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
6 changes: 3 additions & 3 deletions Tests/WorkspaceTests/ManifestSourceGenerationTests.swift
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2020-2021 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 Down Expand Up @@ -33,8 +33,7 @@ extension String {
}
}

class ManifestSourceGenerationTests: XCTestCase {

final class ManifestSourceGenerationTests: XCTestCase {
/// 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.
@discardableResult
private func testManifestWritingRoundTrip(
Expand Down Expand Up @@ -591,6 +590,7 @@ class ManifestSourceGenerationTests: XCTestCase {
}

func testManifestGenerationWithSwiftLanguageVersion() async throws {
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)
let manifest = Manifest.createRootManifest(
displayName: "pkg",
path: "/pkg",
Expand Down
6 changes: 5 additions & 1 deletion Tests/WorkspaceTests/WorkspaceTests.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 Down Expand Up @@ -156,6 +156,8 @@ final class WorkspaceTests: XCTestCase {
}

func testInterpreterFlags() throws {
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)

let fs = localFileSystem

try testWithTemporaryDirectory { path in
Expand Down Expand Up @@ -5252,6 +5254,8 @@ final class WorkspaceTests: XCTestCase {

// This verifies that the simplest possible loading APIs are available for package clients.
func testSimpleAPI() async throws {
try await UserToolchain.default.skipUnlessSwiftVersion(major: 6, minor: 0)

try await testWithTemporaryDirectory { path in
// Create a temporary package as a test case.
let packagePath = path.appending("MyPkg")
Expand Down

0 comments on commit 417bfc8

Please sign in to comment.