Extending an automatically watched tree to a new directory swallowed every error, so a reached watch limit or an unreadable directory left part of the tree unwatched without any sign. No call of the consumer is running at that moment, so the failures now arrive in the event stream as InotifyEvent.watchFailed, after the event that triggered the extension. The library watches what it can first: a reached limit ends the attempt, an unreadable directory is skipped with its subtree, and a directory that vanished in between is not reported. The buffer now carries the library's own events next to the kernel's, which keeps them in order and hides the stream's element type. The test runner drops root's DAC capabilities so that an unreadable directory can be tested.
48 lines
1.5 KiB
Swift
48 lines
1.5 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",
|
|
// Root ignores directory permissions unless these are dropped; a
|
|
// test relies on an unreadable directory.
|
|
"--cap-drop", "DAC_OVERRIDE", "--cap-drop", "DAC_READ_SEARCH",
|
|
"--platform", Docker.getLinuxPlatformStringWithHostArchitecture(),
|
|
"-w", "/code", "swift:latest",
|
|
"/bin/bash", "-c", "swift test --skip InotifyLimitTests && swift test --skip-build --filter InotifyLimitTests"
|
|
],
|
|
output: .currentStandardOutput,
|
|
error: .currentStandardError
|
|
)
|
|
if dockerRunResult.terminationStatus.isSuccess {
|
|
noora.success("All tests completed successfully.")
|
|
} else {
|
|
noora.error("Not all tests completed successfully.")
|
|
}
|
|
}
|
|
}
|