Skip to content

Commit 8410ce7

Browse files
committed
Tests: APIDiff Tests - mark known issues on AL2
Change swiftlang#8857 added SwiftBUild support for diagnose-api-breaking-changs. However, it appears that some test expectation are failing on Amazon Linux 2. Mark these a known issues until they can be fixed.
1 parent 5e566d4 commit 8410ce7

File tree

5 files changed

+151
-13
lines changed

5 files changed

+151
-13
lines changed

Package.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ let package = Package(
876876
"Basics",
877877
"_InternalTestSupport",
878878
"tsan_utils",
879+
.product(name: "Algorithms", package: "swift-algorithms"),
879880
],
880881
exclude: [
881882
"Archiver/Inputs/archive.tar.gz",
@@ -1130,6 +1131,9 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
11301131
.package(url: "https://github.com/swiftlang/swift-toolchain-sqlite.git", from: "1.0.0"),
11311132
// For use in previewing documentation
11321133
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.1.0"),
1134+
1135+
//Test only package
1136+
.package(url: "https://github.com/apple/swift-algorithms", from: "1.2.1"),
11331137
]
11341138
if !swiftDriverDeps.isEmpty {
11351139
package.dependencies += [
@@ -1140,6 +1144,7 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
11401144
} else {
11411145
package.dependencies += [
11421146
.package(path: "../swift-argument-parser"),
1147+
.package(path: "../swift-algorithms"),
11431148
.package(path: "../swift-crypto"),
11441149
.package(path: "../swift-syntax"),
11451150
.package(path: "../swift-system"),
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2025 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
import Foundation
11+
12+
extension ProcessInfo {
13+
public static func isHostAmazonLinux2(_ content: String? = nil) -> Bool {
14+
let contentString: String
15+
if let content {
16+
contentString = content
17+
} else {
18+
let osReleasePath = "/etc/os-release"
19+
do {
20+
contentString = try String(contentsOfFile: osReleasePath, encoding: .utf8)
21+
} catch {
22+
return false
23+
//print("Error reading \(osReleasePath): \(error)")
24+
}
25+
}
26+
let lines = contentString.components(separatedBy: .newlines)
27+
for line in lines {
28+
if line.starts(with: "ID=") {
29+
let id = line.replacingOccurrences(of: "ID=", with: "").trimmingCharacters(in: .whitespacesAndNewlines)
30+
if id == "amzn" { // ID for Amazon Linux is "amzn"
31+
return true
32+
}
33+
}
34+
}
35+
return false
36+
}
37+
38+
}

Tests/BasicsTests/Environment/EnvironmentTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ struct EnvironmentTests {
148148
/// Important: This test is inherently race-prone, if it is proven to be
149149
/// flaky, it should run in a singled threaded environment/removed entirely.
150150
@Test(
151-
.disabled(if: isInCiEnvironment || CiEnvironment.runningInSelfHostedPipeline, "This test can disrupt other tests running in parallel."),
151+
.disabled(if: CiEnvironment.runningInSmokeTestPipeline || CiEnvironment.runningInSelfHostedPipeline, "This test can disrupt other tests running in parallel."),
152152
)
153153
func makeCustomPathEnv() async throws {
154154
let customEnvironment: Environment = .current
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
import Foundation
13+
import Basics
14+
import Testing
15+
import Algorithms
16+
17+
fileprivate let prefixAndSuffixData = [
18+
[],
19+
[""],
20+
["line1"],
21+
["line1", "line2"],
22+
["line1", "line2", "line3"],
23+
].combinations(ofCount: 2).map( {data in
24+
Content(prefix: data[0], suffix: data[1])
25+
} )
26+
27+
fileprivate struct Content {
28+
let prefix: [String]
29+
let suffix: [String]
30+
31+
init(prefix pre: [String], suffix: [String]) {
32+
self.prefix = pre
33+
self.suffix = suffix
34+
}
35+
36+
func getContent(_ value: String) -> String {
37+
let contentArray: [String] = self.prefix + [value] + self.suffix
38+
let content = contentArray.joined(separator: "\n")
39+
return content
40+
}
41+
}
42+
43+
@Suite
44+
struct ProcessInfoExtensionTests {
45+
46+
@Suite
47+
struct isAmazonLinux2 {
48+
@Test(
49+
arguments: [
50+
(contentUT: "", expected: false),
51+
(contentUT: "ID=", expected: false),
52+
(contentUT: "ID=foo", expected: false),
53+
(contentUT: "ID=amzn", expected: true),
54+
(contentUT: " ID=amzn", expected: false),
55+
], prefixAndSuffixData,
56+
)
57+
fileprivate func isAmazonLinux2ReturnsExpectedValue(
58+
data: (contentUT: String, expected: Bool),
59+
content: Content,
60+
) async throws {
61+
let content = content.getContent(data.contentUT)
62+
63+
let actual = ProcessInfo.isHostAmazonLinux2(content)
64+
65+
#expect(actual == data.expected, "Content is: '\(content)'")
66+
}
67+
68+
@Test(
69+
"isHostAmazonLinux2 returns false when not executed on Linux",
70+
.skipHostOS(.linux),
71+
.tags(Tag.TestSize.medium),
72+
)
73+
func isAmazonLinux2ReturnsFalseWhenNotRunOnLinux() {
74+
let actual = ProcessInfo.isHostAmazonLinux2()
75+
76+
#expect(actual == false)
77+
}
78+
}
79+
}

Tests/CommandsTests/APIDiffTests.swift

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ struct APIDiffTests {
103103
}
104104
}
105105

106-
@Test(.requiresAPIDigester, arguments: SupportedBuildSystemOnAllPlatforms)
106+
@Test(
107+
.requiresAPIDigester,
108+
.issue("https://github.com/swiftlang/swift-package-manager/issues/8926", relationship: .defect),
109+
arguments: SupportedBuildSystemOnAllPlatforms,
110+
)
107111
func testMultiTargetAPIDiff(buildSystem: BuildSystemProvider.Kind) async throws {
108112
try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in
109113
let packageRoot = fixturePath.appending("Bar")
@@ -116,11 +120,15 @@ struct APIDiffTests {
116120
string: "public class Qux<T, U> { private let x = 1 }"
117121
)
118122
try await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)) { error in
119-
#expect(error.stdout.contains("2 breaking changes detected in Qux"))
120-
#expect(error.stdout.contains("💔 API breakage: class Qux has generic signature change from <T> to <T, U>"))
121-
#expect(error.stdout.contains("💔 API breakage: var Qux.x has been removed"))
122-
#expect(error.stdout.contains("1 breaking change detected in Baz"))
123-
#expect(error.stdout.contains("💔 API breakage: func bar() has been removed"))
123+
try withKnownIssue {
124+
#expect(error.stdout.contains("2 breaking changes detected in Qux"))
125+
#expect(error.stdout.contains("💔 API breakage: class Qux has generic signature change from <T> to <T, U>"))
126+
#expect(error.stdout.contains("💔 API breakage: var Qux.x has been removed"))
127+
#expect(error.stdout.contains("1 breaking change detected in Baz"))
128+
#expect(error.stdout.contains("💔 API breakage: func bar() has been removed"))
129+
} when: {
130+
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
131+
}
124132
}
125133
}
126134
}
@@ -156,7 +164,11 @@ struct APIDiffTests {
156164
}
157165
}
158166

159-
@Test(.requiresAPIDigester, arguments: SupportedBuildSystemOnAllPlatforms)
167+
@Test(
168+
.requiresAPIDigester,
169+
.issue("https://github.com/swiftlang/swift-package-manager/issues/8926", relationship: .defect),
170+
arguments: SupportedBuildSystemOnAllPlatforms,
171+
)
160172
func testCheckVendedModulesOnly(buildSystem: BuildSystemProvider.Kind) async throws {
161173
try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in
162174
let packageRoot = fixturePath.appending("NonAPILibraryTargets")
@@ -177,11 +189,15 @@ struct APIDiffTests {
177189
string: "public class Qux<T, U> { private let x = 1 }"
178190
)
179191
try await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)) { error in
180-
#expect(error.stdout.contains("💔 API breakage"))
181-
let regex = try Regex("\\d+ breaking change(s?) detected in Foo")
182-
#expect(error.stdout.contains(regex))
183-
#expect(error.stdout.contains(regex))
184-
#expect(error.stdout.contains(regex))
192+
try withKnownIssue {
193+
#expect(error.stdout.contains("💔 API breakage"))
194+
let regex = try Regex("\\d+ breaking change(s?) detected in Foo")
195+
#expect(error.stdout.contains(regex))
196+
#expect(error.stdout.contains(regex))
197+
#expect(error.stdout.contains(regex))
198+
} when: {
199+
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
200+
}
185201

186202
// Qux is not part of a library product, so any API changes should be ignored
187203
#expect(!error.stdout.contains("Qux"))

0 commit comments

Comments
 (0)