@@ -206,20 +206,29 @@ extension Trait where Self == Testing.ConditionTrait {
206206 }
207207 }
208208
209- package static func requireSystemPackages( apt: String ... , yum: String ... , freebsd: String ... , sourceLocation: SourceLocation = #_sourceLocation) -> Self {
209+ package static func requireSystemPackages( apt: String ... , yum: String ... , freebsd: String ... , openbsd : String ... , sourceLocation: SourceLocation = #_sourceLocation) -> Self {
210210 enabled ( " required system packages are not installed " ) {
211+ func installCommand( packageManagerPath: Path , packageNames: String ) -> String {
212+ switch packageManagerPath. basenameWithoutSuffix {
213+ case " pkg_info " :
214+ return " pkg_add \( packageNames) " // OpenBSD
215+ default :
216+ return " \( packageManagerPath. basenameWithoutSuffix) install \( packageNames) "
217+ }
218+ }
219+
211220 func checkInstalled( hostOS: OperatingSystem , packageManagerPath: Path , args: [ String ] , packages: [ String ] , regex: Regex < ( Substring , name: Substring ) > ) async throws -> Bool {
212221 if try ProcessInfo . processInfo. hostOperatingSystem ( ) == hostOS && localFS. exists ( packageManagerPath) {
213222 var installedPackages : Set < String > = [ ]
214- for line in try await runProcess ( [ packageManagerPath. str] + args + packages) . split ( separator: " \n " ) {
223+ for line in try await runProcess ( [ packageManagerPath. str] + args + ( packageManagerPath . basenameWithoutSuffix == " pkg_info " ? [ ] : packages) ) . split ( separator: " \n " ) {
215224 if let packageName = try regex. firstMatch ( in: line) ? . output. name {
216225 installedPackages. insert ( String ( packageName) )
217226 }
218227 }
219228
220229 let uninstalledPackages = Set ( packages) . subtracting ( installedPackages)
221230 if !uninstalledPackages. isEmpty {
222- Issue . record ( " system packages are missing. Install via ` \( packageManagerPath. basenameWithoutSuffix ) install \( uninstalledPackages. sorted ( ) . joined ( separator: " " ) ) ` " , sourceLocation: sourceLocation)
231+ Issue . record ( " system packages are missing. Install via ` \( installCommand ( packageManagerPath: packageManagerPath , packageNames : uninstalledPackages. sorted ( ) . joined ( separator: " " ) ) ) ` " , sourceLocation: sourceLocation)
223232 return false
224233 }
225234 }
@@ -234,7 +243,9 @@ extension Trait where Self == Testing.ConditionTrait {
234243
235244 let freebsd = try await checkInstalled ( hostOS: . freebsd, packageManagerPath: Path ( " /usr/sbin/pkg " ) , args: [ " info " ] , packages: freebsd, regex: #/^Name(?:[ ]+): (?<name>.+)$/# )
236245
237- return apt && yum && freebsd
246+ let openbsd = try await checkInstalled ( hostOS: . openbsd, packageManagerPath: Path ( " /usr/sbin/pkg_info " ) , args: [ " -A " ] , packages: openbsd, regex: #/^(?<name>.+)-.*/# )
247+
248+ return apt && yum && freebsd && openbsd
238249 }
239250 }
240251
0 commit comments