Implemented the OutdatedDependenciesTask task in the library target.
This commit is contained in:
parent
0079820222
commit
7615e70758
31
Library/Sources/Public/Tasks/OutdatedDependenciesTask.swift
Normal file
31
Library/Sources/Public/Tasks/OutdatedDependenciesTask.swift
Normal file
@ -0,0 +1,31 @@
|
||||
import Foundation
|
||||
|
||||
public struct OutdatedDependenciesTask {
|
||||
|
||||
// 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] = ["package", "update"]
|
||||
|
||||
if let location {
|
||||
arguments.append(contentsOf: ["--package-path", location.pathString])
|
||||
}
|
||||
|
||||
arguments.append("--dry-run")
|
||||
|
||||
try await terminalService.run(executableURL, arguments: arguments)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
import Foundation
|
||||
import Testing
|
||||
|
||||
@testable import ColibriLibrary
|
||||
|
||||
struct OutdatedDependenciesTaskTests {
|
||||
|
||||
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||
func task(at location: URL?) async throws {
|
||||
// GIVEN
|
||||
let terminalService = TerminalServiceSpy()
|
||||
let task = OutdatedDependenciesTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
try await task(at: location)
|
||||
|
||||
// THEN
|
||||
let executableURL = URL(at: "/usr/bin/swift")
|
||||
let arguments = if let location {
|
||||
["package", "update", "--package-path", location.pathString, "--dry-run"]
|
||||
} else {
|
||||
["package", "update", "--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 = BuildProjectTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: error) {
|
||||
try await task(at: location)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user