Skip to content

Respect module name argument order precedence #1549

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 1 commit into from
Jul 4, 2024
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
4 changes: 2 additions & 2 deletions Sources/SKCore/BuildSystemManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ extension BuildSystemManager {
switch language {
case .swift:
// Module name is specified in the form -module-name MyLibrary
guard let moduleNameFlagIndex = buildSettings.compilerArguments.firstIndex(of: "-module-name") else {
guard let moduleNameFlagIndex = buildSettings.compilerArguments.lastIndex(of: "-module-name") else {
return nil
}
return buildSettings.compilerArguments[safe: moduleNameFlagIndex + 1]
case .objective_c:
// Specified in the form -fmodule-name=MyLibrary
guard
let moduleNameArgument = buildSettings.compilerArguments.first(where: {
let moduleNameArgument = buildSettings.compilerArguments.last(where: {
$0.starts(with: "-fmodule-name=")
}),
let moduleName = moduleNameArgument.split(separator: "=").last
Expand Down
51 changes: 51 additions & 0 deletions Tests/SourceKitLSPTests/WorkspaceTestDiscoveryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,57 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
)
}

func testTargetWithCustomModuleName() async throws {
let packageManifestWithCustomModuleName = """
let package = Package(
name: "MyLibrary",
targets: [
.testTarget(
name: "MyLibraryTests",
swiftSettings: [
.unsafeFlags(["-module-name", "Foo", "-module-name", "Bar"])
]
)
]
)
"""

let project = try await SwiftPMTestProject(
files: [
"Tests/MyLibraryTests/MyTests.swift": """
import XCTest

1️⃣class MyTests: XCTestCase {
2️⃣func testMyLibrary() {}3️⃣
}4️⃣
"""
],
manifest: packageManifestWithCustomModuleName
)

// Last argument takes precedence, so expect Bar as the module name.

let tests = try await project.testClient.send(WorkspaceTestsRequest())

XCTAssertEqual(
tests,
[
TestItem(
id: "Bar.MyTests",
label: "MyTests",
location: try project.location(from: "1️⃣", to: "4️⃣", in: "MyTests.swift"),
children: [
TestItem(
id: "Bar.MyTests/testMyLibrary()",
label: "testMyLibrary()",
location: try project.location(from: "2️⃣", to: "3️⃣", in: "MyTests.swift")
)
]
)
]
)
}

func testMultipleTargetsWithSameXCTestClassName() async throws {
let packageManifestWithTwoTestTargets = """
let package = Package(
Expand Down