Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ced12d509e | |||
| ab5f589547 | |||
| 7ee071010d | |||
| 6a3b9b5141 |
@@ -7,7 +7,14 @@ struct Colibri: AsyncParsableCommand {
|
|||||||
|
|
||||||
static let configuration = CommandConfiguration(
|
static let configuration = CommandConfiguration(
|
||||||
abstract: "The utility to manage your Hummingbird apps",
|
abstract: "The utility to manage your Hummingbird apps",
|
||||||
subcommands: [Create.self]
|
subcommands: [
|
||||||
|
Build.self,
|
||||||
|
Clean.self,
|
||||||
|
Create.self,
|
||||||
|
Outdated.self,
|
||||||
|
Update.self
|
||||||
|
],
|
||||||
|
defaultSubcommand: Create.self
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import ArgumentParser
|
||||||
|
import ColibriLibrary
|
||||||
|
|
||||||
|
extension Colibri {
|
||||||
|
struct Build: AsyncParsableCommand {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
static let configuration = CommandConfiguration(
|
||||||
|
commandName: "build-project",
|
||||||
|
abstract: "Build a Hummingbird app",
|
||||||
|
helpNames: .shortAndLong,
|
||||||
|
aliases: ["build"]
|
||||||
|
)
|
||||||
|
|
||||||
|
@OptionGroup var options: Options
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
mutating func run() async throws {
|
||||||
|
let terminalService = TerminalService()
|
||||||
|
|
||||||
|
let buildProject = BuildProjectTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
try await buildProject(at: options.locationURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import ArgumentParser
|
||||||
|
import ColibriLibrary
|
||||||
|
|
||||||
|
extension Colibri {
|
||||||
|
struct Clean: AsyncParsableCommand {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
static let configuration = CommandConfiguration(
|
||||||
|
commandName: "clean-project",
|
||||||
|
abstract: "Clean a Hummingbird app",
|
||||||
|
helpNames: .shortAndLong,
|
||||||
|
aliases: ["clean"]
|
||||||
|
)
|
||||||
|
|
||||||
|
@OptionGroup var options: Options
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
mutating func run() async throws {
|
||||||
|
let terminalService = TerminalService()
|
||||||
|
|
||||||
|
let cleanProject = CleanProjectTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
try await cleanProject(at: options.locationURL,
|
||||||
|
shouldReset: options.reset,
|
||||||
|
purgeCache: options.purgeCache)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import ArgumentParser
|
||||||
|
import ColibriLibrary
|
||||||
|
|
||||||
|
extension Colibri {
|
||||||
|
struct Outdated: AsyncParsableCommand {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
static let configuration = CommandConfiguration(
|
||||||
|
commandName: "outdated-dependencies",
|
||||||
|
abstract: "Check for outdated package dependencies in a Hummingbird app",
|
||||||
|
helpNames: .shortAndLong,
|
||||||
|
aliases: ["outdated"]
|
||||||
|
)
|
||||||
|
|
||||||
|
@OptionGroup var options: Options
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
mutating func run() async throws {
|
||||||
|
let terminalService = TerminalService()
|
||||||
|
|
||||||
|
let updateDependencies = UpdateDependenciesTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
try await updateDependencies(at: options.locationURL, checkOutdated: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import ArgumentParser
|
||||||
|
import ColibriLibrary
|
||||||
|
|
||||||
|
extension Colibri {
|
||||||
|
struct Update: AsyncParsableCommand {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
static let configuration = CommandConfiguration(
|
||||||
|
commandName: "update-dependencies",
|
||||||
|
abstract: "Update package dependencies in a Hummingbird app",
|
||||||
|
helpNames: .shortAndLong,
|
||||||
|
aliases: ["update"]
|
||||||
|
)
|
||||||
|
|
||||||
|
@OptionGroup var options: Options
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
mutating func run() async throws {
|
||||||
|
let terminalService = TerminalService()
|
||||||
|
|
||||||
|
let updateDependencies = UpdateDependenciesTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
try await updateDependencies(at: options.locationURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import ArgumentParser
|
||||||
|
import ColibriLibrary
|
||||||
|
|
||||||
|
extension Colibri.Build {
|
||||||
|
struct Options: ParsableArguments, Locationable {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
@Option(name: .shortAndLong)
|
||||||
|
var location: String?
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import ArgumentParser
|
||||||
|
import ColibriLibrary
|
||||||
|
|
||||||
|
extension Colibri.Clean {
|
||||||
|
struct Options: ParsableArguments, Locationable {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
@Flag(name: .shortAndLong)
|
||||||
|
var reset: Bool = false
|
||||||
|
|
||||||
|
@Flag(name: .shortAndLong)
|
||||||
|
var purgeCache: Bool = false
|
||||||
|
|
||||||
|
@Option(name: .shortAndLong)
|
||||||
|
var location: String?
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import ArgumentParser
|
import ArgumentParser
|
||||||
import Foundation
|
import ColibriLibrary
|
||||||
|
|
||||||
extension Colibri.Create {
|
extension Colibri.Create {
|
||||||
struct Options: ParsableArguments {
|
struct Options: ParsableArguments, Locationable {
|
||||||
|
|
||||||
// MARK: Properties
|
// MARK: Properties
|
||||||
|
|
||||||
@@ -12,11 +12,5 @@ extension Colibri.Create {
|
|||||||
@Option(name: .shortAndLong)
|
@Option(name: .shortAndLong)
|
||||||
var location: String?
|
var location: String?
|
||||||
|
|
||||||
// MARK: Computed
|
|
||||||
|
|
||||||
var locationURL: URL? {
|
|
||||||
location.flatMap { URL(fileURLWithPath: $0) }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import ArgumentParser
|
||||||
|
import ColibriLibrary
|
||||||
|
|
||||||
|
extension Colibri.Outdated {
|
||||||
|
struct Options: ParsableArguments, Locationable {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
@Option(name: .shortAndLong)
|
||||||
|
var location: String?
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import ArgumentParser
|
||||||
|
import ColibriLibrary
|
||||||
|
|
||||||
|
extension Colibri.Update {
|
||||||
|
struct Options: ParsableArguments, Locationable {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
@Option(name: .shortAndLong)
|
||||||
|
var location: String?
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ extension URL {
|
|||||||
|
|
||||||
var pathString: String {
|
var pathString: String {
|
||||||
if #available(macOS 13.0, *) {
|
if #available(macOS 13.0, *) {
|
||||||
path(percentEncoded: true)
|
path(percentEncoded: false)
|
||||||
} else {
|
} else {
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
public protocol Locationable {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
var location: String? { get set }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Locationable+Properties
|
||||||
|
|
||||||
|
public extension Locationable {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
var locationURL: URL? {
|
||||||
|
location.flatMap { URL(fileURLWithPath: $0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
public struct BuildProjectTask {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
private let terminalService: TerminalServicing
|
||||||
|
|
||||||
|
// MARK: Initialisers
|
||||||
|
|
||||||
|
public init(terminalService: TerminalServicing) {
|
||||||
|
self.terminalService = terminalService
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
public func callAsFunction(at location: URL? = nil) async throws (TerminalServiceError) {
|
||||||
|
let executableURL = URL(at: "/usr/bin/swift")
|
||||||
|
|
||||||
|
var arguments: [String] = ["build"]
|
||||||
|
|
||||||
|
if let location {
|
||||||
|
arguments.append(contentsOf: ["--package-path", location.pathString])
|
||||||
|
}
|
||||||
|
|
||||||
|
try await terminalService.run(executableURL, arguments: arguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
public struct CleanProjectTask {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
private let terminalService: TerminalServicing
|
||||||
|
|
||||||
|
// MARK: Initialisers
|
||||||
|
|
||||||
|
public init(terminalService: TerminalServicing) {
|
||||||
|
self.terminalService = terminalService
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
public func callAsFunction(
|
||||||
|
at location: URL? = nil,
|
||||||
|
shouldReset: Bool = false,
|
||||||
|
purgeCache: Bool = false
|
||||||
|
) async throws (TerminalServiceError) {
|
||||||
|
let executableURL = URL(at: "/usr/bin/swift")
|
||||||
|
|
||||||
|
var arguments: [String] = ["package"]
|
||||||
|
|
||||||
|
if let location {
|
||||||
|
arguments.append(contentsOf: ["--package-path", location.pathString])
|
||||||
|
}
|
||||||
|
|
||||||
|
arguments.insert("clean", at: 1)
|
||||||
|
|
||||||
|
try await terminalService.run(executableURL, arguments: arguments)
|
||||||
|
|
||||||
|
if shouldReset {
|
||||||
|
arguments.remove(at: 1)
|
||||||
|
arguments.insert("reset", at: 1)
|
||||||
|
|
||||||
|
try await terminalService.run(executableURL, arguments: arguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
if purgeCache {
|
||||||
|
arguments.remove(at: 1)
|
||||||
|
arguments.insert("purge-cache", at: 1)
|
||||||
|
|
||||||
|
try await terminalService.run(executableURL, arguments: arguments)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
public struct UpdateDependenciesTask {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
private let terminalService: TerminalServicing
|
||||||
|
|
||||||
|
// MARK: Initialisers
|
||||||
|
|
||||||
|
public init(terminalService: TerminalServicing) {
|
||||||
|
self.terminalService = terminalService
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
public func callAsFunction(at location: URL? = nil, checkOutdated: Bool = false) async throws (TerminalServiceError) {
|
||||||
|
let executableURL = URL(at: "/usr/bin/swift")
|
||||||
|
|
||||||
|
var arguments: [String] = ["package", "update"]
|
||||||
|
|
||||||
|
if let location {
|
||||||
|
arguments.append(contentsOf: ["--package-path", location.pathString])
|
||||||
|
}
|
||||||
|
|
||||||
|
if checkOutdated {
|
||||||
|
arguments.append("--dry-run")
|
||||||
|
}
|
||||||
|
|
||||||
|
try await terminalService.run(executableURL, arguments: arguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -24,8 +24,8 @@ struct URL_ExtensionsTests {
|
|||||||
|
|
||||||
// MARK: Computed tests
|
// MARK: Computed tests
|
||||||
|
|
||||||
@Test(arguments: zip([URL.someFile, .dotFile, .tildeFile, .someURL],
|
@Test(arguments: zip([URL.someFile, .dotFile, .tildeFile, .someEncodedFile, .someURL],
|
||||||
[String.someFilePath, .dotPath, .tildePath, .empty]))
|
[String.someFilePath, .dotPath, .tildePath, .someEncodedPath, .empty]))
|
||||||
func pathString(
|
func pathString(
|
||||||
with url: URL,
|
with url: URL,
|
||||||
expects path: String
|
expects path: String
|
||||||
@@ -63,6 +63,7 @@ private extension String {
|
|||||||
static let dotPath = "."
|
static let dotPath = "."
|
||||||
static let empty = ""
|
static let empty = ""
|
||||||
static let tildePath = "~"
|
static let tildePath = "~"
|
||||||
|
static let someEncodedPath = "/sömê/páth/fîlê"
|
||||||
static let someFilePath = "/some/file/path"
|
static let someFilePath = "/some/file/path"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,6 +71,7 @@ private extension String {
|
|||||||
|
|
||||||
private extension URL {
|
private extension URL {
|
||||||
static let dotFile = URL(at: .dotPath)
|
static let dotFile = URL(at: .dotPath)
|
||||||
|
static let someEncodedFile = URL(at: "/sömê/páth/fîlê")
|
||||||
static let someFile = URL(at: .someFilePath)
|
static let someFile = URL(at: .someFilePath)
|
||||||
static let someURL = URL(string: "https://some.url.path")!
|
static let someURL = URL(string: "https://some.url.path")!
|
||||||
static let tildeFile = URL(at: .tildePath)
|
static let tildeFile = URL(at: .tildePath)
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import Foundation
|
||||||
|
import Testing
|
||||||
|
|
||||||
|
@testable import ColibriLibrary
|
||||||
|
|
||||||
|
struct BuildProjectTaskTests {
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||||
|
func task(at location: URL?) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceSpy()
|
||||||
|
let task = BuildProjectTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
try await task(at: location)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
let executableURL = URL(at: "/usr/bin/swift")
|
||||||
|
let arguments = if let location {
|
||||||
|
["build", "--package-path", location.pathString]
|
||||||
|
} else {
|
||||||
|
["build"]
|
||||||
|
}
|
||||||
|
|
||||||
|
#expect(terminalService.actions.count == 1)
|
||||||
|
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder], [TerminalServiceError.unexpected, .output(""), .captured("")])
|
||||||
|
func task(at location: URL?, throws error: TerminalServiceError) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceMock(action: .error(error))
|
||||||
|
let task = BuildProjectTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
// THEN
|
||||||
|
await #expect(throws: error) {
|
||||||
|
try await task(at: location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
import Foundation
|
||||||
|
import Testing
|
||||||
|
|
||||||
|
@testable import ColibriLibrary
|
||||||
|
|
||||||
|
struct CleanProjectTaskTests {
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||||
|
func task(at location: URL?) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceSpy()
|
||||||
|
let task = CleanProjectTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
try await task(at: location)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
let executableURL = URL(at: "/usr/bin/swift")
|
||||||
|
let arguments = if let location {
|
||||||
|
["package", "clean", "--package-path", location.pathString]
|
||||||
|
} else {
|
||||||
|
["package", "clean"]
|
||||||
|
}
|
||||||
|
|
||||||
|
#expect(terminalService.actions.count == 1)
|
||||||
|
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||||
|
func taskWithReset(at location: URL?) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceSpy()
|
||||||
|
let task = CleanProjectTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
try await task(at: location, shouldReset: true)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
let executableURL = URL(at: "/usr/bin/swift")
|
||||||
|
|
||||||
|
var arguments = if let location {
|
||||||
|
["package", "clean", "--package-path", location.pathString]
|
||||||
|
} else {
|
||||||
|
["package", "clean"]
|
||||||
|
}
|
||||||
|
|
||||||
|
#expect(terminalService.actions.count == 2)
|
||||||
|
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||||
|
|
||||||
|
arguments.remove(at: 1)
|
||||||
|
arguments.insert("reset", at: 1)
|
||||||
|
|
||||||
|
#expect(terminalService.actions[1] == .ran(executableURL, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||||
|
func taskWithPurgeCache(at location: URL?) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceSpy()
|
||||||
|
let task = CleanProjectTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
try await task(at: location, purgeCache: true)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
let executableURL = URL(at: "/usr/bin/swift")
|
||||||
|
|
||||||
|
var arguments = if let location {
|
||||||
|
["package", "clean", "--package-path", location.pathString]
|
||||||
|
} else {
|
||||||
|
["package", "clean"]
|
||||||
|
}
|
||||||
|
|
||||||
|
#expect(terminalService.actions.count == 2)
|
||||||
|
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||||
|
|
||||||
|
arguments.remove(at: 1)
|
||||||
|
arguments.insert("purge-cache", at: 1)
|
||||||
|
|
||||||
|
#expect(terminalService.actions[1] == .ran(executableURL, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||||
|
func taskWithResetAndPurgeCache(at location: URL?) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceSpy()
|
||||||
|
let task = CleanProjectTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
try await task(at: location, shouldReset: true, purgeCache: true)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
let executableURL = URL(at: "/usr/bin/swift")
|
||||||
|
|
||||||
|
var arguments = if let location {
|
||||||
|
["package", "clean", "--package-path", location.pathString]
|
||||||
|
} else {
|
||||||
|
["package", "clean"]
|
||||||
|
}
|
||||||
|
|
||||||
|
#expect(terminalService.actions.count == 3)
|
||||||
|
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||||
|
|
||||||
|
arguments.remove(at: 1)
|
||||||
|
arguments.insert("reset", at: 1)
|
||||||
|
|
||||||
|
#expect(terminalService.actions[1] == .ran(executableURL, arguments))
|
||||||
|
|
||||||
|
arguments.remove(at: 1)
|
||||||
|
arguments.insert("purge-cache", at: 1)
|
||||||
|
|
||||||
|
#expect(terminalService.actions[2] == .ran(executableURL, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder], [TerminalServiceError.unexpected, .output(""), .captured("")])
|
||||||
|
func task(at location: URL?, throws error: TerminalServiceError) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceMock(action: .error(error))
|
||||||
|
let task = CleanProjectTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
// THEN
|
||||||
|
await #expect(throws: error) {
|
||||||
|
try await task(at: location, shouldReset: .random(), purgeCache: .random())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import Foundation
|
||||||
|
import Testing
|
||||||
|
|
||||||
|
@testable import ColibriLibrary
|
||||||
|
|
||||||
|
struct UpdateDependenciesTaskTests {
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder], [false, true])
|
||||||
|
func task(at location: URL?, checkOutdated: Bool) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceSpy()
|
||||||
|
let task = UpdateDependenciesTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
try await task(at: location, checkOutdated: checkOutdated)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
let executableURL = URL(at: "/usr/bin/swift")
|
||||||
|
|
||||||
|
var arguments = if let location {
|
||||||
|
["package", "update", "--package-path", location.pathString]
|
||||||
|
} else {
|
||||||
|
["package", "update"]
|
||||||
|
}
|
||||||
|
|
||||||
|
if checkOutdated {
|
||||||
|
arguments.append("--dry-run")
|
||||||
|
}
|
||||||
|
|
||||||
|
#expect(terminalService.actions.count == 1)
|
||||||
|
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder], [TerminalServiceError.unexpected, .output(""), .captured("")])
|
||||||
|
func task(at location: URL?, throws error: TerminalServiceError) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceMock(action: .error(error))
|
||||||
|
let task = UpdateDependenciesTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
// THEN
|
||||||
|
await #expect(throws: error) {
|
||||||
|
try await task(at: location, checkOutdated: .random())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -19,6 +19,14 @@ final class TemplateServiceMock {
|
|||||||
self.spy = spy
|
self.spy = spy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init(
|
||||||
|
actions: [Action],
|
||||||
|
spy: TemplateServiceSpy? = nil
|
||||||
|
) {
|
||||||
|
self.actions = actions
|
||||||
|
self.spy = spy
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - TemplateServicing
|
// MARK: - TemplateServicing
|
||||||
|
|||||||
@@ -19,6 +19,14 @@ final class TerminalServiceMock {
|
|||||||
self.spy = spy
|
self.spy = spy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init(
|
||||||
|
actions: [Action],
|
||||||
|
spy: TerminalServiceSpy? = nil
|
||||||
|
) {
|
||||||
|
self.actions = actions
|
||||||
|
self.spy = spy
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - TerminalServicing
|
// MARK: - TerminalServicing
|
||||||
|
|||||||
Reference in New Issue
Block a user