Skip to content

Commit 5efd210

Browse files
authored
completion-tool list-executables should list executable names (#8053)
Update the completion tool so it prints the list of executable names instead of target names. The executable products names determines the name fo the actual binary written to disk, which is what you'd want from a completion-tool. That patch also adds a few tests for completion-tool around this specific behaviour. There weren't existing tests for the completion-tool. More tests to follow in a subsequent PR focusing on testing this area specifically. Fixes #8033
1 parent 4095b90 commit 5efd210

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// swift-tools-version:5.2
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "Foo",
6+
products: [
7+
.executable(name: "Foo", targets: ["Bar"]),
8+
],
9+
targets: [
10+
.target(name: "Bar", path: "./"),
11+
]
12+
)

Fixtures/Miscellaneous/DifferentProductTargetName/main.swift

Whitespace-only changes.

Sources/Commands/PackageCommands/CompletionCommand.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ extension SwiftPackageCommand {
7676
case .listExecutables:
7777
let graph = try await swiftCommandState.loadPackageGraph()
7878
let package = graph.rootPackages[graph.rootPackages.startIndex].underlying
79-
let executables = package.modules.filter { $0.type == .executable }
79+
let executables = package.products.filter { $0.type == .executable }
8080
for executable in executables {
8181
print(executable.name)
8282
}

Tests/CommandsTests/PackageCommandTests.swift

+14
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,20 @@ final class PackageCommandTests: CommandsTestCase {
551551
}
552552
}
553553

554+
func testCompletionToolListExecutables() async throws {
555+
try await fixture(name: "Miscellaneous/MultipleExecutables") { fixturePath in
556+
let result = try await execute(["completion-tool", "list-executables"], packagePath: fixturePath)
557+
XCTAssertEqual(result.stdout, "exec1\nexec2\n")
558+
}
559+
}
560+
561+
func testCompletionToolListExecutablesDifferentNames() async throws {
562+
try await fixture(name: "Miscellaneous/DifferentProductTargetName") { fixturePath in
563+
let result = try await execute(["completion-tool", "list-executables"], packagePath: fixturePath)
564+
XCTAssertEqual(result.stdout, "Foo\n")
565+
}
566+
}
567+
554568
func testShowExecutables() async throws {
555569
try await fixture(name: "Miscellaneous/ShowExecutables") { fixturePath in
556570
let packageRoot = fixturePath.appending("app")

0 commit comments

Comments
 (0)