Skip to content

Commit ce35984

Browse files
committed
Copy helpers internally (#8467)
Until #8223 is fixed copy some helpers from `IntergrationTests/Source/IntegrationTests` to `Test/_InternalTestSupport` so we can re-use the functionality. Also, to workaround a Build preset issue, add a dependency on Swift Testing when we are building using local dependencies. Related to: #8433 rdar://148248105
1 parent 8432220 commit ce35984

File tree

3 files changed

+128
-5
lines changed

3 files changed

+128
-5
lines changed

Package.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ let swiftPMDataModelProduct = (
5555
]
5656
)
5757

58+
let usePackageDependencies = ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil
59+
60+
let swiftTestingDeps: [Target.Dependency]
61+
if usePackageDependencies {
62+
swiftTestingDeps = []
63+
} else {
64+
swiftTestingDeps = [.product(name: "Testing", package: "swift-testing")]
65+
}
66+
5867
/** The `libSwiftPM` set of interfaces to programmatically work with Swift
5968
packages. `libSwiftPM` includes all of the SwiftPM code except the
6069
command line tools, while `libSwiftPMDataModel` includes only the data model.
@@ -733,7 +742,7 @@ let package = Package(
733742
"XCBuildSupport",
734743
"SwiftBuildSupport",
735744
"_InternalTestSupport"
736-
],
745+
] + swiftTestingDeps,
737746
swiftSettings: [
738747
.unsafeFlags(["-static"]),
739748
]
@@ -753,7 +762,7 @@ let package = Package(
753762
.product(name: "TSCTestSupport", package: "swift-tools-support-core"),
754763
.product(name: "OrderedCollections", package: "swift-collections"),
755764
"Workspace",
756-
],
765+
] + swiftTestingDeps,
757766
swiftSettings: [
758767
.unsafeFlags(["-static"]),
759768
]
@@ -998,7 +1007,7 @@ func swiftSyntaxDependencies(_ names: [String]) -> [Target.Dependency] {
9981007
let relatedDependenciesBranch = "main"
9991008

10001009
if ProcessInfo.processInfo.environment["SWIFTPM_LLBUILD_FWK"] == nil {
1001-
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
1010+
if usePackageDependencies {
10021011
package.dependencies += [
10031012
.package(url: "https://github.com/swiftlang/swift-llbuild.git", branch: relatedDependenciesBranch),
10041013
]
@@ -1014,7 +1023,7 @@ if ProcessInfo.processInfo.environment["SWIFTPM_LLBUILD_FWK"] == nil {
10141023
]
10151024
}
10161025

1017-
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
1026+
if usePackageDependencies {
10181027
package.dependencies += [
10191028
.package(url: "https://github.com/swiftlang/swift-tools-support-core.git", branch: relatedDependenciesBranch),
10201029
// The 'swift-argument-parser' version declared here must match that
@@ -1040,6 +1049,7 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
10401049
.package(path: "../swift-collections"),
10411050
.package(path: "../swift-certificates"),
10421051
.package(path: "../swift-toolchain-sqlite"),
1052+
.package(path: "../swift-testing"),
10431053
]
10441054
}
10451055

@@ -1063,7 +1073,7 @@ if ProcessInfo.processInfo.environment["SWIFTPM_SWBUILD_FRAMEWORK"] == nil &&
10631073
.product(name: "SWBBuildService", package: "swift-build"),
10641074
]
10651075

1066-
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
1076+
if usePackageDependencies {
10671077
package.dependencies += [
10681078
.package(url: "https://github.com/swiftlang/swift-build.git", branch: relatedDependenciesBranch),
10691079
]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
public import Foundation
12+
13+
public enum OperatingSystem: Hashable, Sendable {
14+
case macOS
15+
case windows
16+
case linux
17+
case android
18+
case unknown
19+
}
20+
21+
extension ProcessInfo {
22+
#if os(macOS)
23+
public static let hostOperatingSystem = OperatingSystem.macOS
24+
#elseif os(Linux)
25+
public static let hostOperatingSystem = OperatingSystem.linux
26+
#elseif os(Windows)
27+
public static let hostOperatingSystem = OperatingSystem.windows
28+
#else
29+
public static let hostOperatingSystem = OperatingSystem.unknown
30+
#endif
31+
32+
#if os(Windows)
33+
public static let EOL = "\r\n"
34+
#else
35+
public static let EOL = "\n"
36+
#endif
37+
38+
#if os(Windows)
39+
public static let exeSuffix = ".exe"
40+
#else
41+
public static let exeSuffix = ""
42+
#endif
43+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
/*
3+
This source file is part of the Swift.org open source project
4+
5+
Copyright (c) 2014 - 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 Swift project authors
10+
*/
11+
12+
import class Foundation.FileManager
13+
import class Foundation.ProcessInfo
14+
import Testing
15+
16+
extension Trait where Self == Testing.ConditionTrait {
17+
/// Skip test if the host operating system does not match the running OS.
18+
public static func requireHostOS(_ os: OperatingSystem, when condition: Bool = true) -> Self {
19+
enabled("This test requires a \(os) host OS.") {
20+
ProcessInfo.hostOperatingSystem == os && condition
21+
}
22+
}
23+
24+
/// Skip test if the host operating system matches the running OS.
25+
public static func skipHostOS(_ os: OperatingSystem, _ comment: Comment? = nil) -> Self {
26+
disabled(comment ?? "This test cannot run on a \(os) host OS.") {
27+
ProcessInfo.hostOperatingSystem == os
28+
}
29+
}
30+
31+
/// Skip test unconditionally
32+
public static func skip(_ comment: Comment? = nil) -> Self {
33+
disabled(comment ?? "Unconditional skip, a comment should be added for the reason") { true }
34+
}
35+
36+
/// Skip test if the environment is self hosted.
37+
public static func skipSwiftCISelfHosted(_ comment: Comment? = nil) -> Self {
38+
disabled(comment ?? "SwiftCI is self hosted") {
39+
ProcessInfo.processInfo.environment["SWIFTCI_IS_SELF_HOSTED"] != nil
40+
}
41+
}
42+
43+
/// Skip test if the test environment has a restricted network access, i.e. cannot get to internet.
44+
public static func requireUnrestrictedNetworkAccess(_ comment: Comment? = nil) -> Self {
45+
disabled(comment ?? "CI Environment has restricted network access") {
46+
ProcessInfo.processInfo.environment["SWIFTCI_RESTRICTED_NETWORK_ACCESS"] != nil
47+
}
48+
}
49+
50+
/// Skip test if built by XCode.
51+
public static func skipIfXcodeBuilt() -> Self {
52+
disabled("Tests built by Xcode") {
53+
#if Xcode
54+
true
55+
#else
56+
false
57+
#endif
58+
}
59+
}
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+
}
70+
}

0 commit comments

Comments
 (0)