File: Testing.md

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (19 lines) | stat: -rw-r--r-- 1,705 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Testing

Most tests in SourceKit-LSP are integration tests that create a `SourceKitLSPServer` instance in-process, initialize it and send messages to it. The test support modules essentially define four ways of creating test projects.

### `TestSourceKitLSPClient`

Launches a `SourceKitLSPServer` in-process. Documents can be opened within it but these documents don't have any representation on the file system. `TestSourceKitLSPClient` has the lowest overhead and is the basis for all the other test projects. Because there are no files on disk, this type cannot test anything that requires cross-file functionality or exercise requests that require an index.

### `IndexedSingleSwiftFileTestProject`

Creates a single `.swift` file on disk, indexes it and then opens it using a `TestSourceKitLSPClient`. This is the best choice for tests that require an index but don’t need to exercise any cross-file functionality.

### `SwiftPMTestProject`

Creates a SwiftPM project on disk that allows testing of cross-file and cross-module functionality. By default the `SwiftPMTestProject` does not build an index or build any Swift modules, which is often sufficient when testing cross-file functionality within a single module. When cross-module functionality or an index is needed, background indexing can be enabled using `enableBackgroundIndexing: true`, which waits for background indexing to finish before allowing any requests.

## `MultiFileTestProject`

This is the most flexible test type that writes arbitrary files to disk. It provides less functionality out-of-the-box but is capable of eg. representing workspaces with multiple SwiftPM projects or projects that have `compile_commands.json`.