tools: Index | Files

package regtest

import ""

Package regtest provides an environment for writing regression tests.


Package Files


type DiagnosticExpectation Uses

type DiagnosticExpectation struct {
    IsMet       func(map[string]*protocol.PublishDiagnosticsParams) bool
    Description string

A DiagnosticExpectation is a condition that must be met by the current set of diagnostics.

func DiagnosticAt Uses

func DiagnosticAt(name string, line, col int) DiagnosticExpectation

DiagnosticAt asserts that there is a diagnostic entry at the position specified by line and col, for the workspace-relative path name.

func EmptyDiagnostics Uses

func EmptyDiagnostics(name string) DiagnosticExpectation

EmptyDiagnostics asserts that diagnostics are empty for the workspace-relative path name.

type Env Uses

type Env struct {

    // Most tests should not need to access the workspace or editor, or server,
    // but they are available if needed.
    W      *fake.Workspace
    E      *fake.Editor
    Server servertest.Connector
    // contains filtered or unexported fields

Env holds an initialized fake Editor, Workspace, and Server, which may be used for writing tests. It also provides adapter methods that call t.Fatal on any error, so that tests for the happy path may be written without checking errors.

func NewEnv Uses

func NewEnv(ctx context.Context, t *testing.T, ws *fake.Workspace, ts servertest.Connector) *Env

NewEnv creates a new test environment using the given workspace and gopls server.

func (*Env) Await Uses

func (e *Env) Await(expectations ...DiagnosticExpectation)

Await waits for all diagnostic expectations to simultaneously be met.

func (*Env) CloseEditor Uses

func (e *Env) CloseEditor()

CloseEditor shuts down the editor, calling t.Fatal on any error.

func (*Env) CreateBuffer Uses

func (e *Env) CreateBuffer(name string, content string)

CreateBuffer creates a buffer in the editor, calling t.Fatal on any error.

func (*Env) EditBuffer Uses

func (e *Env) EditBuffer(name string, edits ...fake.Edit)

EditBuffer applies edits to an editor buffer, calling t.Fatal on any error.

func (*Env) GoToDefinition Uses

func (e *Env) GoToDefinition(name string, pos fake.Pos) (string, fake.Pos)

GoToDefinition goes to definition in the editor, calling t.Fatal on any error.

func (*Env) OpenFile Uses

func (e *Env) OpenFile(name string)

OpenFile opens a file in the editor, calling t.Fatal on any error.

func (*Env) RemoveFileFromWorkspace Uses

func (e *Env) RemoveFileFromWorkspace(name string)

RemoveFileFromWorkspace deletes a file on disk but does nothing in the editor. It calls t.Fatal on any error.

type EnvMode Uses

type EnvMode int

EnvMode is a bitmask that defines in which execution environments a test should run.

const (
    // Singleton mode uses a separate cache for each test.
    Singleton EnvMode = 1 << iota
    // Shared mode uses a Shared cache.
    // Forwarded forwards connections to an in-process gopls instance.
    // SeparateProcess runs a separate gopls process, and forwards connections to
    // it.
    // NormalModes runs tests in all modes.
    NormalModes = Singleton | Shared | Forwarded

type Runner Uses

type Runner struct {
    // contains filtered or unexported fields

A Runner runs tests in gopls execution environments, as specified by its modes. For modes that share state (for example, a shared cache or common remote), any tests that execute on the same Runner will share the same state.

func NewTestRunner Uses

func NewTestRunner(modes EnvMode, testTimeout time.Duration, goplsPath string) *Runner

NewTestRunner creates a Runner with its shared state initialized, ready to run tests.

func (*Runner) Close Uses

func (r *Runner) Close() error

Close cleans up resource that have been allocated to this workspace.

func (*Runner) Modes Uses

func (r *Runner) Modes() EnvMode

Modes returns the bitmask of environment modes this runner is configured to test.

func (*Runner) Run Uses

func (r *Runner) Run(t *testing.T, filedata string, test func(context.Context, *testing.T, *Env))

Run executes the test function in the default configured gopls execution modes. For each a test run, a new workspace is created containing the un-txtared files specified by filedata.

func (*Runner) RunInMode Uses

func (r *Runner) RunInMode(modes EnvMode, t *testing.T, filedata string, test func(ctx context.Context, t *testing.T, e *Env))

RunInMode runs the test in the execution modes specified by the modes bitmask.

Package regtest imports 16 packages (graph). Updated 2020-02-20. Refresh now. Tools for package owners.