|
9 | 9 | See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
10 | 10 | */
|
11 | 11 |
|
| 12 | +import class Foundation.FileManager |
12 | 13 | import class Foundation.ProcessInfo
|
13 | 14 | import Testing
|
14 | 15 |
|
15 | 16 | extension Trait where Self == Testing.ConditionTrait {
|
16 |
| - // Skip test if the host operating system does not match the running OS. |
| 17 | + /// Skip test if the host operating system does not match the running OS. |
17 | 18 | public static func requireHostOS(_ os: OperatingSystem, when condition: Bool = true) -> Self {
|
18 | 19 | enabled("This test requires a \(os) host OS.") {
|
19 | 20 | ProcessInfo.hostOperatingSystem == os && condition
|
20 | 21 | }
|
21 | 22 | }
|
22 | 23 |
|
23 |
| - // Skip test if the host operating system matches the running OS. |
| 24 | + /// Skip test if the host operating system matches the running OS. |
24 | 25 | public static func skipHostOS(_ os: OperatingSystem, _ comment: Comment? = nil) -> Self {
|
25 | 26 | disabled(comment ?? "This test cannot run on a \(os) host OS.") {
|
26 | 27 | ProcessInfo.hostOperatingSystem == os
|
27 | 28 | }
|
28 | 29 | }
|
29 | 30 |
|
30 |
| - // Skip test unconditionally |
| 31 | + /// Skip test unconditionally |
31 | 32 | public static func skip(_ comment: Comment? = nil) -> Self {
|
32 | 33 | disabled(comment ?? "Unconditional skip, a comment should be added for the reason") { true }
|
33 | 34 | }
|
34 | 35 |
|
35 |
| - // Skip test if the environment is self hosted. |
| 36 | + /// Skip test if the environment is self hosted. |
36 | 37 | public static func skipSwiftCISelfHosted(_ comment: Comment? = nil) -> Self {
|
37 | 38 | disabled(comment ?? "SwiftCI is self hosted") {
|
38 | 39 | ProcessInfo.processInfo.environment["SWIFTCI_IS_SELF_HOSTED"] != nil
|
39 | 40 | }
|
40 | 41 | }
|
41 | 42 |
|
42 |
| - // Skip test if built by XCode. |
| 43 | + /// Skip test if built by XCode. |
43 | 44 | public static func skipIfXcodeBuilt() -> Self {
|
44 |
| - disabled { |
| 45 | + disabled("Tests built by Xcode") { |
45 | 46 | #if Xcode
|
46 | 47 | true
|
47 | 48 | #else
|
48 | 49 | false
|
49 | 50 | #endif
|
50 | 51 | }
|
51 | 52 | }
|
| 53 | + |
| 54 | + /// Constructs a condition trait that causes a test to be disabled if the Foundation process spawning implementation |
| 55 | + /// is not using `posix_spawn_file_actions_addchdir`. |
| 56 | + public static var requireThreadSafeWorkingDirectory: Self { |
| 57 | + disabled("Thread-safe process working directory support is unavailable.") { |
| 58 | + // Amazon Linux 2 has glibc 2.26, and glibc 2.29 is needed for posix_spawn_file_actions_addchdir_np support |
| 59 | + FileManager.default.contents(atPath: "/etc/system-release") |
| 60 | + .map { String(decoding: $0, as: UTF8.self) == "Amazon Linux release 2 (Karoo)\n" } ?? false |
| 61 | + } |
| 62 | + } |
52 | 63 | }
|
0 commit comments