TestRunner

package
v0.0.0-...-55cb7e4 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

filepath: /Users/skelly/Documents/GoProjects/GoLib/TestRunner/packagerunner.go

filepath: /Users/skelly/Documents/GoProjects/GoLib/TestRunner/projectrunner.go

Package TestRunner provides utilities for running Go tests across a project.

TestRunner offers functionality to find test packages, run vetting and tests, and collect test results in a structured way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindFiles

func FindFiles(root, fileName string, ignoreDirs []string) ([]string, error)

FindFiles finds all files with the given name in the directory tree

func HasTestFailures

func HasTestFailures(results []ProjectTestResult) bool

HasTestFailures returns true if any tests failed

func PrintTestSummary

func PrintTestSummary(results []ProjectTestResult, totalTime time.Duration)

PrintTestSummary prints a summary of test results

func RunPackageTests

func RunPackageTests(runner *PackageTestRunner, verbose, debug bool, runShellScript bool, coverMode, testPattern string, isParent bool) error

RunPackageTests runs tests for a specific package

Types

type Options

type Options struct {
	// Verbose enables detailed output
	Verbose bool

	// SkipVet skips running 'go vet' on packages
	SkipVet bool

	// FailFast stops on first test failure
	FailFast bool

	// TestPattern is a regex to filter tests
	TestPattern string

	// Parallel runs tests in parallel when possible
	Parallel bool

	// Count sets the -count flag for go test
	Count int

	// CoverMode enables code coverage with the specified mode
	CoverMode string

	// IgnoreDirs specifies directories to skip
	IgnoreDirs []string
}

Options configures how the TestRunner behaves

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns the default options for the TestRunner

type PackageTestRunner

type PackageTestRunner struct {
	// Package directory
	Dir string
	// Package name
	Name string
	// Custom test setup
	Setup func() error
	// Custom test teardown
	Teardown func() error
	// Package-specific test options
	Options *Options
}

PackageTestRunner provides package-specific test configuration

func DefaultPackageRunner

func DefaultPackageRunner() *PackageTestRunner

DefaultPackageRunner creates a default package test runner configuration

type ProjectRunnerConfig

type ProjectRunnerConfig struct {
	// Root directory to search for test runners
	RootDir string
	// Run tests in parallel
	Parallel bool
	// Verbose output
	Verbose bool
	// Generate coverage reports
	Coverage bool
	// Coverage mode
	CoverageMode string
	// Test pattern to filter tests
	TestPattern string
	// Run legacy shell scripts instead of Go test runners
	UseLegacyScripts bool
	// Also run original shell scripts alongside Go runners
	RunShellScripts bool
	// Debug output
	Debug bool
	// Directories to ignore
	IgnoreDirs []string
	// Name of the project
	ProjectName string
	// Packages to test (if nil, all packages will be tested)
	Packages []string
}

ProjectRunnerConfig configures how the project-level test runner behaves

func DefaultProjectConfig

func DefaultProjectConfig(projectName string) *ProjectRunnerConfig

DefaultProjectConfig returns the default configuration for a project runner

type ProjectTestResult

type ProjectTestResult struct {
	// Package name or directory
	Package string
	// Whether the test succeeded
	Success bool
	// Error if the test failed
	Error error
	// Time taken to run the test
	Time time.Duration
}

ProjectTestResult represents the result of running tests in a package

func RunProjectTests

func RunProjectTests(config *ProjectRunnerConfig) ([]ProjectTestResult, error)

RunProjectTests finds and executes all test runners in the project

type TestResult

type TestResult struct {
	Package string
	Success bool
	Output  string
	Error   error
	Time    time.Duration
}

TestResult represents the result of a test run

type TestRunner

type TestRunner struct {
	Options     *Options
	VetResults  []TestResult
	TestResults []TestResult
	// contains filtered or unexported fields
}

TestRunner runs tests across a Go project

func NewTestRunner

func NewTestRunner(options *Options) *TestRunner

NewTestRunner creates a new TestRunner with the given options

func (*TestRunner) FindGoDirectories

func (r *TestRunner) FindGoDirectories(rootDir string) ([]string, error)

FindGoDirectories finds all directories containing Go files

func (*TestRunner) FindTestPackages

func (r *TestRunner) FindTestPackages(rootDir string) ([]string, error)

FindTestPackages finds all directories containing test files

func (*TestRunner) GetOptions

func (r *TestRunner) GetOptions() *Options

GetOptions returns the current options

func (*TestRunner) HasFailures

func (r *TestRunner) HasFailures() bool

HasFailures returns true if any tests failed

func (*TestRunner) PrintSummary

func (r *TestRunner) PrintSummary(totalTime time.Duration)

PrintSummary prints a summary of test results

func (*TestRunner) RunAll

func (r *TestRunner) RunAll(rootDir string) error

RunAll runs the entire test suite

func (*TestRunner) RunTestPackages

func (r *TestRunner) RunTestPackages(packages []string) (bool, error)

RunTestPackages runs go test on each package

func (*TestRunner) RunTests

func (r *TestRunner) RunTests(dirs []string) error

RunTests runs 'go test' on each directory

func (*TestRunner) RunVet

func (r *TestRunner) RunVet(dirs []string) error

RunVet runs 'go vet' on each directory

type TestRunnerIfc

type TestRunnerIfc interface {
	// FindGoDirectories finds all directories containing Go files
	FindGoDirectories(rootDir string) ([]string, error)

	// FindTestPackages finds all directories containing test files
	FindTestPackages(rootDir string) ([]string, error)

	// RunVet runs 'go vet' on each directory
	RunVet(dirs []string) error

	// RunTests runs 'go test' on each directory
	RunTests(dirs []string) error

	// RunTestPackages runs go test on each package
	RunTestPackages(packages []string) (bool, error)

	// RunAll runs the entire test suite
	RunAll(rootDir string) error

	// PrintSummary prints a summary of test results
	PrintSummary(totalTime time.Duration)

	// HasFailures returns true if any tests failed
	HasFailures() bool

	// GetOptions returns the current options
	GetOptions() *Options
}

TestRunnerIfc defines the interface for running tests across a Go project

Jump to

Keyboard shortcuts

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