1313import Basics
1414import XCBuildSupport
1515import XCTest
16+ import Testing
1617
1718public func PIFTester( _ pif: PIF . TopLevelObject , _ body: ( PIFWorkspaceTester ) throws -> Void ) throws {
1819 try body ( PIFWorkspaceTester ( workspace: pif. workspace) )
@@ -36,10 +37,16 @@ public final class PIFWorkspaceTester {
3637 _ guid: PIF . GUID ,
3738 file: StaticString = #file,
3839 line: UInt = #line,
40+ sourceLocation: SourceLocation = #_sourceLocation,
3941 body: ( PIFProjectTester ) -> Void
4042 ) throws {
4143 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+ }
4350 }
4451
4552 body ( try PIFProjectTester ( project: project, targetMap: targetMap) )
@@ -72,15 +79,26 @@ public final class PIFProjectTester {
7279 _ guid: PIF . GUID ,
7380 file: StaticString = #file,
7481 line: UInt = #line,
82+ sourceLocation: SourceLocation = #_sourceLocation,
7583 body: ( ( PIFTargetTester ) -> Void ) ? = nil
7684 ) {
7785 guard let baseTarget = baseTarget ( withGUID: guid) else {
7886 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+ }
8093 }
8194
8295 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+ }
84102 }
85103
86104 body ? ( PIFTargetTester ( target: target, targetMap: targetMap, fileMap: fileMap) )
@@ -90,26 +108,42 @@ public final class PIFProjectTester {
90108 _ guid: PIF . GUID ,
91109 file: StaticString = #file,
92110 line: UInt = #line,
111+ sourceLocation: SourceLocation = #_sourceLocation,
93112 body: ( ( PIFTargetTester ) -> Void ) ? = nil
94113 ) {
95114 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+ }
97120 }
98121 }
99122
100123 public func checkAggregateTarget(
101124 _ guid: PIF . GUID ,
102125 file: StaticString = #file,
103126 line: UInt = #line,
127+ sourceLocation: SourceLocation = #_sourceLocation,
104128 body: ( ( PIFAggregateTargetTester ) -> Void ) ? = nil
105129 ) {
106130 guard let baseTarget = baseTarget ( withGUID: guid) else {
107131 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+ }
109138 }
110139
111140 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+ }
113147 }
114148
115149 body ? ( PIFAggregateTargetTester ( target: target, targetMap: targetMap, fileMap: fileMap) )
@@ -119,11 +153,17 @@ public final class PIFProjectTester {
119153 _ name: String ,
120154 file: StaticString = #file,
121155 line: UInt = #line,
156+ sourceLocation: SourceLocation = #_sourceLocation,
122157 body: ( PIFBuildConfigurationTester ) -> Void
123158 ) {
124159 guard let configuration = buildConfiguration ( withName: name) else {
125160 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+ }
127167 }
128168
129169 body ( PIFBuildConfigurationTester ( buildConfiguration: configuration) )
@@ -185,10 +225,16 @@ public class PIFBaseTargetTester {
185225 _ name: String ,
186226 file: StaticString = #file,
187227 line: UInt = #line,
228+ sourceLocation: SourceLocation = #_sourceLocation,
188229 body: ( PIFBuildConfigurationTester ) -> Void
189230 ) {
190231 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+ }
192238 }
193239
194240 body ( PIFBuildConfigurationTester ( buildConfiguration: configuration) )
@@ -319,20 +365,42 @@ public final class PIFBuildSettingsTester {
319365 }
320366 }
321367
322- public func checkUncheckedSettings( file: StaticString = #file, line: UInt = #line) {
368+ public func checkUncheckedSettings( file: StaticString = #file, line: UInt = #line, sourceLocation : SourceLocation = #_sourceLocation ) {
323369 let uncheckedKeys =
324370 Array ( buildSettings. singleValueSettings. keys. map { $0. rawValue } ) +
325371 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+ }
327381
328382 for (platform, settings) in buildSettings. platformSpecificSingleValueSettings {
329383 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+ }
331392 }
332393
333394 for (platform, settings) in buildSettings. platformSpecificMultipleValueSettings {
334395 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+ }
336404 }
337405 }
338406}
0 commit comments