Skip to content

Commit 9bbfd45

Browse files
committed
Ignore exit code when checking for system-level packages
FreeBSD's pkg returns 1 if a package isn't installed. Across all platforms, we really only care about parsing the tool's output, not whether it exited successfully or not. This allows tests to be properly skipped on FreeBSD when the requisite tool is not installed.
1 parent 3bdc19e commit 9bbfd45

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Sources/SWBTestSupport/SkippedTestSupport.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,17 @@ extension Trait where Self == Testing.ConditionTrait {
217217
}
218218
}
219219

220+
func runProcessIgnoringExitCode(_ args: [String]) async throws -> String {
221+
guard let first = args.first else {
222+
throw StubError.error("Invalid number of arguments")
223+
}
224+
return try await String(decoding: Process.getOutput(url: URL(filePath: first), arguments: Array(args.dropFirst())).stdout, as: UTF8.self)
225+
}
226+
220227
func checkInstalled(hostOS: OperatingSystem, packageManagerPath: Path, args: [String], packages: [String], regex: Regex<(Substring, name: Substring)>) async throws -> Bool {
221228
if try ProcessInfo.processInfo.hostOperatingSystem() == hostOS && localFS.exists(packageManagerPath) {
222229
var installedPackages: Set<String> = []
223-
for line in try await runProcess([packageManagerPath.str] + args + (packageManagerPath.basenameWithoutSuffix == "pkg_info" ? [] : packages)).split(separator: "\n") {
230+
for line in try await runProcessIgnoringExitCode([packageManagerPath.str] + args + (packageManagerPath.basenameWithoutSuffix == "pkg_info" ? [] : packages)).split(separator: "\n") {
224231
if let packageName = try regex.firstMatch(in: line)?.output.name {
225232
installedPackages.insert(String(packageName))
226233
}

0 commit comments

Comments
 (0)