test

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AssertionErrorClass *value.Class // Std::Test::AssertionError
View Source
var CurrentSuite = RootSuite
View Source
var Filters []Filter
View Source
var RootSuite = NewSuite("", nil, nil)

Functions

func CaseMatchesFilters

func CaseMatchesFilters(testCase *Case) bool

func Init

func Init()

func ListenForInterrupt

func ListenForInterrupt(
	shutdown context.CancelFunc,
)

func RegisterFilter

func RegisterFilter(filter Filter)

func TraverseReport

func TraverseReport(report Report, enter func(report Report) TraverseOption, leave func(report Report) TraverseOption)

func TraverseSuite

func TraverseSuite(test SuiteOrCase, enter func(test SuiteOrCase) TraverseOption, leave func(test SuiteOrCase) TraverseOption)

Types

type Case

type Case struct {
	Name   string
	Fn     *vm.Closure
	Parent *Suite
}

Represents a single test case

func NewCase

func NewCase(name string, fn *vm.Closure, parent *Suite) *Case

func (*Case) FullMatch

func (c *Case) FullMatch() bool

func (*Case) FullName

func (c *Case) FullName() string

func (*Case) FullNameWithSeparator

func (c *Case) FullNameWithSeparator() string

func (*Case) Location

func (c *Case) Location() *position.Location

func (*Case) Parents

func (c *Case) Parents() iter.Seq[*Suite]

func (*Case) Run

func (c *Case) Run(v *vm.Thread, events chan<- *ReportEvent, ctx context.Context) *CaseReport

type CaseReport

type CaseReport struct {
	Case *Case
	// contains filtered or unexported fields
}

Contains the result of running a test case

func NewCaseReport

func NewCaseReport(cas *Case) *CaseReport

func (*CaseReport) Duration

func (c *CaseReport) Duration() time.Duration

func (*CaseReport) Err

func (c *CaseReport) Err() []Err

func (*CaseReport) FullNameWithSeparator

func (c *CaseReport) FullNameWithSeparator() string

func (*CaseReport) RegisterErr

func (c *CaseReport) RegisterErr(err Err)

func (*CaseReport) Status

func (c *CaseReport) Status() TestStatus

func (*CaseReport) Stderr

func (c *CaseReport) Stderr() *bytes.Buffer

func (*CaseReport) Stdout

func (c *CaseReport) Stdout() *bytes.Buffer

func (*CaseReport) UpdateStatus

func (c *CaseReport) UpdateStatus(newStatus TestStatus)

type Err

type Err struct {
	Typ        ErrTyp
	Err        value.Value
	StackTrace *value.StackTrace
}

type ErrTyp

type ErrTyp uint8
const (
	ErrCase ErrTyp = iota
	ErrBeforeAll
	ErrBeforeEach
	ErrAfterAll
	ErrAfterEach
)

func (ErrTyp) String

func (e ErrTyp) String() string

type Filter

type Filter interface {
	CaseMatches(test *Case) bool
	SuiteMatches(suite *Suite) SuiteMatch
}

Filter checks if a test case/suite matches and discards the test if it does not match

type PathFilter

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

PathFilter matches tests on filepaths and lines

func NewPathFilter

func NewPathFilter(path string) (*PathFilter, error)

func (*PathFilter) CaseMatches

func (p *PathFilter) CaseMatches(test *Case) bool

func (*PathFilter) LocationMatches

func (p *PathFilter) LocationMatches(loc *position.Location) bool

func (*PathFilter) SuiteMatches

func (p *PathFilter) SuiteMatches(suite *Suite) SuiteMatch

type PlainReporter

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

func NewPlainReporter

func NewPlainReporter() *PlainReporter

func (*PlainReporter) Report

func (s *PlainReporter) Report(events chan *ReportEvent, shutdown context.CancelFunc)

type RegexFilter

type RegexFilter struct {
	Regex *value.Regex
}

RegexFilter matches tests based on a regular expression

func NewRegexFilter

func NewRegexFilter(pattern string) (*RegexFilter, error)

func (*RegexFilter) CaseMatches

func (r *RegexFilter) CaseMatches(test *Case) bool

func (*RegexFilter) SuiteMatches

func (r *RegexFilter) SuiteMatches(suite *Suite) SuiteMatch

type Report

type Report interface {
	Duration() time.Duration
	Err() []Err
	Status() TestStatus
	Stdout() *bytes.Buffer
	Stderr() *bytes.Buffer
	FullNameWithSeparator() string
	// contains filtered or unexported methods
}

type ReportEvent

type ReportEvent struct {
	SuiteReport *SuiteReport
	CaseReport  *CaseReport
	Type        ReportEventType
}

func NewCaseReportEvent

func NewCaseReportEvent(caseReport *CaseReport, typ ReportEventType) *ReportEvent

func NewSuiteReportEvent

func NewSuiteReportEvent(suiteReport *SuiteReport, typ ReportEventType) *ReportEvent

type ReportEventType

type ReportEventType uint8
const (
	REPORT_START_SUITE ReportEventType = iota
	REPORT_FINISH_SUITE
	REPORT_START_CASE
	REPORT_FINISH_CASE
)

type Reporter

type Reporter interface {
	Report(events chan *ReportEvent, shutdown context.CancelFunc)
}

Contains the result of running a test suite

type RichReporter

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

func NewRichReporter

func NewRichReporter() *RichReporter

func (*RichReporter) Duration

func (r *RichReporter) Duration() time.Duration

func (*RichReporter) ETA

func (r *RichReporter) ETA() time.Duration

func (*RichReporter) Init

func (r *RichReporter) Init() tea.Cmd

func (*RichReporter) Percent

func (r *RichReporter) Percent() float64

func (*RichReporter) Report

func (r *RichReporter) Report(events chan *ReportEvent, shutdown context.CancelFunc)

func (*RichReporter) Update

func (r *RichReporter) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*RichReporter) View

func (r *RichReporter) View() string

type Suite

type Suite struct {
	Name       string
	Location   *position.Location
	Parent     *Suite
	SubSuites  []*Suite
	Cases      []*Case
	BeforeEach []*vm.Closure
	AfterEach  []*vm.Closure
	BeforeAll  []*vm.Closure
	AfterAll   []*vm.Closure
	FullMatch  bool
	// contains filtered or unexported fields
}

Represents a test suite, a group of tests like `describe` or `context`

func NewSuite

func NewSuite(name string, parent *Suite, loc *position.Location) *Suite

Create a new tests suite

func (*Suite) CaseCount

func (s *Suite) CaseCount() int

func (*Suite) FullName

func (s *Suite) FullName() string

func (*Suite) FullNameWithSeparator

func (s *Suite) FullNameWithSeparator() string

func (*Suite) NewCase

func (s *Suite) NewCase(name string, fn *vm.Closure) *Case

func (*Suite) NewSubSuite

func (s *Suite) NewSubSuite(name string, loc *position.Location) *Suite

func (*Suite) RegisterAfterAll

func (s *Suite) RegisterAfterAll(fn *vm.Closure)

func (*Suite) RegisterAfterEach

func (s *Suite) RegisterAfterEach(fn *vm.Closure)

func (*Suite) RegisterBeforeAll

func (s *Suite) RegisterBeforeAll(fn *vm.Closure)

func (*Suite) RegisterBeforeEach

func (s *Suite) RegisterBeforeEach(fn *vm.Closure)

func (*Suite) RegisterCase

func (s *Suite) RegisterCase(testCase *Case)

func (*Suite) RegisterSubSuite

func (s *Suite) RegisterSubSuite(subSuite *Suite)

func (*Suite) Run

func (s *Suite) Run(v *vm.Thread, events chan<- *ReportEvent, rng *rand.Rand, ctx context.Context) *SuiteReport

type SuiteMatch

type SuiteMatch uint8
const (
	SUITE_MATCH_FALSE SuiteMatch = iota
	SUITE_MATCH_TRUE
	SUITE_MATCH_FULL
)

func SuiteMatchesFilters

func SuiteMatchesFilters(suite *Suite) SuiteMatch

type SuiteOrCase

type SuiteOrCase interface {
	// contains filtered or unexported methods
}

type SuiteReport

type SuiteReport struct {
	Suite           *Suite
	CaseReports     []*CaseReport
	SubSuiteReports []*SuiteReport
	// contains filtered or unexported fields
}

Contains the result of running a test suite

func NewSuiteReport

func NewSuiteReport(suite *Suite) *SuiteReport

func Run

func Run() *SuiteReport

func RunWith

func RunWith(v *vm.Thread, reporter Reporter, events chan *ReportEvent, seed uint64) *SuiteReport

Run the all tests under the root suite

func (*SuiteReport) Duration

func (s *SuiteReport) Duration() time.Duration

func (*SuiteReport) Err

func (s *SuiteReport) Err() []Err

func (*SuiteReport) FullNameWithSeparator

func (s *SuiteReport) FullNameWithSeparator() string

func (*SuiteReport) RegisterCaseReport

func (s *SuiteReport) RegisterCaseReport(caseReport *CaseReport)

func (*SuiteReport) RegisterErr

func (s *SuiteReport) RegisterErr(err Err)

func (*SuiteReport) RegisterSubSuiteReport

func (s *SuiteReport) RegisterSubSuiteReport(subSuiteReport *SuiteReport)

func (*SuiteReport) Status

func (s *SuiteReport) Status() TestStatus

func (*SuiteReport) Stderr

func (s *SuiteReport) Stderr() *bytes.Buffer

func (*SuiteReport) Stdout

func (s *SuiteReport) Stdout() *bytes.Buffer

func (*SuiteReport) UpdateStatus

func (s *SuiteReport) UpdateStatus(newStatus TestStatus)

type TestStatus

type TestStatus uint8
const (
	TEST_PENDING TestStatus = iota
	TEST_FAILED
	TEST_ERROR
	TEST_SKIPPED
	TEST_RUNNING
	TEST_SUCCESS
)

type TraverseOption

type TraverseOption uint8

Value used to decide what whether to skip the children of the report, break the traversal or continue in the Report Traverse method. The zero value continues the traversal.

const (
	TraverseContinue TraverseOption = iota
	TraverseSkip
	TraverseBreak
)

Jump to

Keyboard shortcuts

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