Skip to content

Commit c0f4f8e

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. Related to: #8433 rdar://148248105
1 parent 8432220 commit c0f4f8e

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
+43
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+
}
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)