13
13
import Basics
14
14
import XCBuildSupport
15
15
import XCTest
16
+ import Testing
16
17
17
18
public func PIFTester( _ pif: PIF . TopLevelObject , _ body: ( PIFWorkspaceTester ) throws -> Void ) throws {
18
19
try body ( PIFWorkspaceTester ( workspace: pif. workspace) )
@@ -36,10 +37,16 @@ public final class PIFWorkspaceTester {
36
37
_ guid: PIF . GUID ,
37
38
file: StaticString = #file,
38
39
line: UInt = #line,
40
+ sourceLocation: SourceLocation = #_sourceLocation,
39
41
body: ( PIFProjectTester ) -> Void
40
42
) throws {
41
43
guard let project = projectMap [ guid] else {
42
- return XCTFail ( " project \( guid) not found " , file: file, line: line)
44
+ if Test . current != nil {
45
+ Issue . record ( " project \( guid) not found " , sourceLocation: sourceLocation)
46
+ return
47
+ } else {
48
+ return XCTFail ( " project \( guid) not found " , file: file, line: line)
49
+ }
43
50
}
44
51
45
52
body ( try PIFProjectTester ( project: project, targetMap: targetMap) )
@@ -72,15 +79,26 @@ public final class PIFProjectTester {
72
79
_ guid: PIF . GUID ,
73
80
file: StaticString = #file,
74
81
line: UInt = #line,
82
+ sourceLocation: SourceLocation = #_sourceLocation,
75
83
body: ( ( PIFTargetTester ) -> Void ) ? = nil
76
84
) {
77
85
guard let baseTarget = baseTarget ( withGUID: guid) else {
78
86
let guids = project. targets. map { $0. guid } . joined ( separator: " , " )
79
- return XCTFail ( " target \( guid) not found among \( guids) " , file: file, line: line)
87
+ if Test . current != nil {
88
+ Issue . record ( " target \( guid) not found among \( guids) " , sourceLocation: sourceLocation)
89
+ return
90
+ } else {
91
+ return XCTFail ( " target \( guid) not found among \( guids) " , file: file, line: line)
92
+ }
80
93
}
81
94
82
95
guard let target = baseTarget as? PIF . Target else {
83
- return XCTFail ( " target \( guid) is not a standard target " , file: file, line: line)
96
+ if Test . current != nil {
97
+ Issue . record ( " target \( guid) is not a standard target " , sourceLocation: sourceLocation)
98
+ return
99
+ } else {
100
+ return XCTFail ( " target \( guid) is not a standard target " , file: file, line: line)
101
+ }
84
102
}
85
103
86
104
body ? ( PIFTargetTester ( target: target, targetMap: targetMap, fileMap: fileMap) )
@@ -90,26 +108,42 @@ public final class PIFProjectTester {
90
108
_ guid: PIF . GUID ,
91
109
file: StaticString = #file,
92
110
line: UInt = #line,
111
+ sourceLocation: SourceLocation = #_sourceLocation,
93
112
body: ( ( PIFTargetTester ) -> Void ) ? = nil
94
113
) {
95
114
if baseTarget ( withGUID: guid) != nil {
96
- XCTFail ( " target \( guid) found " , file: file, line: line)
115
+ if Test . current != nil {
116
+ Issue . record ( " target \( guid) found " , sourceLocation: sourceLocation)
117
+ } else {
118
+ XCTFail ( " target \( guid) found " , file: file, line: line)
119
+ }
97
120
}
98
121
}
99
122
100
123
public func checkAggregateTarget(
101
124
_ guid: PIF . GUID ,
102
125
file: StaticString = #file,
103
126
line: UInt = #line,
127
+ sourceLocation: SourceLocation = #_sourceLocation,
104
128
body: ( ( PIFAggregateTargetTester ) -> Void ) ? = nil
105
129
) {
106
130
guard let baseTarget = baseTarget ( withGUID: guid) else {
107
131
let guids = project. targets. map { $0. guid } . joined ( separator: " , " )
108
- return XCTFail ( " target \( guid) not found among \( guids) " , file: file, line: line)
132
+ if Test . current != nil {
133
+ Issue . record ( " target \( guid) not found among \( guids) " , sourceLocation: sourceLocation)
134
+ return
135
+ } else {
136
+ return XCTFail ( " target \( guid) not found among \( guids) " , file: file, line: line)
137
+ }
109
138
}
110
139
111
140
guard let target = baseTarget as? PIF . AggregateTarget else {
112
- return XCTFail ( " target \( guid) is not an aggregate target " , file: file, line: line)
141
+ if Test . current != nil {
142
+ Issue . record ( " target \( guid) is not an aggregate target " , sourceLocation: sourceLocation)
143
+ return
144
+ } else {
145
+ return XCTFail ( " target \( guid) is not an aggregate target " , file: file, line: line)
146
+ }
113
147
}
114
148
115
149
body ? ( PIFAggregateTargetTester ( target: target, targetMap: targetMap, fileMap: fileMap) )
@@ -119,11 +153,17 @@ public final class PIFProjectTester {
119
153
_ name: String ,
120
154
file: StaticString = #file,
121
155
line: UInt = #line,
156
+ sourceLocation: SourceLocation = #_sourceLocation,
122
157
body: ( PIFBuildConfigurationTester ) -> Void
123
158
) {
124
159
guard let configuration = buildConfiguration ( withName: name) else {
125
160
let names = project. buildConfigurations. map { $0. name } . joined ( separator: " , " )
126
- return XCTFail ( " build configuration \( name) not found among \( names) " , file: file, line: line)
161
+ if Test . current != nil {
162
+ Issue . record ( " build configuration \( name) not found among \( names) " , sourceLocation: sourceLocation)
163
+ return
164
+ } else {
165
+ return XCTFail ( " build configuration \( name) not found among \( names) " , file: file, line: line)
166
+ }
127
167
}
128
168
129
169
body ( PIFBuildConfigurationTester ( buildConfiguration: configuration) )
@@ -185,10 +225,16 @@ public class PIFBaseTargetTester {
185
225
_ name: String ,
186
226
file: StaticString = #file,
187
227
line: UInt = #line,
228
+ sourceLocation: SourceLocation = #_sourceLocation,
188
229
body: ( PIFBuildConfigurationTester ) -> Void
189
230
) {
190
231
guard let configuration = buildConfiguration ( withName: name) else {
191
- return XCTFail ( " build configuration \( name) not found " , file: file, line: line)
232
+ if Test . current != nil {
233
+ Issue . record ( " build configuration \( name) not found " , sourceLocation: #_sourceLocation)
234
+ return
235
+ } else {
236
+ return XCTFail ( " build configuration \( name) not found " , file: file, line: line)
237
+ }
192
238
}
193
239
194
240
body ( PIFBuildConfigurationTester ( buildConfiguration: configuration) )
@@ -319,20 +365,42 @@ public final class PIFBuildSettingsTester {
319
365
}
320
366
}
321
367
322
- public func checkUncheckedSettings( file: StaticString = #file, line: UInt = #line) {
368
+ public func checkUncheckedSettings( file: StaticString = #file, line: UInt = #line, sourceLocation : SourceLocation = #_sourceLocation ) {
323
369
let uncheckedKeys =
324
370
Array ( buildSettings. singleValueSettings. keys. map { $0. rawValue } ) +
325
371
Array( buildSettings. multipleValueSettings. keys. map { $0. rawValue } )
326
- XCTAssert ( uncheckedKeys. isEmpty, " settings are left unchecked: \( uncheckedKeys) " , file: file, line: line)
372
+ if Test . current != nil {
373
+ #expect(
374
+ uncheckedKeys. isEmpty,
375
+ " settings are left unchecked: \( uncheckedKeys) " ,
376
+ sourceLocation: sourceLocation,
377
+ )
378
+ } else {
379
+ XCTAssert ( uncheckedKeys. isEmpty, " settings are left unchecked: \( uncheckedKeys) " , file: file, line: line)
380
+ }
327
381
328
382
for (platform, settings) in buildSettings. platformSpecificSingleValueSettings {
329
383
let uncheckedKeys = Array ( settings. keys. map { $0. rawValue } )
330
- XCTAssert ( uncheckedKeys. isEmpty, " \( platform) settings are left unchecked: \( uncheckedKeys) " , file: file, line: line)
384
+ if Test . current != nil {
385
+ #expect(
386
+ uncheckedKeys. isEmpty, " \( platform) settings are left unchecked: \( uncheckedKeys) " ,
387
+ sourceLocation: sourceLocation,
388
+ )
389
+ } else {
390
+ XCTAssert ( uncheckedKeys. isEmpty, " \( platform) settings are left unchecked: \( uncheckedKeys) " , file: file, line: line)
391
+ }
331
392
}
332
393
333
394
for (platform, settings) in buildSettings. platformSpecificMultipleValueSettings {
334
395
let uncheckedKeys = Array ( settings. keys. map { $0. rawValue } )
335
- XCTAssert ( uncheckedKeys. isEmpty, " \( platform) settings are left unchecked: \( uncheckedKeys) " , file: file, line: line)
396
+ if Test . current != nil {
397
+ #expect(
398
+ uncheckedKeys. isEmpty, " \( platform) settings are left unchecked: \( uncheckedKeys) " ,
399
+ sourceLocation: sourceLocation,
400
+ )
401
+ } else {
402
+ XCTAssert ( uncheckedKeys. isEmpty, " \( platform) settings are left unchecked: \( uncheckedKeys) " , file: file, line: line)
403
+ }
336
404
}
337
405
}
338
406
}
0 commit comments