.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.1.0 / internal / lsp / tests / README.md
1 # Testing
2
3 LSP has "marker tests" defined in `internal/lsp/testdata`, as well as
4 traditional tests.
5
6 ## Marker tests
7
8 Marker tests have a standard input file, like
9 `internal/lsp/testdata/foo/bar.go`, and some may have a corresponding golden
10 file, like `internal/lsp/testdata/foo/bar.go.golden`. The former is the "input"
11 and the latter is the expected output.
12
13 Each input file contains annotations like
14 `//@suggestedfix("}", "refactor.rewrite")`. These annotations are interpreted by
15 test runners to perform certain actions. The expected output after those actions
16 is encoded in the golden file.
17
18 When tests are run, each annotation results in a new subtest, which is encoded
19 in the golden file with a heading like,
20
21 ```bash
22 -- suggestedfix_bar_11_21 --
23 // expected contents go here
24 -- suggestedfix_bar_13_20 --
25 // expected contents go here
26 ```
27
28 The format of these headings vary: they are defined by the
29 [`Golden`](https://pkg.go.dev/golang.org/x/tools/internal/lsp/tests#Data.Golden)
30 function for each annotation. In the case above, the format is: annotation
31 name, file name, annotation line location, annotation character location.
32
33 So, if `internal/lsp/testdata/foo/bar.go` has three `suggestedfix` annotations,
34 the golden file should have three headers with `suggestedfix_bar_xx_yy`
35 headings.
36
37 To see a list of all available annotations, see the exported "expectations" in
38 [tests.go](https://github.com/golang/tools/blob/299f270db45902e93469b1152fafed034bb3f033/internal/lsp/tests/tests.go#L418-L447).
39
40 To run marker tests,
41
42 ```bash
43 cd /path/to/tools
44
45 # The marker tests are located in "internal/lsp", "internal/lsp/cmd, and
46 # "internal/lsp/source".
47 go test ./internal/lsp/...
48 ```
49
50 There are quite a lot of marker tests, so to run one individually, pass the test
51 path and heading into a -run argument:
52
53 ```bash
54 cd /path/to/tools
55 go test ./internal/lsp -v -run TestLSP/Modules/SuggestedFix/bar_11_21
56 ```
57
58 ## Resetting marker tests
59
60 Sometimes, a change is made to lsp that requires a change to multiple golden
61 files. When this happens, you can run,
62
63 ```bash
64 cd /path/to/tools
65 ./internal/lsp/reset_golden.sh
66 ```