testcase

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Provides functionality for analyzing and storing test cases extracted from Go source files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidTestCase

func IsValidTestCase(funcDecl *ast.FuncDecl) (valid bool, badFormat bool)

Determine if the given function declaration is a valid test case. Returns two booleans: `valid` indicating whether this is a valid test case, and `badFormat` indicating whether the test case has an incorrect (but acceptable) format. `badFormat` is false if the function is not valid.

The test case is validated using the following criteria: - The function name starts with "Test" followed by a capital letter - The function has `*testing.T` as its only formal parameter - The function does not have any receiver (i.e., it is not a method) - The function does not have any generic type parameters - The function does not return any values

Types

type TestCase

type TestCase struct {
	// High-level identifiers for the test case
	Name     string // the name of the test case
	Package  string // the fully qualified package name where the test case is defined
	FileName string // the name of the file where the test case is defined
	Project  string // the overarching project directory that the test case's package is part of

	// Actual syntax data
	FuncDecl *ast.FuncDecl // the actual declaration of the test case
	File     *ast.File     // the actual file where the test case is defined (for context, e.g. imports)
	// contains filtered or unexported fields
}

Represents an individual test case defined at the top level of a Go source file

func CreateTestCase

func CreateTestCase(funcDecl *ast.FuncDecl, file *ast.File, fset *token.FileSet, project string) TestCase

Create a new TestCase struct for storage

func (*TestCase) Analyze

func (t *TestCase) Analyze()

Extract relevant information about this TestCase and save the results into its own corresponding fields

func (*TestCase) GetStatements

func (t *TestCase) GetStatements() []ast.Stmt

Return the list of statements in this test case

func (TestCase) MarshalJSON

func (t TestCase) MarshalJSON() ([]byte, error)

Marshal the TestCase for JSON output

func (TestCase) NumLines

func (t TestCase) NumLines() int

Return the number of individual lines (not statements) that the test case spans

func (TestCase) NumStatements

func (t TestCase) NumStatements() int

Return the number of statements in the test case

func (TestCase) SaveAsJSON

func (t TestCase) SaveAsJSON() error

Save the TestCase as JSON to a file named like `<project>/<project>_<package>_<testcase>.json` in the output directory

func (TestCase) String

func (t TestCase) String() string

Return a string representation of the TestCase for logging and debugging purposes

func (*TestCase) UnmarshalJSON

func (t *TestCase) UnmarshalJSON(data []byte) error

Unmarshal the TestCase from JSON

Jump to

Keyboard shortcuts

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