Documentation
¶
Overview ¶
Package analyzertest runs analyzer tests against in-memory files.
The package provides view construction, single-analyzer runs, fixpoint runs, and diagnostic projections. Tests in package analyzers use it, and third-party analyzer authors can use it too. It imports sema and store only, so it cannot form an import cycle.
Index ¶
- func File(t *testing.T, view sema.Graph, name string) sema.File
- func Messages(ds []sema.Diagnostic) []string
- func Run(t *testing.T, a sema.Analyzer, files map[string]string, targets ...string) sema.Report
- func RunFixAll(t *testing.T, p *sema.Pipeline, files map[string]string, targets ...string) sema.FixResult
- func RunOnView(t *testing.T, a sema.Analyzer, view sema.Graph, targets ...uri.URI) sema.Report
- func URI(name string) uri.URI
- func View(t *testing.T, files map[string]string) *store.View
- type Diag
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func File ¶
File parses a test file and returns the sema.File for direct Analyzer, Fixer, or ActionProvider calls. The returned File carries a fresh index over the view.
func Messages ¶
func Messages(ds []sema.Diagnostic) []string
Messages returns diagnostic messages in order. It returns nil for an empty input.
func Run ¶
Run builds a view from files and runs one analyzer over targets. Targets name files in the map. An empty target list analyzes every file in sorted name order.
func RunFixAll ¶
func RunFixAll(t *testing.T, p *sema.Pipeline, files map[string]string, targets ...string) sema.FixResult
RunFixAll runs the pipeline fixpoint loop over targets and writes each applied result back into files. An empty target list fixes every file in sorted name order.
The view uses a memfs file source, not the overlay that View builds. FixAll requires persist to write content through to the view's file source before returning, and the shared map is the only file source a test can write. Against an overlay view, re-parses read stale content and the loop never converges.
func RunOnView ¶
RunOnView runs one analyzer over targets and returns the full report. The run shares one index across all targets.
Types ¶
type Diag ¶
type Diag struct {
StartLine, StartCol int
EndLine, EndCol int
Severity sema.Severity
Code string
Message string
}
Diag holds the parts of a diagnostic that tests assert: span endpoints in line and rune columns, severity, code, and message. Byte offsets are excluded.
func Simplify ¶
func Simplify(ds []sema.Diagnostic) []Diag
Simplify converts diagnostics to Diags. It returns nil for an empty input. Use Messages to compare message text only.