Collapse Diagnostic.Kind, Source, and Category into just Source. Remove code that converted from Diagnostic to Diagnostic. Notes on the changes I had to make along the way: - We used to use Kind to determine Severity. Set Severity when the Diagnostic is created instead. - Use constants for Source as much as possible -- we still need to use Analyzer.Name for analysis diagnostics. It would be nice to break that dependency so that Source was totally opaque, but that's a separate issue. - Introduce a new Source for gc_details, "optimizer details". It was "go compiler" previously. - Some of the assignments are a little arbitrary. Is inconsistent vendoring really a "go list" error? - GetTypeCheckDiagnostics had code to cope with diagnostics that had no URI associated with them. We now spread such diagnostics to all files when they are generated. - Analyze modifies Diagnostics by adding a Tag to them. That means it has to own them, so I had it clone them. I would like to push that logic down to the diagnostics, per the TODO, but that's another CL. And some observations: - It's obviously tempting to combine DiagnosticSource and diagnosticSource, but they mean very different things. I'm open to a better name for one or the other. Change-Id: If2e861d6fe16bfd2e5ba216cf7e29cf338d0fd25 Reviewed-on: https://go-review.googlesource.com/c/tools/+/288215 Trust: Heschi Kreinick <heschi@google.com> Run-TryBot: Heschi Kreinick <heschi@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org> |
||
|---|---|---|
| .. | ||
| README.md | ||
| normalizer.go | ||
| tests.go | ||
| util.go | ||
README.md
Testing
LSP has "marker tests" defined in internal/lsp/testdata, as well as
traditional tests.
Marker tests
Marker tests have a standard input file, like
internal/lsp/testdata/foo/bar.go, and some may have a corresponding golden
file, like internal/lsp/testdata/foo/bar.go.golden. The former is the "input"
and the latter is the expected output.
Each input file contains annotations like
//@suggestedfix("}", "refactor.rewrite"). These annotations are interpreted by
test runners to perform certain actions. The expected output after those actions
is encoded in the golden file.
When tests are run, each annotation results in a new subtest, which is encoded in the golden file with a heading like,
-- suggestedfix_bar_11_21 --
// expected contents go here
-- suggestedfix_bar_13_20 --
// expected contents go here
The format of these headings vary: they are defined by the
Golden
function for each annotation. In the case above, the format is: annotation
name, file name, annotation line location, annotation character location.
So, if internal/lsp/testdata/foo/bar.go has three suggestedfix annotations,
the golden file should have three headers with suggestedfix_bar_xx_yy
headings.
To see a list of all available annotations, see the exported "expectations" in tests.go.
To run marker tests,
cd /path/to/tools
# The marker tests are located in "internal/lsp", "internal/lsp/cmd, and
# "internal/lsp/source".
go test ./internal/lsp/...
There are quite a lot of marker tests, so to run one individually, pass the test path and heading into a -run argument:
cd /path/to/tools
go test ./internal/lsp -v -run TestLSP/Modules/SuggestedFix/bar_11_21
Resetting marker tests
Sometimes, a change is made to lsp that requires a change to multiple golden files. When this happens, you can run,
cd /path/to/tools
./internal/lsp/reset_golden.sh