Documentation
¶
Overview ¶
Provides functionality for analyzing and storing test cases extracted from Go source files.
Index ¶
- func IsValidTestCase(funcDecl *ast.FuncDecl) (valid bool, badFormat bool)
- type TestCase
- func (t *TestCase) Analyze()
- func (t *TestCase) GetStatements() []ast.Stmt
- func (t TestCase) MarshalJSON() ([]byte, error)
- func (t TestCase) NumLines() int
- func (t TestCase) NumStatements() int
- func (t TestCase) SaveAsJSON() error
- func (t TestCase) String() string
- func (t *TestCase) UnmarshalJSON(data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidTestCase ¶
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 ¶
Return the list of statements in this test case
func (TestCase) MarshalJSON ¶
Marshal the TestCase for JSON output
func (TestCase) NumLines ¶
Return the number of individual lines (not statements) that the test case spans
func (TestCase) NumStatements ¶
Return the number of statements in the test case
func (TestCase) SaveAsJSON ¶
Save the TestCase as JSON to a file named like `<project>/<project>_<package>_<testcase>.json` in the output directory
func (TestCase) String ¶
Return a string representation of the TestCase for logging and debugging purposes
func (*TestCase) UnmarshalJSON ¶
Unmarshal the TestCase from JSON