Skip to content

Commit 9138b4e

Browse files
committed
Tests: Migrate BuildSystemDelegateTests to Swift Testing and augment
Migrate the `BuildSystemDelegateTests` test to Swift Testing and augment the test to run against both the Native and SwiftBUild build system, in addition to the `debug`` and `release` build configuration. Depends on: swiftlang#9012 Relates to: swiftlang#8997 issue: rdar://157669245
1 parent 37217a5 commit 9138b4e

File tree

3 files changed

+119
-30
lines changed

3 files changed

+119
-30
lines changed

Sources/_InternalTestSupport/BuildSystemProvider+Configuration.swift

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212

1313
import struct SPMBuildCore.BuildSystemProvider
1414
import enum PackageModel.BuildConfiguration
15+
import class PackageModel.UserToolchain
1516

1617
extension BuildSystemProvider.Kind {
1718

19+
@available(*, deprecated, message: "use binPath(for:scrathPath:triple) instead")
1820
public func binPathSuffixes(for config: BuildConfiguration) -> [String] {
1921
let suffix: String
2022

2123
#if os(Linux)
2224
suffix = "-linux"
2325
#elseif os(Windows)
24-
suffix = "-windows"
26+
suffix = "-windows"
2527
#else
2628
suffix = ""
2729
#endif
@@ -34,4 +36,40 @@ extension BuildSystemProvider.Kind {
3436
return ["apple", "Products" , "\(config)".capitalized + suffix]
3537
}
3638
}
39+
40+
public func binPath(
41+
for config: BuildConfiguration,
42+
scratchPath: [String] = [".build"],
43+
triple: String? = nil,
44+
) throws -> [String] {
45+
let suffix: String
46+
47+
#if os(Linux)
48+
suffix = "-linux"
49+
#elseif os(Windows)
50+
suffix = "-windows"
51+
#else
52+
suffix = ""
53+
#endif
54+
55+
let tripleString: String
56+
if let triple {
57+
tripleString = triple
58+
} else {
59+
do {
60+
tripleString = try UserToolchain.default.targetTriple.platformBuildPathComponent
61+
} catch {
62+
tripleString = ""
63+
}
64+
}
65+
switch self {
66+
case .native:
67+
return scratchPath + [tripleString, "\(config)".lowercased()]
68+
case .swiftbuild:
69+
return scratchPath + [tripleString, "Products", "\(config)".capitalized + suffix]
70+
case .xcode:
71+
return scratchPath + ["apple", "Products", "\(config)".capitalized + suffix]
72+
}
73+
}
74+
3775
}

Sources/_InternalTestSupport/SwiftTesting+TraitConditional.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ extension Trait where Self == Testing.ConditionTrait {
7979
}
8080
}
8181

82+
/// Enabled if toolsupm suported SDK Dependent Tests
83+
public static var requiresSDKDependentTestsSupport: Self {
84+
enabled("skipping because test environment doesn't support this test") {
85+
(try? UserToolchain.default)!.supportsSDKDependentTests()
86+
}
87+
}
88+
8289
// Enabled if the toolchain has supported features
8390
public static var supportsSupportedFeatures: Self {
8491
enabled("skipping because test environment compiler doesn't support `-print-supported-features`") {

Tests/BuildTests/BuildSystemDelegateTests.swift

Lines changed: 73 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,94 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2024-2025 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
99
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12+
import Foundation
1213

1314
import PackageModel
1415
import _InternalTestSupport
15-
import XCTest
16+
import Testing
1617

1718
import var TSCBasic.localFileSystem
1819

19-
final class BuildSystemDelegateTests: XCTestCase {
20-
func testDoNotFilterLinkerDiagnostics() async throws {
21-
try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test")
22-
try await fixtureXCTest(name: "Miscellaneous/DoNotFilterLinkerDiagnostics") { fixturePath in
23-
#if !os(macOS)
24-
// These linker diagnostics are only produced on macOS.
25-
try XCTSkipIf(true, "test is only supported on macOS")
26-
#endif
27-
let (fullLog, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native)
28-
XCTAssertTrue(fullLog.contains("ld: warning: search path 'foobar' not found"), "log didn't contain expected linker diagnostics")
20+
@Suite(
21+
.tags(
22+
.TestSize.large,
23+
)
24+
)
25+
struct BuildSystemDelegateTests {
26+
@Test(
27+
.requiresSDKDependentTestsSupport,
28+
.requireHostOS(.macOS), // These linker diagnostics are only produced on macOS.
29+
arguments: getBuildData(for: SupportedBuildSystemOnAllPlatforms),
30+
)
31+
func doNotFilterLinkerDiagnostics(
32+
data: BuildData,
33+
) async throws {
34+
try await fixture(name: "Miscellaneous/DoNotFilterLinkerDiagnostics") { fixturePath in
35+
let (stdout, stderr) = try await executeSwiftBuild(
36+
fixturePath,
37+
configuration: data.config,
38+
buildSystem: data.buildSystem,
39+
)
40+
switch data.buildSystem {
41+
42+
case .native:
43+
#expect(
44+
stdout.contains("ld: warning: search path 'foobar' not found"),
45+
"log didn't contain expected linker diagnostics. stderr: '\(stderr)')",
46+
)
47+
case .swiftbuild:
48+
#expect(
49+
!stderr.contains("warning: search path 'foobar' not found"),
50+
"log didn't contain expected linker diagnostics. stdout: '\(stdout)')",
51+
)
52+
#expect(
53+
!stdout.contains("warning: search path 'foobar' not found"),
54+
"log didn't contain expected linker diagnostics. stderr: '\(stderr)')",
55+
)
56+
case .xcode:
57+
Issue.record("Test expectation has not be implemented")
58+
}
2959
}
3060
}
3161

32-
func testFilterNonFatalCodesignMessages() async throws {
33-
try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8540: Package fails to build when the test is being executed")
34-
35-
try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test")
36-
// Note: we can re-use the `TestableExe` fixture here since we just need an executable.
37-
#if os(Windows)
38-
let executableExt = ".exe"
39-
#else
40-
let executableExt = ""
41-
#endif
42-
try await fixtureXCTest(name: "Miscellaneous/TestableExe") { fixturePath in
43-
_ = try await executeSwiftBuild(fixturePath, buildSystem: .native)
44-
let execPath = fixturePath.appending(components: ".build", "debug", "TestableExe1\(executableExt)")
45-
XCTAssertTrue(localFileSystem.exists(execPath), "executable not found at '\(execPath)'")
46-
try localFileSystem.removeFileTree(execPath)
47-
let (fullLog, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native)
48-
XCTAssertFalse(fullLog.contains("replacing existing signature"), "log contained non-fatal codesigning messages")
62+
@Test(
63+
.issue("https://github.com/swiftlang/swift-package-manager/issues/8540", relationship: .defect), // Package fails to build when the test is being executed"
64+
.requiresSDKDependentTestsSupport,
65+
arguments: getBuildData(for: SupportedBuildSystemOnAllPlatforms),
66+
)
67+
func filterNonFatalCodesignMessages(
68+
data: BuildData,
69+
) async throws {
70+
try await withKnownIssue {
71+
// Note: we can re-use the `TestableExe` fixture here since we just need an executable.
72+
try await fixture(name: "Miscellaneous/TestableExe") { fixturePath in
73+
_ = try await executeSwiftBuild(
74+
fixturePath,
75+
configuration: data.config,
76+
buildSystem: data.buildSystem,
77+
)
78+
let execPath = try fixturePath.appending(
79+
components: data.buildSystem.binPath(for: data.config) + [executableName("TestableExe1")]
80+
)
81+
expectFileExists(at: execPath)
82+
try localFileSystem.removeFileTree(execPath)
83+
let (stdout, stderr) = try await executeSwiftBuild(
84+
fixturePath,
85+
configuration: data.config,
86+
buildSystem: data.buildSystem,
87+
)
88+
#expect(!stdout.contains("replacing existing signature"), "log contained non-fatal codesigning messages stderr: '\(stderr)'")
89+
#expect(!stderr.contains("replacing existing signature"), "log contained non-fatal codesigning messages. stdout: '\(stdout)'")
90+
}
91+
} when: {
92+
ProcessInfo.hostOperatingSystem == .windows
4993
}
5094
}
5195
}

0 commit comments

Comments
 (0)