feat: Updates dependencies and cli commands to be async.
This commit is contained in:
@@ -8,7 +8,7 @@ import TestSupport
|
||||
struct CliClientTests {
|
||||
|
||||
@Test(
|
||||
arguments: TestTarget.testCases
|
||||
arguments: TestArguments.testCases
|
||||
)
|
||||
func testBuild(target: String) async throws {
|
||||
try await run {
|
||||
@@ -27,11 +27,12 @@ struct CliClientTests {
|
||||
}
|
||||
|
||||
@Test(
|
||||
arguments: CliClient.BumpOption.allCases
|
||||
arguments: TestArguments.bumpCases
|
||||
)
|
||||
func bump(type: CliClient.BumpOption) async throws {
|
||||
func bump(type: CliClient.BumpOption, optional: Bool) async throws {
|
||||
let template = optional ? Template.optional("1.0.0") : Template.build("1.0.0")
|
||||
try await run {
|
||||
$0.fileClient.read = { _ in Template.optional("1.0.0") }
|
||||
$0.fileClient.read = { _ in template }
|
||||
} operation: {
|
||||
let client = CliClient.liveValue
|
||||
let output = try await client.bump(
|
||||
@@ -50,7 +51,7 @@ struct CliClientTests {
|
||||
}
|
||||
|
||||
@Test(
|
||||
arguments: TestTarget.testCases
|
||||
arguments: TestArguments.testCases
|
||||
)
|
||||
func generate(target: String) async throws {
|
||||
// let (stream, continuation) = AsyncStream<Data>.makeStream()
|
||||
@@ -68,7 +69,7 @@ struct CliClientTests {
|
||||
}
|
||||
|
||||
@Test(
|
||||
arguments: TestTarget.testCases
|
||||
arguments: TestArguments.testCases
|
||||
)
|
||||
func update(target: String) async throws {
|
||||
// let (stream, continuation) = AsyncStream<Data>.makeStream()
|
||||
@@ -101,6 +102,10 @@ struct CliClientTests {
|
||||
}
|
||||
}
|
||||
|
||||
enum TestTarget {
|
||||
enum TestArguments {
|
||||
static let testCases = ["bar", "Sources/bar", "/Sources/bar", "./Sources/bar"]
|
||||
static let bumpCases = CliClient.BumpOption.allCases.reduce(into: [(CliClient.BumpOption, Bool)]()) {
|
||||
$0.append(($1, true))
|
||||
$0.append(($1, false))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ final class GitVersionTests: XCTestCase {
|
||||
withDependencies({
|
||||
$0.logger.logLevel = .debug
|
||||
$0.logger = .liveValue
|
||||
$0.shellClient = .liveValue
|
||||
$0.asyncShellClient = .liveValue
|
||||
$0.gitVersionClient = .liveValue
|
||||
$0.fileClient = .liveValue
|
||||
}, operation: {
|
||||
@@ -26,67 +26,56 @@ final class GitVersionTests: XCTestCase {
|
||||
.cleanFilePath
|
||||
}
|
||||
|
||||
func test_overrides_work() throws {
|
||||
try withDependencies {
|
||||
$0.gitVersionClient.override(with: "blob")
|
||||
} operation: {
|
||||
@Dependency(\.gitVersionClient) var versionClient
|
||||
|
||||
let version = try versionClient.currentVersion()
|
||||
XCTAssertEqual(version, "blob")
|
||||
}
|
||||
}
|
||||
|
||||
func test_live() throws {
|
||||
func test_live() async throws {
|
||||
@Dependency(\.gitVersionClient) var versionClient: GitVersionClient
|
||||
|
||||
let version = try versionClient.currentVersion(in: gitDir)
|
||||
let version = try await versionClient.currentVersion(in: gitDir)
|
||||
print("VERSION: \(version)")
|
||||
// can't really have a predictable result for the live client.
|
||||
XCTAssertNotEqual(version, "blob")
|
||||
}
|
||||
|
||||
func test_commands() throws {
|
||||
@Dependency(\.shellClient) var shellClient: ShellClient
|
||||
// func test_commands() throws {
|
||||
// @Dependency(\.asyncShellClient) var shellClient: ShellClient
|
||||
//
|
||||
// XCTAssertNoThrow(
|
||||
// try shellClient.background(
|
||||
// .gitCurrentBranch(gitDirectory: gitDir),
|
||||
// trimmingCharactersIn: .whitespacesAndNewlines
|
||||
// )
|
||||
// )
|
||||
//
|
||||
// XCTAssertNoThrow(
|
||||
// try shellClient.background(
|
||||
// .gitCurrentSha(gitDirectory: gitDir),
|
||||
// trimmingCharactersIn: .whitespacesAndNewlines
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
|
||||
XCTAssertNoThrow(
|
||||
try shellClient.background(
|
||||
.gitCurrentBranch(gitDirectory: gitDir),
|
||||
trimmingCharactersIn: .whitespacesAndNewlines
|
||||
)
|
||||
)
|
||||
|
||||
XCTAssertNoThrow(
|
||||
try shellClient.background(
|
||||
.gitCurrentSha(gitDirectory: gitDir),
|
||||
trimmingCharactersIn: .whitespacesAndNewlines
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
func test_file_client() throws {
|
||||
try withTemporaryDirectory { tmpDir in
|
||||
func test_file_client() async throws {
|
||||
try await withTemporaryDirectory { tmpDir in
|
||||
@Dependency(\.fileClient) var fileClient
|
||||
|
||||
let filePath = tmpDir.appendingPathComponent("blob.txt")
|
||||
try fileClient.write(string: "Blob", to: filePath)
|
||||
try await fileClient.write(string: "Blob", to: filePath)
|
||||
|
||||
let contents = try fileClient.read(filePath)
|
||||
let contents = try await fileClient.read(filePath)
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
XCTAssertEqual(contents, "Blob")
|
||||
}
|
||||
}
|
||||
|
||||
func test_file_client_with_string_path() throws {
|
||||
try withTemporaryDirectory { tmpDir in
|
||||
func test_file_client_with_string_path() async throws {
|
||||
try await withTemporaryDirectory { tmpDir in
|
||||
@Dependency(\.fileClient) var fileClient
|
||||
|
||||
let filePath = tmpDir.appendingPathComponent("blob.txt")
|
||||
let fileString = filePath.cleanFilePath
|
||||
|
||||
try fileClient.write(string: "Blob", to: fileString)
|
||||
try await fileClient.write(string: "Blob", to: fileString)
|
||||
|
||||
let contents = try fileClient.read(fileString)
|
||||
let contents = try await fileClient.read(fileString)
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
XCTAssertEqual(contents, "Blob")
|
||||
|
||||
Reference in New Issue
Block a user