diff --git a/Tests/AppTests/AllTests.swift b/Tests/AppTests/AllTests.swift index 1b10052c9..6800ebdb2 100644 --- a/Tests/AppTests/AllTests.swift +++ b/Tests/AppTests/AllTests.swift @@ -55,7 +55,6 @@ extension AllTests { @Suite struct ErrorPageModelTests { } @Suite struct ErrorReportingTests { } @Suite struct FundingLinkTests { } - @Suite struct GitLiveTests { } @Suite struct GitTests { } @Suite struct GithubTests { } @Suite struct GitlabBuilderTests { } diff --git a/Tests/AppTests/AnalyzeErrorTests.swift b/Tests/AppTests/AnalyzeErrorTests.swift index 1a7761d4b..9707b61d9 100644 --- a/Tests/AppTests/AnalyzeErrorTests.swift +++ b/Tests/AppTests/AnalyzeErrorTests.swift @@ -188,11 +188,8 @@ extension AllTests.AnalyzeErrorTests { extension AllTests.AnalyzeErrorTests { -#if compiler(>=6.1) -#warning("Move this into a trait on @Test") - // See https://forums.swift.org/t/converting-xctest-invoketest-to-swift-testing/77692/4 for details -#endif - var defaultDependencies: (inout DependencyValues) async throws -> Void { + // Cannot be a trait, because it references the member `socialPosts` + var defaultDependencies: @Sendable (inout DependencyValues) async throws -> Void { { $0.date.now = .t0 $0.environment.allowSocialPosts = { true } diff --git a/Tests/AppTests/AnalyzerTests.swift b/Tests/AppTests/AnalyzerTests.swift index 28db4db9a..dc4027425 100644 --- a/Tests/AppTests/AnalyzerTests.swift +++ b/Tests/AppTests/AnalyzerTests.swift @@ -763,7 +763,7 @@ extension AllTests.AnalyzerTests { do { // validate #expect(try await Version.query(on: app.db).count() == 2) - let versions = try #require(await Version.query(on: app.db).sort(\.$commit).all()) + let versions = try await Version.query(on: app.db).sort(\.$commit).all() #expect(versions[0].docArchives == [.init(name: "foo", title: "Foo")]) #expect(versions[1].docArchives == nil) } diff --git a/Tests/AppTests/GitLiveTests.swift b/Tests/AppTests/GitLiveTests.swift index 51773d08b..43fa34e3e 100644 --- a/Tests/AppTests/GitLiveTests.swift +++ b/Tests/AppTests/GitLiveTests.swift @@ -21,30 +21,45 @@ import ShellOut import Testing +private extension DependenciesProvider { + static var `default`: Self { + .init { + $0.logger = .noop + $0.shell = .liveValue + } + } +} + + +extension AllTests { + @Suite(.dependencies(.default)) struct GitLiveTests { } +} + + extension AllTests.GitLiveTests { @Test func commitCount() async throws { - try await withGitRepository(defaultDependencies) { path throws in + try await withGitRepository { path throws in #expect(try await Git.commitCount(at: path) == 57) } } @Test func firstCommitDate() async throws { - try await withGitRepository(defaultDependencies) { path throws in + try await withGitRepository { path throws in #expect(try await Git.firstCommitDate(at: path) == Date(timeIntervalSince1970: 1426918070)) // Sat, 21 March 2015 } } @Test func lastCommitDate() async throws { - try await withGitRepository(defaultDependencies) { path throws in + try await withGitRepository { path throws in #expect(try await Git.lastCommitDate(at: path) == Date(timeIntervalSince1970: 1554248253)) // Sat, 21 March 2015 } } @Test func getTags() async throws { - try await withGitRepository(defaultDependencies) { path throws in + try await withGitRepository { path throws in #expect( try await Git.getTags(at: path) == [ .tag(0,2,0), @@ -72,14 +87,14 @@ extension AllTests.GitLiveTests { } @Test func hasBranch() async throws { - try await withGitRepository(defaultDependencies) { path throws in + try await withGitRepository { path throws in #expect(try await Git.hasBranch(.branch("master"), at: path) == true) #expect(try await Git.hasBranch(.branch("main"), at: path) == false) } } @Test func revisionInfo() async throws { - try await withGitRepository(defaultDependencies) { path throws in + try await withGitRepository { path throws in #expect(try await Git.revisionInfo(.tag(0,5,2), at: path) == .init(commit: "178566b112afe6bef3770678f1bbab6e5c626993", date: .init(timeIntervalSince1970: 1554248253))) @@ -90,7 +105,7 @@ extension AllTests.GitLiveTests { } @Test func shortlog() async throws { - try await withGitRepository(defaultDependencies) { path throws in + try await withGitRepository { path throws in #expect(try await Git.shortlog(at: path) == """ 36\tNeil Pankey 21\tJacob Williams @@ -101,30 +116,11 @@ extension AllTests.GitLiveTests { } -private func withGitRepository( - _ updateValuesForOperation: (inout DependencyValues) async throws -> Void = { _ in }, - _ test: (_ zipFilePath: String) async throws -> Void -) async throws { - try await withDependencies(updateValuesForOperation) { - try await withTempDir { tempDir in - let fixtureFile = fixturesDirectory().appendingPathComponent("ErrNo.zip").path - try await ShellOut.shellOut(to: .init(command: "unzip", arguments: [fixtureFile]), at: tempDir) - let path = "\(tempDir)/ErrNo" - try await test(path) - } - } -} - - -extension AllTests.GitLiveTests { -#if compiler(>=6.1) -#warning("Move this into a trait on @Test") - // See https://forums.swift.org/t/converting-xctest-invoketest-to-swift-testing/77692/4 for details -#endif - var defaultDependencies: (inout DependencyValues) async throws -> Void { - { - $0.logger = .noop - $0.shell = .liveValue - } +private func withGitRepository(_ test: (_ zipFilePath: String) async throws -> Void) async throws { + try await withTempDir { tempDir in + let fixtureFile = fixturesDirectory().appendingPathComponent("ErrNo.zip").path + try await ShellOut.shellOut(to: .init(command: "unzip", arguments: [fixtureFile]), at: tempDir) + let path = "\(tempDir)/ErrNo" + try await test(path) } } diff --git a/Tests/AppTests/Helpers/TestSupport.swift b/Tests/AppTests/Helpers/TestSupport.swift index 670fdd48d..535419f6f 100644 --- a/Tests/AppTests/Helpers/TestSupport.swift +++ b/Tests/AppTests/Helpers/TestSupport.swift @@ -19,10 +19,12 @@ import Vapor import PostgresNIO -func withApp(_ setup: (Application) async throws -> Void = { _ in }, - _ updateValuesForOperation: (inout DependencyValues) async throws -> Void = { _ in }, - environment: Environment = .testing, - _ test: (Application) async throws -> Void) async throws { +func withApp( + environment: Environment = .testing, + _ setup: @Sendable (Application) async throws -> Void = { _ in }, + _ updateValuesForOperation: @Sendable (inout DependencyValues) async throws -> Void = { _ in }, + _ test: @Sendable (Application) async throws -> Void +) async throws { prepareDependencies { $0.logger = .noop } diff --git a/Tests/AppTests/PackageCollectionTests.swift b/Tests/AppTests/PackageCollectionTests.swift index bcd3ae165..03ef768d6 100644 --- a/Tests/AppTests/PackageCollectionTests.swift +++ b/Tests/AppTests/PackageCollectionTests.swift @@ -869,7 +869,7 @@ extension AllTests.PackageCollectionTests { // so we don't fail for that reason let revokedUrl = fixtureUrl(for: "revoked.cer") #expect(Foundation.FileManager.default.fileExists(atPath: revokedUrl.path)) - let revokedKey = try #require(try fixtureData(for: "revoked.pem")) + let revokedKey = try fixtureData(for: "revoked.pem") await withDependencies { $0.environment.collectionSigningCertificateChain = { diff --git a/Tests/AppTests/ReferenceTests.swift b/Tests/AppTests/ReferenceTests.swift index 586ddaed1..779d20738 100644 --- a/Tests/AppTests/ReferenceTests.swift +++ b/Tests/AppTests/ReferenceTests.swift @@ -71,11 +71,11 @@ extension AllTests.ReferenceTests { #expect(Reference.branch("foo-bar").pathEncoded == "foo-bar") #expect(Reference.tag(.init("1.2.3")!).pathEncoded == "1.2.3") do { - let s = try #require(SemanticVersion(1, 2, 3, "foo/bar")) + let s = SemanticVersion(1, 2, 3, "foo/bar") #expect(Reference.tag(s).pathEncoded == "1.2.3-foo-bar") } do { - let s = try #require(SemanticVersion(1, 2, 3, "foo/bar", "bar/baz")) + let s = SemanticVersion(1, 2, 3, "foo/bar", "bar/baz") #expect(Reference.tag(s).pathEncoded == "1.2.3-foo-bar+bar-baz") } } diff --git a/Tests/AppTests/WebpageSnapshotTests.swift b/Tests/AppTests/WebpageSnapshotTests.swift index 829d7510f..1d7366574 100644 --- a/Tests/AppTests/WebpageSnapshotTests.swift +++ b/Tests/AppTests/WebpageSnapshotTests.swift @@ -335,7 +335,7 @@ extension AllTests.WebpageSnapshotTests { } @Test func MarkdownPage_document_styling() throws { - let data = try #require(try fixtureData(for: "markdown-test.md")) + let data = try fixtureData(for: "markdown-test.md") let markdown = try #require(String(data: data, encoding: .utf8)) let html = MarkdownParser().parse(markdown).html let page = { MarkdownPage(path: "", html: html).document() }