Implemented the BuildProjectTask task in the library target.
This commit is contained in:
parent
a38c9e1d98
commit
4425a1ce73
29
Library/Sources/Public/Tasks/BuildProjectTask.swift
Normal file
29
Library/Sources/Public/Tasks/BuildProjectTask.swift
Normal file
@ -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)
|
||||
}
|
||||
|
||||
}
|
42
Test/Sources/Cases/Public/Tasks/BuildProjectTaskTests.swift
Normal file
42
Test/Sources/Cases/Public/Tasks/BuildProjectTaskTests.swift
Normal file
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -19,6 +19,14 @@ final class TemplateServiceMock {
|
||||
self.spy = spy
|
||||
}
|
||||
|
||||
init(
|
||||
actions: [Action],
|
||||
spy: TemplateServiceSpy? = nil
|
||||
) {
|
||||
self.actions = actions
|
||||
self.spy = spy
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - TemplateServicing
|
||||
|
@ -19,6 +19,14 @@ final class TerminalServiceMock {
|
||||
self.spy = spy
|
||||
}
|
||||
|
||||
init(
|
||||
actions: [Action],
|
||||
spy: TerminalServiceSpy? = nil
|
||||
) {
|
||||
self.actions = actions
|
||||
self.spy = spy
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - TerminalServicing
|
||||
|
Loading…
x
Reference in New Issue
Block a user