1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15+ import Foundation
16+
1517@testable import App
1618
1719import Plot
18- import XCTVapor
20+ import Testing
1921
2022
21- class BuildIndexModelTests : AppTestCase {
23+ @ Suite struct BuildIndexModelTests {
2224
23- func test_init_no_name ( ) async throws {
25+ @ Test func init_no_name ( ) async throws {
2426 // Tests behaviour when we're lacking data
25- // setup package without package name
26- let pkg = try await savePackage ( on: app. db, " 1 " . url)
27- try await Repository ( package : pkg,
28- defaultBranch: " main " ,
29- forks: 42 ,
30- license: . mit,
31- name: " bar " ,
32- owner: " foo " ,
33- stars: 17 ,
34- summary: " summary " ) . save ( on: app. db)
35- try await Version ( package : pkg, latest: . defaultBranch) . save ( on: app. db)
36- let ( pkgInfo, buildInfo) = try await PackageController . BuildsRoute
37- . query ( on: app. db, owner: " foo " , repository: " bar " )
38-
39- // MUT
40- let m = BuildIndex . Model ( packageInfo: pkgInfo, buildInfo: buildInfo)
41-
42- // validate
43- XCTAssertNotNil ( m)
27+ try await withApp { app in
28+ // setup package without package name
29+ let pkg = try await savePackage ( on: app. db, " 1 " . url)
30+ try await Repository ( package : pkg,
31+ defaultBranch: " main " ,
32+ forks: 42 ,
33+ license: . mit,
34+ name: " bar " ,
35+ owner: " foo " ,
36+ stars: 17 ,
37+ summary: " summary " ) . save ( on: app. db)
38+ try await Version ( package : pkg, latest: . defaultBranch) . save ( on: app. db)
39+ let ( pkgInfo, buildInfo) = try await PackageController . BuildsRoute
40+ . query ( on: app. db, owner: " foo " , repository: " bar " )
41+
42+ // MUT
43+ let m = BuildIndex . Model ( packageInfo: pkgInfo, buildInfo: buildInfo)
44+
45+ // validate
46+ #expect( m != nil )
47+ }
4448 }
4549
46- func test_completedBuildCount ( ) throws {
50+ @ Test func completedBuildCount ( ) throws {
4751 let m = BuildIndex . Model. mock
4852 // mock contains build for three Swift versions, 5.3, 5.4, 5.5
4953 // each has the same default setup:
@@ -58,15 +62,15 @@ class BuildIndexModelTests: AppTestCase {
5862 // -> 44 the tvos/5.5 build to test .timeout does not change the completed tally
5963 // -> 43 minus the watchos/5.5 build to test .infrastructureError
6064 // -> 43 completed in total
61- XCTAssertEqual ( m. completedBuildCount, 43 )
65+ #expect ( m. completedBuildCount == 43 )
6266 }
6367
64- func test_packageURL ( ) throws {
68+ @ Test func packageURL ( ) throws {
6569 let m = BuildIndex . Model. mock
66- XCTAssertEqual ( m. packageURL, " /foo/foobar " )
70+ #expect ( m. packageURL == " /foo/foobar " )
6771 }
6872
69- func test_buildMatrix ( ) throws {
73+ @ Test func buildMatrix ( ) throws {
7074 // setup
7175 let id = UUID ( )
7276 let stable : [ BuildInfo ] = [
@@ -92,31 +96,26 @@ class BuildIndexModelTests: AppTestCase {
9296 let matrix = model. buildMatrix
9397
9498 // validate
95- XCTAssertEqual ( matrix. values. keys. count, 27 )
96- XCTAssertEqual (
97- matrix. values [ . init( swiftVersion: . v3, platform: . iOS) ] ? . map ( \. column. label) ,
98- [ " 1.2.3 " , " 2.0.0-b1 " , " main " ]
99+ #expect( matrix. values. keys. count == 27 )
100+ #expect(
101+ matrix. values [ . init( swiftVersion: . v3, platform: . iOS) ] ? . map ( \. column. label) == [ " 1.2.3 " , " 2.0.0-b1 " , " main " ]
99102 )
100- XCTAssertEqual (
101- matrix. values [ . init( swiftVersion: . v3, platform: . iOS) ] ? . map ( \. value? . status) ,
102- . some( [ . ok, nil , nil ] )
103+ #expect(
104+ matrix. values [ . init( swiftVersion: . v3, platform: . iOS) ] ? . map ( \. value? . status) == . some( [ . ok, nil , nil ] )
103105 )
104- XCTAssertEqual (
106+ #expect (
105107 matrix. values [ . init( swiftVersion: . v2,
106- platform: . macosXcodebuild) ] ? . map ( \. value? . status) ,
107- [ . ok, nil , nil ]
108+ platform: . macosXcodebuild) ] ? . map ( \. value? . status) == [ . ok, nil , nil ]
108109 )
109- XCTAssertEqual (
110- matrix. values [ . init( swiftVersion: . v2, platform: . macosSpm) ] ? . map ( \. value? . status) ,
111- [ nil , nil , . failed]
110+ #expect(
111+ matrix. values [ . init( swiftVersion: . v2, platform: . macosSpm) ] ? . map ( \. value? . status) == [ nil , nil , . failed]
112112 )
113- XCTAssertEqual (
114- matrix. values [ . init( swiftVersion: . v1, platform: . tvOS) ] ? . map ( \. value? . status) ,
115- [ . ok, nil , . ok]
113+ #expect(
114+ matrix. values [ . init( swiftVersion: . v1, platform: . tvOS) ] ? . map ( \. value? . status) == [ . ok, nil , . ok]
116115 )
117116 }
118117
119- func test_buildMatrix_no_beta ( ) throws {
118+ @ Test func buildMatrix_no_beta ( ) throws {
120119 // Test BuildMatrix mapping, in particular absence of a beta version
121120 // setup
122121 let id = UUID ( )
@@ -142,48 +141,43 @@ class BuildIndexModelTests: AppTestCase {
142141 let matrix = model. buildMatrix
143142
144143 // validate
145- XCTAssertEqual ( matrix. values. keys. count, 27 )
146- XCTAssertEqual (
147- matrix. values [ . init( swiftVersion: . v3, platform: . iOS) ] ? . map ( \. column. label) ,
148- [ " 1.2.3 " , " main " ]
144+ #expect( matrix. values. keys. count == 27 )
145+ #expect(
146+ matrix. values [ . init( swiftVersion: . v3, platform: . iOS) ] ? . map ( \. column. label) == [ " 1.2.3 " , " main " ]
149147 )
150- XCTAssertEqual (
151- matrix. values [ . init( swiftVersion: . v3, platform: . iOS) ] ? . map ( \. value? . status) ,
152- [ . ok, nil ]
148+ #expect(
149+ matrix. values [ . init( swiftVersion: . v3, platform: . iOS) ] ? . map ( \. value? . status) == [ . ok, nil ]
153150 )
154- XCTAssertEqual (
151+ #expect (
155152 matrix. values [ . init( swiftVersion: . v2,
156- platform: . macosXcodebuild) ] ? . map ( \. value? . status) ,
157- [ . ok, nil ]
153+ platform: . macosXcodebuild) ] ? . map ( \. value? . status) == [ . ok, nil ]
158154 )
159- XCTAssertEqual (
155+ #expect (
160156 matrix. values [ . init( swiftVersion: . v2,
161- platform: . macosSpm) ] ? . map ( \. value? . status) ,
162- [ nil , . failed]
157+ platform: . macosSpm) ] ? . map ( \. value? . status) == [ nil , . failed]
163158 )
164- XCTAssertEqual (
165- matrix. values [ . init( swiftVersion: . v1, platform: . tvOS) ] ? . map ( \. value? . status) ,
166- [ . ok, . ok]
159+ #expect(
160+ matrix. values [ . init( swiftVersion: . v1, platform: . tvOS) ] ? . map ( \. value? . status) == [ . ok, . ok]
167161 )
168162 }
169163
170- func test_BuildCell ( ) throws {
164+ @ Test func render_BuildCell ( ) throws {
171165 let id = UUID ( )
172- XCTAssertEqual ( BuildCell ( " 1.2.3 " , . release, id, . ok, docStatus: nil ) . node. render ( ) , """
166+ #expect ( BuildCell ( " 1.2.3 " , . release, id, . ok, docStatus: nil ) . node. render ( ) == """
173167 <div class= " succeeded " ><a href= " /builds/ \( id. uuidString) " >Succeeded</a></div>
174168 """ )
175- XCTAssertEqual ( BuildCell ( " 1.2.3 " , . release, id, . ok, docStatus: . ok) . node. render ( ) , """
169+ #expect ( BuildCell ( " 1.2.3 " , . release, id, . ok, docStatus: . ok) . node. render ( ) == """
176170 <div class= " succeeded " ><a href= " /builds/ \( id. uuidString) " >Succeeded</a><span class= " generated-docs " title= " If successful, this build generated package documentation. " ></span></div>
177171 """ )
178- XCTAssertEqual ( BuildCell ( " 1.2.3 " , . release, id, . failed, docStatus: nil ) . node. render ( ) , """
172+ #expect ( BuildCell ( " 1.2.3 " , . release, id, . failed, docStatus: nil ) . node. render ( ) == """
179173 <div class= " failed " ><a href= " /builds/ \( id. uuidString) " >Failed</a></div>
180174 """ )
181- XCTAssertEqual ( BuildCell ( " 1.2.3 " , . release) . node. render ( ) , """
175+ #expect ( BuildCell ( " 1.2.3 " , . release) . node. render ( ) == """
182176 <div><span>Pending</span></div>
183177 """ )
184178 }
185179
186- func test_BuildItem ( ) throws {
180+ @ Test func render_BuildItem ( ) throws {
187181 // setup
188182 let id = UUID ( )
189183 let bi = BuildItem ( index: . init( swiftVersion: . v3, platform: . iOS) ,
@@ -213,10 +207,10 @@ class BuildIndexModelTests: AppTestCase {
213207 . div( . class( " failed " ) , . a( . href( " /builds/ \( id. uuidString) " ) , . text( " Failed " ) ) )
214208 )
215209 )
216- XCTAssertEqual ( node. render ( ) , expectation. render ( ) )
210+ #expect ( node. render ( ) == expectation. render ( ) )
217211 }
218212
219- func test_BuildItem_generatedDocs ( ) throws {
213+ @ Test func BuildItem_generatedDocs ( ) throws {
220214 // setup
221215 let id = UUID ( )
222216 let bi = BuildItem ( index: . init( swiftVersion: . v3, platform: . iOS) ,
@@ -250,7 +244,7 @@ class BuildIndexModelTests: AppTestCase {
250244 )
251245 )
252246 )
253- XCTAssertEqual ( node. render ( ) , expectation. render ( ) )
247+ #expect ( node. render ( ) == expectation. render ( ) )
254248 }
255249}
256250
0 commit comments