Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Tests/AppTests/AllTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
Expand Down
7 changes: 2 additions & 5 deletions Tests/AppTests/AnalyzeErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/AnalyzerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
60 changes: 28 additions & 32 deletions Tests/AppTests/GitLiveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)))
Expand All @@ -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
Expand All @@ -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)
}
}
10 changes: 6 additions & 4 deletions Tests/AppTests/Helpers/TestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/PackageCollectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions Tests/AppTests/ReferenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/WebpageSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down
Loading