Documentation ¶
Overview ¶
Package testcase contains functionality for generating all necessary information in order to create test cases
Index ¶
- func BasicLitString(val string) ast.Expr
- func CreatePrintfStmt(args []ast.Expr) ast.Stmt
- func MustPrettyPrintElement(e interface{}) string
- func PrettyPrintElement(e interface{}) (string, error)
- func Println() ast.Stmt
- func PrintlnVal(val string) ast.Stmt
- type CycleInfo
- type DuplMapChecker
- type Dynamic
- type FieldToAssignRes
- type Options
- type PrintRecursionInput
- type PrintResult
- type RecursionInput
- type TestCase
- func (g *TestCase) ArrayExprToPrintStmt(t *ast.ArrayType, input *PrintRecursionInput) *PrintResult
- func (g *TestCase) ArrayExprToValExpr(input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) BasicExprToPrintStmt(input *PrintRecursionInput, typeIdentifier, varIdentifier string) *PrintResult
- func (g *TestCase) BasicExprToValExpr(identifier string) ast.Expr
- func (g *TestCase) ChanTypeToValExpr(t *ast.ChanType, input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) CheckIfCanGenExpr(input *RecursionInput) bool
- func (g *TestCase) CheckIfCanGenFunc(f *ast.FuncType, input *RecursionInput) bool
- func (g *TestCase) CheckIfCanGenInterface(t *ast.InterfaceType, input *RecursionInput) bool
- func (g *TestCase) CorrectTypeExpr(e ast.Expr, input *RecursionInput) ast.Expr
- func (g *TestCase) Create()
- func (g *TestCase) ErrExprToPrintStmt(input *PrintRecursionInput) *PrintResult
- func (g *TestCase) ErrExprToValExpr() *TypeExprToValExprRes
- func (g *TestCase) FieldToAssignStmt(p *ast.Field, funcName string, pointer *importer.PkgResolverPointer) *FieldToAssignRes
- func (g *TestCase) FieldToAssignStmts(params *ast.FieldList, funcName string, pointer *importer.PkgResolverPointer) *FieldToAssignRes
- func (g *TestCase) FieldToPrintStmt(field *ast.Field, funcName string, pointer *importer.PkgResolverPointer) ([]ast.Expr, *PrintResult)
- func (g *TestCase) FuncDeclToExprStmt(f *ast.FuncDecl, recvIdent, paramIdent []*ast.Ident, printIdents []ast.Expr) (ast.Stmt, ast.Stmt)
- func (g *TestCase) FuncNilFunc(t ast.Expr, input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) FuncReturnListToBodyStatements(input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) FuncTypeToValExpr(input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) GetFuncReceiverStmts(recv *ast.FieldList, funcName string, pointer *importer.PkgResolverPointer) *FieldToAssignRes
- func (g *TestCase) GetUnnamedStructIdent(fieldType ast.Expr, input *RecursionInput) *ast.Ident
- func (g *TestCase) HasChan() bool
- func (g *TestCase) HasPrintStmts() bool
- func (g *TestCase) IdentToPrintStmt(t, oType *ast.Ident, input *PrintRecursionInput) *PrintResult
- func (g *TestCase) IdentWithNilObjectToValExpr(t *ast.Ident, input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) InterfaceGenDecl(input *RecursionInput, interfaceImplIdent *ast.Ident) *ast.GenDecl
- func (g *TestCase) InterfaceNilFunc(t ast.Expr, input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) InterfaceTypeToFuncImpl(input *RecursionInput, interfaceImplIdent *ast.Ident) *TypeExprToValExprRes
- func (g *TestCase) InterfaceTypeToValExpr(input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) IsBasicExpr(x ast.Expr) (string, bool)
- func (g *TestCase) IsBasicLit(identifier string) bool
- func (g *TestCase) IsError(identifier string) bool
- func (g *TestCase) MapExprToPrintStmt(t *ast.MapType, input *PrintRecursionInput) *PrintResult
- func (g *TestCase) MapExprToValExpr(input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) MethodFuncTypeToFuncImpl(funcType *ast.FuncType, method *ast.Field, input *RecursionInput, ...) *TypeExprToValExprRes
- func (g *TestCase) PreIdentToPrintStmt(t *ast.Ident, input *PrintRecursionInput) *PrintResult
- func (g *TestCase) PrintBodyStatements(funcBody *ast.BlockStmt)
- func (g *TestCase) ResultsToPrintStmts(results *ast.FieldList, funcName string, pointer *importer.PkgResolverPointer) ([]ast.Expr, *PrintResult, []ast.Stmt)
- func (g *TestCase) ReturnFieldToStmt(res *ast.Field, input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) SelectorExprToPrintStmt(input *PrintRecursionInput) *PrintResult
- func (g *TestCase) SelectorExprToValExpr(input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) ShouldReturnForFunc(expr ast.Expr, input *RecursionInput) bool
- func (g *TestCase) ShouldReturnForInterface(expr ast.Expr, input *RecursionInput) bool
- func (g *TestCase) StarExprToPrintStmt(t *ast.StarExpr, input *PrintRecursionInput) *PrintResult
- func (g *TestCase) StarExprToValExpr(input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) StructExprToPrintStmt(input *PrintRecursionInput) *PrintResult
- func (g *TestCase) StructExprToValExpr(input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) StructFieldsToKeyValExpr(res *ast.CompositeLit, input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) TestCasePrefix(funcDecl *ast.FuncDecl) string
- func (g *TestCase) TypeExprToValExpr(input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) TypeExpressionToPrintStmt(input *PrintRecursionInput) *PrintResult
- func (g *TestCase) TypeSpecToValExpr(t *ast.Ident, objectDeclType *ast.TypeSpec, input *RecursionInput) *TypeExprToValExprRes
- func (g *TestCase) TypeToPrefix(e ast.Expr) string
- func (g *TestCase) UnnamedStructToValExpr(t *ast.StructType, input *RecursionInput) *TypeExprToValExprRes
- type TypeExprToValExprRes
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BasicLitString ¶
BasicLitString creates an ast string expression from value
func CreatePrintfStmt ¶
CreatePrintfStmt creates sprintf statement from a list of expressions
func MustPrettyPrintElement ¶
func MustPrettyPrintElement(e interface{}) string
MustPrettyPrintElement pretty prints an AST element or panics
func PrettyPrintElement ¶
PrettyPrintElement pretty prints an AST element
func PrintlnVal ¶
PrintlnVal create println statement for input value
Types ¶
type CycleInfo ¶
type CycleInfo struct { Structs map[string]int StructByStruct map[*ast.StructType]int Interfaces map[*ast.InterfaceType]int StructMem map[*ast.StructType]ast.Expr InterfaceMem map[*ast.InterfaceType]ast.Decl }
CycleInfo stores information about possible cycles in parsed code
func FreshCycleInfo ¶
func FreshCycleInfo() CycleInfo
FreshCycleInfo creates a fresh cycle info struct
type DuplMapChecker ¶
type DuplMapChecker struct { StructTypeMap map[ast.StructType]bool IdentMap map[ast.Ident]bool BasicLitMap map[ast.BasicLit]bool StarExprMap map[ast.StarExpr]bool ArrayTypeMap map[ast.ArrayType]bool MapTypeMap map[ast.MapType]bool ChanTypeMap map[ast.ChanType]bool FuncTypeMap map[ast.FuncType]bool InterfaceTypeMap map[ast.InterfaceType]bool SelectorExprMap map[ast.SelectorExpr]bool EllipsisMap map[ast.Ellipsis]bool FuncLitMap map[ast.FuncLit]bool }
DuplMapChecker checker which identifies duplicate map keys
func NewDuplMapChecker ¶
func NewDuplMapChecker() *DuplMapChecker
NewDuplMapChecker creates a new dupl map checker
func (*DuplMapChecker) IsDuplExpr ¶
func (d *DuplMapChecker) IsDuplExpr(e ast.Expr) bool
IsDuplExpr checks if we are dealing with a duplicate map key expression
type FieldToAssignRes ¶
type FieldToAssignRes struct { Idents []*ast.Ident Statements []ast.Stmt Declarations []ast.Decl // FIXME: ChanIdents []*ast.Ident }
FieldToAssignRes result for converting func fields to assign stmts
func (*FieldToAssignRes) Append ¶
func (res *FieldToAssignRes) Append(idents, chanIdents []*ast.Ident, stmts []ast.Stmt, decls []ast.Decl)
Append appends idents, statements and declarations to a fieldToAssignRes
func (*FieldToAssignRes) AppendRes ¶
func (res *FieldToAssignRes) AppendRes(otherRes *FieldToAssignRes)
AppendRes appends other into this
type Options ¶
type Options struct { ValTestCase values.IGen VarTestCase variables.IGen IdentGen ident.IGen MaxRecursion int }
Options test case generation options
type PrintRecursionInput ¶
type PrintRecursionInput struct {
// contains filtered or unexported fields
}
PrintRecursionInput input object for traversing the AST
func NewPrintRecursionInput ¶
func NewPrintRecursionInput(valType ast.Expr, identifierName string, pointer *importer.PkgResolverPointer) *PrintRecursionInput
NewPrintRecursionInput creates new recursion input
type RecursionInput ¶
type RecursionInput struct {
// contains filtered or unexported fields
}
RecursionInput input object for traversing the AST
func NewRecursionInput ¶
func NewRecursionInput(valType ast.Expr, identifierName string, pointer *importer.PkgResolverPointer, ident *ast.Ident) *RecursionInput
NewRecursionInput creates new recursion input
func NewRecursionInputWithExpr ¶
func NewRecursionInputWithExpr(e ast.Expr, input *RecursionInput) *RecursionInput
NewRecursionInputWithExpr helper function for creating new recursion inputs
func (*RecursionInput) Copy ¶
func (r *RecursionInput) Copy() *RecursionInput
Copy copies recursion input with a fresh cycle info
type TestCase ¶
type TestCase struct { // Properties used for generating mutations when doing crossover in evolution FuncDecl *ast.FuncDecl Pointer *importer.PkgResolverPointer PackageInfo *importer.PackageInfo Opts Options Deco *decorator.Deco Dynamic RunTimeInfo *runtime.Info // Properties used to create value stmts in test cases Decls []string Stmts []string FuncStmt string ChanIdents []string // Properties used for creating assert stmts in test cases ResultStmts []string ResultUsageStmts []string FuncPrintStmt string }
TestCase contains all information for generating a test case
func New ¶
func New(f *ast.FuncDecl, pointer *importer.PkgResolverPointer, pkgInfo *importer.PackageInfo, opts Options, decorator *decorator.Deco, ) *TestCase
New creates a new test case
func (*TestCase) ArrayExprToPrintStmt ¶
func (g *TestCase) ArrayExprToPrintStmt(t *ast.ArrayType, input *PrintRecursionInput) *PrintResult
ArrayExprToPrintStmt converts an array type to print statements
func (*TestCase) ArrayExprToValExpr ¶
func (g *TestCase) ArrayExprToValExpr(input *RecursionInput) *TypeExprToValExprRes
ArrayExprToValExpr convert a array expression to value expression
func (*TestCase) BasicExprToPrintStmt ¶
func (g *TestCase) BasicExprToPrintStmt(input *PrintRecursionInput, typeIdentifier, varIdentifier string) *PrintResult
BasicExprToPrintStmt converts a basic identifier to a print stmt
func (*TestCase) BasicExprToValExpr ¶
BasicExprToValExpr converts a basic identifier to an expression
func (*TestCase) ChanTypeToValExpr ¶
func (g *TestCase) ChanTypeToValExpr(t *ast.ChanType, input *RecursionInput) *TypeExprToValExprRes
ChanTypeToValExpr converts a chan type to a value expression
func (*TestCase) CheckIfCanGenExpr ¶
func (g *TestCase) CheckIfCanGenExpr(input *RecursionInput) bool
CheckIfCanGenExpr recurse interface expression and discover if we find any non exported expressions
func (*TestCase) CheckIfCanGenFunc ¶
func (g *TestCase) CheckIfCanGenFunc(f *ast.FuncType, input *RecursionInput) bool
CheckIfCanGenFunc check if we are able to gen func implementation
func (*TestCase) CheckIfCanGenInterface ¶
func (g *TestCase) CheckIfCanGenInterface(t *ast.InterfaceType, input *RecursionInput) bool
CheckIfCanGenInterface if any non exported values are present in an interface, we need to return it as nil
func (*TestCase) CorrectTypeExpr ¶
CorrectTypeExpr corrects type expressions for imports
func (*TestCase) Create ¶
func (g *TestCase) Create()
Create converts a function declaration to a list of assignment statements and declaration statements
func (*TestCase) ErrExprToPrintStmt ¶
func (g *TestCase) ErrExprToPrintStmt(input *PrintRecursionInput) *PrintResult
ErrExprToPrintStmt converts err expression to print statement
func (*TestCase) ErrExprToValExpr ¶
func (g *TestCase) ErrExprToValExpr() *TypeExprToValExprRes
ErrExprToValExpr converts error expression to val expression
func (*TestCase) FieldToAssignStmt ¶
func (g *TestCase) FieldToAssignStmt(p *ast.Field, funcName string, pointer *importer.PkgResolverPointer) *FieldToAssignRes
FieldToAssignStmt converts a function parameter to an assignment field
func (*TestCase) FieldToAssignStmts ¶
func (g *TestCase) FieldToAssignStmts(params *ast.FieldList, funcName string, pointer *importer.PkgResolverPointer) *FieldToAssignRes
FieldToAssignStmts converts a parameter to assignment statements
func (*TestCase) FieldToPrintStmt ¶
func (g *TestCase) FieldToPrintStmt(field *ast.Field, funcName string, pointer *importer.PkgResolverPointer) ([]ast.Expr, *PrintResult)
FieldToPrintStmt convert field to print statement
func (*TestCase) FuncDeclToExprStmt ¶
func (g *TestCase) FuncDeclToExprStmt(f *ast.FuncDecl, recvIdent, paramIdent []*ast.Ident, printIdents []ast.Expr) (ast.Stmt, ast.Stmt)
FuncDeclToExprStmt converts func declaration to expression statement
func (*TestCase) FuncNilFunc ¶
func (g *TestCase) FuncNilFunc(t ast.Expr, input *RecursionInput) *TypeExprToValExprRes
FuncNilFunc creates a nil func
func (*TestCase) FuncReturnListToBodyStatements ¶
func (g *TestCase) FuncReturnListToBodyStatements(input *RecursionInput) *TypeExprToValExprRes
FuncReturnListToBodyStatements converts a return list of function to statements return values
func (*TestCase) FuncTypeToValExpr ¶
func (g *TestCase) FuncTypeToValExpr(input *RecursionInput) *TypeExprToValExprRes
FuncTypeToValExpr converts a func type to a value expression
func (*TestCase) GetFuncReceiverStmts ¶
func (g *TestCase) GetFuncReceiverStmts(recv *ast.FieldList, funcName string, pointer *importer.PkgResolverPointer) *FieldToAssignRes
GetFuncReceiverStmts retrieve statements for receiverr field
func (*TestCase) GetUnnamedStructIdent ¶
GetUnnamedStructIdent retrieves an identifier for an unnamed struct field
func (*TestCase) HasPrintStmts ¶
HasPrintStmts check if any print statements are generated for current test case
func (*TestCase) IdentToPrintStmt ¶
func (g *TestCase) IdentToPrintStmt(t, oType *ast.Ident, input *PrintRecursionInput) *PrintResult
IdentToPrintStmt converts ident to print statement
func (*TestCase) IdentWithNilObjectToValExpr ¶
func (g *TestCase) IdentWithNilObjectToValExpr(t *ast.Ident, input *RecursionInput) *TypeExprToValExprRes
IdentWithNilObjectToValExpr converts identifier with nil object to val expression
func (*TestCase) InterfaceGenDecl ¶
func (g *TestCase) InterfaceGenDecl(input *RecursionInput, interfaceImplIdent *ast.Ident) *ast.GenDecl
InterfaceGenDecl creates interface gen decl
func (*TestCase) InterfaceNilFunc ¶
func (g *TestCase) InterfaceNilFunc(t ast.Expr, input *RecursionInput) *TypeExprToValExprRes
InterfaceNilFunc creates a function returning nil value for expression
func (*TestCase) InterfaceTypeToFuncImpl ¶
func (g *TestCase) InterfaceTypeToFuncImpl(input *RecursionInput, interfaceImplIdent *ast.Ident) *TypeExprToValExprRes
InterfaceTypeToFuncImpl converts interface type to function implementation declarations
func (*TestCase) InterfaceTypeToValExpr ¶
func (g *TestCase) InterfaceTypeToValExpr(input *RecursionInput) *TypeExprToValExprRes
InterfaceTypeToValExpr converts an interface type to val expression and declarations
func (*TestCase) IsBasicExpr ¶
IsBasicExpr checks if expr is basic expr
func (*TestCase) IsBasicLit ¶
IsBasicLit reports if an idenetifier is a basic literal
func (*TestCase) MapExprToPrintStmt ¶
func (g *TestCase) MapExprToPrintStmt(t *ast.MapType, input *PrintRecursionInput) *PrintResult
MapExprToPrintStmt converts a map type to print statements
func (*TestCase) MapExprToValExpr ¶
func (g *TestCase) MapExprToValExpr(input *RecursionInput) *TypeExprToValExprRes
MapExprToValExpr convert a map expression to value expression
func (*TestCase) MethodFuncTypeToFuncImpl ¶
func (g *TestCase) MethodFuncTypeToFuncImpl(funcType *ast.FuncType, method *ast.Field, input *RecursionInput, interfaceImplIdent *ast.Ident, result *TypeExprToValExprRes) *TypeExprToValExprRes
MethodFuncTypeToFuncImpl converts func type to function implementation declarations
func (*TestCase) PreIdentToPrintStmt ¶
func (g *TestCase) PreIdentToPrintStmt(t *ast.Ident, input *PrintRecursionInput) *PrintResult
PreIdentToPrintStmt converts an Ident type to print statements(diff from IdentToPrintStmt, using by TypeExpressionToPrintStmt)
func (*TestCase) PrintBodyStatements ¶
PrintBodyStatements debug function
func (*TestCase) ResultsToPrintStmts ¶
func (g *TestCase) ResultsToPrintStmts(results *ast.FieldList, funcName string, pointer *importer.PkgResolverPointer) ([]ast.Expr, *PrintResult, []ast.Stmt)
ResultsToPrintStmts converts a results list to print statements
func (*TestCase) ReturnFieldToStmt ¶
func (g *TestCase) ReturnFieldToStmt(res *ast.Field, input *RecursionInput) *TypeExprToValExprRes
ReturnFieldToStmt converts return field to statement and declarations
func (*TestCase) SelectorExprToPrintStmt ¶
func (g *TestCase) SelectorExprToPrintStmt(input *PrintRecursionInput) *PrintResult
SelectorExprToPrintStmt converts a selector expression to a print statement
func (*TestCase) SelectorExprToValExpr ¶
func (g *TestCase) SelectorExprToValExpr(input *RecursionInput) *TypeExprToValExprRes
SelectorExprToValExpr converts a selector expression to a value expression
func (*TestCase) ShouldReturnForFunc ¶
func (g *TestCase) ShouldReturnForFunc(expr ast.Expr, input *RecursionInput) bool
ShouldReturnForFunc checks if should return because unimplementable func type
func (*TestCase) ShouldReturnForInterface ¶
func (g *TestCase) ShouldReturnForInterface(expr ast.Expr, input *RecursionInput) bool
ShouldReturnForInterface checks if should return because unimplementable interface
func (*TestCase) StarExprToPrintStmt ¶
func (g *TestCase) StarExprToPrintStmt(t *ast.StarExpr, input *PrintRecursionInput) *PrintResult
StarExprToPrintStmt converts a star expression to a print statement
func (*TestCase) StarExprToValExpr ¶
func (g *TestCase) StarExprToValExpr(input *RecursionInput) *TypeExprToValExprRes
StarExprToValExpr converts star expression to value expression
func (*TestCase) StructExprToPrintStmt ¶
func (g *TestCase) StructExprToPrintStmt(input *PrintRecursionInput) *PrintResult
StructExprToPrintStmt converts a struct expression to print statement
func (*TestCase) StructExprToValExpr ¶
func (g *TestCase) StructExprToValExpr(input *RecursionInput) *TypeExprToValExprRes
StructExprToValExpr create struct expression
func (*TestCase) StructFieldsToKeyValExpr ¶
func (g *TestCase) StructFieldsToKeyValExpr(res *ast.CompositeLit, input *RecursionInput) *TypeExprToValExprRes
StructFieldsToKeyValExpr converts struct expression to key value expressions for initialising the fields of a struct
func (*TestCase) TestCasePrefix ¶
TestCasePrefix in case of receiver create prefix this is need to ensure test results dont override eachother in case of: func X() func (r T) X()
func (*TestCase) TypeExprToValExpr ¶
func (g *TestCase) TypeExprToValExpr(input *RecursionInput) *TypeExprToValExprRes
TypeExprToValExpr converts a type expression, the type definition in a function parameter, to an expression used in an assignment statement
func (*TestCase) TypeExpressionToPrintStmt ¶
func (g *TestCase) TypeExpressionToPrintStmt(input *PrintRecursionInput) *PrintResult
TypeExpressionToPrintStmt converts type expression of a result to print statement
func (*TestCase) TypeSpecToValExpr ¶
func (g *TestCase) TypeSpecToValExpr(t *ast.Ident, objectDeclType *ast.TypeSpec, input *RecursionInput) *TypeExprToValExprRes
TypeSpecToValExpr converts type spec to val expression Start of type recursion
func (*TestCase) TypeToPrefix ¶
TypeToPrefix converts a function receiver type to a prefix
func (*TestCase) UnnamedStructToValExpr ¶
func (g *TestCase) UnnamedStructToValExpr(t *ast.StructType, input *RecursionInput) *TypeExprToValExprRes
UnnamedStructToValExpr converts unnamed struct to val expression
type TypeExprToValExprRes ¶
type TypeExprToValExprRes struct { Expr ast.Expr Statements []ast.Stmt Declarations []ast.Decl // FIXME: ChanIdents []*ast.Ident ChanStmts []ast.Stmt ChanDecls []ast.Stmt }
TypeExprToValExprRes result for converting input to value expressions
func (*TypeExprToValExprRes) Merge ¶
func (t *TypeExprToValExprRes) Merge(other *TypeExprToValExprRes)
Merge merges two type exr to val expr without using the expression