Skip to content

Commit 1335dd3

Browse files
committed
Tests: Convert Build Command Tests to Swift Testing
Convert the Build Command Tests to Swift Testing, Make use of parameterized tests to reduce duplication and use `withKnownIssue` to get signal when tests have been fixed.
1 parent ff7ea75 commit 1335dd3

File tree

16 files changed

+1107
-702
lines changed

16 files changed

+1107
-702
lines changed

IntegrationTests/Sources/IntegrationTestSupport/SkippedTestSupport.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,4 @@ extension Trait where Self == Testing.ConditionTrait {
5757
#endif
5858
}
5959
}
60-
61-
/// Constructs a condition trait that causes a test to be disabled if the Foundation process spawning implementation
62-
/// is not using `posix_spawn_file_actions_addchdir`.
63-
public static var requireThreadSafeWorkingDirectory: Self {
64-
disabled("Thread-safe process working directory support is unavailable.") {
65-
// Amazon Linux 2 has glibc 2.26, and glibc 2.29 is needed for posix_spawn_file_actions_addchdir_np support
66-
FileManager.default.contents(atPath: "/etc/system-release")
67-
.map { String(decoding: $0, as: UTF8.self) == "Amazon Linux release 2 (Karoo)\n" } ?? false
68-
}
69-
}
7060
}

IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ private struct SwiftPMTests {
7575
}
7676

7777
@Test(
78-
.requireThreadSafeWorkingDirectory,
7978
arguments: [BuildSystemProvider.native]
8079
)
8180
func packageInitExecutable(_ buildSystemProvider: BuildSystemProvider) throws {
@@ -84,7 +83,6 @@ private struct SwiftPMTests {
8483

8584
@Test(
8685
.skipHostOS(.windows),
87-
.requireThreadSafeWorkingDirectory,
8886
.bug(
8987
"https://github.com/swiftlang/swift-package-manager/issues/8416",
9088
"[Linux] swift run using --build-system swiftbuild fails to run executable"
@@ -125,7 +123,6 @@ private struct SwiftPMTests {
125123
}
126124

127125
@Test(
128-
.requireThreadSafeWorkingDirectory,
129126
.bug(id: 0, "SWBINTTODO: Linux: /lib/x86_64-linux-gnu/Scrt1.o:function _start: error:"),
130127
.bug("https://github.com/swiftlang/swift-package-manager/issues/8380", "lld-link: error: subsystem must be defined"),
131128
.bug(id: 0, "SWBINTTODO: MacOS: Could not find or use auto-linked library 'Testing': library 'Testing' not found"),

Sources/Basics/Process.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public enum OperatingSystem: Hashable, Sendable {
1919
case unknown
2020
}
2121

22+
2223
extension ProcessInfo {
2324
public static var hostOperatingSystem: OperatingSystem {
2425
#if os(macOS)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import struct SPMBuildCore.BuildSystemProvider
14+
import enum PackageModel.BuildConfiguration
15+
16+
extension BuildSystemProvider.Kind {
17+
18+
public func binPathSuffixes(for config: BuildConfiguration) -> [String] {
19+
let suffix: String
20+
21+
#if os(Linux)
22+
suffix = "-linux"
23+
#elseif os(Windows)
24+
suffix = "-windows"
25+
#else
26+
suffix = ""
27+
#endif
28+
switch self {
29+
case .native:
30+
return ["\(config)".lowercased()]
31+
case .swiftbuild:
32+
return ["Products" , "\(config)".capitalized + suffix]
33+
case .xcode:
34+
return ["apple", "Products" , "\(config)".capitalized + suffix]
35+
}
36+
}
37+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import struct SPMBuildCore.BuildSystemProvider
14+
15+
16+
public var SupportedBuildSystemOnAllPlatforms: [BuildSystemProvider.Kind] = BuildSystemProvider.Kind.allCases.filter { $0 != .xcode }
17+
18+
public var SupportedBuildSystemOnPlatform: [BuildSystemProvider.Kind] {
19+
#if os(macOS)
20+
BuildSystemProvider.Kind.allCases
21+
#else
22+
SupportedBuildSystemOnAllPlatforms
23+
#endif
24+
}

Sources/_InternalTestSupport/SkippedTestSupport.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,50 @@ extension Trait where Self == Testing.ConditionTrait {
5959
}
6060
}
6161
}
62+
63+
extension Trait where Self == Testing.Bug {
64+
public static func SWBINTTODO(_ comment: Comment) -> Self {
65+
bug(nil, id: 0, comment)
66+
}
67+
}
68+
extension Tag {
69+
public enum TestSize {}
70+
public enum Feature {}
71+
@Tag public static var UserWorkflow: Tag
72+
}
73+
74+
extension Tag.TestSize {
75+
@Tag public static var small: Tag
76+
@Tag public static var medium: Tag
77+
@Tag public static var large: Tag
78+
}
79+
80+
extension Tag.Feature {
81+
public enum Command {}
82+
public enum PackageType {}
83+
84+
@Tag public static var CodeCoverage: Tag
85+
@Tag public static var Resource: Tag
86+
@Tag public static var SpecialCharacters: Tag
87+
}
88+
89+
90+
extension Tag.Feature.Command {
91+
public enum Package {}
92+
@Tag public static var Build: Tag
93+
@Tag public static var Test: Tag
94+
@Tag public static var Run: Tag
95+
}
96+
97+
extension Tag.Feature.Command.Package {
98+
@Tag public static var Init: Tag
99+
}
100+
extension Tag.Feature.PackageType {
101+
@Tag public static var Library: Tag
102+
@Tag public static var Executable: Tag
103+
@Tag public static var Tool: Tag
104+
@Tag public static var Plugin: Tag
105+
@Tag public static var BuildToolPlugin: Tag
106+
@Tag public static var CommandPlugin: Tag
107+
@Tag public static var Macro: Tag
108+
}

Sources/_InternalTestSupport/XCTAssertHelpers.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Basics
1616
import class Foundation.Bundle
1717
#endif
1818
import SPMBuildCore
19+
import enum PackageModel.BuildConfiguration
1920
import TSCTestSupport
2021
import XCTest
2122

@@ -55,7 +56,7 @@ public func XCTSkipIfPlatformCI(because reason: String? = nil, file: StaticStrin
5556

5657
public func XCTSkipIfselfHostedCI(because reason: String, file: StaticString = #filePath, line: UInt = #line) throws {
5758
// TODO: is this actually the right variable now?
58-
if isSelfHostedCiEnvironment {
59+
if CiEnvironment.runningInSelfHostedPipeline {
5960
throw XCTSkip(reason, file: file, line: line)
6061
}
6162
}
@@ -145,7 +146,7 @@ package func XCTAssertAsyncNoThrow<T>(
145146

146147
public func XCTAssertBuilds(
147148
_ path: AbsolutePath,
148-
configurations: Set<Configuration> = [.Debug, .Release],
149+
configurations: Set<BuildConfiguration> = [.debug, .release],
149150
extraArgs: [String] = [],
150151
Xcc: [String] = [],
151152
Xld: [String] = [],
@@ -175,7 +176,7 @@ public func XCTAssertBuilds(
175176

176177
public func XCTAssertSwiftTest(
177178
_ path: AbsolutePath,
178-
configuration: Configuration = .Debug,
179+
configuration: BuildConfiguration = .debug,
179180
extraArgs: [String] = [],
180181
Xcc: [String] = [],
181182
Xld: [String] = [],

Sources/_InternalTestSupport/misc.swift

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,18 @@ import enum TSCUtility.Git
3939
@_exported import func TSCTestSupport.systemQuietly
4040
@_exported import enum TSCTestSupport.StringPattern
4141

42-
public let isInCiEnvironment = ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] != nil
43-
public let isSelfHostedCiEnvironment = ProcessInfo.processInfo.environment["SWIFTCI_IS_SELF_HOSTED"] != nil
42+
@available(*, deprecated, message: "Use CiEnvironment.runningInSmokeTestPipeline")
43+
public let isInCiEnvironment = CiEnvironment.runningInSmokeTestPipeline
44+
45+
@available(*, deprecated, message: "Use CiEnvironment.isSelfHostedCiEnvironment")
46+
public let isSelfHostedCiEnvironment = CiEnvironment.runningInSelfHostedPipeline
47+
48+
public struct CiEnvironmentStruct {
49+
public let runningInSmokeTestPipeline = ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] != nil
50+
public let runningInSelfHostedPipeline = ProcessInfo.processInfo.environment["SWIFTCI_IS_SELF_HOSTED"] != nil
51+
}
52+
53+
public let CiEnvironment = CiEnvironmentStruct()
4454

4555
public let isRealSigningIdentyEcLabelEnvVarSet =
4656
ProcessInfo.processInfo.environment["REAL_SIGNING_IDENTITY_EC_LABEL"] != nil
@@ -281,13 +291,14 @@ public func getBuildSystemArgs(for buildSystem: BuildSystemProvider.Kind?) -> [S
281291
@discardableResult
282292
public func executeSwiftBuild(
283293
_ packagePath: AbsolutePath?,
284-
configuration: Configuration = .Debug,
294+
configuration: BuildConfiguration = .debug,
285295
extraArgs: [String] = [],
286296
Xcc: [String] = [],
287297
Xld: [String] = [],
288298
Xswiftc: [String] = [],
289299
env: Environment? = nil,
290-
buildSystem: BuildSystemProvider.Kind = .native
300+
buildSystem: BuildSystemProvider.Kind = .native,
301+
throwIfCommandFails: Bool = true,
291302
) async throws -> (stdout: String, stderr: String) {
292303
let args = swiftArgs(
293304
configuration: configuration,
@@ -297,14 +308,14 @@ public func executeSwiftBuild(
297308
Xswiftc: Xswiftc,
298309
buildSystem: buildSystem
299310
)
300-
return try await SwiftPM.Build.execute(args, packagePath: packagePath, env: env)
311+
return try await SwiftPM.Build.execute(args, packagePath: packagePath, env: env, throwIfCommandFails: throwIfCommandFails)
301312
}
302313

303314
@discardableResult
304315
public func executeSwiftRun(
305316
_ packagePath: AbsolutePath?,
306317
_ executable: String?,
307-
configuration: Configuration = .Debug,
318+
configuration: BuildConfiguration = .debug,
308319
extraArgs: [String] = [],
309320
Xcc: [String] = [],
310321
Xld: [String] = [],
@@ -329,7 +340,7 @@ public func executeSwiftRun(
329340
@discardableResult
330341
public func executeSwiftPackage(
331342
_ packagePath: AbsolutePath?,
332-
configuration: Configuration = .Debug,
343+
configuration: BuildConfiguration = .debug,
333344
extraArgs: [String] = [],
334345
Xcc: [String] = [],
335346
Xld: [String] = [],
@@ -351,7 +362,7 @@ public func executeSwiftPackage(
351362
@discardableResult
352363
public func executeSwiftPackageRegistry(
353364
_ packagePath: AbsolutePath?,
354-
configuration: Configuration = .Debug,
365+
configuration: BuildConfiguration = .debug,
355366
extraArgs: [String] = [],
356367
Xcc: [String] = [],
357368
Xld: [String] = [],
@@ -373,7 +384,7 @@ public func executeSwiftPackageRegistry(
373384
@discardableResult
374385
public func executeSwiftTest(
375386
_ packagePath: AbsolutePath?,
376-
configuration: Configuration = .Debug,
387+
configuration: BuildConfiguration = .debug,
377388
extraArgs: [String] = [],
378389
Xcc: [String] = [],
379390
Xld: [String] = [],
@@ -394,7 +405,7 @@ public func executeSwiftTest(
394405
}
395406

396407
private func swiftArgs(
397-
configuration: Configuration,
408+
configuration: BuildConfiguration,
398409
extraArgs: [String],
399410
Xcc: [String],
400411
Xld: [String],
@@ -403,9 +414,9 @@ private func swiftArgs(
403414
) -> [String] {
404415
var args = ["--configuration"]
405416
switch configuration {
406-
case .Debug:
417+
case .debug:
407418
args.append("debug")
408-
case .Release:
419+
case .release:
409420
args.append("release")
410421
}
411422

Tests/BasicsTests/ConcurrencyHelpersTests.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ struct ConcurrencyHelpersTest {
2020
struct ThreadSafeKeyValueStoreTests {
2121
let queue = DispatchQueue(label: "ConcurrencyHelpersTest", attributes: .concurrent)
2222

23-
@Test
23+
@Test(
24+
.bug("https://github.com/swiftlang/swift-package-manager/issues/8770"),
25+
)
2426
func threadSafeKeyValueStore() throws {
2527
for _ in 0 ..< 100 {
2628
let sync = DispatchGroup()
@@ -45,14 +47,16 @@ struct ConcurrencyHelpersTest {
4547
}
4648
}
4749

48-
try #require(sync.wait(timeout: .now() + .seconds(2)) == .success)
50+
try #require(sync.wait(timeout: .now() + .seconds(300)) == .success)
4951
expected.forEach { key, value in
5052
#expect(cache[key] == value)
5153
}
5254
}
5355
}
5456

55-
@Test
57+
@Test(
58+
.bug("https://github.com/swiftlang/swift-package-manager/issues/8770"),
59+
)
5660
func threadSafeArrayStore() throws {
5761
for _ in 0 ..< 100 {
5862
let sync = DispatchGroup()
@@ -72,15 +76,18 @@ struct ConcurrencyHelpersTest {
7276
}
7377
}
7478

75-
try #require(sync.wait(timeout: .now() + .seconds(2)) == .success)
79+
80+
try #require(sync.wait(timeout: .now() + .seconds(300)) == .success)
7681
let expectedSorted = expected.sorted()
7782
let resultsSorted = cache.get().sorted()
7883
#expect(expectedSorted == resultsSorted)
7984
}
80-
}
85+
}
8186
}
8287

83-
@Test
88+
@Test(
89+
.bug("https://github.com/swiftlang/swift-package-manager/issues/8770"),
90+
)
8491
func threadSafeBox() throws {
8592
let queue = DispatchQueue(label: "ConcurrencyHelpersTest", attributes: .concurrent)
8693
for _ in 0 ..< 100 {
@@ -108,7 +115,7 @@ struct ConcurrencyHelpersTest {
108115
}
109116
}
110117

111-
try #require(sync.wait(timeout: .now() + .seconds(2)) == .success)
118+
try #require(sync.wait(timeout: .now() + .seconds(300)) == .success)
112119
#expect(cache.get() == winner)
113120
}
114121
}

Tests/BasicsTests/Environment/EnvironmentTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ struct EnvironmentTests {
148148
/// Important: This test is inherently race-prone, if it is proven to be
149149
/// flaky, it should run in a singled threaded environment/removed entirely.
150150
@Test(
151-
.disabled(if: isInCiEnvironment || isSelfHostedCiEnvironment, "This test can disrupt other tests running in parallel."),
151+
.disabled(if: isInCiEnvironment || CiEnvironment.runningInSelfHostedPipeline, "This test can disrupt other tests running in parallel."),
152152
)
153153
func makeCustomPathEnv() async throws {
154154
let customEnvironment: Environment = .current

0 commit comments

Comments
 (0)