feat: Integrates cli-client dependency into cli-version executable
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
@_spi(Internal) import CliVersion
|
||||
import Dependencies
|
||||
import Foundation
|
||||
import Logging
|
||||
import Testing
|
||||
import TestSupport
|
||||
|
||||
@@ -12,16 +13,8 @@ struct CliClientTests {
|
||||
)
|
||||
func testBuild(target: String) async throws {
|
||||
try await run {
|
||||
let client = CliClient.liveValue
|
||||
|
||||
let output = try await client.build(.init(
|
||||
gitDirectory: "/baz",
|
||||
dryRun: false,
|
||||
fileName: "foo",
|
||||
target: target,
|
||||
verbose: true
|
||||
))
|
||||
|
||||
@Dependency(\.cliClient) var client
|
||||
let output = try await client.build(.testOptions(target: target))
|
||||
#expect(output == "/baz/Sources/bar/foo")
|
||||
}
|
||||
}
|
||||
@@ -35,27 +28,21 @@ struct CliClientTests {
|
||||
$0.fileClient.fileExists = { _ in true }
|
||||
$0.fileClient.read = { @Sendable _ in template }
|
||||
} operation: {
|
||||
let client = CliClient.liveValue
|
||||
let output = try await client.bump(
|
||||
type,
|
||||
.init(
|
||||
gitDirectory: "/baz",
|
||||
dryRun: false,
|
||||
fileName: "foo",
|
||||
target: "bar",
|
||||
verbose: true
|
||||
)
|
||||
)
|
||||
@Dependency(\.cliClient) var client
|
||||
let output = try await client.bump(type, .testOptions())
|
||||
#expect(output == "/baz/Sources/bar/foo")
|
||||
} assert: { string, _ in
|
||||
|
||||
#expect(string != nil)
|
||||
let typeString = optional ? "String?" : "String"
|
||||
|
||||
switch type {
|
||||
case .major:
|
||||
#expect(string.contains("let VERSION: \(typeString) = \"2.0.0\""))
|
||||
#expect(string!.contains("let VERSION: \(typeString) = \"2.0.0\""))
|
||||
case .minor:
|
||||
#expect(string.contains("let VERSION: \(typeString) = \"1.1.0\""))
|
||||
#expect(string!.contains("let VERSION: \(typeString) = \"1.1.0\""))
|
||||
case .patch:
|
||||
#expect(string.contains("let VERSION: \(typeString) = \"1.0.1\""))
|
||||
#expect(string!.contains("let VERSION: \(typeString) = \"1.0.1\""))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,42 +51,34 @@ struct CliClientTests {
|
||||
arguments: TestArguments.testCases
|
||||
)
|
||||
func generate(target: String) async throws {
|
||||
// let (stream, continuation) = AsyncStream<Data>.makeStream()
|
||||
try await run {
|
||||
let client = CliClient.liveValue
|
||||
let output = try await client.generate(.init(
|
||||
gitDirectory: "/baz",
|
||||
dryRun: false,
|
||||
fileName: "foo",
|
||||
target: target,
|
||||
verbose: true
|
||||
))
|
||||
@Dependency(\.cliClient) var client
|
||||
let output = try await client.generate(.testOptions(target: target))
|
||||
#expect(output == "/baz/Sources/bar/foo")
|
||||
}
|
||||
}
|
||||
|
||||
@Test(
|
||||
arguments: TestArguments.testCases
|
||||
arguments: TestArguments.updateCases
|
||||
)
|
||||
func update(target: String) async throws {
|
||||
// let (stream, continuation) = AsyncStream<Data>.makeStream()
|
||||
func update(target: String, dryRun: Bool) async throws {
|
||||
try await run {
|
||||
let client = CliClient.liveValue
|
||||
let output = try await client.update(.init(
|
||||
gitDirectory: "/baz",
|
||||
dryRun: false,
|
||||
fileName: "foo",
|
||||
target: target,
|
||||
verbose: true
|
||||
))
|
||||
$0.fileClient.fileExists = { _ in false }
|
||||
} operation: {
|
||||
@Dependency(\.cliClient) var client
|
||||
let output = try await client.update(.testOptions(dryRun: dryRun, target: target))
|
||||
#expect(output == "/baz/Sources/bar/foo")
|
||||
} assert: { string, _ in
|
||||
if dryRun {
|
||||
#expect(string == nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func run(
|
||||
setupDependencies: @escaping (inout DependencyValues) -> Void = { _ in },
|
||||
operation: @Sendable @escaping () async throws -> Void,
|
||||
assert: @escaping (String, URL) -> Void = { _, _ in }
|
||||
assert: @escaping (String?, URL?) -> Void = { _, _ in }
|
||||
) async throws {
|
||||
let captured = CapturingWrite()
|
||||
|
||||
@@ -108,18 +87,17 @@ struct CliClientTests {
|
||||
$0.fileClient = .capturing(captured)
|
||||
$0.fileClient.fileExists = { _ in false }
|
||||
$0.gitVersionClient = .init { _, _ in "1.0.0" }
|
||||
$0.cliClient = .liveValue
|
||||
setupDependencies(&$0)
|
||||
} operation: {
|
||||
try await operation()
|
||||
}
|
||||
let data = await captured.data
|
||||
let url = await captured.url
|
||||
var string: String?
|
||||
|
||||
guard let data,
|
||||
let string = String(bytes: data, encoding: .utf8),
|
||||
let url
|
||||
else {
|
||||
throw TestError()
|
||||
if let data {
|
||||
string = String(bytes: data, encoding: .utf8)
|
||||
}
|
||||
|
||||
assert(string, url)
|
||||
@@ -132,6 +110,26 @@ enum TestArguments {
|
||||
$0.append(($1, true))
|
||||
$0.append(($1, false))
|
||||
}
|
||||
|
||||
static let updateCases = testCases.map { ($0, Bool.random()) }
|
||||
}
|
||||
|
||||
struct TestError: Error {}
|
||||
|
||||
extension CliClient.SharedOptions {
|
||||
static func testOptions(
|
||||
gitDirectory: String? = "/baz",
|
||||
dryRun: Bool = false,
|
||||
fileName: String = "foo",
|
||||
target: String = "bar",
|
||||
logLevel: Logger.Level = .trace
|
||||
) -> Self {
|
||||
.init(
|
||||
gitDirectory: gitDirectory,
|
||||
dryRun: dryRun,
|
||||
fileName: fileName,
|
||||
target: target,
|
||||
logLevel: logLevel
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user