From 1ad3b153dd09d58046fb49de3948fe53aba22e3c Mon Sep 17 00:00:00 2001 From: omochimetaru Date: Tue, 23 Sep 2025 01:51:16 +0900 Subject: [PATCH 1/3] dump defaultLocalization --- .../DependencyResolution/External/Complex/app/Package.swift | 3 ++- Sources/PackageModel/Manifest/Manifest.swift | 1 + Tests/CommandsTests/PackageCommandTests.swift | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Fixtures/DependencyResolution/External/Complex/app/Package.swift b/Fixtures/DependencyResolution/External/Complex/app/Package.swift index bb4de73fefa..d5c129f1119 100644 --- a/Fixtures/DependencyResolution/External/Complex/app/Package.swift +++ b/Fixtures/DependencyResolution/External/Complex/app/Package.swift @@ -1,8 +1,9 @@ -// swift-tools-version:5.0 +// swift-tools-version:5.3 import PackageDescription let package = Package( name: "Dealer", + defaultLocalization: "en", platforms: [ .macOS(.v10_12), .iOS(.v10), diff --git a/Sources/PackageModel/Manifest/Manifest.swift b/Sources/PackageModel/Manifest/Manifest.swift index 17cc309b1c1..396961e11d7 100644 --- a/Sources/PackageModel/Manifest/Manifest.swift +++ b/Sources/PackageModel/Manifest/Manifest.swift @@ -655,6 +655,7 @@ extension Manifest: Encodable { } try container.encode(self.toolsVersion, forKey: .toolsVersion) + try container.encode(self.defaultLocalization, forKey: .defaultLocalization) try container.encode(self.pkgConfig, forKey: .pkgConfig) try container.encode(self.providers, forKey: .providers) try container.encode(self.cLanguageStandard, forKey: .cLanguageStandard) diff --git a/Tests/CommandsTests/PackageCommandTests.swift b/Tests/CommandsTests/PackageCommandTests.swift index 30ecf38a3dc..e1544984a59 100644 --- a/Tests/CommandsTests/PackageCommandTests.swift +++ b/Tests/CommandsTests/PackageCommandTests.swift @@ -1003,11 +1003,16 @@ struct PackageCommandTests { Issue.record("unexpected result") return } + guard case .string(let defaultLocalization)? = contents["defaultLocalization"] else { + Issue.record("unexpected result") + return + } guard case .array(let platforms)? = contents["platforms"] else { Issue.record("unexpected result") return } #expect(name == "Dealer") + #expect(defaultLocalization == "en") #expect( platforms == [ .dictionary([ From d803ac7090c4a11d89a351e2533615b09a0a8269 Mon Sep 17 00:00:00 2001 From: omochimetaru Date: Wed, 24 Sep 2025 16:49:12 +0900 Subject: [PATCH 2/3] create dedicated fixture --- .../External/Complex/app/Package.swift | 3 +- .../DumpPackage/PlayingCard/Package.swift | 12 +++++++ .../PlayingCard/src/PlayingCard.swift | 25 +++++++++++++ .../DumpPackage/PlayingCard/src/Rank.swift | 35 +++++++++++++++++++ .../DumpPackage/PlayingCard/src/Suit.swift | 33 +++++++++++++++++ .../DumpPackage/app/Package.swift | 23 ++++++++++++ .../Miscellaneous/DumpPackage/app/main.swift | 20 +++++++++++ Tests/CommandsTests/PackageCommandTests.swift | 16 +++++---- 8 files changed, 158 insertions(+), 9 deletions(-) create mode 100644 Fixtures/Miscellaneous/DumpPackage/PlayingCard/Package.swift create mode 100644 Fixtures/Miscellaneous/DumpPackage/PlayingCard/src/PlayingCard.swift create mode 100644 Fixtures/Miscellaneous/DumpPackage/PlayingCard/src/Rank.swift create mode 100644 Fixtures/Miscellaneous/DumpPackage/PlayingCard/src/Suit.swift create mode 100644 Fixtures/Miscellaneous/DumpPackage/app/Package.swift create mode 100644 Fixtures/Miscellaneous/DumpPackage/app/main.swift diff --git a/Fixtures/DependencyResolution/External/Complex/app/Package.swift b/Fixtures/DependencyResolution/External/Complex/app/Package.swift index d5c129f1119..bb4de73fefa 100644 --- a/Fixtures/DependencyResolution/External/Complex/app/Package.swift +++ b/Fixtures/DependencyResolution/External/Complex/app/Package.swift @@ -1,9 +1,8 @@ -// swift-tools-version:5.3 +// swift-tools-version:5.0 import PackageDescription let package = Package( name: "Dealer", - defaultLocalization: "en", platforms: [ .macOS(.v10_12), .iOS(.v10), diff --git a/Fixtures/Miscellaneous/DumpPackage/PlayingCard/Package.swift b/Fixtures/Miscellaneous/DumpPackage/PlayingCard/Package.swift new file mode 100644 index 00000000000..ef346d15f66 --- /dev/null +++ b/Fixtures/Miscellaneous/DumpPackage/PlayingCard/Package.swift @@ -0,0 +1,12 @@ +// swift-tools-version: 6.0 +import PackageDescription + +let package = Package( + name: "PlayingCard", + products: [ + .library(name: "PlayingCard", targets: ["PlayingCard"]), + ], + targets: [ + .target(name: "PlayingCard", path: "src"), + ] +) diff --git a/Fixtures/Miscellaneous/DumpPackage/PlayingCard/src/PlayingCard.swift b/Fixtures/Miscellaneous/DumpPackage/PlayingCard/src/PlayingCard.swift new file mode 100644 index 00000000000..bbbb52deb7d --- /dev/null +++ b/Fixtures/Miscellaneous/DumpPackage/PlayingCard/src/PlayingCard.swift @@ -0,0 +1,25 @@ +public struct PlayingCard: Equatable { + let rank: Rank + let suit: Suit + + public init(rank: Rank, suit: Suit) { + self.rank = rank + self.suit = suit + } +} + +// MARK: - Comparable + +extension PlayingCard: Comparable {} + +public func <(lhs: PlayingCard, rhs: PlayingCard) -> Bool { + return lhs.suit < rhs.suit || (lhs.suit == rhs.suit && lhs.rank < rhs.rank) +} + +// MARK: - CustomStringConvertible + +extension PlayingCard : CustomStringConvertible { + public var description: String { + return "\(suit)\(rank)" + } +} diff --git a/Fixtures/Miscellaneous/DumpPackage/PlayingCard/src/Rank.swift b/Fixtures/Miscellaneous/DumpPackage/PlayingCard/src/Rank.swift new file mode 100644 index 00000000000..530371d5f39 --- /dev/null +++ b/Fixtures/Miscellaneous/DumpPackage/PlayingCard/src/Rank.swift @@ -0,0 +1,35 @@ +public enum Rank : Int { + case Ace = 1 + case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten + case Jack, Queen, King +} + +// MARK: - Comparable + +extension Rank : Comparable {} + +public func <(lhs: Rank, rhs: Rank) -> Bool { + switch (lhs, rhs) { + case (_, _) where lhs == rhs: + return false + case (.Ace, _): + return false + default: + return lhs.rawValue < rhs.rawValue + } +} + +// MARK: - CustomStringConvertible + +extension Rank : CustomStringConvertible { + public var description: String { + switch self { + case .Ace: return "A" + case .Jack: return "J" + case .Queen: return "Q" + case .King: return "K" + default: + return "\(rawValue)" + } + } +} diff --git a/Fixtures/Miscellaneous/DumpPackage/PlayingCard/src/Suit.swift b/Fixtures/Miscellaneous/DumpPackage/PlayingCard/src/Suit.swift new file mode 100644 index 00000000000..8fabbc4d86b --- /dev/null +++ b/Fixtures/Miscellaneous/DumpPackage/PlayingCard/src/Suit.swift @@ -0,0 +1,33 @@ +public enum Suit: String { + case Spades, Hearts, Diamonds, Clubs +} + +// MARK: - Comparable + +extension Suit: Comparable {} + +public func <(lhs: Suit, rhs: Suit) -> Bool { + switch (lhs, rhs) { + case (_, _) where lhs == rhs: + return false + case (.Spades, _), + (.Hearts, .Diamonds), (.Hearts, .Clubs), + (.Diamonds, .Clubs): + return false + default: + return true + } +} + +// MARK: - CustomStringConvertible + +extension Suit : CustomStringConvertible { + public var description: String { + switch self { + case .Spades: return "♠︎" + case .Hearts: return "♡" + case .Diamonds: return "♢" + case .Clubs: return "♣︎" + } + } +} diff --git a/Fixtures/Miscellaneous/DumpPackage/app/Package.swift b/Fixtures/Miscellaneous/DumpPackage/app/Package.swift new file mode 100644 index 00000000000..dcf621e8e8c --- /dev/null +++ b/Fixtures/Miscellaneous/DumpPackage/app/Package.swift @@ -0,0 +1,23 @@ +// swift-tools-version: 6.0 +import PackageDescription + +let package = Package( + name: "Dealer", + defaultLocalization: "en", + platforms: [ + .macOS(.v10_13), + .iOS(.v12), + .tvOS(.v12), + .watchOS(.v5) + ], + dependencies: [ + .package(path: "../PlayingCard"), + ], + targets: [ + .target( + name: "Dealer", + dependencies: ["PlayingCard"], + path: "./" + ), + ] +) diff --git a/Fixtures/Miscellaneous/DumpPackage/app/main.swift b/Fixtures/Miscellaneous/DumpPackage/app/main.swift new file mode 100644 index 00000000000..4cf8762b715 --- /dev/null +++ b/Fixtures/Miscellaneous/DumpPackage/app/main.swift @@ -0,0 +1,20 @@ +/* + This source file is part of the Swift.org open source project + + Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + + See http://swift.org/LICENSE.txt for license information + See http://swift.org/CONTRIBUTORS.txt for Swift project authors +*/ + +import PlayingCard + +let hand: [PlayingCard] = [ + .init(rank: .Ace, suit: .Hearts), + .init(rank: .King, suit: .Spades), +] + +for card in hand { + print(card) +} diff --git a/Tests/CommandsTests/PackageCommandTests.swift b/Tests/CommandsTests/PackageCommandTests.swift index e1544984a59..f732e2fdd93 100644 --- a/Tests/CommandsTests/PackageCommandTests.swift +++ b/Tests/CommandsTests/PackageCommandTests.swift @@ -986,7 +986,7 @@ struct PackageCommandTests { func dumpPackage( data: BuildData, ) async throws { - try await fixture(name: "DependencyResolution/External/Complex") { fixturePath in + try await fixture(name: "Miscellaneous/DumpPackage") { fixturePath in let packageRoot = fixturePath.appending("app") let (dumpOutput, _) = try await execute( ["dump-package"], @@ -995,20 +995,21 @@ struct PackageCommandTests { buildSystem: data.buildSystem, ) let json = try JSON(bytes: ByteString(encodingAsUTF8: dumpOutput)) + print(json) guard case .dictionary(let contents) = json else { Issue.record("unexpected result") return } guard case .string(let name)? = contents["name"] else { - Issue.record("unexpected result") + Issue.record("unexpected name") return } guard case .string(let defaultLocalization)? = contents["defaultLocalization"] else { - Issue.record("unexpected result") + Issue.record("unexpected defaultLocalization") return } guard case .array(let platforms)? = contents["platforms"] else { - Issue.record("unexpected result") + Issue.record("unexpected platforms") return } #expect(name == "Dealer") @@ -1017,17 +1018,17 @@ struct PackageCommandTests { platforms == [ .dictionary([ "platformName": .string("macos"), - "version": .string("10.12"), + "version": .string("10.13"), "options": .array([]), ]), .dictionary([ "platformName": .string("ios"), - "version": .string("10.0"), + "version": .string("12.0"), "options": .array([]), ]), .dictionary([ "platformName": .string("tvos"), - "version": .string("11.0"), + "version": .string("12.0"), "options": .array([]), ]), .dictionary([ @@ -1037,6 +1038,7 @@ struct PackageCommandTests { ]), ] ) + // FIXME: We should also test dependencies and targets here. } } From 0352d647e61900c9edf930cdf770fac5ccd8d96a Mon Sep 17 00:00:00 2001 From: omochimetaru Date: Wed, 24 Sep 2025 16:50:16 +0900 Subject: [PATCH 3/3] rm debug print --- Tests/CommandsTests/PackageCommandTests.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/CommandsTests/PackageCommandTests.swift b/Tests/CommandsTests/PackageCommandTests.swift index f732e2fdd93..f7c628bdbbe 100644 --- a/Tests/CommandsTests/PackageCommandTests.swift +++ b/Tests/CommandsTests/PackageCommandTests.swift @@ -995,7 +995,6 @@ struct PackageCommandTests { buildSystem: data.buildSystem, ) let json = try JSON(bytes: ByteString(encodingAsUTF8: dumpOutput)) - print(json) guard case .dictionary(let contents) = json else { Issue.record("unexpected result") return