Skip to content

Commit 4fbb8a3

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 7c5b0bc commit 4fbb8a3

File tree

10 files changed

+1071
-689
lines changed

10 files changed

+1071
-689
lines changed

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)\(suffix)".capitalized]
33+
case .xcode:
34+
return ["apple", "Products" , "\(config)\(suffix)".capitalized]
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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,62 @@ extension Trait where Self == Testing.ConditionTrait {
6868
.map { String(decoding: $0, as: UTF8.self) == "Amazon Linux release 2 (Karoo)\n" } ?? false
6969
}
7070
}
71+
72+
/// Skips the test if running on a platform which lacks the ability for build tasks to set a working directory due to lack of requisite system API.
73+
///
74+
/// Presently, relevant platforms include Amazon Linux 2 and OpenBSD.
75+
///
76+
/// - seealso: https://github.com/swiftlang/swift-package-manager/issues/8560
77+
public static var disableIfWorkingDirectoryUnsupported: Self {
78+
disabled("https://github.com/swiftlang/swift-package-manager/issues/8560: Thread-safe process working directory support is unavailable on this platform.") {
79+
!workingDirectoryIsSupported()
80+
}
81+
}
82+
}
83+
84+
extension Trait where Self == Testing.Bug {
85+
public static func SWBINTTODO(_ comment: Comment) -> Self {
86+
bug(nil, id: 0, comment)
87+
}
88+
}
89+
extension Tag {
90+
public enum TestSize {}
91+
public enum Feature {}
92+
@Tag public static var UserWorkflow: Tag
93+
}
94+
95+
extension Tag.TestSize {
96+
@Tag public static var small: Tag
97+
@Tag public static var medium: Tag
98+
@Tag public static var large: Tag
99+
}
100+
101+
extension Tag.Feature {
102+
public enum Command {}
103+
public enum PackageType {}
104+
105+
@Tag public static var CodeCoverage: Tag
106+
@Tag public static var Resource: Tag
107+
@Tag public static var SpecialCharacters: Tag
108+
}
109+
110+
111+
extension Tag.Feature.Command {
112+
public enum Package {}
113+
@Tag public static var Build: Tag
114+
@Tag public static var Test: Tag
115+
@Tag public static var Run: Tag
116+
}
117+
118+
extension Tag.Feature.Command.Package {
119+
@Tag public static var Init: Tag
71120
}
121+
extension Tag.Feature.PackageType {
122+
@Tag public static var Library: Tag
123+
@Tag public static var Executable: Tag
124+
@Tag public static var Tool: Tag
125+
@Tag public static var Plugin: Tag
126+
@Tag public static var BuildToolPlugin: Tag
127+
@Tag public static var CommandPlugin: Tag
128+
@Tag public static var Macro: Tag
129+
}

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

@@ -139,7 +140,7 @@ package func XCTAssertAsyncNoThrow<T>(
139140

140141
public func XCTAssertBuilds(
141142
_ path: AbsolutePath,
142-
configurations: Set<Configuration> = [.Debug, .Release],
143+
configurations: Set<BuildConfiguration> = [.debug, .release],
143144
extraArgs: [String] = [],
144145
Xcc: [String] = [],
145146
Xld: [String] = [],
@@ -169,7 +170,7 @@ public func XCTAssertBuilds(
169170

170171
public func XCTAssertSwiftTest(
171172
_ path: AbsolutePath,
172-
configuration: Configuration = .Debug,
173+
configuration: BuildConfiguration = .debug,
173174
extraArgs: [String] = [],
174175
Xcc: [String] = [],
175176
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

0 commit comments

Comments
 (0)