Skip to content

completion-tool list-executables should list executable names #8053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions Fixtures/Miscellaneous/DifferentProductTargetName/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// swift-tools-version:5.2
import PackageDescription

let package = Package(
name: "Foo",
products: [
.executable(name: "Foo", targets: ["Foo"]),
],
targets: [
.target(name: "Foo", path: "./"),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public func foo() {
{}()
}
2 changes: 1 addition & 1 deletion Sources/Commands/PackageCommands/CompletionCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ extension SwiftPackageCommand {
case .listExecutables:
let graph = try await swiftCommandState.loadPackageGraph()
let package = graph.rootPackages[graph.rootPackages.startIndex].underlying
let executables = package.modules.filter { $0.type == .executable }
let executables = package.products.filter { $0.type == .executable }
for executable in executables {
print(executable.name)
}
Expand Down
27 changes: 27 additions & 0 deletions Tests/CommandsTests/CompletionCommandTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Basics
import _InternalTestSupport
import XCTest

final class CompletionCommandTests: CommandsTestCase {

private func execute(
_ args: [String] = [],
packagePath: AbsolutePath? = nil
) async throws -> (stdout: String, stderr: String) {
return try await SwiftPM.Package.execute(args, packagePath: packagePath)
}

func testListExecutables() async throws {
try await fixture(name: "Miscellaneous/MultipleExecutables") { fixturePath in
let result = try await execute(["completion-tool", "list-executables"], packagePath: fixturePath)
XCTAssertEqual(result.stdout, "exec1\nexec2\n")
}
}

func testListExecutablesDifferentNames() async throws {
try await fixture(name: "Miscellaneous/DifferentProductTargetName") { fixturePath in
let result = try await execute(["completion-tool", "list-executables"], packagePath: fixturePath)
XCTAssertEqual(result.stdout, "Foo\n")
}
}
}