@@ -15,12 +15,12 @@ import Testing
1515@testable import struct _InternalTestSupport. CombinationsWithRepetition
1616
1717fileprivate let d = [
18- [ ] ,
19- [ " " ] ,
20- [ " line1 " ] ,
21- [ " line1 " , " line2 " ] ,
22- [ " line1 " , " line2 " , " line3 " ] ,
23- ]
18+ [ ] ,
19+ [ " " ] ,
20+ [ " line1 " ] ,
21+ [ " line1 " , " line2 " ] ,
22+ [ " line1 " , " line2 " , " line3 " ] ,
23+ ]
2424fileprivate let prefixAndSuffixData = CombinationsWithRepetition ( of: d, length: 2 ) . map ( { data in
2525 // Content(prefix: data.0, suffix: data.1)
2626 Content ( prefix: data [ 0 ] , suffix: data [ 1 ] )
@@ -46,18 +46,20 @@ fileprivate struct Content {
4646struct ProcessInfoExtensionTests {
4747
4848 @Suite
49- struct isAmazonLinux2 {
49+ struct isHostOsTests {
5050 @Test (
5151 arguments: [
52- ( contentUT: " " , expected: false ) ,
53- ( contentUT: " PRETTY_NAME= " , expected: false ) ,
54- ( contentUT: " PRETTY_NAME=foo " , expected: false ) ,
55- ( contentUT: " PRETTY_NAME=amzn " , expected: false ) ,
56- ( contentUT: " PRETTY_NAME=Amazon Linux 2 " , expected: false ) ,
57- ( contentUT: " PRETTY_NAME=Amazon Linux 2023.6.20250107 " , expected: false ) ,
58- ( contentUT: " PRETTY_NAME=amzn " , expected: false ) ,
59- ( contentUT: " PRETTY_NAME= \" Amazon Linux 2 \" " , expected: true ) ,
60- ( contentUT: " PRETTY_NAME= \" Amazon Linux 2 (something else) \" " , expected: false ) ,
52+ ( contentUT: " " , nameUT: " Amazon Linux 2 " , expected: false ) ,
53+ ( contentUT: " PRETTY_NAME= " , nameUT: " Amazon Linux 2 " , expected: false ) ,
54+ ( contentUT: " PRETTY_NAME=foo " , nameUT: " Amazon Linux 2 " , expected: false ) ,
55+ ( contentUT: " PRETTY_NAME=amzn " , nameUT: " Amazon Linux 2 " , expected: false ) ,
56+ ( contentUT: " PRETTY_NAME=Amazon Linux 2 " , nameUT: " Amazon Linux 2 " , expected: false ) ,
57+ ( contentUT: " PRETTY_NAME=Amazon Linux 2 " , nameUT: " Amazon Linux 2 " , expected: false ) ,
58+ ( contentUT: " PRETTY_NAME=Amazon Linux 2023.6.20250107 " , nameUT: " Amazon Linux 2 " , expected: false ) ,
59+ ( contentUT: " PRETTY_NAME=amzn " , nameUT: " Amazon Linux 2 " , expected: false ) ,
60+ ( contentUT: " PRETTY_NAME= \" Amazon Linux 2 \" " , nameUT: " Amazon Linux 2 " , expected: true ) ,
61+ ( contentUT: " PRETTY_NAME= \" Amazon Linux 2 \" " , nameUT: " Amazon Linux 2 " , expected: true ) ,
62+ ( contentUT: " PRETTY_NAME= \" Amazon Linux 2 (something else) \" " , nameUT: " Amazon Linux 2 " , expected: false ) ,
6163 (
6264 contentUT: """
6365 NAME= " Amazon Linux "
@@ -71,6 +73,7 @@ struct ProcessInfoExtensionTests {
7173 HOME_URL= " https://amazonlinux.com/ "
7274 SUPPORT_END= " 2026-06-30 "
7375 """ ,
76+ nameUT: " Amazon Linux 2 " ,
7477 expected: true
7578 ) ,
7679 (
@@ -86,6 +89,7 @@ struct ProcessInfoExtensionTests {
8689 HOME_URL= " https://amazonlinux.com/ "
8790 SUPPORT_END= " 2026-06-30 "
8891 """ ,
92+ nameUT: " Amazon Linux 2 " ,
8993 expected: false
9094 ) ,
9195 (
@@ -101,6 +105,7 @@ struct ProcessInfoExtensionTests {
101105 HOME_URL= " https://amazonlinux.com/ "
102106 SUPPORT_END= " 2026-06-30 "
103107 """ ,
108+ nameUT: " Amazon Linux 2 " ,
104109 expected: false
105110 ) ,
106111 (
@@ -116,6 +121,7 @@ struct ProcessInfoExtensionTests {
116121 HOME_URL= " https://amazonlinux.com/ "
117122 SUPPORT_END= " 2026-06-30 "
118123 """ ,
124+ nameUT: " Amazon Linux 2 " ,
119125 expected: false
120126 ) ,
121127 (
@@ -137,30 +143,62 @@ struct ProcessInfoExtensionTests {
137143 VENDOR_URL= " https://aws.amazon.com/ "
138144 SUPPORT_END= " 2028-03-15 "
139145 """ ,
146+ nameUT: " Amazon Linux 2 " ,
147+ expected: false ,
148+ ) ,
149+ (
150+ contentUT: """
151+ NAME= " Amazon Linux "
152+ PLATFORM_ID= " platform:al2023 "
153+ PRETTY_NAME= " myFoo "
154+ ANSI_COLOR= " 0;33 "
155+ CPE_NAME= " cpe:2.3:o:amazon:amazon_linux:2023 "
156+ """ ,
157+ nameUT: " myfoo " ,
140158 expected: false ,
141159 )
142160 ] , prefixAndSuffixData,
143161 )
144- fileprivate func isAmazonLinux2ReturnsExpectedValue (
145- data: ( contentUT: String , expected: Bool ) ,
162+ fileprivate func isHostOsReturnsExpectedValue (
163+ data: ( contentUT: String , nameUT : String , expected: Bool ) ,
146164 content: Content ,
165+
147166 ) async throws {
148167 let content = content. getContent ( data. contentUT)
149168
150- let actual = ProcessInfo . isHostAmazonLinux2 ( content)
169+ let actual = ProcessInfo . isHostOs ( prettyName : data . nameUT , content : content)
151170
152171 #expect( actual == data. expected, " Content is: ' \( content) ' " )
153172 }
154173
174+ @Test (
175+ . requireHostOS( . windows) ,
176+ . requireHostOS( . macOS) ,
177+ )
178+ func isHostOsReturnsFalseIfTheOSFileContentsCannotBeRead( ) async throws {
179+ let actual = ProcessInfo . isHostOs ( prettyName: " Amazon Linux 2 " )
180+ #expect( actual == false )
181+ }
182+
155183 @Test (
156184 " isHostAmazonLinux2 returns false when not executed on Linux " ,
157- . skipHostOS( . linux) ,
158- . tags( Tag . TestSize. medium ) ,
185+ . skipHostOS( . linux, " Test cannot run on AmazonLinux2, but we can't distinguish linux distributions, so skipping " , ) ,
186+ . tags( Tag . TestSize. small ) ,
159187 )
160188 func isAmazonLinux2ReturnsFalseWhenNotRunOnLinux( ) {
161189 let actual = ProcessInfo . isHostAmazonLinux2 ( )
162190
191+ #expect( actual == false )
192+ }
193+ @Test (
194+ " isHostDebian12 returns false when not executed on Linux " ,
195+ . skipHostOS( . linux, " Test cannot run on Debian 12, but we can't distinguish linux distributions, so skipping " , ) ,
196+ . tags( Tag . TestSize. small) ,
197+ )
198+ func isHostDebian12ReturnsFalseWhenNotRunOnLinux( ) {
199+ let actual = ProcessInfo . isHostDebian12 ( )
200+
163201 #expect( actual == false )
164202 }
165203 }
166- }
204+ }
0 commit comments