Skip to content
Merged
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
10 changes: 9 additions & 1 deletion Sources/Commands/Utilities/DependenciesSerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ final class PlainTextDumper: DependenciesDumper {

let pkgVersion = package.manifest.version?.description ?? "unspecified"

stream.send("\(hanger)\(package.identity.description)<\(package.manifest.packageLocation)@\(pkgVersion)>\n")
let traitsEnabled: String
if let enabled = package.enabledTraits, !enabled.isEmpty {
traitsEnabled = "(traits: \(package.enabledTraits?.joined(separator: ", ") ?? ""))"
} else {
traitsEnabled = ""
}

stream.send("\(hanger)\(package.identity.description)<\(package.manifest.packageLocation)@\(pkgVersion)>\(traitsEnabled)\n")

if !package.dependencies.isEmpty {
let replacement = (index == packages.count - 1) ? " " : "│ "
Expand Down Expand Up @@ -130,6 +137,7 @@ final class JSONDumper: DependenciesDumper {
"url": .string(package.manifest.packageLocation),
"version": .string(package.manifest.version?.description ?? "unspecified"),
"path": .string(package.path.pathString),
"traits": .array(package.enabledTraits?.map { .string($0) } ?? []),
"dependencies": .array(package.dependencies.compactMap { graph.packages[$0] }.map(convert)),
])
}
Expand Down
49 changes: 49 additions & 0 deletions Tests/CommandsTests/PackageCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,55 @@ struct PackageCommandTests {
}
}

@Test(
.tags(
.Feature.Command.Package.ShowDependencies,
),
arguments: getBuildData(for: SupportedBuildSystemOnAllPlatforms),
)
func showDependenciesWithTraits(
data: BuildData,
) async throws {
try await fixture(name: "Traits") { fixturePath in
let packageRoot = fixturePath.appending("Example")
let (textOutput, _) = try await execute(
["show-dependencies", "--format=text"],
packagePath: packageRoot,
configuration: data.config,
buildSystem: data.buildSystem,
)
#expect(textOutput.contains("(traits: Package3Trait3)"))

let (jsonOutput, _) = try await execute(
["show-dependencies", "--format=json"],
packagePath: packageRoot,
configuration: data.config,
buildSystem: data.buildSystem,
)
let json = try JSON(bytes: ByteString(encodingAsUTF8: jsonOutput))
guard case .dictionary(let contents) = json else {
Issue.record("unexpected result")
return
}
guard case .string(let name)? = contents["name"] else {
Issue.record("unexpected result")
return
}
#expect(name == "TraitsExample")

// verify the traits JSON entry lists each of the traits in the fixture
guard case .array(let traitsProperty)? = contents["traits"] else {
Issue.record("unexpected result")
return
}
#expect(traitsProperty.contains(.string("Package1")))
#expect(traitsProperty.contains(.string("Package2")))
#expect(traitsProperty.contains(.string("Package3")))
#expect(traitsProperty.contains(.string("Package4")))
#expect(traitsProperty.contains(.string("BuildCondition1")))
}
}

@Test(
arguments: getBuildData(for: SupportedBuildSystemOnAllPlatforms),
)
Expand Down