22//
33// This source file is part of the Swift.org open source project
44//
5- // Copyright (c) 2024 Apple Inc. and the Swift project authors
5+ // Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
66// Licensed under Apache License v2.0 with Runtime Library Exception
77//
88// See https://swift.org/LICENSE.txt for license information
99// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010//
1111//===----------------------------------------------------------------------===//
1212
13- import XCTest
14- @ testable import SwiftXcodeGen
13+ import Foundation
14+ import Testing
1515
16- fileprivate func expectEqual< T: Equatable > (
17- expected: [ T ] , actual: [ T ] , description: String ,
18- file: StaticString = #file, line: UInt = #line
19- ) {
20- guard expected. count == actual. count else {
21- XCTFail (
22- """
23- Expected \( expected. count) ' \( description) ', \
24- got \( actual. count) ( \( actual) )
25- """ ,
26- file: file, line: line
27- )
28- return
29- }
30- for (expected, actual) in zip ( expected, actual) {
31- XCTAssertEqual ( expected, actual, file: file, line: line)
32- }
33- }
34-
35- fileprivate func expectEqual< T, U: Equatable > (
36- _ expected: T , _ actual: T , _ kp: KeyPath < T , U > ,
37- file: StaticString = #file, line: UInt = #line
38- ) {
39- XCTAssertEqual (
40- expected [ keyPath: kp] , actual [ keyPath: kp] , file: file, line: line
41- )
42- }
16+ @testable import SwiftXcodeGen
4317
4418fileprivate func expectEqual< T, U: Equatable > (
45- _ expected: T , _ actual: T , _ kp: KeyPath < T , [ U ] > ,
46- file: StaticString = #file, line: UInt = #line
19+ _ expected: T ,
20+ _ actual: T ,
21+ _ kp: KeyPath < T , U > ,
22+ sourceLocation: SourceLocation = #_sourceLocation
4723) {
48- expectEqual (
49- expected: expected [ keyPath: kp] , actual : actual [ keyPath: kp] ,
50- description : " \( kp ) " , file : file , line : line
24+ #expect (
25+ expected [ keyPath: kp] == actual [ keyPath: kp] ,
26+ sourceLocation : sourceLocation
5127 )
5228}
5329
@@ -56,13 +32,20 @@ fileprivate func assertParse(
5632 bindings: [ String: String] = [ : ] ,
5733 rules: [ String: NinjaBuildFile . Rule] = [ : ] ,
5834 edges: [ NinjaBuildFile . BuildEdge] ,
59- file : StaticString = #file , line : UInt = #line
35+ sourceLocation : SourceLocation = #_sourceLocation
6036) {
6137 let filePath : AbsolutePath = " /tmp/build.ninja "
6238 let files : [ AbsolutePath : String ] = [
6339 filePath: str
6440 ]
65- assertParse ( filePath, in: files, bindings: bindings, rules: rules, edges: edges, file: file, line: line)
41+ assertParse (
42+ filePath,
43+ in: files,
44+ bindings: bindings,
45+ rules: rules,
46+ edges: edges,
47+ sourceLocation: sourceLocation
48+ )
6649}
6750
6851fileprivate func assertParse(
@@ -71,42 +54,43 @@ fileprivate func assertParse(
7154 bindings: [ String: String] = [ : ] ,
7255 rules: [ String: NinjaBuildFile . Rule] = [ : ] ,
7356 edges: [ NinjaBuildFile . BuildEdge] ,
74- file : StaticString = #file , line : UInt = #line
57+ sourceLocation : SourceLocation = #_sourceLocation
7558) {
7659 do {
7760 let buildFile = try NinjaParser . parse ( filePath: filePath, fileReader: { Data ( fileSystem [ $0] !. utf8) } )
7861 guard edges. count == buildFile. buildEdges. count else {
79- XCTFail (
62+ Issue . record (
8063 " Expected \( edges. count) edges, got \( buildFile. buildEdges. count) " ,
81- file : file , line : line
64+ sourceLocation : sourceLocation
8265 )
8366 return
8467 }
85- XCTAssertEqual (
86- bindings,
87- buildFile. bindings. values,
88- file: file, line: line
68+ #expect(
69+ bindings == buildFile. bindings. values,
70+ sourceLocation: sourceLocation
8971 )
90- XCTAssertEqual (
91- rules, buildFile. rules,
92- file : file , line : line
72+ #expect (
73+ rules == buildFile. rules,
74+ sourceLocation : sourceLocation
9375 )
9476 for (expected, actual) in zip ( edges, buildFile. buildEdges) {
95- expectEqual ( expected, actual, \. ruleName, file : file , line : line )
96- expectEqual ( expected, actual, \. inputs, file : file , line : line )
97- expectEqual ( expected, actual, \. outputs, file : file , line : line )
98- expectEqual ( expected, actual, \. dependencies, file : file , line : line )
99- expectEqual ( expected, actual, \. bindings, file : file , line : line )
77+ expectEqual ( expected, actual, \. ruleName, sourceLocation : sourceLocation )
78+ expectEqual ( expected, actual, \. inputs, sourceLocation : sourceLocation )
79+ expectEqual ( expected, actual, \. outputs, sourceLocation : sourceLocation )
80+ expectEqual ( expected, actual, \. dependencies, sourceLocation : sourceLocation )
81+ expectEqual ( expected, actual, \. bindings, sourceLocation : sourceLocation )
10082
101- XCTAssertEqual ( expected, actual, file : file , line : line )
83+ #expect ( expected == actual, sourceLocation : sourceLocation )
10284 }
10385 } catch {
104- XCTFail ( " \( error) " , file : file , line : line )
86+ Issue . record ( " \( error) " , sourceLocation : sourceLocation )
10587 }
10688}
10789
108- class NinjaParserTests : XCTestCase {
109- func testBuildEdge( ) throws {
90+ @Suite
91+ struct NinjaParserTests {
92+ @Test
93+ func buildEdge( ) throws {
11094 assertParse (
11195 """
11296 # ignore comment, build foo.o: a.swift | dep || orderdep
@@ -126,7 +110,8 @@ class NinjaParserTests: XCTestCase {
126110 )
127111 }
128112
129- func testRule( ) throws {
113+ @Test
114+ func rule( ) throws {
130115 assertParse (
131116 """
132117 rule SWIFTC
@@ -146,7 +131,8 @@ class NinjaParserTests: XCTestCase {
146131 )
147132 }
148133
149- func testInclude( ) throws {
134+ @Test
135+ func include( ) throws {
150136 let files : [ AbsolutePath : String ] = [
151137 " /tmp/build.ninja " : """
152138 include path/to/sub.ninja
@@ -180,7 +166,8 @@ class NinjaParserTests: XCTestCase {
180166 )
181167 }
182168
183- func testPhonyRule( ) throws {
169+ @Test
170+ func phonyRule( ) throws {
184171 assertParse (
185172 """
186173 build foo.swiftmodule : phony bar.swiftmodule
@@ -194,7 +181,8 @@ class NinjaParserTests: XCTestCase {
194181 )
195182 }
196183
197- func testBindings( ) throws {
184+ @Test
185+ func bindings( ) throws {
198186 assertParse (
199187 """
200188 x = y
@@ -252,7 +240,8 @@ class NinjaParserTests: XCTestCase {
252240 )
253241 }
254242
255- func testEscape( ) throws {
243+ @Test
244+ func escape( ) throws {
256245 for newline in [ " \n " , " \r " , " \r \n " ] {
257246 assertParse (
258247 """
0 commit comments