analyzertest

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func File

func File(t *testing.T, view sema.Graph, name string) sema.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

func Run(t *testing.T, a sema.Analyzer, files map[string]string, targets ...string) sema.Report

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

func RunOnView(t *testing.T, a sema.Analyzer, view sema.Graph, targets ...uri.URI) sema.Report

RunOnView runs one analyzer over targets and returns the full report. The run shares one index across all targets.

func URI

func URI(name string) uri.URI

URI returns the in-memory URI for a slash-separated test file name.

func View

func View(t *testing.T, files map[string]string) *store.View

View builds an in-memory view from files, which maps test file names to contents.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL