1
-
2
1
/*
3
2
This source file is part of the Swift.org open source project
4
3
@@ -15,7 +14,7 @@ import class PackageModel.UserToolchain
15
14
import DriverSupport
16
15
import Basics
17
16
import Testing
18
- import TSCclibc // for SPM_posix_spawn_file_actions_addchdir_np_supported
17
+ import TSCclibc // for SPM_posix_spawn_file_actions_addchdir_np_supported
19
18
20
19
extension Trait where Self == Testing . ConditionTrait {
21
20
/// Skip test if the host operating system does not match the running OS.
@@ -39,6 +38,72 @@ extension Trait where Self == Testing.ConditionTrait {
39
38
}
40
39
}
41
40
41
+ /// Enabled only if 'llvm-profdata' is available
42
+ public static var requiresLLVMProfData : Self {
43
+ disabled ( " skipping test because the `llvm-profdata` tool isn't available " ) {
44
+ let toolPath = try ( try ? UserToolchain . default) !. getLLVMProf ( )
45
+ return toolPath == nil
46
+ }
47
+ }
48
+
49
+ /// Enabled only if 'llvm-cov' is available
50
+ public static var requiresLLVMCov : Self {
51
+ disabled ( " skipping test because the `llvm-cov` tool isn't available " ) {
52
+ let toolPath = try ( try ? UserToolchain . default) !. getLLVMCov ( )
53
+ return toolPath == nil
54
+ }
55
+ }
56
+
57
+ /// Enabled only if 'swift-symbolgraph-extract' is available
58
+ public static var requiresSymbolgraphExtract : Self {
59
+ disabled ( " skipping test because the `swift-symbolgraph-extract` tools isn't available " ) {
60
+ let toolPath = try ( try ? UserToolchain . default) !. getSymbolGraphExtract ( )
61
+ return toolPath == nil
62
+ }
63
+ }
64
+
65
+ /// Enabled only is stdlib is supported by the toolchain
66
+ public static var requiresStdlibSupport : Self {
67
+ enabled ( " skipping because static stdlib is not supported by the toolchain " ) {
68
+ let args = try [
69
+ UserToolchain . default. swiftCompilerPath. pathString,
70
+ " -static-stdlib " , " -emit-executable " , " -o " , " /dev/null " , " - " ,
71
+ ]
72
+ let process = AsyncProcess ( arguments: args)
73
+ let stdin = try process. launch ( )
74
+ stdin. write ( sequence: " " . utf8)
75
+ try stdin. close ( )
76
+ let result = try await process. waitUntilExit ( )
77
+
78
+ return result. exitStatus == . terminated( code: 0 )
79
+ }
80
+ }
81
+
82
+ // Enabled if the toolchain has supported features
83
+ public static var supportsSupportedFeatures : Self {
84
+ enabled ( " skipping because test environment compiler doesn't support `-print-supported-features` " ) {
85
+ ( try ? UserToolchain . default) !. supportsSupportedFeatures
86
+ }
87
+ }
88
+
89
+ /// Skip of the executable is not available
90
+ public static func requires( executable: String ) -> Self {
91
+ let message : Comment ?
92
+ let isToolAvailable : Bool
93
+ do {
94
+ try _requiresTools ( executable)
95
+ isToolAvailable = true
96
+ message = nil
97
+ } catch ( let AsyncProcessResult . Error . nonZeroExit( result) ) {
98
+ isToolAvailable = false
99
+ message = " Skipping as tool \( executable) is not found in the path. ( \( result. description) ) "
100
+ } catch {
101
+ isToolAvailable = false
102
+ message = " Skipping. Unable to determine if tool exists. Error: \( error) "
103
+ }
104
+ return enabled ( if: isToolAvailable, message)
105
+ }
106
+
42
107
/// Enaled only if marcros are built as dylibs
43
108
public static var requiresBuildingMacrosAsDylibs : Self {
44
109
enabled ( " test is only supported if `BUILD_MACROS_AS_DYLIBS` is set " ) {
@@ -71,16 +136,16 @@ extension Trait where Self == Testing.ConditionTrait {
71
136
/// Ensure platform support working directory
72
137
public static var requiresWorkingDirectorySupport : Self {
73
138
enabled ( " working directory not supported on this platform " ) {
74
- #if !os(Windows)
75
- // needed for archiving
76
- if SPM_posix_spawn_file_actions_addchdir_np_supported ( ) {
139
+ #if !os(Windows)
140
+ // needed for archiving
141
+ if SPM_posix_spawn_file_actions_addchdir_np_supported ( ) {
142
+ return true
143
+ } else {
144
+ return false
145
+ }
146
+ #else
77
147
return true
78
- } else {
79
- return false
80
- }
81
- #else
82
- return true
83
- #endif
148
+ #endif
84
149
}
85
150
}
86
151
@@ -118,9 +183,9 @@ extension Trait where Self == Testing.ConditionTrait {
118
183
public static func skipIfXcodeBuilt( ) -> Self {
119
184
disabled ( " Tests built by Xcode " ) {
120
185
#if Xcode
121
- true
186
+ true
122
187
#else
123
- false
188
+ false
124
189
#endif
125
190
}
126
191
}
@@ -129,9 +194,9 @@ extension Trait where Self == Testing.ConditionTrait {
129
194
public static var requireSwift6_2 : Self {
130
195
enabled ( " This test requires Swift 6.2, or newer. " ) {
131
196
#if compiler(>=6.2)
132
- true
197
+ true
133
198
#else
134
- false
199
+ false
135
200
#endif
136
201
}
137
202
}
0 commit comments