Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
f8a14e46ed | |||
888d00c1e8 | |||
fce5a23734 |
@ -11,6 +11,7 @@ struct Colibri: AsyncParsableCommand {
|
|||||||
Build.self,
|
Build.self,
|
||||||
Clean.self,
|
Clean.self,
|
||||||
Create.self,
|
Create.self,
|
||||||
|
Open.self,
|
||||||
Outdated.self,
|
Outdated.self,
|
||||||
Update.self
|
Update.self
|
||||||
],
|
],
|
||||||
|
@ -20,9 +20,9 @@ extension Colibri {
|
|||||||
mutating func run() async throws {
|
mutating func run() async throws {
|
||||||
let terminalService = TerminalService()
|
let terminalService = TerminalService()
|
||||||
|
|
||||||
let buildProject = BuildProjectTask(terminalService: terminalService)
|
let buildArtifact = BuildArtifactTask(terminalService: terminalService)
|
||||||
|
|
||||||
try await buildProject(at: options.locationURL)
|
try await buildArtifact(options.artifact, at: options.locationURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
29
Executable/Sources/Commands/OpenCommand.swift
Normal file
29
Executable/Sources/Commands/OpenCommand.swift
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import ArgumentParser
|
||||||
|
import ColibriLibrary
|
||||||
|
|
||||||
|
extension Colibri {
|
||||||
|
struct Open: AsyncParsableCommand {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
static let configuration = CommandConfiguration(
|
||||||
|
commandName: "open-project",
|
||||||
|
abstract: "Open a Hummingbird app",
|
||||||
|
helpNames: .shortAndLong,
|
||||||
|
aliases: ["open"]
|
||||||
|
)
|
||||||
|
|
||||||
|
@OptionGroup var options: Options
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
mutating func run() async throws {
|
||||||
|
let terminalService = TerminalService()
|
||||||
|
|
||||||
|
let openProject = OpenProjectTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
try await openProject(with: options.ide, at: options.locationURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
7
Executable/Sources/Definitions/Conformances.swift
Normal file
7
Executable/Sources/Definitions/Conformances.swift
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import ArgumentParser
|
||||||
|
import ColibriLibrary
|
||||||
|
|
||||||
|
// MARK: - ExpressibleByArgument
|
||||||
|
|
||||||
|
extension Artifact: ExpressibleByArgument {}
|
||||||
|
extension IDE: ExpressibleByArgument {}
|
@ -6,6 +6,9 @@ extension Colibri.Build {
|
|||||||
|
|
||||||
// MARK: Properties
|
// MARK: Properties
|
||||||
|
|
||||||
|
@Option(name: .shortAndLong)
|
||||||
|
var artifact: Artifact = .executable
|
||||||
|
|
||||||
@Option(name: .shortAndLong)
|
@Option(name: .shortAndLong)
|
||||||
var location: String?
|
var location: String?
|
||||||
|
|
||||||
|
16
Executable/Sources/Options/OpenOptions.swift
Normal file
16
Executable/Sources/Options/OpenOptions.swift
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import ArgumentParser
|
||||||
|
import ColibriLibrary
|
||||||
|
|
||||||
|
extension Colibri.Open {
|
||||||
|
struct Options: ParsableArguments, Locationable {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
@Option(name: .shortAndLong)
|
||||||
|
var ide: IDE = .xcode
|
||||||
|
|
||||||
|
@Option(name: .shortAndLong)
|
||||||
|
var location: String?
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
7
Library/Resources/Files/Sources/DockerCompose
Normal file
7
Library/Resources/Files/Sources/DockerCompose
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
app:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
port:
|
||||||
|
- 3000:8080
|
||||||
|
command: ["--hostname", "0.0.0.0", "--port", "8080"]
|
@ -1,7 +1,7 @@
|
|||||||
# ================================
|
# ================================
|
||||||
# Build image
|
# Build image
|
||||||
# ================================
|
# ================================
|
||||||
FROM swift:6.0-noble as build
|
FROM swift:6.0.3-noble AS build
|
||||||
|
|
||||||
# Install OS updates
|
# Install OS updates
|
||||||
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
|
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
|
||||||
@ -83,5 +83,5 @@ USER hummingbird:hummingbird
|
|||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
# Start the Hummingbird service when the image is run, default to listening on 8080 in production environment
|
# Start the Hummingbird service when the image is run, default to listening on 8080 in production environment
|
||||||
ENTRYPOINT ["./App]
|
ENTRYPOINT ["./App"]
|
||||||
CMD ["--hostname", "0.0.0.0", "--port", "8080"]
|
CMD ["--hostname", "0.0.0.0", "--port", "8080"]
|
||||||
|
@ -2,6 +2,7 @@ enum File: String {
|
|||||||
case appArguments = "AppArguments"
|
case appArguments = "AppArguments"
|
||||||
case appBuilder = "AppBuilder"
|
case appBuilder = "AppBuilder"
|
||||||
case appOptions = "AppOptions"
|
case appOptions = "AppOptions"
|
||||||
|
case dockerCompose = "DockerCompose"
|
||||||
case dockerFile = "DockerFile"
|
case dockerFile = "DockerFile"
|
||||||
case dockerIgnore = "DockerIgnore"
|
case dockerIgnore = "DockerIgnore"
|
||||||
case environment = "Environment"
|
case environment = "Environment"
|
||||||
@ -24,6 +25,7 @@ extension File {
|
|||||||
case .appArguments: "AppArguments.swift"
|
case .appArguments: "AppArguments.swift"
|
||||||
case .appBuilder: "AppBuilder.swift"
|
case .appBuilder: "AppBuilder.swift"
|
||||||
case .appOptions: "AppOptions.swift"
|
case .appOptions: "AppOptions.swift"
|
||||||
|
case .dockerCompose: "docker-compose.yml"
|
||||||
case .dockerFile: "Dockerfile"
|
case .dockerFile: "Dockerfile"
|
||||||
case .dockerIgnore: ".dockerignore"
|
case .dockerIgnore: ".dockerignore"
|
||||||
case .environment: "Environment+Properties.swift"
|
case .environment: "Environment+Properties.swift"
|
||||||
|
7
Library/Sources/Internal/Protocols/Randomable.swift
Normal file
7
Library/Sources/Internal/Protocols/Randomable.swift
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
protocol Randomable: CaseIterable {
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
static func random() -> Self
|
||||||
|
|
||||||
|
}
|
16
Library/Sources/Public/Enumerations/Artifact.swift
Normal file
16
Library/Sources/Public/Enumerations/Artifact.swift
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
public enum Artifact: String {
|
||||||
|
case executable
|
||||||
|
case image
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Randomable
|
||||||
|
|
||||||
|
extension Artifact: Randomable {
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
static func random() -> Artifact {
|
||||||
|
.allCases.randomElement() ?? .executable
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
Library/Sources/Public/Enumerations/IDE.swift
Normal file
16
Library/Sources/Public/Enumerations/IDE.swift
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
public enum IDE: String {
|
||||||
|
case vscode
|
||||||
|
case xcode
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Randomable
|
||||||
|
|
||||||
|
extension IDE: Randomable {
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
static func random() -> IDE {
|
||||||
|
.allCases.randomElement() ?? .xcode
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
40
Library/Sources/Public/Tasks/BuildArtifactTask.swift
Normal file
40
Library/Sources/Public/Tasks/BuildArtifactTask.swift
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
public struct BuildArtifactTask {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
private let terminalService: TerminalServicing
|
||||||
|
|
||||||
|
// MARK: Initialisers
|
||||||
|
|
||||||
|
public init(terminalService: TerminalServicing) {
|
||||||
|
self.terminalService = terminalService
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
public func callAsFunction(_ artifact: Artifact, at location: URL? = nil) async throws (TerminalServiceError) {
|
||||||
|
let executableURL: URL = switch artifact {
|
||||||
|
case .executable: .init(at: "/usr/bin/swift")
|
||||||
|
case .image: .init(at: "/usr/local/bin/docker")
|
||||||
|
}
|
||||||
|
|
||||||
|
var arguments: [String] = switch artifact {
|
||||||
|
case .executable: ["build"]
|
||||||
|
case .image: ["compose", "build"]
|
||||||
|
}
|
||||||
|
|
||||||
|
if let location {
|
||||||
|
if case .executable = artifact {
|
||||||
|
arguments.append(contentsOf: ["--package-path", location.pathString])
|
||||||
|
} else if case .image = artifact {
|
||||||
|
arguments.insert(contentsOf: ["--project-directory", location.pathString], at: 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try await terminalService.run(executableURL, arguments: arguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,29 +0,0 @@
|
|||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
44
Library/Sources/Public/Tasks/OpenProjectTask.swift
Normal file
44
Library/Sources/Public/Tasks/OpenProjectTask.swift
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
public struct OpenProjectTask {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
private let terminalService: TerminalServicing
|
||||||
|
|
||||||
|
// MARK: Initialisers
|
||||||
|
|
||||||
|
public init(terminalService: TerminalServicing) {
|
||||||
|
self.terminalService = terminalService
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
public func callAsFunction(with ide: IDE, at location: URL? = nil) async throws (TerminalServiceError) {
|
||||||
|
let executableURL: URL = switch ide {
|
||||||
|
case .vscode: .init(at: "/usr/local/bin/code")
|
||||||
|
case .xcode: .init(at: "/usr/bin/open")
|
||||||
|
}
|
||||||
|
|
||||||
|
let locationPath = switch ide {
|
||||||
|
case .vscode: location?.pathString ?? "."
|
||||||
|
case .xcode: location?.appendingPath(.Path.package).pathString ?? .Path.package
|
||||||
|
}
|
||||||
|
|
||||||
|
let arguments: [String] = switch ide {
|
||||||
|
case .vscode: [locationPath]
|
||||||
|
case .xcode: ["-a", "Xcode", locationPath]
|
||||||
|
}
|
||||||
|
|
||||||
|
try await terminalService.run(executableURL, arguments: arguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - String+Constants
|
||||||
|
|
||||||
|
private extension String {
|
||||||
|
enum Path {
|
||||||
|
static let package = "Package.swift"
|
||||||
|
}
|
||||||
|
}
|
59
Makefile
Normal file
59
Makefile
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
# VARIABLES
|
||||||
|
|
||||||
|
BINARY_FOLDER = $(prefix)/bin
|
||||||
|
BUILD_FOLDER = .build/release
|
||||||
|
EXECUTABLE_FILE = colibri
|
||||||
|
|
||||||
|
# INPUT ARGUMENTS
|
||||||
|
|
||||||
|
prefix ?= /usr/local
|
||||||
|
|
||||||
|
# EXECUTABLE MANAGEMENT
|
||||||
|
|
||||||
|
build: ## Build the executable from source code
|
||||||
|
@swift build -c release --disable-sandbox
|
||||||
|
|
||||||
|
install: build ## Install the built executable into the system
|
||||||
|
@install -d "$(BINARY_FOLDER)"
|
||||||
|
@install "$(BUILD_FOLDER)/$(EXECUTABLE_FILE)" "$(BINARY_FOLDER)"
|
||||||
|
|
||||||
|
uninstall: ## Uninstall the built executable from the system
|
||||||
|
@rm -rf "$(BINARY_FOLDER)/$(EXECUTABLE_FILE)"
|
||||||
|
|
||||||
|
# PACKAGE MANAGEMENT
|
||||||
|
|
||||||
|
clean: ## Delete built SPM artifacts from the package
|
||||||
|
@swift package clean
|
||||||
|
|
||||||
|
outdated: ## List the SPM package dependencies that can be updated
|
||||||
|
@swift package update --dry-run
|
||||||
|
|
||||||
|
purge: ## Purge the global SPM package repository
|
||||||
|
@swift package purge-cache
|
||||||
|
|
||||||
|
reset: ## Reset the complete SPM cache/build folder from the package
|
||||||
|
@swift package reset
|
||||||
|
|
||||||
|
update: ## Update the SPM package dependencies
|
||||||
|
@swift package update
|
||||||
|
|
||||||
|
wipe: clean reset purge ## Wipe all SPM package dependencies and purge the global SPM repository
|
||||||
|
|
||||||
|
# OPEN IDEs
|
||||||
|
|
||||||
|
vscode: ## Opens this project with Visual Studio Code
|
||||||
|
@code .
|
||||||
|
|
||||||
|
xcode: ## Opens this project with Xcode
|
||||||
|
@open -a Xcode Package.swift
|
||||||
|
|
||||||
|
# HELP
|
||||||
|
|
||||||
|
# Output the documentation for each of the defined tasks when `help` is called.
|
||||||
|
# Reference: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
|
||||||
|
.PHONY: help
|
||||||
|
|
||||||
|
help: ## Prints the written documentation for all the defined tasks
|
||||||
|
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
||||||
|
|
||||||
|
.DEFAULT_GOAL := help
|
@ -56,6 +56,7 @@ private extension FileTests {
|
|||||||
"AppArguments.swift",
|
"AppArguments.swift",
|
||||||
"AppBuilder.swift",
|
"AppBuilder.swift",
|
||||||
"AppOptions.swift",
|
"AppOptions.swift",
|
||||||
|
"docker-compose.yml",
|
||||||
"Dockerfile",
|
"Dockerfile",
|
||||||
".dockerignore",
|
".dockerignore",
|
||||||
"Environment+Properties.swift",
|
"Environment+Properties.swift",
|
||||||
@ -70,6 +71,7 @@ private extension FileTests {
|
|||||||
"Library/Sources/Public/AppArguments.swift",
|
"Library/Sources/Public/AppArguments.swift",
|
||||||
"Library/Sources/Public/AppBuilder.swift",
|
"Library/Sources/Public/AppBuilder.swift",
|
||||||
"App/Sources/AppOptions.swift",
|
"App/Sources/AppOptions.swift",
|
||||||
|
"docker-compose.yml",
|
||||||
"Dockerfile",
|
"Dockerfile",
|
||||||
".dockerignore",
|
".dockerignore",
|
||||||
"Library/Sources/Internal/Environment+Properties.swift",
|
"Library/Sources/Internal/Environment+Properties.swift",
|
||||||
@ -86,6 +88,7 @@ private extension FileTests {
|
|||||||
.app,
|
.app,
|
||||||
.root,
|
.root,
|
||||||
.root,
|
.root,
|
||||||
|
.root,
|
||||||
.libraryInternal,
|
.libraryInternal,
|
||||||
.root,
|
.root,
|
||||||
.root,
|
.root,
|
||||||
@ -100,6 +103,7 @@ private extension FileTests {
|
|||||||
"Resources/Files/Sources/App",
|
"Resources/Files/Sources/App",
|
||||||
"Resources/Files/Sources",
|
"Resources/Files/Sources",
|
||||||
"Resources/Files/Sources",
|
"Resources/Files/Sources",
|
||||||
|
"Resources/Files/Sources",
|
||||||
"Resources/Files/Sources/Library",
|
"Resources/Files/Sources/Library",
|
||||||
"Resources/Files/Sources",
|
"Resources/Files/Sources",
|
||||||
"Resources/Files/Sources",
|
"Resources/Files/Sources",
|
||||||
|
32
Test/Sources/Cases/Internal/Protocols/RandomableTests.swift
Normal file
32
Test/Sources/Cases/Internal/Protocols/RandomableTests.swift
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import Testing
|
||||||
|
|
||||||
|
@testable import ColibriLibrary
|
||||||
|
|
||||||
|
struct RandomableTest {
|
||||||
|
|
||||||
|
@Test func random() {
|
||||||
|
// GIVEN
|
||||||
|
let allCases = TestRandomable.allCases
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
let random = TestRandomable.random()
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
#expect(allCases.contains(random))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Enumerations
|
||||||
|
|
||||||
|
enum TestRandomable: Randomable {
|
||||||
|
case someCase
|
||||||
|
case someOtherCase
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
static func random() -> TestRandomable {
|
||||||
|
.allCases.randomElement() ?? .someCase
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
63
Test/Sources/Cases/Public/Tasks/BuildArtifactTaskTests.swift
Normal file
63
Test/Sources/Cases/Public/Tasks/BuildArtifactTaskTests.swift
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import Foundation
|
||||||
|
import Testing
|
||||||
|
|
||||||
|
@testable import ColibriLibrary
|
||||||
|
|
||||||
|
struct BuildArtifactTaskTests {
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||||
|
func taskForExecutable(at location: URL?) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceSpy()
|
||||||
|
let task = BuildArtifactTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
try await task(.executable, 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])
|
||||||
|
func taskForImage(at location: URL?) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceSpy()
|
||||||
|
let task = BuildArtifactTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
try await task(.image, at: location)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
let executableURL = URL(at: "/usr/local/bin/docker")
|
||||||
|
let arguments = if let location {
|
||||||
|
["compose", "--project-directory", location.pathString, "build"]
|
||||||
|
} else {
|
||||||
|
["compose", "build"]
|
||||||
|
}
|
||||||
|
|
||||||
|
#expect(terminalService.actions.count == 1)
|
||||||
|
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder], [TerminalServiceError.unexpected, .output(""), .captured("")])
|
||||||
|
func taskForArtifact(at location: URL?, throws error: TerminalServiceError) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceMock(action: .error(error))
|
||||||
|
let task = BuildArtifactTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
// THEN
|
||||||
|
await #expect(throws: error) {
|
||||||
|
try await task(.random(), at: location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,42 +0,0 @@
|
|||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
56
Test/Sources/Cases/Public/Tasks/OpenProjectTaskTests.swift
Normal file
56
Test/Sources/Cases/Public/Tasks/OpenProjectTaskTests.swift
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import Foundation
|
||||||
|
import Testing
|
||||||
|
|
||||||
|
@testable import ColibriLibrary
|
||||||
|
|
||||||
|
struct OpenProjectTaskTests {
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||||
|
func taskWithVSCodeIDE(at location: URL?) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceSpy()
|
||||||
|
let task = OpenProjectTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
try await task(with: .vscode, at: location)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
let executableURL = URL(at: "/usr/local/bin/code")
|
||||||
|
let arguments = [location?.pathString ?? "."]
|
||||||
|
|
||||||
|
#expect(terminalService.actions.count == 1)
|
||||||
|
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||||
|
func taskWithXcodeIDE(at location: URL?) async throws {
|
||||||
|
// GIVEN
|
||||||
|
let terminalService = TerminalServiceSpy()
|
||||||
|
let task = OpenProjectTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
try await task(with: .xcode, at: location)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
let locationPath = location?.appendingPath("Package.swift").pathString ?? "Package.swift"
|
||||||
|
let executableURL = URL(at: "/usr/bin/open")
|
||||||
|
let arguments = ["-a", "Xcode", locationPath]
|
||||||
|
|
||||||
|
#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 = OpenProjectTask(terminalService: terminalService)
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
// THEN
|
||||||
|
await #expect(throws: error) {
|
||||||
|
try await task(with: .random(), at: location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user