Skip to content

Commit de23f92

Browse files
Merge pull request #3715 from SwiftPackageIndex/issue-3655-swift-testing-post-conversion-cleanup
Issue 3655 swift testing post conversion cleanup
2 parents 730c993 + f12b0d4 commit de23f92

19 files changed

+87
-131
lines changed

Tests/AppTests/AnalyzerTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ import Vapor
738738

739739
do { // validate
740740
#expect(try await Version.query(on: app.db).count() == 1)
741-
let v = try await XCTUnwrapAsync(await Version.query(on: app.db).first())
741+
let v = try #require(await Version.query(on: app.db).first())
742742
#expect(v.docArchives == [.init(name: "foo", title: "Foo")])
743743
}
744744
}
@@ -763,7 +763,7 @@ import Vapor
763763

764764
do { // validate
765765
#expect(try await Version.query(on: app.db).count() == 2)
766-
let versions = try await XCTUnwrapAsync(await Version.query(on: app.db).sort(\.$commit).all())
766+
let versions = try #require(await Version.query(on: app.db).sort(\.$commit).all())
767767
#expect(versions[0].docArchives == [.init(name: "foo", title: "Foo")])
768768
#expect(versions[1].docArchives == nil)
769769
}
@@ -834,7 +834,7 @@ import Vapor
834834
packageInfo: .init(packageManifest: manifest, spiManifest: spiManifest))
835835

836836
// read back and validate
837-
let v = try await XCTUnwrapAsync(await Version.query(on: app.db).first())
837+
let v = try #require(await Version.query(on: app.db).first())
838838
#expect(v.packageName == "foo")
839839
#expect(v.resolvedDependencies?.map(\.packageName) == nil)
840840
#expect(v.swiftVersions == ["1", "2", "3.0.0"].asSwiftVersions)

Tests/AppTests/ApiTests.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ import Vapor
203203
#expect(v.resolvedDependencies == [.init(packageName: "packageName",
204204
repositoryURL: "repositoryURL")])
205205
// build failed, hence no package platform compatibility yet
206-
let p = try await XCTUnwrapAsync(try await Package.find(p.id, on: app.db))
206+
let p = try #require(try await Package.find(p.id, on: app.db))
207207
#expect(p.platformCompatibility == [])
208208
})
209209
}
@@ -237,7 +237,7 @@ import Vapor
237237
#expect(v.resolvedDependencies == [.init(packageName: "foo",
238238
repositoryURL: "http://foo/bar")])
239239
// build ok now -> package is macos compatible
240-
let p = try await XCTUnwrapAsync(try await Package.find(p.id, on: app.db))
240+
let p = try #require(try await Package.find(p.id, on: app.db))
241241
#expect(p.platformCompatibility == [.macOS])
242242
})
243243
}
@@ -262,7 +262,7 @@ import Vapor
262262
let builds = try await Build.query(on: app.db).all()
263263
#expect(Set(builds.map(\.id)) == Set([.id0, .id1]))
264264
// additional ios build ok -> package is also ios compatible
265-
let p = try await XCTUnwrapAsync(try await Package.find(p.id, on: app.db))
265+
let p = try #require(try await Package.find(p.id, on: app.db))
266266
#expect(p.platformCompatibility == [.iOS, .macOS])
267267
})
268268
}
@@ -376,10 +376,10 @@ import Vapor
376376
"api/versions/\(versionId)/build-report",
377377
headers: .applicationJSON,
378378
body: body,
379-
afterResponse: { res in
379+
afterResponse: { res async throws in
380380
// validation
381381
#expect(res.status == .unauthorized)
382-
try await XCTAssertEqualAsync(try await Build.query(on: db).count(), 0)
382+
#expect(try await Build.query(on: db).count() == 0)
383383
}
384384
)
385385

@@ -389,10 +389,10 @@ import Vapor
389389
"api/versions/\(versionId)/build-report",
390390
headers: .bearerApplicationJSON("wrong"),
391391
body: body,
392-
afterResponse: { res in
392+
afterResponse: { res async throws in
393393
// validation
394394
#expect(res.status == .unauthorized)
395-
try await XCTAssertEqualAsync(try await Build.query(on: db).count(), 0)
395+
#expect(try await Build.query(on: db).count() == 0)
396396
}
397397
)
398398

@@ -405,10 +405,10 @@ import Vapor
405405
"api/versions/\(versionId)/build-report",
406406
headers: .bearerApplicationJSON("secr3t"),
407407
body: body,
408-
afterResponse: { res in
408+
afterResponse: { res async throws in
409409
// validation
410410
#expect(res.status == .unauthorized)
411-
try await XCTAssertEqualAsync(try await Build.query(on: db).count(), 0)
411+
#expect(try await Build.query(on: db).count() == 0)
412412
}
413413
)
414414
}
@@ -491,7 +491,7 @@ import Vapor
491491
body: body,
492492
afterResponse: { res async throws in
493493
// validation
494-
let p = try await XCTUnwrapAsync(await Package.find(p.id, on: app.db))
494+
let p = try #require(await Package.find(p.id, on: app.db))
495495
#if os(Linux)
496496
if p.updatedAt == originalPackageUpdate {
497497
logWarning()
@@ -707,10 +707,10 @@ import Vapor
707707
"api/builds/\(buildId)/doc-report",
708708
headers: .applicationJSON,
709709
body: body,
710-
afterResponse: { res in
710+
afterResponse: { res async throws in
711711
// validation
712712
#expect(res.status == .unauthorized)
713-
try await XCTAssertEqualAsync(try await DocUpload.query(on: app.db).count(), 0)
713+
#expect(try await DocUpload.query(on: app.db).count() == 0)
714714
}
715715
)
716716

@@ -720,10 +720,10 @@ import Vapor
720720
"api/builds/\(buildId)/doc-report",
721721
headers: .bearerApplicationJSON("wrong"),
722722
body: body,
723-
afterResponse: { res in
723+
afterResponse: { res async throws in
724724
// validation
725725
#expect(res.status == .unauthorized)
726-
try await XCTAssertEqualAsync(try await DocUpload.query(on: app.db).count(), 0)
726+
#expect(try await DocUpload.query(on: app.db).count() == 0)
727727
}
728728
)
729729

@@ -736,10 +736,10 @@ import Vapor
736736
"api/builds/\(buildId)/doc-report",
737737
headers: .bearerApplicationJSON("secr3t"),
738738
body: body,
739-
afterResponse: { res in
739+
afterResponse: { res async throws in
740740
// validation
741741
#expect(res.status == .unauthorized)
742-
try await XCTAssertEqualAsync(try await DocUpload.query(on: app.db).count(), 0)
742+
#expect(try await DocUpload.query(on: app.db).count() == 0)
743743
}
744744
)
745745
}

Tests/AppTests/BuildTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import Vapor
4444
try await b.save(on: app.db)
4545

4646
do { // validate
47-
let b = try await XCTUnwrapAsync(try await Build.find(b.id, on: app.db))
47+
let b = try #require(try await Build.find(b.id, on: app.db))
4848
#expect(b.buildCommand == #"xcrun xcodebuild -scheme "Foo""#)
4949
#expect(b.jobUrl == "https://example.com/jobs/1")
5050
#expect(b.logUrl == "https://example.com/logs/1")
@@ -419,7 +419,7 @@ import Vapor
419419
try await UpdateBuildPendingToTriggered().prepare(on: app.db)
420420

421421
// validate
422-
let b = try await XCTUnwrapAsync(try await Build.find(.id0, on: app.db))
422+
let b = try #require(try await Build.find(.id0, on: app.db))
423423
#expect(b.status == .triggered)
424424
}
425425
}

Tests/AppTests/BuildTriggerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ import Vapor
13111311

13121312

13131313
private func updateBuildCreatedAt(id: Build.Id, addTimeInterval timeInterval: TimeInterval, on database: Database) async throws {
1314-
let b = try await XCTUnwrapAsync(await Build.find(id, on: database))
1314+
let b = try #require(await Build.find(id, on: database))
13151315
b.createdAt = b.createdAt?.addingTimeInterval(timeInterval)
13161316
try await b.save(on: database)
13171317
}

Tests/AppTests/ErrorReportingTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Testing
3030
try await Analyze.recordError(database: app.db,
3131
error: AppError.cacheDirectoryDoesNotExist(pkg.id, "path"))
3232
do {
33-
let pkg = try await XCTUnwrapAsync(try await Package.find(pkg.id, on: app.db))
33+
let pkg = try #require(try await Package.find(pkg.id, on: app.db))
3434
#expect(pkg.status == .cacheDirectoryDoesNotExist)
3535
#expect(pkg.processingStage == .analysis)
3636
}

Tests/AppTests/Helpers/Extensions.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,11 @@ import Foundation
1616

1717
@testable import App
1818
import Fluent
19-
import XCTest
2019

2120

2221
// MARK: - Useful extensions
2322

2423

25-
extension XCTestCase {
26-
var isRunningInCI: Bool {
27-
ProcessInfo.processInfo.environment.keys.contains("GITHUB_WORKFLOW")
28-
}
29-
30-
var runQueryPerformanceTests: Bool {
31-
ProcessInfo.processInfo.environment.keys.contains("RUN_QUERY_PERFORMANCE_TESTS")
32-
}
33-
34-
func assertEquals<Root, Value: Equatable>(_ values: [Root],
35-
_ keyPath: KeyPath<Root, Value>,
36-
_ expectations: [Value],
37-
file: StaticString = #filePath,
38-
line: UInt = #line) {
39-
XCTAssertEqual(values.map { $0[keyPath: keyPath] },
40-
expectations,
41-
"\(values.map { $0[keyPath: keyPath] }) not equal to \(expectations)",
42-
file: (file), line: line)
43-
}
44-
}
45-
46-
4724
extension Foundation.URL: Swift.ExpressibleByStringLiteral {
4825
public init(stringLiteral value: String) {
4926
precondition(!value.isEmpty, "cannot convert empty string to URL")

Tests/AppTests/Helpers/Snapshotting+html.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ import Plot
1818
import SnapshotTesting
1919
import Dependencies
2020

21+
2122
extension Snapshotting where Value == String, Format == String {
22-
public static let html = Snapshotting(pathExtension: "html", diffing: .lines)
23+
public static var html: Snapshotting<String, String> {
24+
Snapshotting(pathExtension: "html", diffing: .lines)
25+
}
2326
}
2427

28+
2529
extension Snapshotting where Value == () -> HTML, Format == String {
2630
public static var html: Snapshotting {
2731
Snapshotting<String, String>.init(pathExtension: "html", diffing: .lines).pullback { node in
@@ -34,15 +38,11 @@ extension Snapshotting where Value == () -> HTML, Format == String {
3438
}
3539
}
3640

41+
3742
extension Snapshotting where Value == () -> Node<HTML.BodyContext>, Format == String {
3843
public static var html: Snapshotting {
3944
Snapshotting<() -> HTML, String>.html.pullback { node in
4045
{ HTML(.body(node())) }
4146
}
4247
}
4348
}
44-
45-
46-
#warning("drop this")
47-
extension Snapshotting: @unchecked Swift.Sendable {}
48-
extension Diffing: @unchecked Swift.Sendable {}

Tests/AppTests/Helpers/XCTAsync.swift

Lines changed: 0 additions & 20 deletions
This file was deleted.

Tests/AppTests/JoinedTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import Testing
5252
try await Repository(package: p).save(on: app.db)
5353

5454
// MUT
55-
let jpr = try await XCTUnwrapAsync(try await JPR.query(on: app.db).first())
55+
let jpr = try #require(try await JPR.query(on: app.db).first())
5656

5757
// validate
5858
#expect(jpr.repository != nil)
@@ -74,7 +74,7 @@ import Testing
7474
let p = try await savePackage(on: app.db, "1")
7575
try await Repository(package: p).save(on: app.db)
7676

77-
let jpr = try await XCTUnwrapAsync(try await JPR.query(on: app.db).first())
77+
let jpr = try #require(try await JPR.query(on: app.db).first())
7878
let repo = try #require(jpr.repository)
7979
#expect(repo.name == nil)
8080
repo.name = "foo"
@@ -88,9 +88,9 @@ import Testing
8888
#expect(jpr.repository?.name == "foo")
8989
}
9090
do { // ensure value is persisted
91-
let r = try await XCTUnwrapAsync(try await Repository.query(on: app.db).first())
91+
let r = try #require(try await Repository.query(on: app.db).first())
9292
#expect(r.name == "foo")
93-
let reloadedJPR = try await XCTUnwrapAsync(try await JPR.query(on: app.db).first())
93+
let reloadedJPR = try #require(try await JPR.query(on: app.db).first())
9494
#expect(reloadedJPR.repository?.name == "foo")
9595
}
9696
}

Tests/AppTests/PackageCollectionTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ import Vapor
254254
swiftVersion: .v2).save(on: app.db)
255255
}
256256
}
257-
let v = try await XCTUnwrapAsync(try await VersionResult.query(on: app.db,filterBy: .urls(["1"])).first?.version)
257+
let v = try #require(try await VersionResult.query(on: app.db,filterBy: .urls(["1"])).first?.version)
258258

259259
// MUT
260260
let res = try #require(
@@ -310,7 +310,7 @@ import Vapor
310310
type: .library(.automatic),
311311
name: "product").save(on: app.db)
312312
}
313-
let result = try await XCTUnwrapAsync(
313+
let result = try #require(
314314
try await VersionResult.query(on: app.db, filterBy: .urls(["1"])).first
315315
)
316316
let group = VersionResultGroup(package: result.package,
@@ -682,7 +682,7 @@ import Vapor
682682
try await Version(package: p, latest: .release).save(on: app.db)
683683
try await Repository(package: p).save(on: app.db)
684684
}
685-
let res = try await XCTUnwrapAsync(
685+
let res = try #require(
686686
try await VersionResult.query(on: app.db, filterBy: .urls(["2"])).first
687687
)
688688
let group = VersionResultGroup(package: res.package,

0 commit comments

Comments
 (0)