testrunner

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package testrunner provides test runner functionality.

Index

Constants

View Source
const (
	// TestStatusPending represents a test that is pending.
	TestStatusPending = iota
	// TestStatusRunning represents a test that is running.
	TestStatusRunning
	// TestStatusPassed represents a test that has passed.
	TestStatusPassed
	// TestStatusFailed represents a test that has failed.
	TestStatusFailed
	// TestStatusNoCodeToCover represents a file with no code that can be covered.
	TestStatusNoCodeToCover
)

Variables

This section is empty.

Functions

func GetFunctionsFromFiles

func GetFunctionsFromFiles(files []string) (map[string]File, error)

GetFunctionsFromFiles gets all functions from the supplied files.

func GetModuleName

func GetModuleName(path string) string

GetModuleName gets the module name of the Go project in the specified path.

func GetOverallCoveragePercentage

func GetOverallCoveragePercentage(output []byte) float64

GetOverallCoveragePercentage gets the overall coverage percentage.

func HighlightCode

func HighlightCode(language string, code string) string

HighlightCode highlights code for a given language.

Types

type CoverageLine

type CoverageLine struct {
	File               string `json:"file"`
	StartLine          int    `json:"startLine"`
	StartColumn        int    `json:"startColumn"`
	EndLine            int    `json:"endLine"`
	EndColumn          int    `json:"endColumn"`
	NumberOfStatements int    `json:"numberOfStatements"`
	ExecutionCount     int    `json:"executionCount"`
}

CoverageLine defines a coverage line.

type File

type File struct {
	Name            string     `json:"name"`
	Functions       []Function `json:"functions"`
	Code            string     `json:"code"`
	HighlightedCode string     `json:"highlightedCode"`
	Status          TestStatus `json:"status"`
	Coverage        float64    `json:"coverage"`
	CoveredLines    []Line     `json:"coveredLines"`
}

File defines a test file.

type Function

type Function struct {
	Name   string     `json:"name"`
	Result TestResult `json:"result"`
}

Function defines a single function.

func GetFunctionsFromFile

func GetFunctionsFromFile(file string) ([]Function, string, error)

GetFunctionsFromFile gets all functions from a file.

type Line

type Line struct {
	Number             int `json:"number"`
	StartLine          int `json:"startLine"`
	StartColumn        int `json:"startColumn"`
	EndLine            int `json:"endLine"`
	EndColumn          int `json:"endColumn"`
	ExecutionCount     int `json:"executionCount"`
	NumberOfStatements int `json:"numberOfStatements"`
}

Line defines a line of code in a coverage report.

type TestEvent

type TestEvent struct {
	Time    string  `json:"time"`
	Action  string  `json:"action"`
	Package string  `json:"package"`
	Test    string  `json:"test"`
	Output  string  `json:"output"`
	Elapsed float64 `json:"elapsed"`
}

TestEvent represents a single test event from Go test output in JSON format.

type TestResult

type TestResult struct {
	Coverage float64 `json:"coverage"`
}

TestResult defines the result of a test.

type TestRunner

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

TestRunner defines a test runner.

func NewTestRunner

func NewTestRunner(
	files []string,
	fw *filewatcher.FileWatcher,
	onFileChange func(),
) (*TestRunner, error)

NewTestRunner creates a new test runner.

func (*TestRunner) AddOutput

func (t *TestRunner) AddOutput(output []string) []string

AddOutput adds output lines to the output buffer.

func (*TestRunner) Close

func (t *TestRunner) Close()

Close closes the test runner.

func (*TestRunner) GetCoverage

func (t *TestRunner) GetCoverage() float64

GetCoverage gets the overall coverage percentage from the last test run.

func (*TestRunner) GetFiles

func (t *TestRunner) GetFiles() map[string]File

GetFiles gets the files.

func (*TestRunner) GetFuncCoveragePercentages

func (t *TestRunner) GetFuncCoveragePercentages(
	coverageFile string,
) (map[string]map[string]float64, float64, error)

GetFuncCoveragePercentages gets coverage percentages for each function.

func (*TestRunner) GetHasRunTests

func (t *TestRunner) GetHasRunTests() bool

GetHasRunTests checks if tests have been run.

func (*TestRunner) GetIsRunning

func (t *TestRunner) GetIsRunning() bool

GetIsRunning checks if tests are currently running.

func (*TestRunner) GetOutput

func (t *TestRunner) GetOutput() []string

GetOutput gets the output buffer.

func (*TestRunner) ParseCoverage

func (t *TestRunner) ParseCoverage(coverageFile string) ([]CoverageLine, error)

ParseCoverage parses the coverage report.

func (*TestRunner) ParseCoverageLines

func (t *TestRunner) ParseCoverageLines(
	coverageLines []CoverageLine,
	coveragePercentages map[string]map[string]float64,
) []File

ParseCoverageLines parses the coverage lines.

func (*TestRunner) ParseErrorFromOutput

func (t *TestRunner) ParseErrorFromOutput(output string) string

ParseErrorFromOutput extracts error messages from the output.

func (*TestRunner) RunAllTests

func (t *TestRunner) RunAllTests(
	testCompleteCallback func(file File) error,
	outputCallback func(output string) error,
	completionCallback func(),
)

RunAllTests runs all tests.

func (*TestRunner) SetCoverage

func (t *TestRunner) SetCoverage(coverage float64)

SetCoverage sets the overall coverage percentage.

func (*TestRunner) SetHasRunTests

func (t *TestRunner) SetHasRunTests(hasRunTests bool)

SetHasRunTests sets if tests have been run.

func (*TestRunner) SetIsRunning

func (t *TestRunner) SetIsRunning(running bool)

SetIsRunning sets if tests are running.

func (*TestRunner) SetOnFileChange

func (t *TestRunner) SetOnFileChange(callback func())

SetOnFileChange sets the file change callback.

func (*TestRunner) StopTests

func (t *TestRunner) StopTests()

StopTests stops the currently running tests.

type TestStatus

type TestStatus int

TestStatus defines the status of a test.

Jump to

Keyboard shortcuts

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