Skip to content

Commit a351274

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 66ea47d commit a351274

File tree

12 files changed

+1017
-704
lines changed

12 files changed

+1017
-704
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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
switch self {
20+
case .native:
21+
return ["\(config)".lowercased()]
22+
case .swiftbuild:
23+
return ["Products" , "\(config)".capitalized]
24+
case .xcode:
25+
return ["apple", "Products" , "\(config)".capitalized]
26+
}
27+
}
28+
}
29+
30+
public var SupportedBuildSystemOnPlatform: [BuildSystemProvider.Kind] {
31+
#if os(macOS)
32+
BuildSystemProvider.Kind.allCases
33+
#else
34+
BuildSystemProvider.Kind.allCases.filter { $0 != .xcode }
35+
#endif
36+
}

Sources/_InternalTestSupport/SkippedTestSupport.swift

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,25 @@ 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+
}
7182
}
7283

84+
85+
extension Trait where Self == Testing.Bug {
86+
public static func SWBINTTODO(_ comment: Comment) -> Self {
87+
bug(nil, id: 0, comment)
88+
}
89+
}
7390
extension Tag {
7491
public enum TestSize {}
7592
public enum Feature {}
@@ -84,21 +101,23 @@ extension Tag.TestSize {
84101
extension Tag.Feature {
85102
public enum Command {}
86103
public enum PackageType {}
104+
105+
@Tag public static var CodeCoverage: Tag
87106
}
88107

89108
extension Tag.Feature.Command {
90-
@Tag public static var package: Tag
91-
@Tag public static var build: Tag
92-
@Tag public static var test: Tag
93-
@Tag public static var run: Tag
109+
@Tag public static var Package: Tag
110+
@Tag public static var Build: Tag
111+
@Tag public static var Test: Tag
112+
@Tag public static var Run: Tag
94113
}
95114

96115
extension Tag.Feature.PackageType {
97-
@Tag public static var library: Tag
98-
@Tag public static var executable: Tag
99-
@Tag public static var tool: Tag
100-
@Tag public static var plugin: Tag
101-
@Tag public static var buildToolPlugin: Tag
102-
@Tag public static var commandPlugin: Tag
103-
@Tag public static var macro: Tag
116+
@Tag public static var Library: Tag
117+
@Tag public static var Executable: Tag
118+
@Tag public static var Tool: Tag
119+
@Tag public static var Plugin: Tag
120+
@Tag public static var BuildToolPlugin: Tag
121+
@Tag public static var CommandPlugin: Tag
122+
@Tag public static var Macro: Tag
104123
}

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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ 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] = [],
@@ -304,7 +304,7 @@ public func executeSwiftBuild(
304304
public func executeSwiftRun(
305305
_ packagePath: AbsolutePath?,
306306
_ executable: String?,
307-
configuration: Configuration = .Debug,
307+
configuration: BuildConfiguration = .debug,
308308
extraArgs: [String] = [],
309309
Xcc: [String] = [],
310310
Xld: [String] = [],
@@ -329,7 +329,7 @@ public func executeSwiftRun(
329329
@discardableResult
330330
public func executeSwiftPackage(
331331
_ packagePath: AbsolutePath?,
332-
configuration: Configuration = .Debug,
332+
configuration: BuildConfiguration = .debug,
333333
extraArgs: [String] = [],
334334
Xcc: [String] = [],
335335
Xld: [String] = [],
@@ -351,7 +351,7 @@ public func executeSwiftPackage(
351351
@discardableResult
352352
public func executeSwiftPackageRegistry(
353353
_ packagePath: AbsolutePath?,
354-
configuration: Configuration = .Debug,
354+
configuration: BuildConfiguration = .debug,
355355
extraArgs: [String] = [],
356356
Xcc: [String] = [],
357357
Xld: [String] = [],
@@ -373,7 +373,7 @@ public func executeSwiftPackageRegistry(
373373
@discardableResult
374374
public func executeSwiftTest(
375375
_ packagePath: AbsolutePath?,
376-
configuration: Configuration = .Debug,
376+
configuration: BuildConfiguration = .debug,
377377
extraArgs: [String] = [],
378378
Xcc: [String] = [],
379379
Xld: [String] = [],
@@ -394,7 +394,7 @@ public func executeSwiftTest(
394394
}
395395

396396
private func swiftArgs(
397-
configuration: Configuration,
397+
configuration: BuildConfiguration,
398398
extraArgs: [String],
399399
Xcc: [String],
400400
Xld: [String],
@@ -403,9 +403,9 @@ private func swiftArgs(
403403
) -> [String] {
404404
var args = ["--configuration"]
405405
switch configuration {
406-
case .Debug:
406+
case .debug:
407407
args.append("debug")
408-
case .Release:
408+
case .release:
409409
args.append("release")
410410
}
411411

Tests/BasicsTests/ConcurrencyHelpersTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import Foundation
1515
import TSCTestSupport
1616
import Testing
1717

18+
@Suite(
19+
.serialized, // as suite may be flaky otherwise
20+
)
1821
struct ConcurrencyHelpersTest {
1922
let queue = DispatchQueue(label: "ConcurrencyHelpersTest", attributes: .concurrent)
2023

0 commit comments

Comments
 (0)