Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 1 addition & 1 deletion Tests/AppTests/AppTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ extension AppTestCase {
}


// FIXME: Move this once AppTestCase can be removed. These are helpers created during the transition to Swift Testing.
// 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.
extension Database {
func renderSQL(_ builder: SQLSelectBuilder) -> String {
renderSQL(builder.query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import Dependencies

extension Snapshotting where Value == String, Format == String {
public static let html = Snapshotting(pathExtension: "html", diffing: .lines)
public static let html = Snapshotting(pathExtension: "html", diffing: .lines)
}

extension Snapshotting where Value == () -> HTML, Format == String {
Expand All @@ -41,3 +41,8 @@
}
}
}


#warning("drop this")

Check warning on line 46 in Tests/AppTests/Helpers/Snapshotting+html.swift

View workflow job for this annotation

GitHub Actions / Test

drop this

Check warning on line 46 in Tests/AppTests/Helpers/Snapshotting+html.swift

View workflow job for this annotation

GitHub Actions / Test

drop this

Check warning on line 46 in Tests/AppTests/Helpers/Snapshotting+html.swift

View workflow job for this annotation

GitHub Actions / Test

drop this

Check warning on line 46 in Tests/AppTests/Helpers/Snapshotting+html.swift

View workflow job for this annotation

GitHub Actions / Test

drop this

Check warning on line 46 in Tests/AppTests/Helpers/Snapshotting+html.swift

View workflow job for this annotation

GitHub Actions / Test

drop this

Check warning on line 46 in Tests/AppTests/Helpers/Snapshotting+html.swift

View workflow job for this annotation

GitHub Actions / Test

drop this

Check warning on line 46 in Tests/AppTests/Helpers/Snapshotting+html.swift

View workflow job for this annotation

GitHub Actions / Test

drop this

Check warning on line 46 in Tests/AppTests/Helpers/Snapshotting+html.swift

View workflow job for this annotation

GitHub Actions / Test

drop this
extension Snapshotting: @unchecked Swift.Sendable {}
extension Diffing: @unchecked Swift.Sendable {}
File renamed without changes.
File renamed without changes.
35 changes: 19 additions & 16 deletions Tests/AppTests/SQLKitExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,30 @@
@testable import App

import SQLKit
import XCTest
import Testing


class SQLKitExtensionTests: AppTestCase {
@Suite struct SQLKitExtensionTests {

func test_OrderByGroup() throws {
let b = SQLOrderBy(SQLIdentifier("id"), .ascending)
.then(SQLIdentifier("foo"), .descending)
XCTAssertEqual(renderSQL(b), #""id" ASC, "foo" DESC"#)
@Test func OrderByGroup() async throws {
try await withApp { app in
let b = SQLOrderBy(SQLIdentifier("id"), .ascending)
.then(SQLIdentifier("foo"), .descending)
#expect(app.db.renderSQL(b) == #""id" ASC, "foo" DESC"#)
}
}

func test_OrderByGroup_complex() throws {
let packageName = SQLIdentifier("package_name")
let mergedTerms = SQLBind("a b")
let score = SQLIdentifier("score")

let orderBy = SQLOrderBy(eq(lower(packageName), mergedTerms), .descending)
.then(score, .descending)
.then(packageName, .ascending)
XCTAssertEqual(renderSQL(orderBy),
#"LOWER("package_name") = $1 DESC, "score" DESC, "package_name" ASC"#)
@Test func OrderByGroup_complex() async throws {
try await withApp { app in
let packageName = SQLIdentifier("package_name")
let mergedTerms = SQLBind("a b")
let score = SQLIdentifier("score")

let orderBy = SQLOrderBy(eq(lower(packageName), mergedTerms), .descending)
.then(score, .descending)
.then(packageName, .ascending)
#expect(app.db.renderSQL(orderBy) == #"LOWER("package_name") = $1 DESC, "score" DESC, "package_name" ASC"#)
}
}

}
85 changes: 36 additions & 49 deletions Tests/AppTests/ShellOutCommandExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,88 +14,75 @@

@testable import App

import XCTest
import ShellOut
import Testing


class ShellOutCommandExtensionTests: XCTestCase {
@Suite struct ShellOutCommandExtensionTests {

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

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

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

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

func test_gitLastCommitDate() throws {
XCTAssertEqual(ShellOutCommand.gitLastCommitDate.description,
#"git log -n1 --format=format:"%ct""#)
@Test func gitLastCommitDate() throws {
#expect(ShellOutCommand.gitLastCommitDate.description == #"git log -n1 --format=format:"%ct""#)
}

func test_gitReset() throws {
XCTAssertEqual(ShellOutCommand.gitReset(hard: true).description,
"git reset --hard")
XCTAssertEqual(ShellOutCommand.gitReset(hard: false).description,
"git reset")
@Test func gitReset() throws {
#expect(ShellOutCommand.gitReset(hard: true).description == "git reset --hard")
#expect(ShellOutCommand.gitReset(hard: false).description == "git reset")
}

func test_gitReset_branch() throws {
XCTAssertEqual(ShellOutCommand.gitReset(to: "foo", hard: true).description,
"git reset origin/foo --hard")
XCTAssertEqual(ShellOutCommand.gitReset(to: "foo", hard: false).description,
"git reset origin/foo")
@Test func gitReset_branch() throws {
#expect(ShellOutCommand.gitReset(to: "foo", hard: true).description == "git reset origin/foo --hard")
#expect(ShellOutCommand.gitReset(to: "foo", hard: false).description == "git reset origin/foo")
}

func test_gitRevisionInfo() throws {
@Test func gitRevisionInfo() throws {
let dash = "-"
XCTAssertEqual(
#expect(
ShellOutCommand
.gitRevisionInfo(reference: .tag(1, 2, 3), separator: dash).description,
#"git log -n1 --format=tformat:"%H\#(dash)%ct" 1.2.3"#
.gitRevisionInfo(reference: .tag(1, 2, 3), separator: dash).description == #"git log -n1 --format=tformat:"%H\#(dash)%ct" 1.2.3"#
)
XCTAssertEqual(
#expect(
ShellOutCommand
.gitRevisionInfo(reference: .branch("foo"), separator: dash).description,
#"git log -n1 --format=tformat:"%H\#(dash)%ct" foo"#
.gitRevisionInfo(reference: .branch("foo"), separator: dash).description == #"git log -n1 --format=tformat:"%H\#(dash)%ct" foo"#
)
XCTAssertEqual(
#expect(
ShellOutCommand
.gitRevisionInfo(reference: .branch("ba\nd"), separator: dash).description,
"git log -n1 --format=tformat:\"%H\(dash)%ct\" 'ba\nd'"
.gitRevisionInfo(reference: .branch("ba\nd"), separator: dash).description == "git log -n1 --format=tformat:\"%H\(dash)%ct\" 'ba\nd'"
)
}

func test_gitShowDate() throws {
XCTAssertEqual(ShellOutCommand.gitShowDate("abc").description,
#"git show -s --format=%ct abc"#)
@Test func gitShowDate() throws {
#expect(ShellOutCommand.gitShowDate("abc").description == #"git show -s --format=%ct abc"#)
}

func test_gitListTags() throws {
XCTAssertEqual(ShellOutCommand.gitListTags.description, "git tag")
@Test func gitListTags() throws {
#expect(ShellOutCommand.gitListTags.description == "git tag")
}

func test_quoting() throws {
XCTAssertEqual(
ShellOutCommand.gitReset(to: "foo ; rm *", hard: false).description,
"git reset origin/'foo ; rm *'"
@Test func quoting() throws {
#expect(
ShellOutCommand.gitReset(to: "foo ; rm *", hard: false).description == "git reset origin/'foo ; rm *'"
)
XCTAssertEqual(
ShellOutCommand.gitRevisionInfo(reference: .branch("foo ; rm *")).description,
#"git log -n1 --format=tformat:"%H-%ct" 'foo ; rm *'"#
#expect(
ShellOutCommand.gitRevisionInfo(reference: .branch("foo ; rm *")).description == #"git log -n1 --format=tformat:"%H-%ct" 'foo ; rm *'"#
)
XCTAssertEqual(
ShellOutCommand.gitShowDate("foo ; rm *").description,
#"git show -s --format=%ct 'foo ; rm *'"#
#expect(
ShellOutCommand.gitShowDate("foo ; rm *").description == #"git show -s --format=%ct 'foo ; rm *'"#
)
}

Expand Down
36 changes: 18 additions & 18 deletions Tests/AppTests/SignificantBuildsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

@testable import App

import XCTest
import Testing


class SignificantBuildsTests: XCTestCase {
@Suite struct SignificantBuildsTests {

func test_swiftVersionCompatibility() throws {
@Test func swiftVersionCompatibility() throws {
// setup
let sb = SignificantBuilds(buildInfo: [
(.v3, .linux, .ok),
Expand All @@ -28,13 +28,13 @@ class SignificantBuildsTests: XCTestCase {
])

// MUT
let res = try XCTUnwrap(sb.swiftVersionCompatibility().values)
let res = try #require(sb.swiftVersionCompatibility().values)

// validate
XCTAssertEqual(res.sorted(), [.v2, .v3])
#expect(res.sorted() == [.v2, .v3])
}

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

// validate
XCTAssertEqual(res, .pending)
#expect(res == .pending)
}

func test_swiftVersionCompatibility_partialPending() throws {
@Test func swiftVersionCompatibility_partialPending() throws {
// setup
let sb = SignificantBuilds(buildInfo: [
(.v3, .linux, .ok),
Expand All @@ -58,13 +58,13 @@ class SignificantBuildsTests: XCTestCase {
])

// MUT
let res = try XCTUnwrap(sb.swiftVersionCompatibility().values)
let res = try #require(sb.swiftVersionCompatibility().values)

// validate
XCTAssertEqual(res.sorted(), [ .v3 ])
#expect(res.sorted() == [ .v3 ])
}

func test_platformCompatibility() throws {
@Test func platformCompatibility() throws {
// setup
let sb = SignificantBuilds(buildInfo: [
(.v3, .linux, .ok),
Expand All @@ -73,13 +73,13 @@ class SignificantBuildsTests: XCTestCase {
])

// MUT
let res = try XCTUnwrap(sb.platformCompatibility().values)
let res = try #require(sb.platformCompatibility().values)

// validate
XCTAssertEqual(res.sorted(), [.macosSpm, .linux])
#expect(res.sorted() == [.macosSpm, .linux])
}

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

// validate
XCTAssertEqual(res, .pending)
#expect(res == .pending)
}

func test_platformCompatibility_partialPending() throws {
@Test func platformCompatibility_partialPending() throws {
// setup
let sb = SignificantBuilds(buildInfo: [
(.v3, .linux, .ok),
Expand All @@ -103,10 +103,10 @@ class SignificantBuildsTests: XCTestCase {
])

// MUT
let res = try XCTUnwrap(sb.platformCompatibility().values)
let res = try #require(sb.platformCompatibility().values)

// validate
XCTAssertEqual(res.sorted(), [ .linux ])
#expect(res.sorted() == [ .linux ])
}

}
Expand Down
Loading
Loading