Files
swift-inotify/Sources/TaskCLI/Test Command.swift
T. R. Bernstein 6927464d47
Some checks failed
Docs / docs (push) Has been cancelled
Docs / deploy (push) Has been cancelled
Use Subprocess instead of Shwift
Drop Shwift: it is incompatible with musl (used by the Swift static
linking SDK), and its API is not meaningfully more concise than
Subprocess upon closer inspection.
2026-03-23 19:50:58 +01:00

45 lines
1.3 KiB
Swift

import ArgumentParser
import Foundation
import Noora
import Subprocess
struct TestCommand: AsyncParsableCommand {
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
noora.info("Running tests on Linux.")
logger.debug("Current directory", metadata: ["current-directory": "\(currentDirectory)"])
let dockerRunResult = try await Subprocess.run(
.name("docker"),
arguments: [
"run",
"-v", "\(currentDirectory):/code",
"-v", "swift-inotify-build-cache:/code/.build",
"--security-opt", "systempaths=unconfined",
"--platform", Docker.getLinuxPlatformStringWithHostArchitecture(),
"-w", "/code", "swift:latest",
"/bin/bash", "-c", "swift test --skip InotifyLimitTests; swift test --skip-build --filter InotifyLimitTests"
],
output: .standardOutput,
error: .standardError
)
if dockerRunResult.terminationStatus.isSuccess {
noora.success("All tests completed successfully.")
} else {
noora.error("Not all tests completed successfully.")
}
}
}