Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Sources/_InternalTestSupport/ProcessInfo+hostutils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import Foundation

extension ProcessInfo {
public static func isHostAmazonLinux2(_ content: String? = nil) -> Bool {
package static func isHostOs(prettyName: String, content: String? = nil) -> Bool {
let contentString: String
if let content {
contentString = content
Expand All @@ -22,8 +22,16 @@ extension ProcessInfo {
return false
}
}
let al2_name = "PRETTY_NAME=\"Amazon Linux 2\""
return contentString.contains(al2_name)
let name = "PRETTY_NAME=\"\(prettyName)\""
return contentString.contains(name)

}
public static func isHostAmazonLinux2() -> Bool {
return Self.isHostOs(prettyName: "Amazon Linux 2")
}

public static func isHostDebian12() -> Bool {
return Self.isHostOs(prettyName: "Debian GNU/Linux 12 (bookworm)")
}

}
}
1 change: 1 addition & 0 deletions Sources/_InternalTestSupport/SwiftTesting+Tags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extension Tag.Feature {
@Tag public static var CodeCoverage: Tag
@Tag public static var CTargets: Tag
@Tag public static var DependencyResolution: Tag
@Tag public static var LibraryEvolution: Tag
@Tag public static var ModuleAliasing: Tag
@Tag public static var Mirror: Tag
@Tag public static var NetRc: Tag
Expand Down
82 changes: 60 additions & 22 deletions Tests/BasicsTests/ProcessInfoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import Testing
@testable import struct _InternalTestSupport.CombinationsWithRepetition

fileprivate let d = [
[],
[""],
["line1"],
["line1", "line2"],
["line1", "line2", "line3"],
]
[],
[""],
["line1"],
["line1", "line2"],
["line1", "line2", "line3"],
]
fileprivate let prefixAndSuffixData = CombinationsWithRepetition(of: d, length: 2).map( {data in
// Content(prefix: data.0, suffix: data.1)
Content(prefix: data[0], suffix: data[1])
Expand All @@ -46,18 +46,20 @@ fileprivate struct Content {
struct ProcessInfoExtensionTests {

@Suite
struct isAmazonLinux2 {
struct isHostOsTests {
@Test(
arguments: [
(contentUT: "", expected: false),
(contentUT: "PRETTY_NAME=", expected: false),
(contentUT: "PRETTY_NAME=foo", expected: false),
(contentUT: "PRETTY_NAME=amzn", expected: false),
(contentUT: "PRETTY_NAME=Amazon Linux 2", expected: false),
(contentUT: "PRETTY_NAME=Amazon Linux 2023.6.20250107", expected: false),
(contentUT: " PRETTY_NAME=amzn", expected: false),
(contentUT: "PRETTY_NAME=\"Amazon Linux 2\"", expected: true),
(contentUT: "PRETTY_NAME=\"Amazon Linux 2 (something else)\"", expected: false),
(contentUT: "", nameUT: "Amazon Linux 2", expected: false),
(contentUT: "PRETTY_NAME=", nameUT: "Amazon Linux 2", expected: false),
(contentUT: "PRETTY_NAME=foo", nameUT: "Amazon Linux 2", expected: false),
(contentUT: "PRETTY_NAME=amzn", nameUT: "Amazon Linux 2", expected: false),
(contentUT: "PRETTY_NAME=Amazon Linux 2", nameUT: "Amazon Linux 2", expected: false),
(contentUT: "PRETTY_NAME=Amazon Linux 2", nameUT: "Amazon Linux 2", expected: false),
(contentUT: "PRETTY_NAME=Amazon Linux 2023.6.20250107", nameUT: "Amazon Linux 2", expected: false),
(contentUT: " PRETTY_NAME=amzn", nameUT: "Amazon Linux 2", expected: false),
(contentUT: "PRETTY_NAME=\"Amazon Linux 2\"", nameUT: "Amazon Linux 2", expected: true),
(contentUT: " PRETTY_NAME=\"Amazon Linux 2\"", nameUT: "Amazon Linux 2", expected: true),
(contentUT: "PRETTY_NAME=\"Amazon Linux 2 (something else)\"", nameUT: "Amazon Linux 2", expected: false),
(
contentUT: """
NAME="Amazon Linux"
Expand All @@ -71,6 +73,7 @@ struct ProcessInfoExtensionTests {
HOME_URL="https://amazonlinux.com/"
SUPPORT_END="2026-06-30"
""",
nameUT: "Amazon Linux 2",
expected: true
),
(
Expand All @@ -86,6 +89,7 @@ struct ProcessInfoExtensionTests {
HOME_URL="https://amazonlinux.com/"
SUPPORT_END="2026-06-30"
""",
nameUT: "Amazon Linux 2",
expected: false
),
(
Expand All @@ -101,6 +105,7 @@ struct ProcessInfoExtensionTests {
HOME_URL="https://amazonlinux.com/"
SUPPORT_END="2026-06-30"
""",
nameUT: "Amazon Linux 2",
expected: false
),
(
Expand All @@ -116,6 +121,7 @@ struct ProcessInfoExtensionTests {
HOME_URL="https://amazonlinux.com/"
SUPPORT_END="2026-06-30"
""",
nameUT: "Amazon Linux 2",
expected: false
),
(
Expand All @@ -137,30 +143,62 @@ struct ProcessInfoExtensionTests {
VENDOR_URL="https://aws.amazon.com/"
SUPPORT_END="2028-03-15"
""",
nameUT: "Amazon Linux 2",
expected: false,
),
(
contentUT: """
NAME="Amazon Linux"
PLATFORM_ID="platform:al2023"
PRETTY_NAME="myFoo"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023"
""",
nameUT: "myfoo",
expected: false,
)
], prefixAndSuffixData,
)
fileprivate func isAmazonLinux2ReturnsExpectedValue(
data: (contentUT: String, expected: Bool),
fileprivate func isHostOsReturnsExpectedValue(
data: (contentUT: String, nameUT: String, expected: Bool),
content: Content,

) async throws {
let content = content.getContent(data.contentUT)

let actual = ProcessInfo.isHostAmazonLinux2(content)
let actual = ProcessInfo.isHostOs(prettyName: data.nameUT, content: content)

#expect(actual == data.expected, "Content is: '\(content)'")
}

@Test(
.requireHostOS(.windows),
.requireHostOS(.macOS),
)
func isHostOsReturnsFalseIfTheOSFileContentsCannotBeRead() async throws {
let actual = ProcessInfo.isHostOs(prettyName: "Amazon Linux 2")
#expect(actual == false)
}

@Test(
"isHostAmazonLinux2 returns false when not executed on Linux",
.skipHostOS(.linux),
.tags(Tag.TestSize.medium),
.skipHostOS(.linux, "Test cannot run on AmazonLinux2, but we can't distinguish linux distributions, so skipping",),
.tags(Tag.TestSize.small),
)
func isAmazonLinux2ReturnsFalseWhenNotRunOnLinux() {
let actual = ProcessInfo.isHostAmazonLinux2()

#expect(actual == false)
}
@Test(
"isHostDebian12 returns false when not executed on Linux",
.skipHostOS(.linux, "Test cannot run on Debian 12, but we can't distinguish linux distributions, so skipping",),
.tags(Tag.TestSize.small),
)
func isHostDebian12ReturnsFalseWhenNotRunOnLinux() {
let actual = ProcessInfo.isHostDebian12()

#expect(actual == false)
}
}
}
}
16 changes: 14 additions & 2 deletions Tests/FunctionalTests/LibraryEvolutionXCFLinuxTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@
//
//===----------------------------------------------------------------------===//

import Foundation
import _InternalTestSupport
import Basics
import Testing
import PackageLoading

private struct SwiftPMTests {
@Test(
.requireSwift6_2,
.requireHostOS(.linux)
.requireHostOS(.linux),
.tags(
.TestSize.large,
.Feature.Command.Run,
.Feature.LibraryEvolution,
),
.issue("https://github.com/swiftlang/swift-package-manager/issues/9372", relationship: .defect),
)
func libraryEvolutionLinuxXCFramework() async throws {
try await withKnownIssue {
try await fixture(name: "Miscellaneous/LibraryEvolutionLinuxXCF") { fixturePath in
let swiftFramework = "SwiftFramework"
try await withTemporaryDirectory(removeTreeOnDeinit: false) { tmpDir in
Expand Down Expand Up @@ -105,5 +114,8 @@ private struct SwiftPMTests {
#expect(!runOutput.stderr.contains("error:"))
#expect(runOutput.stdout.contains("Latest Framework with LibraryEvolution version: v2"))
}
} when: {
ProcessInfo.isHostAmazonLinux2() || ProcessInfo.isHostDebian12()
}
}
}
}