Files
swift-inotify/Sources/TaskCLI/Test Command.swift
T. R. Bernstein 541b9d68a0
Some checks failed
Docs / docs (push) Has been cancelled
Docs / deploy (push) Has been cancelled
Use Shwift library instead of Subprocess
Shwift has a concise API, which makes writing shell code nice and easy.
This is an opinionated decision.
2026-03-20 21:44:05 +01:00

39 lines
1.1 KiB
Swift

import Foundation
import Script
import Noora
struct TestCommand: Script {
static let configuration = CommandConfiguration(
commandName: "test",
abstract: "Run swift test in a linux container.",
aliases: ["t"],
)
@OptionGroup var global: GlobalOptions
// MARK: - Run
func run() async throws {
let noora = Noora()
let logger = global.makeLogger(labeled: "swift-inotify.cli.task.test")
let currentDirectory = FileManager.default.currentDirectoryPath
let docker = Executable(path: "/opt/homebrew/bin/docker")
noora.info("Running tests on Linux.")
logger.debug("Current directory", metadata: ["current-directory": "\(currentDirectory)"])
do {
try await docker(
"run",
"-v", "\(currentDirectory):/code",
"--security-opt", "systempaths=unconfined",
"--platform", "linux/arm64",
"-w", "/code", "swift:latest",
"/bin/bash", "-c", "swift test --skip InotifyLimitTests; swift test --skip-build --filter InotifyLimitTests"
)
noora.success("All tests completed successfully.")
} catch {
noora.error("Not all tests completed successfully.")
}
}
}