Skip to content

Commit bc975ca

Browse files
Merge pull request #3735 from SwiftPackageIndex/pull-forward
Pull forward some more changes from parallelise-tests-3
2 parents 68e9242 + d34da8f commit bc975ca

File tree

8 files changed

+41
-47
lines changed

8 files changed

+41
-47
lines changed

Tests/AppTests/AllTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ extension AllTests {
5555
@Suite struct ErrorPageModelTests { }
5656
@Suite struct ErrorReportingTests { }
5757
@Suite struct FundingLinkTests { }
58-
@Suite struct GitLiveTests { }
5958
@Suite struct GitTests { }
6059
@Suite struct GithubTests { }
6160
@Suite struct GitlabBuilderTests { }

Tests/AppTests/AnalyzeErrorTests.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,8 @@ extension AllTests.AnalyzeErrorTests {
188188

189189

190190
extension AllTests.AnalyzeErrorTests {
191-
#if compiler(>=6.1)
192-
#warning("Move this into a trait on @Test")
193-
// See https://forums.swift.org/t/converting-xctest-invoketest-to-swift-testing/77692/4 for details
194-
#endif
195-
var defaultDependencies: (inout DependencyValues) async throws -> Void {
191+
// Cannot be a trait, because it references the member `socialPosts`
192+
var defaultDependencies: @Sendable (inout DependencyValues) async throws -> Void {
196193
{
197194
$0.date.now = .t0
198195
$0.environment.allowSocialPosts = { true }

Tests/AppTests/AnalyzerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ extension AllTests.AnalyzerTests {
763763

764764
do { // validate
765765
#expect(try await Version.query(on: app.db).count() == 2)
766-
let versions = try #require(await Version.query(on: app.db).sort(\.$commit).all())
766+
let versions = try 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
}

Tests/AppTests/GitLiveTests.swift

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,45 @@ import ShellOut
2121
import Testing
2222

2323

24+
private extension DependenciesProvider {
25+
static var `default`: Self {
26+
.init {
27+
$0.logger = .noop
28+
$0.shell = .liveValue
29+
}
30+
}
31+
}
32+
33+
34+
extension AllTests {
35+
@Suite(.dependencies(.default)) struct GitLiveTests { }
36+
}
37+
38+
2439
extension AllTests.GitLiveTests {
2540

2641
@Test func commitCount() async throws {
27-
try await withGitRepository(defaultDependencies) { path throws in
42+
try await withGitRepository { path throws in
2843
#expect(try await Git.commitCount(at: path) == 57)
2944
}
3045
}
3146

3247
@Test func firstCommitDate() async throws {
33-
try await withGitRepository(defaultDependencies) { path throws in
48+
try await withGitRepository { path throws in
3449
#expect(try await Git.firstCommitDate(at: path)
3550
== Date(timeIntervalSince1970: 1426918070)) // Sat, 21 March 2015
3651
}
3752
}
3853

3954
@Test func lastCommitDate() async throws {
40-
try await withGitRepository(defaultDependencies) { path throws in
55+
try await withGitRepository { path throws in
4156
#expect(try await Git.lastCommitDate(at: path)
4257
== Date(timeIntervalSince1970: 1554248253)) // Sat, 21 March 2015
4358
}
4459
}
4560

4661
@Test func getTags() async throws {
47-
try await withGitRepository(defaultDependencies) { path throws in
62+
try await withGitRepository { path throws in
4863
#expect(
4964
try await Git.getTags(at: path) == [
5065
.tag(0,2,0),
@@ -72,14 +87,14 @@ extension AllTests.GitLiveTests {
7287
}
7388

7489
@Test func hasBranch() async throws {
75-
try await withGitRepository(defaultDependencies) { path throws in
90+
try await withGitRepository { path throws in
7691
#expect(try await Git.hasBranch(.branch("master"), at: path) == true)
7792
#expect(try await Git.hasBranch(.branch("main"), at: path) == false)
7893
}
7994
}
8095

8196
@Test func revisionInfo() async throws {
82-
try await withGitRepository(defaultDependencies) { path throws in
97+
try await withGitRepository { path throws in
8398
#expect(try await Git.revisionInfo(.tag(0,5,2), at: path)
8499
== .init(commit: "178566b112afe6bef3770678f1bbab6e5c626993",
85100
date: .init(timeIntervalSince1970: 1554248253)))
@@ -90,7 +105,7 @@ extension AllTests.GitLiveTests {
90105
}
91106

92107
@Test func shortlog() async throws {
93-
try await withGitRepository(defaultDependencies) { path throws in
108+
try await withGitRepository { path throws in
94109
#expect(try await Git.shortlog(at: path) == """
95110
36\tNeil Pankey
96111
21\tJacob Williams
@@ -101,30 +116,11 @@ extension AllTests.GitLiveTests {
101116
}
102117

103118

104-
private func withGitRepository(
105-
_ updateValuesForOperation: (inout DependencyValues) async throws -> Void = { _ in },
106-
_ test: (_ zipFilePath: String) async throws -> Void
107-
) async throws {
108-
try await withDependencies(updateValuesForOperation) {
109-
try await withTempDir { tempDir in
110-
let fixtureFile = fixturesDirectory().appendingPathComponent("ErrNo.zip").path
111-
try await ShellOut.shellOut(to: .init(command: "unzip", arguments: [fixtureFile]), at: tempDir)
112-
let path = "\(tempDir)/ErrNo"
113-
try await test(path)
114-
}
115-
}
116-
}
117-
118-
119-
extension AllTests.GitLiveTests {
120-
#if compiler(>=6.1)
121-
#warning("Move this into a trait on @Test")
122-
// See https://forums.swift.org/t/converting-xctest-invoketest-to-swift-testing/77692/4 for details
123-
#endif
124-
var defaultDependencies: (inout DependencyValues) async throws -> Void {
125-
{
126-
$0.logger = .noop
127-
$0.shell = .liveValue
128-
}
119+
private func withGitRepository(_ test: (_ zipFilePath: String) async throws -> Void) async throws {
120+
try await withTempDir { tempDir in
121+
let fixtureFile = fixturesDirectory().appendingPathComponent("ErrNo.zip").path
122+
try await ShellOut.shellOut(to: .init(command: "unzip", arguments: [fixtureFile]), at: tempDir)
123+
let path = "\(tempDir)/ErrNo"
124+
try await test(path)
129125
}
130126
}

Tests/AppTests/Helpers/TestSupport.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ import Vapor
1919
import PostgresNIO
2020

2121

22-
func withApp(_ setup: (Application) async throws -> Void = { _ in },
23-
_ updateValuesForOperation: (inout DependencyValues) async throws -> Void = { _ in },
24-
environment: Environment = .testing,
25-
_ test: (Application) async throws -> Void) async throws {
22+
func withApp(
23+
environment: Environment = .testing,
24+
_ setup: @Sendable (Application) async throws -> Void = { _ in },
25+
_ updateValuesForOperation: @Sendable (inout DependencyValues) async throws -> Void = { _ in },
26+
_ test: @Sendable (Application) async throws -> Void
27+
) async throws {
2628
prepareDependencies {
2729
$0.logger = .noop
2830
}

Tests/AppTests/PackageCollectionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ extension AllTests.PackageCollectionTests {
869869
// so we don't fail for that reason
870870
let revokedUrl = fixtureUrl(for: "revoked.cer")
871871
#expect(Foundation.FileManager.default.fileExists(atPath: revokedUrl.path))
872-
let revokedKey = try #require(try fixtureData(for: "revoked.pem"))
872+
let revokedKey = try fixtureData(for: "revoked.pem")
873873

874874
await withDependencies {
875875
$0.environment.collectionSigningCertificateChain = {

Tests/AppTests/ReferenceTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ extension AllTests.ReferenceTests {
7171
#expect(Reference.branch("foo-bar").pathEncoded == "foo-bar")
7272
#expect(Reference.tag(.init("1.2.3")!).pathEncoded == "1.2.3")
7373
do {
74-
let s = try #require(SemanticVersion(1, 2, 3, "foo/bar"))
74+
let s = SemanticVersion(1, 2, 3, "foo/bar")
7575
#expect(Reference.tag(s).pathEncoded == "1.2.3-foo-bar")
7676
}
7777
do {
78-
let s = try #require(SemanticVersion(1, 2, 3, "foo/bar", "bar/baz"))
78+
let s = SemanticVersion(1, 2, 3, "foo/bar", "bar/baz")
7979
#expect(Reference.tag(s).pathEncoded == "1.2.3-foo-bar+bar-baz")
8080
}
8181
}

Tests/AppTests/WebpageSnapshotTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ extension AllTests.WebpageSnapshotTests {
335335
}
336336

337337
@Test func MarkdownPage_document_styling() throws {
338-
let data = try #require(try fixtureData(for: "markdown-test.md"))
338+
let data = try fixtureData(for: "markdown-test.md")
339339
let markdown = try #require(String(data: data, encoding: .utf8))
340340
let html = MarkdownParser().parse(markdown).html
341341
let page = { MarkdownPage(path: "", html: html).document() }

0 commit comments

Comments
 (0)