mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-02 18:23:24 +01:00
Define sources for mixed package tests inline with the tests
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
// swift-tools-version:5.1
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "pkg",
|
||||
targets: [
|
||||
.target(name: "lib", dependencies: []),
|
||||
.target(name: "clib", dependencies: []),
|
||||
]
|
||||
)
|
||||
@@ -1,3 +0,0 @@
|
||||
#include "clib.h"
|
||||
|
||||
void clib_func(void) {/*clib_func:body*/}
|
||||
@@ -1,7 +0,0 @@
|
||||
#ifndef CLIB_H
|
||||
#define CLIB_H
|
||||
|
||||
void clib_func(void);
|
||||
void clib_other(void);
|
||||
|
||||
#endif // CLIB_H
|
||||
@@ -1,5 +0,0 @@
|
||||
public struct Lib {
|
||||
public func foo() {}
|
||||
public init() {}
|
||||
}
|
||||
/*lib.swift:toplevel*/
|
||||
@@ -17,10 +17,10 @@ import SKCore
|
||||
/// The location of a test file within test workspace.
|
||||
public struct RelativeFileLocation: Hashable, ExpressibleByStringLiteral {
|
||||
/// The subdirectories in which the file is located.
|
||||
fileprivate let directories: [String]
|
||||
let directories: [String]
|
||||
|
||||
/// The file's name.
|
||||
fileprivate let fileName: String
|
||||
let fileName: String
|
||||
|
||||
public init(directories: [String] = [], _ fileName: String) {
|
||||
self.directories = directories
|
||||
|
||||
@@ -36,14 +36,22 @@ public class SwiftPMTestWorkspace: MultiFileTestWorkspace {
|
||||
///
|
||||
/// If `index` is `true`, then the package will be built, indexing all modules within the package.
|
||||
public init(
|
||||
files: [String: String],
|
||||
files: [RelativeFileLocation: String],
|
||||
manifest: String = SwiftPMTestWorkspace.defaultPackageManifest,
|
||||
build: Bool = false,
|
||||
testName: String = #function
|
||||
) async throws {
|
||||
var filesByPath: [RelativeFileLocation: String] = [:]
|
||||
for (fileName, contents) in files {
|
||||
filesByPath[RelativeFileLocation(directories: ["Sources", "MyLibrary"], fileName)] = contents
|
||||
for (fileLocation, contents) in files {
|
||||
let directories =
|
||||
if fileLocation.directories.isEmpty {
|
||||
["Sources", "MyLibrary"]
|
||||
} else if fileLocation.directories.first != "Sources" {
|
||||
["Sources"] + fileLocation.directories
|
||||
} else {
|
||||
fileLocation.directories
|
||||
}
|
||||
filesByPath[RelativeFileLocation(directories: directories, fileLocation.fileName)] = contents
|
||||
}
|
||||
filesByPath["Package.swift"] = manifest
|
||||
try await super.init(
|
||||
|
||||
@@ -238,18 +238,57 @@ final class WorkspaceTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testMixedPackage() async throws {
|
||||
guard let ws = try await staticSourceKitSwiftPMWorkspace(name: "MixedPackage") else { return }
|
||||
try ws.buildAndIndex()
|
||||
let ws = try await SwiftPMTestWorkspace(
|
||||
files: [
|
||||
"clib/include/clib.h": """
|
||||
#ifndef CLIB_H
|
||||
#define CLIB_H
|
||||
|
||||
let cLoc = ws.testLoc("clib_func:body")
|
||||
let swiftLoc = ws.testLoc("lib.swift:toplevel")
|
||||
void clib_func(void);
|
||||
void clib_other(void);
|
||||
|
||||
try ws.openDocument(swiftLoc.url, language: .swift)
|
||||
try ws.openDocument(cLoc.url, language: .c)
|
||||
#endif // CLIB_H
|
||||
""",
|
||||
"clib/clib.c": """
|
||||
#include "clib.h"
|
||||
|
||||
await assertNoThrow {
|
||||
_ = try await ws.testClient.send(CompletionRequest(textDocument: cLoc.docIdentifier, position: cLoc.position))
|
||||
}
|
||||
void clib_func(void) {1️⃣}
|
||||
""",
|
||||
"lib/lib.swift": """
|
||||
public struct Lib {
|
||||
public func foo() {}
|
||||
public init() {}
|
||||
}
|
||||
2️⃣
|
||||
""",
|
||||
],
|
||||
manifest: """
|
||||
// swift-tools-version: 5.7
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "MyLibrary",
|
||||
targets: [
|
||||
.target(name: "lib", dependencies: []),
|
||||
.target(name: "clib", dependencies: []),
|
||||
]
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
let (swiftUri, swiftPositions) = try ws.openDocument("lib.swift")
|
||||
let (cUri, cPositions) = try ws.openDocument("clib.c")
|
||||
|
||||
let cCompletions = try await ws.testClient.send(
|
||||
CompletionRequest(textDocument: TextDocumentIdentifier(cUri), position: cPositions["1️⃣"])
|
||||
)
|
||||
XCTAssertGreaterThanOrEqual(cCompletions.items.count, 0)
|
||||
|
||||
let swiftCompletions = try await ws.testClient.send(
|
||||
CompletionRequest(textDocument: TextDocumentIdentifier(swiftUri), position: swiftPositions["2️⃣"])
|
||||
)
|
||||
XCTAssertGreaterThanOrEqual(swiftCompletions.items.count, 0)
|
||||
}
|
||||
|
||||
func testChangeWorkspaceFolders() async throws {
|
||||
|
||||
Reference in New Issue
Block a user