Skip to content

Commit a6e3346

Browse files
authored
Merge pull request #1618 from ahoppen/test-case-no-package-resolve
Add a test case that we get build settings for a SwiftPM package if package hasn't been resolved
2 parents 219b11d + 1d78975 commit a6e3346

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Tests/BuildSystemIntegrationTests/SwiftPMBuildSystemTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,47 @@ final class SwiftPMBuildSystemTests: XCTestCase {
842842
assertArgumentsContain(aswift.pathString, arguments: arguments)
843843
}
844844
}
845+
846+
func testPackageWithDependencyWithoutResolving() async throws {
847+
// This package has a dependency but we haven't run `swift package resolve`. We don't want to resolve packages from
848+
// SourceKit-LSP because it has side-effects to the build directory.
849+
// But even without the dependency checked out, we should be able to create a SwiftPMBuildSystem and retrieve the
850+
// existing source files.
851+
let project = try await SwiftPMTestProject(
852+
files: [
853+
"Tests/PackageTests/PackageTests.swift": """
854+
import Testing
855+
856+
1️⃣@Test func topLevelTestPassing() {}2️⃣
857+
"""
858+
],
859+
manifest: """
860+
let package = Package(
861+
name: "MyLibrary",
862+
dependencies: [.package(url: "https://github.com/swiftlang/swift-testing.git", branch: "main")],
863+
targets: [
864+
.testTarget(name: "PackageTests", dependencies: [.product(name: "Testing", package: "swift-testing")]),
865+
]
866+
)
867+
"""
868+
)
869+
870+
let tests = try await project.testClient.send(WorkspaceTestsRequest())
871+
XCTAssertEqual(
872+
tests,
873+
[
874+
TestItem(
875+
id: "PackageTests.topLevelTestPassing()",
876+
label: "topLevelTestPassing()",
877+
disabled: false,
878+
style: "swift-testing",
879+
location: try project.location(from: "1️⃣", to: "2️⃣", in: "PackageTests.swift"),
880+
children: [],
881+
tags: []
882+
)
883+
]
884+
)
885+
}
845886
}
846887

847888
private func assertArgumentsDoNotContain(

0 commit comments

Comments
 (0)