coverage

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package coverage is the statement-coverage extension of the runner: a collector the interpreter reports statement executions to, and the profile blocks a host renders from it.

Coverage is an interpreter feature. flatstack is a performance-oriented backend and carries no coverage support; a runner holding a collector executes interpreted (see runner.Runtime.SetCoverage).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	File      string
	StartLine int
	EndLine   int
	NumStmt   int
	Count     int
}

Block is one line-range entry of a coverage profile. Lines only: the parser records no columns, so a profile writer chooses them (the test command derives them from the source text).

type Collector

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

Collector accumulates statement execution counts, keyed by the statement nodes the parser produced.

A program is registered before it runs, seeding every executable statement at count zero under the filename it was loaded from. The entrypoint and every include register, so the files in a profile are the files get_included_files reports, and an included-but-unexecuted statement still appears, at zero.

func New

func New() *Collector

New returns an empty collector.

func (*Collector) Blocks

func (c *Collector) Blocks() []Block

Blocks renders the collected counts as profile entries, sorted by file and position. Statements sharing a line range merge into one block: NumStmt adds up, and Count is the largest of theirs, which is how many times the line was reached — summing would charge `$a = 1; $b = 2;` twice per pass.

func (*Collector) Files

func (c *Collector) Files() []string

Files returns every registered filename, sorted. A file appears whether or not it holds an executable statement: a file of pure declarations registers no counts, and a report that renders only counted blocks would omit it, reading as a gap where there is nothing to run.

func (*Collector) Functions

func (c *Collector) Functions() []FuncSpan

Functions returns the registered declaration spans, sorted by file and position. Every function of every registered file appears, called or not: an uncalled function is the zero row a per-function report exists to show.

func (*Collector) Hit

func (c *Collector) Hit(s model.Stmt)

Hit charges one execution to a registered statement. An unregistered statement (a declaration, or a program built without the parser) is not counted.

func (*Collector) Register

func (c *Collector) Register(filename string, program *model.Program)

Register seeds every executable statement of program at count zero under filename. Declarations are not executable and are skipped; their bodies' statements carry spans of their own. A statement already registered keeps its count, so re-including a cached program does not reset it.

type FuncSpan

type FuncSpan struct {
	File      string
	Name      string
	StartLine int
	EndLine   int
}

FuncSpan is the source range of one declared function: a free function under its name, a method under Class::name. A per-function report charges the blocks inside the range to it.

Jump to

Keyboard shortcuts

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