diff --git a/Sources/_InternalTestSupport/ProcessInfo+hostutils.swift b/Sources/_InternalTestSupport/ProcessInfo+hostutils.swift index c09a1c59812..5bd47e21544 100644 --- a/Sources/_InternalTestSupport/ProcessInfo+hostutils.swift +++ b/Sources/_InternalTestSupport/ProcessInfo+hostutils.swift @@ -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 @@ -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)") } -} \ No newline at end of file +} diff --git a/Sources/_InternalTestSupport/SwiftTesting+Tags.swift b/Sources/_InternalTestSupport/SwiftTesting+Tags.swift index 1a9a2ffd677..a3baac3bd04 100644 --- a/Sources/_InternalTestSupport/SwiftTesting+Tags.swift +++ b/Sources/_InternalTestSupport/SwiftTesting+Tags.swift @@ -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 diff --git a/Tests/BasicsTests/ProcessInfoTests.swift b/Tests/BasicsTests/ProcessInfoTests.swift index eeab84dec79..266e8612995 100644 --- a/Tests/BasicsTests/ProcessInfoTests.swift +++ b/Tests/BasicsTests/ProcessInfoTests.swift @@ -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]) @@ -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" @@ -71,6 +73,7 @@ struct ProcessInfoExtensionTests { HOME_URL="https://amazonlinux.com/" SUPPORT_END="2026-06-30" """, + nameUT: "Amazon Linux 2", expected: true ), ( @@ -86,6 +89,7 @@ struct ProcessInfoExtensionTests { HOME_URL="https://amazonlinux.com/" SUPPORT_END="2026-06-30" """, + nameUT: "Amazon Linux 2", expected: false ), ( @@ -101,6 +105,7 @@ struct ProcessInfoExtensionTests { HOME_URL="https://amazonlinux.com/" SUPPORT_END="2026-06-30" """, + nameUT: "Amazon Linux 2", expected: false ), ( @@ -116,6 +121,7 @@ struct ProcessInfoExtensionTests { HOME_URL="https://amazonlinux.com/" SUPPORT_END="2026-06-30" """, + nameUT: "Amazon Linux 2", expected: false ), ( @@ -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) } } -} \ No newline at end of file +} diff --git a/Tests/FunctionalTests/LibraryEvolutionXCFLinuxTests.swift b/Tests/FunctionalTests/LibraryEvolutionXCFLinuxTests.swift index 54e21ca73ab..691735fd255 100644 --- a/Tests/FunctionalTests/LibraryEvolutionXCFLinuxTests.swift +++ b/Tests/FunctionalTests/LibraryEvolutionXCFLinuxTests.swift @@ -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 @@ -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() + } } -} \ No newline at end of file +}