Skip to content

Commit b56cd7e

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 542279e commit b56cd7e

File tree

13 files changed

+1075
-694
lines changed

13 files changed

+1075
-694
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ public enum OperatingSystem: Hashable, Sendable {
1919
case unknown
2020
}
2121

22+
23+
public func workingDirectoryIsSupported() -> Bool {
24+
#if os(Linux)
25+
if FileManager.default.contents(atPath: "/etc/system-release").map({ String(decoding: $0, as: UTF8.self) == "Amazon Linux release 2 (Karoo)\n" }) ?? false {
26+
return false
27+
}
28+
#elseif os(OpenBSD)
29+
return false
30+
#endif
31+
return true
32+
33+
}
2234
extension ProcessInfo {
2335
public static var hostOperatingSystem: OperatingSystem {
2436
#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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
public var SupportedBuildSystemOnPlatform: [BuildSystemProvider.Kind] {
16+
#if os(macOS)
17+
BuildSystemProvider.Kind.allCases
18+
#else
19+
BuildSystemProvider.Kind.allCases.filter { $0 != .xcode }
20+
#endif
21+
}

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Basics
1515
import class Foundation.Bundle
1616
#endif
1717
import SPMBuildCore
18+
import enum PackageModel.BuildConfiguration
1819
import TSCTestSupport
1920
import XCTest
2021

@@ -144,7 +145,7 @@ package func XCTAssertAsyncNoThrow<T>(
144145

145146
public func XCTAssertBuilds(
146147
_ path: AbsolutePath,
147-
configurations: Set<Configuration> = [.Debug, .Release],
148+
configurations: Set<BuildConfiguration> = [.debug, .release],
148149
extraArgs: [String] = [],
149150
Xcc: [String] = [],
150151
Xld: [String] = [],
@@ -174,7 +175,7 @@ public func XCTAssertBuilds(
174175

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

Sources/_InternalTestSupport/misc.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,14 @@ public func getBuildSystemArgs(for buildSystem: BuildSystemProvider.Kind?) -> [S
281281
@discardableResult
282282
public func executeSwiftBuild(
283283
_ packagePath: AbsolutePath?,
284-
configuration: Configuration = .Debug,
284+
configuration: BuildConfiguration = .debug,
285285
extraArgs: [String] = [],
286286
Xcc: [String] = [],
287287
Xld: [String] = [],
288288
Xswiftc: [String] = [],
289289
env: Environment? = nil,
290-
buildSystem: BuildSystemProvider.Kind = .native
290+
buildSystem: BuildSystemProvider.Kind = .native,
291+
throwIfCommandFails: Bool = true,
291292
) async throws -> (stdout: String, stderr: String) {
292293
let args = swiftArgs(
293294
configuration: configuration,
@@ -297,14 +298,14 @@ public func executeSwiftBuild(
297298
Xswiftc: Xswiftc,
298299
buildSystem: buildSystem
299300
)
300-
return try await SwiftPM.Build.execute(args, packagePath: packagePath, env: env)
301+
return try await SwiftPM.Build.execute(args, packagePath: packagePath, env: env, throwIfCommandFails: throwIfCommandFails)
301302
}
302303

303304
@discardableResult
304305
public func executeSwiftRun(
305306
_ packagePath: AbsolutePath?,
306307
_ executable: String?,
307-
configuration: Configuration = .Debug,
308+
configuration: BuildConfiguration = .debug,
308309
extraArgs: [String] = [],
309310
Xcc: [String] = [],
310311
Xld: [String] = [],
@@ -329,7 +330,7 @@ public func executeSwiftRun(
329330
@discardableResult
330331
public func executeSwiftPackage(
331332
_ packagePath: AbsolutePath?,
332-
configuration: Configuration = .Debug,
333+
configuration: BuildConfiguration = .debug,
333334
extraArgs: [String] = [],
334335
Xcc: [String] = [],
335336
Xld: [String] = [],
@@ -351,7 +352,7 @@ public func executeSwiftPackage(
351352
@discardableResult
352353
public func executeSwiftPackageRegistry(
353354
_ packagePath: AbsolutePath?,
354-
configuration: Configuration = .Debug,
355+
configuration: BuildConfiguration = .debug,
355356
extraArgs: [String] = [],
356357
Xcc: [String] = [],
357358
Xld: [String] = [],
@@ -373,7 +374,7 @@ public func executeSwiftPackageRegistry(
373374
@discardableResult
374375
public func executeSwiftTest(
375376
_ packagePath: AbsolutePath?,
376-
configuration: Configuration = .Debug,
377+
configuration: BuildConfiguration = .debug,
377378
extraArgs: [String] = [],
378379
Xcc: [String] = [],
379380
Xld: [String] = [],
@@ -394,7 +395,7 @@ public func executeSwiftTest(
394395
}
395396

396397
private func swiftArgs(
397-
configuration: Configuration,
398+
configuration: BuildConfiguration,
398399
extraArgs: [String],
399400
Xcc: [String],
400401
Xld: [String],
@@ -403,9 +404,9 @@ private func swiftArgs(
403404
) -> [String] {
404405
var args = ["--configuration"]
405406
switch configuration {
406-
case .Debug:
407+
case .debug:
407408
args.append("debug")
408-
case .Release:
409+
case .release:
409410
args.append("release")
410411
}
411412

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
}

0 commit comments

Comments
 (0)