3 LSP has "marker tests" defined in `internal/lsp/testdata`, as well as
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.
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.
18 When tests are run, each annotation results in a new subtest, which is encoded
19 in the golden file with a heading like,
22 -- suggestedfix_bar_11_21 --
23 // expected contents go here
24 -- suggestedfix_bar_13_20 --
25 // expected contents go here
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.
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`
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).
45 # The marker tests are located in "internal/lsp", "internal/lsp/cmd, and
46 # "internal/lsp/source".
47 go test ./internal/lsp/...
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:
55 go test ./internal/lsp -v -run TestLSP/Modules/SuggestedFix/bar_11_21
58 ## Resetting marker tests
60 Sometimes, a change is made to lsp that requires a change to multiple golden
61 files. When this happens, you can run,
65 ./internal/lsp/reset_golden.sh