testing

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testing is the Testing view container (SPEC §10.32, step 26.2): the Test Explorer, a tree (or list) of the tests the controllers of the extensions describe, with the state, the duration and the buttons of each test, the filter box with its terms, the sort order and the view mode, and the summary of the last run. The tree is a model over the test service of internal/core/testing (the controllers, the items and the results are its data; a view keeps only what is expanded, selected, hidden and typed in the filter) and a widget over kit's tree. Everything here runs on the UI thread: the events of the service come on any goroutine and are handed over with Opts.Post.

The window (internal/gui/app) binds the view to its menus, commands and context keys; the view of a client of a hosted workspace builds the same view over the host's service (D46).

Ported from VS Code: src/vs/workbench/contrib/testing/browser/testingExplorerView.ts, testingExplorerFilter.ts, icons.ts and theme.ts, browser/explorerProjections/{listProjection,treeProjection,display}.ts, common/testExplorerFilterState.ts, testingProgressMessages.ts and testingStates.ts

Index

Constants

View Source
const (
	// TermFailed shows the tests that failed or errored, TermExecuted the tests that have a result.
	TermFailed   = "@failed"
	TermExecuted = "@executed"
	// TermDoc shows the tests of the active editor's file, TermOpenedFiles those of all the open files.
	TermDoc         = "@doc"
	TermOpenedFiles = "@openedFiles"
	// TermHidden shows the tests the user hid as well.
	TermHidden = "@hidden"
)

A filter term is one of the words the text of the filter box understands.

View Source
const FilterPlaceholder = "Filter (e.g. text, !exclude, @tag)"

FilterPlaceholder is the text of the empty filter box.

View Source
const ListDelimiter = " › "

ListDelimiter is written between the labels of the path of a test in the list.

Variables

View Source
var (
	// TreeKey is the key of the tree, MessageKey that of the text in place of a tree with no rows, FilterKey that of the filter box,
	// FilterMenuKey that of the button of its menu and SummaryKey that of the summary line.
	TreeKey       = foundation.NewValueKey("testing:tree")
	MessageKey    = foundation.NewValueKey("testing:message")
	FilterKey     = foundation.NewValueKey("testing:filter")
	FilterMenuKey = foundation.NewValueKey("testing:filter-menu")
	SummaryKey    = foundation.NewValueKey("testing:summary")
)

Keys of the widgets of the view, which tests find them by.

View Source
var (
	// ResultsTreeKey is the key of the tree, ResultsTextKey that of the text beside it and ResultsEmptyKey that of the message of a view
	// with no result.
	ResultsTreeKey  = foundation.NewValueKey("testresults:tree")
	ResultsTextKey  = foundation.NewValueKey("testresults:text")
	ResultsEmptyKey = foundation.NewValueKey("testresults:empty")
)

Keys of the widgets of Test Results, which tests find them by.

View Source
var CoverageSortChoices = []CoverageSortChoice{
	{CoverageByLocation, "Sort by Location", "Files are sorted alphabetically, declarations are sorted by position"},
	{CoverageByCoverage, "Sort by Coverage", "Files and declarations are sorted by total coverage"},
	{CoverageByName, "Sort by Name", "Files and declarations are sorted alphabetically"},
}

CoverageSortChoices are the entries of the picker, in VS Code's order and words.

View Source
var (
	// CoverageTreeKey is the key of the tree.
	CoverageTreeKey = foundation.NewValueKey("testcoverage:tree")
)

Keys of the widgets of the view, which tests find them by.

View Source
var TermDescriptions = map[string]string{
	TermFailed:      "Show Only Failed Tests",
	TermExecuted:    "Show Only Executed Tests",
	TermDoc:         "Show in Active File Only",
	TermOpenedFiles: "Show in Opened Files Only",
	TermHidden:      "Show Hidden Tests",
}

TermDescriptions are the labels of the terms in the menu of the filter.

Terms are the terms in the order of the filter's menu.

Functions

func BadgeCount

func BadgeCount(s Summary, setting string) int

BadgeCount is the number the count badge of the activity bar icon shows for the setting testing.countBadge ("failed", "passed", "skipped"; "off" and anything else give 0).

Ported from VS Code: src/vs/workbench/contrib/testing/browser/testingExplorerView.ts (ResultSummaryView.renderActivityBadge)

func BadgeTooltip

func BadgeTooltip(setting string, n int) string

BadgeTooltip is the hover text of the count badge.

func BarsTooltip

func BarsTooltip(src BarSource) string

BarsTooltip is the text of the hover of the bars: the statements, the functions and the branches that were covered.

func CoverageRowKey

func CoverageRowKey(key string) foundation.Key

CoverageRowKey is the key of the widget of a row of the tree.

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration is how a duration is written after a test: 0.0 to 9.9 ms with a decimal, up to a second in whole ms, then seconds with a decimal.

Ported from VS Code: src/vs/workbench/contrib/testing/browser/testingExplorerView.ts (formatDuration)

func MessageNodeKey

func MessageNodeKey(res *coretesting.Result, testID string, index int) string

MessageNodeKey is the key of the node of the message with the index of a test in a run.

func MessageText

func MessageText(m coretesting.Message, display func(path string) string) string

MessageText is the details of a message: its text, the expected and the actual text of a diff, and the stack. display writes the path of a file of a frame (nil writes it as it is).

func NamespaceTag

func NamespaceTag(controllerID, tag string) string

NamespaceTag is how a tag is told apart from the tags of other controllers: the controller's id, a NUL byte and the tag.

func NewCoverageBars

func NewCoverageBars(bc widgets.BuildContext, src BarSource, opts CoverageBarsOpts) widgets.Widget

NewCoverageBars draws the percentage and the bars of a file: in the compact form the percentage and the bar of the displayed percentage, otherwise (unless NoOverall) the percentage with two decimals and a bar each for the statements, the functions and the branches that were measured.

func NodeText

func NodeText(n *ResultNode, display func(path string) string) string

NodeText is the text beside the tree for a node, with the ANSI sequences it holds. display writes the path of a file of a stack frame (nil writes it as it is).

func ProgressText

func ProgressText(s Summary) string

ProgressText is the line that says how the run is going: "Running tests...", "Running tests, 2/5 passed (40%)", "3/5 tests passed (60%)", and with skipped tests "3/5 tests passed (60%, 1 skipped)".

Ported from VS Code: src/vs/workbench/contrib/testing/common/testingProgressMessages.ts (getTestProgressText)

func ResultKey

func ResultKey(res *coretesting.Result) string

ResultKey is the key of the node of a run; TestKey and MessageNodeKey are those of a test of it and of a message of the test.

func RowKey

func RowKey(rowKey string) foundation.Key

RowKey is the key of the widget of a row of the tree, which tests find it by.

func RunOutput

func RunOutput(res *coretesting.Result) string

RunOutput is the output of all the tasks of a run.

func StateColor

func StateColor(colors kit.Colors, s coretesting.State, retired bool) ui.Color

StateColor is the color of the icon of a state in the colors of a theme; the foreground for a state with none.

func StateColorID

func StateColorID(s coretesting.State, retired bool) string

StateColorID is the theme color of the icon of a state, and of a state of an outdated result.

Ported from VS Code: src/vs/workbench/contrib/testing/browser/theme.ts (testStatesToIconColors, testStatesToRetiredIconColors)

func StateIcon

func StateIcon(s coretesting.State) int

StateIcon is the Codicon of a state (testing-passed-icon and the others); a test the controller is working on shows as running. The running icon does not turn (decision 1549).

Ported from VS Code: src/vs/workbench/contrib/testing/browser/icons.ts (testingStatesToIcons)

func StateName

func StateName(s coretesting.State) string

StateName is how a state is called in a hover ("Passed", "Not yet run").

func SummaryDuration

func SummaryDuration(d time.Duration) string

SummaryDuration is the duration at the end of the summary line: "850 ms" below a second, "2.1 s" from there (the SPEC's example; VS Code writes "850ms" and "2.1s" without the space, decision 1548).

func TestKey

func TestKey(res *coretesting.Result, testID string) string

TestKey is the key of the node of a test in a run.

func TestOutput

func TestOutput(res *coretesting.Result, t coretesting.TestResult) string

TestOutput is the output that belongs to a test in a run: the pieces of the output of each task that its messages name, in order.

func ToggleTerm

func ToggleTerm(text, term string, on bool) string

ToggleTerm gives the text with the term added (on) or taken out (off).

Ported from VS Code: src/vs/workbench/contrib/testing/common/testExplorerFilterState.ts (toggleFilteringFor)

func Visible

func Visible(roots []*Element, f *Filter, ctx FilterContext) map[*Element]bool

Visible marks which elements the filter shows: the elements it includes, and those that have an element it includes below them. An element it excludes hides everything below it.

Ported from VS Code: src/vs/workbench/contrib/testing/browser/testingExplorerView.ts (TestsFilter)

Types

type BarSource

type BarSource struct {
	Statement   coretesting.Count
	Branch      *coretesting.Count
	Declaration *coretesting.Count
}

BarSource is the numbers the bars show.

func BarsOf

BarsOf is the source of the bars of a file or folder.

type Body

type Body struct {
	widgets.StatefulWidget
	// contains filtered or unexported fields
}

Body is the body of the Test Explorer: the filter box, the summary line and the tree.

func NewBody

func NewBody(ex *Explorer, opts ...BodyOpts) *Body

NewBody makes the body of the explorer.

func (*Body) CreateState

func (b *Body) CreateState() widgets.State

CreateState implements widgets.StatefulWidget.

type BodyOpts

type BodyOpts struct {
	// Select is called when the user selects a row (a click, Enter) and Open for Enter and a double click.
	Select func(*Element)
	Open   func(*Element)
	// Menu opens the context menu of a row at a position of the window; the row is nil for the part below the rows.
	Menu func(row *Element, at ui.Offset)
	// FilterMenu opens the menu of the filter at a position of the window.
	FilterMenu func(at ui.Offset)
	// Actions gives the buttons of a row, shown while the pointer is over it or it is selected; RunAction runs one.
	Actions   func(*Element) []kit.Action
	RunAction func(row *Element, id string)
	// SummaryActions are the buttons after the summary line (rerun the last run, debug it) and RunSummaryAction runs one.
	SummaryActions   func(SummaryState) []kit.Action
	RunSummaryAction func(id string)
	OnFocusChange    func(has bool)
	// Summary gives the summary line.
	Summary func() SummaryState
	// Message is the text in place of the tree when it has no rows because no test was found; the filter's own message when rows exist
	// but the filter shows none.
	Message string
}

BodyOpts are the options of NewBody.

type Coverage

type Coverage struct {
	// contains filtered or unexported fields
}

Coverage is the model of the view.

func NewCoverage

func NewCoverage(opts CoverageOpts) *Coverage

NewCoverage makes the model and follows the service.

func (*Coverage) CollapseAll

func (c *Coverage) CollapseAll()

CollapseAll folds every node.

func (*Coverage) Controller

func (c *Coverage) Controller() *kit.TreeController

Controller gives access to the tree widget.

func (*Coverage) Dispose

func (c *Coverage) Dispose()

Dispose stops following the service.

func (*Coverage) Model

func (c *Coverage) Model() *kit.TreeModel

Model is the tree and Controller gives access to the tree widget.

func (*Coverage) Node

func (c *Coverage) Node(key string) (*CoverageNode, bool)

Node is the node with the key.

func (*Coverage) OnChange

func (c *Coverage) OnChange(fn func()) (stop func())

OnChange registers a function called when the rows or the order change; the returned function removes it.

func (*Coverage) Percent

func (c *Coverage) Percent() string

Percent is the value of testing.displayedCoveragePercent.

func (*Coverage) Refresh

func (c *Coverage) Refresh()

Refresh makes the rows again from the open coverage.

func (*Coverage) SetSort

func (c *Coverage) SetSort(s CoverageSort)

SetSort changes the order of the rows.

func (*Coverage) Sort

func (c *Coverage) Sort() CoverageSort

Sort is the order of the rows.

func (*Coverage) Thresholds

func (c *Coverage) Thresholds() coretesting.BarThresholds

Thresholds are the thresholds of the bars now, and Percent the way the percentage is worked out.

type CoverageBarsOpts

type CoverageBarsOpts struct {
	// Compact shows only the overall bar after the percentage, with no decimals; the details are in the hover.
	Compact bool
	// NoOverall leaves the percentage out.
	NoOverall bool
	// Percent is testing.displayedCoveragePercent and Thresholds testing.coverageBarThresholds.
	Percent    string
	Thresholds coretesting.BarThresholds
	// Key is the key of the widget.
	Key foundation.Key
}

CoverageBarsOpts are the options of NewCoverageBars.

type CoverageBody

type CoverageBody struct {
	widgets.StatefulWidget
	// contains filtered or unexported fields
}

CoverageBody is the body of the Test Coverage view.

func NewCoverageBody

func NewCoverageBody(c *Coverage) *CoverageBody

NewCoverageBody makes the body of the view.

func (*CoverageBody) CreateState

func (b *CoverageBody) CreateState() widgets.State

CreateState implements widgets.StatefulWidget.

type CoverageKind

type CoverageKind int

CoverageKind says what a node of the tree is.

const (
	// CoverageFolder is a folder (or a chain of folders with one folder each), CoverageFile a file the controller reported and
	// CoverageDeclaration a function of a file.
	CoverageFolder CoverageKind = iota
	CoverageFile
	CoverageDeclaration
)

The kinds of node.

type CoverageNode

type CoverageNode struct {
	Kind  CoverageKind
	Key   string
	Label string
	// URI is the file or folder, and for a declaration the file it is in.
	URI string
	// Coverage is the numbers of a file or folder.
	Coverage coretesting.FileCoverage
	// Name, Executed and Range are those of a declaration; Attr is the coverage of the statements inside it, nil when it is not known (a
	// declaration that did not run, or with no statements).
	Name     string
	Executed int
	Range    coretesting.Range
	Attr     *coretesting.FileCoverage
	// contains filtered or unexported fields
}

CoverageNode is a node of the tree of the view.

func (*CoverageNode) TotalPercent

func (n *CoverageNode) TotalPercent() float64

TotalPercent is the total coverage of the node, from 0 to 1; a declaration has it when its statements are known and -1 otherwise.

type CoverageOpts

type CoverageOpts struct {
	// Ctx ends what the view asked for when it is done.
	Ctx context.Context
	// Service holds the open coverage.
	Service *coretesting.CoverageService
	// Post runs a function on the UI thread, later.
	Post func(func())
	// Top writes the label of the folder the coverage starts in from its path; nil writes the last part of the path.
	Top func(path string) string
	// Icons gives the file icon theme and Language the language of a file by its path; nil for none.
	Icons    func() *theme.FileIconTheme
	Language func(path string) string
	// Percent gives testing.displayedCoveragePercent and Thresholds the value of testing.coverageBarThresholds; nil for the defaults.
	Percent    func() string
	Thresholds func() coretesting.BarThresholds
	// OnOpen is called when the user opens a file or a declaration (Enter, a double click or a click on a leaf).
	OnOpen func(*CoverageNode)
	// OnFocusChange is told when the tree gains or loses the keyboard focus.
	OnFocusChange func(has bool)
}

CoverageOpts are what the view needs of its window.

type CoverageSort

type CoverageSort string

CoverageSort is the order of the rows of the view.

const (
	// CoverageByLocation sorts the files by path and the declarations by position, CoverageByCoverage both by total coverage (the best
	// first) and CoverageByName both by name.
	CoverageByLocation CoverageSort = "location"
	CoverageByCoverage CoverageSort = "coverage"
	CoverageByName     CoverageSort = "name"
)

The orders (VS Code's CoverageSortOrder).

type CoverageSortChoice

type CoverageSortChoice struct {
	Sort               CoverageSort
	Label, Description string
}

CoverageSortChoice is an entry of the picker of the order.

type Element

type Element struct {
	Kind Kind
	// Key is the key of the row in the tree.
	Key string
	// Item is the test (the zero value for a controller or an error row); ID is its id (the controller's id for a controller).
	Item coretesting.Item
	ID   string
	// Label is the text of the row; Description follows it (the path in the list, the item's description in the tree).
	Label, Description string
	// State is the state shown, Duration the duration shown (NoDuration, -1, for none) and Retired says that the result is outdated.
	State    coretesting.State
	Duration time.Duration
	Retired  bool
	// Busy says that the controller is working on the item: it shows as running.
	Busy bool
	// Hidden says that the user hid the test (or one above it).
	Hidden bool
	// Error is the message of an error row.
	Error string
	// Children and Parent are the rows below and above.
	Children []*Element
	Parent   *Element
}

Element is a row of the Test Explorer.

func Project

func Project(src Source, o ProjectOptions) []*Element

Project makes the rows of the explorer: the roots (the items of the single controller, or the controllers), sorted. The filter is not applied here (Visible).

Ported from VS Code: src/vs/workbench/contrib/testing/browser/explorerProjections/treeProjection.ts and listProjection.ts

func (*Element) HasDuration

func (e *Element) HasDuration() bool

HasDuration reports whether a duration is to be shown.

type Explorer

type Explorer struct {
	// contains filtered or unexported fields
}

Explorer is the Test Explorer's model: the rows of the tests as the mode, the sort order, the hidden tests and the filter make them, over the test service. A burst of events of the service makes the rows again once.

Ported from VS Code: src/vs/workbench/contrib/testing/browser/testingExplorerView.ts (TestingExplorerViewModel)

func NewExplorer

func NewExplorer(opts Opts) *Explorer

NewExplorer makes the explorer and follows the service.

func (*Explorer) CollapseAll

func (x *Explorer) CollapseAll()

CollapseAll folds every row.

func (*Explorer) Controller

func (x *Explorer) Controller() *kit.TreeController

Controller returns the tree controller of the view.

func (*Explorer) Dispose

func (x *Explorer) Dispose()

Dispose stops following the service.

func (*Explorer) Element

func (x *Explorer) Element(id string) *Element

Element is the row of a test (or controller), shown or not.

func (*Explorer) Filter

func (x *Explorer) Filter() *Filter

Filter is the parsed text of the filter box.

func (*Explorer) FilterText

func (x *Explorer) FilterText() string

FilterText is the text of the filter box.

func (*Explorer) Focused

func (x *Explorer) Focused() (*Element, bool)

Focused is the row that has the focus in the tree, if any.

func (*Explorer) HasHidden

func (x *Explorer) HasHidden() bool

HasHidden reports whether the user hid a test.

func (*Explorer) HiddenIDs

func (x *Explorer) HiddenIDs() []string

HiddenIDs are the ids of the tests the user hid, sorted.

func (*Explorer) Hide

func (x *Explorer) Hide(ids ...string)

Hide hides the tests; Unhide shows them again and UnhideAll every one. HasHidden reports whether any test is hidden, and IsHidden whether the test or one above it is.

func (*Explorer) IncludeExclude

func (x *Explorer) IncludeExclude(selectedOnly bool, can func(id string) bool) (include, exclude []string)

IncludeExclude works out which tests to run when the buttons of the title bar run what the tree shows (selectedOnly false), or what is selected in it: the first rows that have a majority of their runnable children shown are included, and the rows the filter hides below an included row are excluded. can says whether the group has a profile for a test.

Ported from VS Code: src/vs/workbench/contrib/testing/browser/testingExplorerView.ts (getTreeIncludeExclude)

func (*Explorer) Input

func (x *Explorer) Input() *kit.InputBoxController

Input returns the filter box controller.

func (*Explorer) IsHidden

func (x *Explorer) IsHidden(id string) bool

IsHidden reports whether the test or a test above it is hidden.

func (*Explorer) Mode

func (x *Explorer) Mode() ViewMode

Mode is how the tests are laid out and Sorting what they are sorted by.

func (*Explorer) Model

func (x *Explorer) Model() *kit.TreeModel

Model is the tree the view shows, Controller gives access to the tree widget (focus, reveal) and Input to the filter box.

func (*Explorer) OnChange

func (x *Explorer) OnChange(fn func()) func()

OnChange calls fn after the rows changed, and returns the function that stops it.

func (*Explorer) Refresh

func (x *Explorer) Refresh()

Refresh makes the rows again from the service.

func (*Explorer) Reveal

func (x *Explorer) Reveal(id string, expand bool) bool

Reveal selects the row of a test and brings it into view, expanding the rows above it when expand is true. Without expand a test whose rows are folded (or filtered out) is left as it is. It says whether the row was revealed; a selection of more than one row is left alone (VS Code does not change a multi-selection).

Ported from VS Code: src/vs/workbench/contrib/testing/browser/testingExplorerView.ts (TestingExplorerView.revealById)

func (*Explorer) Roots

func (x *Explorer) Roots() []*Element

Roots are the rows at the top, as projected (the filter is not applied).

func (*Explorer) Row

func (x *Explorer) Row(key string) (*Element, bool)

Row is the element of a row of the tree.

func (*Explorer) Selected

func (x *Explorer) Selected() []*Element

Selected are the rows that are selected, in the order of the tree.

func (*Explorer) Service

func (x *Explorer) Service() *coretesting.Service

Service is the test service the explorer shows.

func (*Explorer) SetFilterText

func (x *Explorer) SetFilterText(text string)

SetFilterText sets the text of the filter (and of the box): the rows are made again, and all the rows that pass are opened so that the matches are in view.

func (*Explorer) SetMode

func (x *Explorer) SetMode(m ViewMode)

SetMode changes the layout.

func (*Explorer) SetSorting

func (x *Explorer) SetSorting(s Sorting)

SetSorting changes the sort order.

func (*Explorer) Sorting

func (x *Explorer) Sorting() Sorting

Sorting returns the current sort order.

func (*Explorer) ToggleTerm

func (x *Explorer) ToggleTerm(term string)

ToggleTerm adds the term to the text of the filter, or takes it out.

func (*Explorer) Touch

func (x *Explorer) Touch()

Touch tells the view to draw again, for what the rows do not show: the time a live run has taken.

func (*Explorer) Unhide

func (x *Explorer) Unhide(ids ...string)

Unhide shows the tests (and the tests above them that were hidden) again.

func (*Explorer) UnhideAll

func (x *Explorer) UnhideAll()

UnhideAll shows every test.

func (*Explorer) Visible

func (x *Explorer) Visible(e *Element) bool

Visible reports whether the filter shows the row.

type Filter

type Filter struct {
	// Text is the text that was parsed.
	Text string
	// Terms are the special terms the text holds.
	Terms map[string]bool
	// Globs are the words left when the terms and tags are taken out.
	Globs []Glob
	// IncludeTags and ExcludeTags are the tags named with @controller:tag and !@controller:tag, as "controller\x00tag".
	IncludeTags, ExcludeTags map[string]bool
	// Controllers are the ids named with @ctrl:id (decision 1547): only the tests of these controllers show.
	Controllers map[string]bool
	// Fuzzy makes a word match when its letters are in the label in order, not only when they are next to each other.
	Fuzzy bool
}

Filter is the parsed text of the filter box (VS Code's TestExplorerFilterState.setText): the terms, the words, the tags and the controller. The zero value filters nothing.

Ported from VS Code: src/vs/workbench/contrib/testing/common/testExplorerFilterState.ts

func ParseFilter

func ParseFilter(text string, fuzzy bool) *Filter

ParseFilter reads the text of the filter box.

func (*Filter) Empty

func (f *Filter) Empty() bool

Empty reports whether the text filters nothing.

func (*Filter) Has

func (f *Filter) Has(term string) bool

Has reports whether the text holds the term.

type FilterContext

type FilterContext struct {
	// DocumentURIs are the files the terms @doc and @openedFiles stand for.
	DocumentURIs []string
}

FilterContext is what the filter needs to know besides the text.

type Glob

type Glob struct {
	Include bool
	Text    string
}

Glob is one comma-separated word of the text: a test whose label contains it (in lower case) is included, or excluded when the word started with "!".

type Kind

type Kind int

Kind says what an Element is.

const (
	// KindTest is an item of a controller's tree.
	KindTest Kind = iota + 1
	// KindController is the root of a controller, shown when there are several controllers.
	KindController
	// KindError is the row below an item that has an error.
	KindError
)

The kinds of elements.

type Opts

type Opts struct {
	// Ctx ends what the explorer asked for when it is done.
	Ctx context.Context
	// Service is the test service of the workspace; the view of a client of a hosted workspace gets the host's.
	Service *coretesting.Service
	// Post runs a function on the UI thread, later.
	Post func(func())
	// DocumentURIs gives the files @doc (activeOnly) and @openedFiles stand for, as file:// URIs; none when nil.
	DocumentURIs func(activeOnly bool) []string
	// Fuzzy says whether the filter matches fuzzily (the menu of the filter toggles it); false when nil.
	Fuzzy func() bool
}

Opts are what the explorer needs of its window. Everything is called on the UI thread, except Post, which any goroutine may call.

type ProjectOptions

type ProjectOptions struct {
	Mode    ViewMode
	Sorting Sorting
	// Hidden are the ids of the tests the user hid.
	Hidden map[string]bool
}

ProjectOptions say how the elements are made.

type ResultKind

type ResultKind int

ResultKind says what a node of the tree of Test Results is.

const (
	// NodeResult is a run, NodeTest a test that took part in it and NodeMessage a message of the test.
	NodeResult ResultKind = iota
	NodeTest
	NodeMessage
)

The kinds of node.

type ResultNode

type ResultNode struct {
	Kind   ResultKind
	Key    string
	Label  string
	State  coretesting.State
	Result *coretesting.Result
	Test   coretesting.TestResult
	// Message is the message of a NodeMessage and Index its place among the messages of the test (over all its tasks).
	Message coretesting.Message
	Index   int
	// Duration is the duration of a test, coretesting.NoDuration for none.
	Duration time.Duration
	Retired  bool
}

ResultNode is a node of the tree of Test Results.

type Results

type Results struct {
	// contains filtered or unexported fields
}

Results is the model of Test Results: the nodes as the service has them, and the selected one.

func NewResults

func NewResults(opts ResultsOpts) *Results

NewResults makes the model and follows the service.

func (*Results) Controller

func (r *Results) Controller() *kit.TreeController

Controller returns the tree controller of the view.

func (*Results) Dispose

func (r *Results) Dispose()

Dispose stops following the service.

func (*Results) Model

func (r *Results) Model() *kit.TreeModel

Model is the tree and Controller gives access to the tree widget.

func (*Results) Node

func (r *Results) Node(key string) (*ResultNode, bool)

Node is the node with the key.

func (*Results) OnChange

func (r *Results) OnChange(fn func()) func()

OnChange calls fn after the nodes or the selection changed, and returns the function that stops it.

func (*Results) Refresh

func (r *Results) Refresh()

Refresh makes the nodes again from the service: the runs newest first, and in each the tests that have a state, in a tree of their parents, and the messages of the tests.

func (*Results) Select

func (r *Results) Select(key string) bool

Select selects the node with the key and shows its text; false when there is none.

func (*Results) Selected

func (r *Results) Selected() (*ResultNode, bool)

Selected is the node whose text shows: the one chosen, else the newest run.

func (*Results) ShowLatest

func (r *Results) ShowLatest()

ShowLatest selects the newest run (VS Code's showLatestRun).

type ResultsBody

type ResultsBody struct {
	widgets.StatefulWidget
	// contains filtered or unexported fields
}

ResultsBody is the body of Test Results: the tree of the runs and beside it the text of the selected node.

func NewResultsBody

func NewResultsBody(r *Results) *ResultsBody

NewResultsBody makes the body of Test Results.

func (*ResultsBody) CreateState

func (b *ResultsBody) CreateState() widgets.State

CreateState implements widgets.StatefulWidget.

type ResultsOpts

type ResultsOpts struct {
	// Ctx ends what the view asked for when it is done.
	Ctx context.Context
	// Service is the test service of the workspace.
	Service *coretesting.Service
	// Post runs a function on the UI thread, later.
	Post func(func())
	// Links make the paths in the text of a node links; nil for none.
	Links *kit.AnsiLinks
	// Display writes the path of a file of a stack frame; nil writes it as it is.
	Display func(path string) string
	// OnSelect is called when a node is selected.
	OnSelect func(*ResultNode)
}

ResultsOpts are what Test Results needs of its window.

type Sorting

type Sorting string

Sorting is what the tests are sorted by.

const (
	SortByLocation Sorting = "location"
	SortByStatus   Sorting = "status"
	SortByDuration Sorting = "duration"
)

The sort orders.

type Source

type Source interface {
	Controllers() []coretesting.ControllerInfo
	Children(id string) []coretesting.Item
	StateOf(id string) (*coretesting.Result, coretesting.TestResult, bool)
}

Source is the test model the projections read; *coretesting.Service is one.

type Summary

type Summary struct {
	Running                  bool
	Passed, Failed, Skipped  int
	RunSoFar, TotalWillBeRun int
	Queued, RunningTests     int
}

Summary counts the tests of the results the summary line reports on.

Ported from VS Code: src/vs/workbench/contrib/testing/common/testingProgressMessages.ts (collectTestStateCounts)

func Collect

func Collect(running bool, results []*coretesting.Result) Summary

Collect counts the states of the results: failed and errored tests are failed.

func (Summary) Percent

func (s Summary) Percent() float64

Percent is the share of the tests run so far that passed, as a number to show: never 100 while a test failed, 0 when none ran.

type SummaryState

type SummaryState struct {
	// None says that there is no result yet.
	None bool
	// Running says that a run goes on; Dominant is the most important state of the counted tests.
	Running  bool
	Dominant coretesting.State
	Counts   Summary
	// Duration is how long the run took (so far, for a live one).
	Duration time.Duration
	Text     string
}

SummaryState says how the last run went (or the live ones are going).

func SummaryOf

func SummaryOf(svc *coretesting.Service, elapsed func(*coretesting.Result) time.Duration) SummaryState

SummaryOf reads the summary line from the results of the service; elapsed says how long a run that goes on has taken.

Ported from VS Code: src/vs/workbench/contrib/testing/browser/testingExplorerView.ts (ResultSummaryView.render)

type ViewMode

type ViewMode string

ViewMode is how the tests are laid out: a tree of the items as the controller made it, or a flat list of the tests that have no children (each with the path to it after its label).

const (
	ModeList ViewMode = "list"
	ModeTree ViewMode = "true"
)

The view modes. VS Code's constant for the tree is the string "true" (a slip of its source), and so is the value of the context key testing.explorerViewMode; it is kept so that a when-clause written for VS Code works.

Jump to

Keyboard shortcuts

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