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 099871f
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 40 deletions.
Expand Up @@ -4,23 +4,32 @@ import Foundation
struct Tool {
static func main() async throws {
print("warning: Whoops! Coming from the executable", to: &StdErr.shared)

let path = CommandLine.arguments[2]

let path: String
if CommandLine.argc >= 3, let cPath = CommandLine.unsafeArgv[2] {
path = String(cString: cPath)
} else {
path = "<unknown>"
}

print("Writing a file to \(path)")

try #"""
public struct MyGeneratedStruct {
public static var message: String = "You got struct'd"
public static let message: String = "You got struct'd"
}
"""#.write(to: URL(fileURLWithPath: path), atomically: true, encoding: .utf8)
}
}

struct StdErr: TextOutputStream {
@MainActor
static var shared: Self = .init()
mutating func write(_ string: String) {
string.withCString { ptr in
_ = fputs(ptr, stderr)
Task { @MainActor in
string.withCString { ptr in
_ = fputs(ptr, stderr)
}
}
}
}
Expand Up @@ -3,7 +3,13 @@ import Foundation
@main
struct Tool {
static func main() async throws {
let path = CommandLine.arguments[2]
let path: String
if CommandLine.argc >= 3, let cPath = CommandLine.unsafeArgv[2] {
path = String(cString: cPath)
} else {
path = "<unknown>"
}

print("Printing file at \(path)")
print(try String(contentsOfFile: path))
}
Expand Down
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

0 comments on commit 099871f

Please sign in to comment.