Skip to content

Commit da115a6

Browse files
Merge pull request #3711 from SwiftPackageIndex/issue-3655-swift-testing-part-26
Issue 3655 swift testing part 26
2 parents 59061ca + db6fcfa commit da115a6

18 files changed

+555
-568
lines changed

Tests/AppTests/AppTestCase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ extension AppTestCase {
182182
}
183183

184184

185-
// FIXME: Move this once AppTestCase can be removed. These are helpers created during the transition to Swift Testing.
185+
// FIXME: Move this once AppTestCase can be removed. These are helpers created during the transition to Swift Testing. Also check if we can just create a PostgresDB object from scratch rather than using withApp and app.db for this at the call site. That does a whole migration + reset just to render the SQL needlessly.
186186
extension Database {
187187
func renderSQL(_ builder: SQLSelectBuilder) -> String {
188188
renderSQL(builder.query)
File renamed without changes.

Tests/AppTests/Snapshotting+html.swift renamed to Tests/AppTests/Helpers/Snapshotting+html.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import SnapshotTesting
1919
import Dependencies
2020

2121
extension Snapshotting where Value == String, Format == String {
22-
public static let html = Snapshotting(pathExtension: "html", diffing: .lines)
22+
public static let html = Snapshotting(pathExtension: "html", diffing: .lines)
2323
}
2424

2525
extension Snapshotting where Value == () -> HTML, Format == String {
@@ -41,3 +41,8 @@ extension Snapshotting where Value == () -> Node<HTML.BodyContext>, Format == St
4141
}
4242
}
4343
}
44+
45+
46+
#warning("drop this")
47+
extension Snapshotting: @unchecked Swift.Sendable {}
48+
extension Diffing: @unchecked Swift.Sendable {}

Tests/AppTests/SQLKitExtensionTests.swift

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,30 @@
1515
@testable import App
1616

1717
import SQLKit
18-
import XCTest
18+
import Testing
1919

2020

21-
class SQLKitExtensionTests: AppTestCase {
21+
@Suite struct SQLKitExtensionTests {
2222

23-
func test_OrderByGroup() throws {
24-
let b = SQLOrderBy(SQLIdentifier("id"), .ascending)
25-
.then(SQLIdentifier("foo"), .descending)
26-
XCTAssertEqual(renderSQL(b), #""id" ASC, "foo" DESC"#)
23+
@Test func OrderByGroup() async throws {
24+
try await withApp { app in
25+
let b = SQLOrderBy(SQLIdentifier("id"), .ascending)
26+
.then(SQLIdentifier("foo"), .descending)
27+
#expect(app.db.renderSQL(b) == #""id" ASC, "foo" DESC"#)
28+
}
2729
}
2830

29-
func test_OrderByGroup_complex() throws {
30-
let packageName = SQLIdentifier("package_name")
31-
let mergedTerms = SQLBind("a b")
32-
let score = SQLIdentifier("score")
33-
34-
let orderBy = SQLOrderBy(eq(lower(packageName), mergedTerms), .descending)
35-
.then(score, .descending)
36-
.then(packageName, .ascending)
37-
XCTAssertEqual(renderSQL(orderBy),
38-
#"LOWER("package_name") = $1 DESC, "score" DESC, "package_name" ASC"#)
31+
@Test func OrderByGroup_complex() async throws {
32+
try await withApp { app in
33+
let packageName = SQLIdentifier("package_name")
34+
let mergedTerms = SQLBind("a b")
35+
let score = SQLIdentifier("score")
36+
37+
let orderBy = SQLOrderBy(eq(lower(packageName), mergedTerms), .descending)
38+
.then(score, .descending)
39+
.then(packageName, .ascending)
40+
#expect(app.db.renderSQL(orderBy) == #"LOWER("package_name") = $1 DESC, "score" DESC, "package_name" ASC"#)
41+
}
3942
}
4043

4144
}

Tests/AppTests/ShellOutCommandExtensionTests.swift

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,88 +14,75 @@
1414

1515
@testable import App
1616

17-
import XCTest
1817
import ShellOut
18+
import Testing
1919

2020

21-
class ShellOutCommandExtensionTests: XCTestCase {
21+
@Suite struct ShellOutCommandExtensionTests {
2222

23-
func test_gitClean() throws {
24-
XCTAssertEqual(ShellOutCommand.gitClean.description, "git clean -fdx")
23+
@Test func gitClean() throws {
24+
#expect(ShellOutCommand.gitClean.description == "git clean -fdx")
2525
}
2626

27-
func test_gitCommitCount() throws {
28-
XCTAssertEqual(ShellOutCommand.gitCommitCount.description, "git rev-list --count HEAD")
27+
@Test func gitCommitCount() throws {
28+
#expect(ShellOutCommand.gitCommitCount.description == "git rev-list --count HEAD")
2929
}
3030

31-
func test_gitFetch() throws {
32-
XCTAssertEqual(ShellOutCommand.gitFetchAndPruneTags.description, "git fetch --tags --prune-tags --prune")
31+
@Test func gitFetch() throws {
32+
#expect(ShellOutCommand.gitFetchAndPruneTags.description == "git fetch --tags --prune-tags --prune")
3333
}
3434

35-
func test_gitFirstCommitDate() throws {
36-
XCTAssertEqual(ShellOutCommand.gitFirstCommitDate.description,
37-
#"git log --max-parents=0 -n1 --format=format:"%ct""#)
35+
@Test func gitFirstCommitDate() throws {
36+
#expect(ShellOutCommand.gitFirstCommitDate.description == #"git log --max-parents=0 -n1 --format=format:"%ct""#)
3837
}
3938

40-
func test_gitLastCommitDate() throws {
41-
XCTAssertEqual(ShellOutCommand.gitLastCommitDate.description,
42-
#"git log -n1 --format=format:"%ct""#)
39+
@Test func gitLastCommitDate() throws {
40+
#expect(ShellOutCommand.gitLastCommitDate.description == #"git log -n1 --format=format:"%ct""#)
4341
}
4442

45-
func test_gitReset() throws {
46-
XCTAssertEqual(ShellOutCommand.gitReset(hard: true).description,
47-
"git reset --hard")
48-
XCTAssertEqual(ShellOutCommand.gitReset(hard: false).description,
49-
"git reset")
43+
@Test func gitReset() throws {
44+
#expect(ShellOutCommand.gitReset(hard: true).description == "git reset --hard")
45+
#expect(ShellOutCommand.gitReset(hard: false).description == "git reset")
5046
}
5147

52-
func test_gitReset_branch() throws {
53-
XCTAssertEqual(ShellOutCommand.gitReset(to: "foo", hard: true).description,
54-
"git reset origin/foo --hard")
55-
XCTAssertEqual(ShellOutCommand.gitReset(to: "foo", hard: false).description,
56-
"git reset origin/foo")
48+
@Test func gitReset_branch() throws {
49+
#expect(ShellOutCommand.gitReset(to: "foo", hard: true).description == "git reset origin/foo --hard")
50+
#expect(ShellOutCommand.gitReset(to: "foo", hard: false).description == "git reset origin/foo")
5751
}
5852

59-
func test_gitRevisionInfo() throws {
53+
@Test func gitRevisionInfo() throws {
6054
let dash = "-"
61-
XCTAssertEqual(
55+
#expect(
6256
ShellOutCommand
63-
.gitRevisionInfo(reference: .tag(1, 2, 3), separator: dash).description,
64-
#"git log -n1 --format=tformat:"%H\#(dash)%ct" 1.2.3"#
57+
.gitRevisionInfo(reference: .tag(1, 2, 3), separator: dash).description == #"git log -n1 --format=tformat:"%H\#(dash)%ct" 1.2.3"#
6558
)
66-
XCTAssertEqual(
59+
#expect(
6760
ShellOutCommand
68-
.gitRevisionInfo(reference: .branch("foo"), separator: dash).description,
69-
#"git log -n1 --format=tformat:"%H\#(dash)%ct" foo"#
61+
.gitRevisionInfo(reference: .branch("foo"), separator: dash).description == #"git log -n1 --format=tformat:"%H\#(dash)%ct" foo"#
7062
)
71-
XCTAssertEqual(
63+
#expect(
7264
ShellOutCommand
73-
.gitRevisionInfo(reference: .branch("ba\nd"), separator: dash).description,
74-
"git log -n1 --format=tformat:\"%H\(dash)%ct\" 'ba\nd'"
65+
.gitRevisionInfo(reference: .branch("ba\nd"), separator: dash).description == "git log -n1 --format=tformat:\"%H\(dash)%ct\" 'ba\nd'"
7566
)
7667
}
7768

78-
func test_gitShowDate() throws {
79-
XCTAssertEqual(ShellOutCommand.gitShowDate("abc").description,
80-
#"git show -s --format=%ct abc"#)
69+
@Test func gitShowDate() throws {
70+
#expect(ShellOutCommand.gitShowDate("abc").description == #"git show -s --format=%ct abc"#)
8171
}
8272

83-
func test_gitListTags() throws {
84-
XCTAssertEqual(ShellOutCommand.gitListTags.description, "git tag")
73+
@Test func gitListTags() throws {
74+
#expect(ShellOutCommand.gitListTags.description == "git tag")
8575
}
8676

87-
func test_quoting() throws {
88-
XCTAssertEqual(
89-
ShellOutCommand.gitReset(to: "foo ; rm *", hard: false).description,
90-
"git reset origin/'foo ; rm *'"
77+
@Test func quoting() throws {
78+
#expect(
79+
ShellOutCommand.gitReset(to: "foo ; rm *", hard: false).description == "git reset origin/'foo ; rm *'"
9180
)
92-
XCTAssertEqual(
93-
ShellOutCommand.gitRevisionInfo(reference: .branch("foo ; rm *")).description,
94-
#"git log -n1 --format=tformat:"%H-%ct" 'foo ; rm *'"#
81+
#expect(
82+
ShellOutCommand.gitRevisionInfo(reference: .branch("foo ; rm *")).description == #"git log -n1 --format=tformat:"%H-%ct" 'foo ; rm *'"#
9583
)
96-
XCTAssertEqual(
97-
ShellOutCommand.gitShowDate("foo ; rm *").description,
98-
#"git show -s --format=%ct 'foo ; rm *'"#
84+
#expect(
85+
ShellOutCommand.gitShowDate("foo ; rm *").description == #"git show -s --format=%ct 'foo ; rm *'"#
9986
)
10087
}
10188

Tests/AppTests/SignificantBuildsTests.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
@testable import App
1616

17-
import XCTest
17+
import Testing
1818

1919

20-
class SignificantBuildsTests: XCTestCase {
20+
@Suite struct SignificantBuildsTests {
2121

22-
func test_swiftVersionCompatibility() throws {
22+
@Test func swiftVersionCompatibility() throws {
2323
// setup
2424
let sb = SignificantBuilds(buildInfo: [
2525
(.v3, .linux, .ok),
@@ -28,13 +28,13 @@ class SignificantBuildsTests: XCTestCase {
2828
])
2929

3030
// MUT
31-
let res = try XCTUnwrap(sb.swiftVersionCompatibility().values)
31+
let res = try #require(sb.swiftVersionCompatibility().values)
3232

3333
// validate
34-
XCTAssertEqual(res.sorted(), [.v2, .v3])
34+
#expect(res.sorted() == [.v2, .v3])
3535
}
3636

37-
func test_swiftVersionCompatibility_allPending() throws {
37+
@Test func swiftVersionCompatibility_allPending() throws {
3838
// setup
3939
let sb = SignificantBuilds(buildInfo: [
4040
(.v3, .linux, .triggered),
@@ -46,10 +46,10 @@ class SignificantBuildsTests: XCTestCase {
4646
let res = sb.swiftVersionCompatibility()
4747

4848
// validate
49-
XCTAssertEqual(res, .pending)
49+
#expect(res == .pending)
5050
}
5151

52-
func test_swiftVersionCompatibility_partialPending() throws {
52+
@Test func swiftVersionCompatibility_partialPending() throws {
5353
// setup
5454
let sb = SignificantBuilds(buildInfo: [
5555
(.v3, .linux, .ok),
@@ -58,13 +58,13 @@ class SignificantBuildsTests: XCTestCase {
5858
])
5959

6060
// MUT
61-
let res = try XCTUnwrap(sb.swiftVersionCompatibility().values)
61+
let res = try #require(sb.swiftVersionCompatibility().values)
6262

6363
// validate
64-
XCTAssertEqual(res.sorted(), [ .v3 ])
64+
#expect(res.sorted() == [ .v3 ])
6565
}
6666

67-
func test_platformCompatibility() throws {
67+
@Test func platformCompatibility() throws {
6868
// setup
6969
let sb = SignificantBuilds(buildInfo: [
7070
(.v3, .linux, .ok),
@@ -73,13 +73,13 @@ class SignificantBuildsTests: XCTestCase {
7373
])
7474

7575
// MUT
76-
let res = try XCTUnwrap(sb.platformCompatibility().values)
76+
let res = try #require(sb.platformCompatibility().values)
7777

7878
// validate
79-
XCTAssertEqual(res.sorted(), [.macosSpm, .linux])
79+
#expect(res.sorted() == [.macosSpm, .linux])
8080
}
8181

82-
func test_platformCompatibility_allPending() throws {
82+
@Test func platformCompatibility_allPending() throws {
8383
// setup
8484
let sb = SignificantBuilds(buildInfo: [
8585
(.v3, .linux, .triggered),
@@ -91,10 +91,10 @@ class SignificantBuildsTests: XCTestCase {
9191
let res = sb.platformCompatibility()
9292

9393
// validate
94-
XCTAssertEqual(res, .pending)
94+
#expect(res == .pending)
9595
}
9696

97-
func test_platformCompatibility_partialPending() throws {
97+
@Test func platformCompatibility_partialPending() throws {
9898
// setup
9999
let sb = SignificantBuilds(buildInfo: [
100100
(.v3, .linux, .ok),
@@ -103,10 +103,10 @@ class SignificantBuildsTests: XCTestCase {
103103
])
104104

105105
// MUT
106-
let res = try XCTUnwrap(sb.platformCompatibility().values)
106+
let res = try #require(sb.platformCompatibility().values)
107107

108108
// validate
109-
XCTAssertEqual(res.sorted(), [ .linux ])
109+
#expect(res.sorted() == [ .linux ])
110110
}
111111

112112
}

0 commit comments

Comments
 (0)