Skip to content

Commit 1a8c516

Browse files
bkhouribnbarham
authored andcommitted
Tests: Update isAmazonLinux2() logic
The ProcessInfo extension to determine if a host is running on Amazon Linux 2 was slightly flawed as it did not take into account the double-quote (") surrounding the values. Update the logic to look at "PRETTY_NAME" since the ID can be used in multiple Amazon Linux OS'es, and use exact logic match. issue: rdar://155612963
1 parent ad9cd11 commit 1a8c516

File tree

4 files changed

+187
-70
lines changed

4 files changed

+187
-70
lines changed

Sources/_InternalTestSupport/ProcessInfo+hostutils.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,8 @@ extension ProcessInfo {
2222
return false
2323
}
2424
}
25-
let lines = contentString.components(separatedBy: .newlines)
26-
for line in lines {
27-
if line.starts(with: "ID=") {
28-
let id = line.replacingOccurrences(of: "ID=", with: "").trimmingCharacters(in: .whitespacesAndNewlines)
29-
if id == "amzn" { // ID for Amazon Linux is "amzn"
30-
return true
31-
}
32-
}
33-
}
34-
return false
25+
let al2_name = "PRETTY_NAME=\"Amazon Linux 2\""
26+
return contentString.contains(al2_name)
3527
}
3628

3729
}

Tests/BasicsTests/ProcessInfoTests.swift

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,95 @@ struct ProcessInfoExtensionTests {
5050
@Test(
5151
arguments: [
5252
(contentUT: "", expected: false),
53-
(contentUT: "ID=", expected: false),
54-
(contentUT: "ID=foo", expected: false),
55-
(contentUT: "ID=amzn", expected: true),
56-
(contentUT: " ID=amzn", 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),
61+
(
62+
contentUT: """
63+
NAME="Amazon Linux"
64+
VERSION="2"
65+
ID="amzn"
66+
ID_LIKE="centos rhel fedora"
67+
VERSION_ID="2"
68+
PRETTY_NAME="Amazon Linux 2"
69+
ANSI_COLOR="0;33"
70+
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
71+
HOME_URL="https://amazonlinux.com/"
72+
SUPPORT_END="2026-06-30"
73+
""",
74+
expected: true
75+
),
76+
(
77+
contentUT: """
78+
NAME="Amazon Linux"
79+
VERSION="2"
80+
ID="amzn"
81+
ID_LIKE="centos rhel fedora"
82+
VERSION_ID="2"
83+
PRETTY_NAME="Amazon Linux 2 (something else)"
84+
ANSI_COLOR="0;33"
85+
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
86+
HOME_URL="https://amazonlinux.com/"
87+
SUPPORT_END="2026-06-30"
88+
""",
89+
expected: false
90+
),
91+
(
92+
contentUT: """
93+
NAME="Amazon Linux"
94+
VERSION="2"
95+
ID="amzn"
96+
ID_LIKE="centos rhel fedora"
97+
VERSION_ID="2"
98+
PRETTY_NAME=Amazon Linux 2 (something else)
99+
ANSI_COLOR="0;33"
100+
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
101+
HOME_URL="https://amazonlinux.com/"
102+
SUPPORT_END="2026-06-30"
103+
""",
104+
expected: false
105+
),
106+
(
107+
contentUT: """
108+
NAME="Amazon Linux"
109+
VERSION="2"
110+
ID="amzn"
111+
ID_LIKE="centos rhel fedora"
112+
VERSION_ID="2"
113+
PRETTY_NAME=Amazon Linux 2
114+
ANSI_COLOR="0;33"
115+
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
116+
HOME_URL="https://amazonlinux.com/"
117+
SUPPORT_END="2026-06-30"
118+
""",
119+
expected: false
120+
),
121+
(
122+
contentUT: """
123+
NAME="Amazon Linux"
124+
VERSION="2023"
125+
ID="amzn"
126+
ID_LIKE="fedora"
127+
VERSION_ID="2023"
128+
PLATFORM_ID="platform:al2023"
129+
PRETTY_NAME="Amazon Linux 2023.6.20250107"
130+
ANSI_COLOR="0;33"
131+
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023"
132+
HOME_URL="https://aws.amazon.com/linux/amazon-linux-2023/"
133+
DOCUMENTATION_URL="https://docs.aws.amazon.com/linux/"
134+
SUPPORT_URL="https://aws.amazon.com/premiumsupport/"
135+
BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023"
136+
VENDOR_NAME="AWS"
137+
VENDOR_URL="https://aws.amazon.com/"
138+
SUPPORT_END="2028-03-15"
139+
""",
140+
expected: false,
141+
)
57142
], prefixAndSuffixData,
58143
)
59144
fileprivate func isAmazonLinux2ReturnsExpectedValue(

Tests/CommandsTests/APIDiffTests.swift

Lines changed: 93 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ struct APIDiffTests {
133133
}
134134
}
135135

136-
@Test(.requiresAPIDigester, arguments: SupportedBuildSystemOnAllPlatforms)
136+
@Test(
137+
.requiresAPIDigester,
138+
.issue("https://github.com/swiftlang/swift-package-manager/issues/8926", relationship: .defect),
139+
arguments: SupportedBuildSystemOnAllPlatforms,
140+
)
137141
func testBreakageAllowlist(buildSystem: BuildSystemProvider.Kind) async throws {
138142
try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in
139143
let packageRoot = fixturePath.appending("Bar")
@@ -154,11 +158,15 @@ struct APIDiffTests {
154158
try await execute(["diagnose-api-breaking-changes", "1.2.3", "--breakage-allowlist-path", customAllowlistPath.pathString],
155159
packagePath: packageRoot, buildSystem: buildSystem)
156160
) { error in
157-
#expect(error.stdout.contains("1 breaking change detected in Qux"))
158161
#expect(!error.stdout.contains("💔 API breakage: class Qux has generic signature change from <T> to <T, U>"))
159-
#expect(error.stdout.contains("💔 API breakage: var Qux.x has been removed"))
160-
#expect(error.stdout.contains("1 breaking change detected in Baz"))
161-
#expect(error.stdout.contains("💔 API breakage: func bar() has been removed"))
162+
withKnownIssue {
163+
#expect(error.stdout.contains("1 breaking change detected in Qux"))
164+
#expect(error.stdout.contains("💔 API breakage: var Qux.x has been removed"))
165+
#expect(error.stdout.contains("1 breaking change detected in Baz"))
166+
#expect(error.stdout.contains("💔 API breakage: func bar() has been removed"))
167+
} when: {
168+
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
169+
}
162170
}
163171

164172
}
@@ -205,7 +213,11 @@ struct APIDiffTests {
205213
}
206214
}
207215

208-
@Test(.requiresAPIDigester, arguments: SupportedBuildSystemOnAllPlatforms)
216+
@Test(
217+
.requiresAPIDigester,
218+
.issue("https://github.com/swiftlang/swift-package-manager/issues/8926", relationship: .defect),
219+
arguments: SupportedBuildSystemOnAllPlatforms,
220+
)
209221
func testFilters(buildSystem: BuildSystemProvider.Kind) async throws {
210222
try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in
211223
let packageRoot = fixturePath.appending("NonAPILibraryTargets")
@@ -228,10 +240,18 @@ struct APIDiffTests {
228240
try await expectThrowsCommandExecutionError(
229241
try await execute(["diagnose-api-breaking-changes", "1.2.3", "--products", "One", "--targets", "Bar"], packagePath: packageRoot, buildSystem: buildSystem)
230242
) { error in
231-
#expect(error.stdout.contains("💔 API breakage"))
243+
withKnownIssue {
244+
#expect(error.stdout.contains("💔 API breakage"))
245+
} when: {
246+
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
247+
}
232248
let regex = try Regex("\\d+ breaking change(s?) detected in Foo")
233-
#expect(error.stdout.contains(regex))
234-
#expect(error.stdout.contains(regex))
249+
250+
withKnownIssue {
251+
#expect(error.stdout.contains(regex))
252+
} when: {
253+
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
254+
}
235255

236256
// Baz and Qux are not included in the filter, so any API changes should be ignored.
237257
#expect(!error.stdout.contains("Baz"))
@@ -242,9 +262,13 @@ struct APIDiffTests {
242262
try await expectThrowsCommandExecutionError(
243263
try await execute(["diagnose-api-breaking-changes", "1.2.3", "--targets", "Baz"], packagePath: packageRoot, buildSystem: buildSystem)
244264
) { error in
245-
#expect(error.stdout.contains("💔 API breakage"))
246-
let regex = try Regex("\\d+ breaking change(s?) detected in Baz")
247-
#expect(error.stdout.contains(regex))
265+
try withKnownIssue {
266+
#expect(error.stdout.contains("💔 API breakage"))
267+
let regex = try Regex("\\d+ breaking change(s?) detected in Baz")
268+
#expect(error.stdout.contains(regex))
269+
} when: {
270+
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
271+
}
248272

249273
// Only Baz is included, we should not see any other API changes.
250274
#expect(!error.stdout.contains("Foo"))
@@ -310,53 +334,69 @@ struct APIDiffTests {
310334
}
311335
}
312336

313-
@Test(.requiresAPIDigester, arguments: SupportedBuildSystemOnAllPlatforms)
337+
@Test(
338+
.requiresAPIDigester,
339+
.issue("https://github.com/swiftlang/swift-package-manager/issues/8926", relationship: .defect),
340+
arguments: SupportedBuildSystemOnAllPlatforms,
341+
)
314342
func testNoBreakingChanges(buildSystem: BuildSystemProvider.Kind) async throws {
315-
try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in
316-
let packageRoot = fixturePath.appending("Bar")
317-
// Introduce an API-compatible change
318-
try localFileSystem.writeFileContents(
319-
packageRoot.appending(components: "Sources", "Baz", "Baz.swift"),
320-
string: "public func bar() -> Int { 100 }"
321-
)
322-
let (output, _) = try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)
323-
#expect(output.contains("No breaking changes detected in Baz"))
324-
#expect(output.contains("No breaking changes detected in Qux"))
343+
try await withKnownIssue {
344+
try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in
345+
let packageRoot = fixturePath.appending("Bar")
346+
// Introduce an API-compatible change
347+
try localFileSystem.writeFileContents(
348+
packageRoot.appending(components: "Sources", "Baz", "Baz.swift"),
349+
string: "public func bar() -> Int { 100 }"
350+
)
351+
let (output, _) = try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)
352+
#expect(output.contains("No breaking changes detected in Baz"))
353+
#expect(output.contains("No breaking changes detected in Qux"))
354+
}
355+
} when : {
356+
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
325357
}
326358
}
327359

328-
@Test(.requiresAPIDigester, arguments: SupportedBuildSystemOnAllPlatforms)
360+
@Test(
361+
.requiresAPIDigester,
362+
.issue("https://github.com/swiftlang/swift-package-manager/issues/8926", relationship: .defect),
363+
arguments: SupportedBuildSystemOnAllPlatforms,
364+
)
329365
func testAPIDiffAfterAddingNewTarget(buildSystem: BuildSystemProvider.Kind) async throws {
330-
try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in
331-
let packageRoot = fixturePath.appending("Bar")
332-
try localFileSystem.createDirectory(packageRoot.appending(components: "Sources", "Foo"))
333-
try localFileSystem.writeFileContents(
334-
packageRoot.appending(components: "Sources", "Foo", "Foo.swift"),
335-
string: #"public let foo = "All new module!""#
336-
)
337-
try localFileSystem.writeFileContents(packageRoot.appending("Package.swift"), string:
338-
"""
339-
// swift-tools-version:4.2
340-
import PackageDescription
341-
342-
let package = Package(
343-
name: "Bar",
344-
products: [
345-
.library(name: "Baz", targets: ["Baz"]),
346-
.library(name: "Qux", targets: ["Qux", "Foo"]),
347-
],
348-
targets: [
349-
.target(name: "Baz"),
350-
.target(name: "Qux"),
351-
.target(name: "Foo")
352-
]
366+
try await withKnownIssue(isIntermittent: true) {
367+
try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in
368+
let packageRoot = fixturePath.appending("Bar")
369+
try localFileSystem.createDirectory(packageRoot.appending(components: "Sources", "Foo"))
370+
try localFileSystem.writeFileContents(
371+
packageRoot.appending(components: "Sources", "Foo", "Foo.swift"),
372+
string: #"public let foo = "All new module!""#
353373
)
354-
"""
355-
)
356-
let (output, _) = try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)
357-
#expect(output.contains("No breaking changes detected in Baz"))
358-
#expect(output.contains("No breaking changes detected in Qux"))
359-
#expect(output.contains("Skipping Foo because it does not exist in the baseline"))
374+
try localFileSystem.writeFileContents(packageRoot.appending("Package.swift"), string:
375+
"""
376+
// swift-tools-version:4.2
377+
import PackageDescription
378+
379+
let package = Package(
380+
name: "Bar",
381+
products: [
382+
.library(name: "Baz", targets: ["Baz"]),
383+
.library(name: "Qux", targets: ["Qux", "Foo"]),
384+
],
385+
targets: [
386+
.target(name: "Baz"),
387+
.target(name: "Qux"),
388+
.target(name: "Foo")
389+
]
390+
)
391+
"""
392+
)
393+
let (output, _) = try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)
394+
#expect(output.contains("No breaking changes detected in Baz"))
395+
#expect(output.contains("No breaking changes detected in Qux"))
396+
#expect(output.contains("Skipping Foo because it does not exist in the baseline"))
397+
}
398+
} when: {
399+
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
360400
}
361401
}
362402

Tests/CommandsTests/TestCommandTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ struct TestCommandTests {
180180
buildSystem: buildSystem,
181181
)
182182
}
183-
guard case SwiftPMError.executionFailure(_, _, let stderr) = try #require(error) else {
183+
guard case let SwiftPMError.executionFailure(_, stdout, stderr) = try #require(error) else {
184184
Issue.record("Incorrect error was raised.")
185185
return
186186
}
@@ -208,7 +208,7 @@ struct TestCommandTests {
208208
throwIfCommandFails: true,
209209
)
210210
}
211-
guard case SwiftPMError.executionFailure(_, _, let stderr) = try #require(error) else {
211+
guard case let SwiftPMError.executionFailure(_, stdout, stderr) = try #require(error) else {
212212
Issue.record("Incorrect error was raised.")
213213
return
214214
}
@@ -262,7 +262,7 @@ struct TestCommandTests {
262262
buildSystem: buildSystem,
263263
)
264264
}
265-
guard case SwiftPMError.executionFailure(_, _, let stderr) = try #require(error) else {
265+
guard case let SwiftPMError.executionFailure(_, stdout, stderr) = try #require(error) else {
266266
Issue.record("Incorrect error was raised.")
267267
return
268268
}

0 commit comments

Comments
 (0)