mod

package
v0.1.44 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Index int = 0

Functions

func CreateEmmiter added in v0.1.35

func CreateEmmiter() (*bytes.Buffer, func(format string, args ...interface{}))

func GenerateFabrics

func GenerateFabrics(
	targets []*Func,
	typeContext *TypeContext,
	qualifier *ImportQualifier,
	maxDepth int,
) map[string][]*GeneratedFunc

Types

type Constructor

type Constructor struct {
	Func *Func

	ReturnType        *types.Named
	SecondResultIsErr bool

	IsSupported bool
}

type Func

type Func struct {
	FuncName    string
	PkgName     string        // package name (should be the same as the package's package statement)
	PkgPath     string        // import path
	PkgDir      string        // local on-disk directory
	TypesFunc   *types.Func   // auxiliary information about a Func from the go/types package
	AstFuncDecl *ast.FuncDecl // ast func declaration
	Uses        []*ast.FuncDecl
}

Func represents a discovered function that will be fuzzed.

func FindSuitables

func FindSuitables(s *types.Signature, existedFuncs []*Func) []*Func

func (*Func) FuzzName

func (f *Func) FuzzName() string

FuzzName returns the '<pkg>.<OrigFuzzFunc>' string. For example, it might be 'fmt.FuzzFmt'. In fzgo, this was used in messages, and as part of the path when creating the corpus location under testdata.

func (*Func) GetSignature

func (f *Func) GetSignature() *types.Signature

func (*Func) Params

func (f *Func) Params() []*types.Var

func (*Func) Receiver added in v0.1.2

func (f *Func) Receiver() *types.Named

func (*Func) String

func (f *Func) String() string

func (*Func) TypeString

func (f *Func) TypeString(qualifier types.Qualifier) string

type GeneratedFunc

type GeneratedFunc struct {
	Name, Body, ReturnType string
	Type                   types.Type
}

func GenerateInitTestFunc

func GenerateInitTestFunc(
	generatedFuncs map[string][]*GeneratedFunc,
	typeContext *TypeContext,
	qualifier *ImportQualifier,
) *GeneratedFunc

func GenerateMockFabrics added in v0.1.9

func GenerateMockFabrics(
	targets []*Func,
	typeContext *TypeContext,
	qualifier *ImportQualifier,
	relativePackagePath string,
	maxDepth int,
) ([]*GeneratedFunc, []byte)

type ImportQualifier

type ImportQualifier struct {
	Imports map[string]string
	// contains filtered or unexported fields
}

func NewQualifier

func NewQualifier(pkgName, pkgPath, outPkgName, outPkgPath string, isLocalTest bool) *ImportQualifier

func (*ImportQualifier) AddImport added in v0.1.9

func (iq *ImportQualifier) AddImport(defaultName, path string) string

func (*ImportQualifier) GetImportStrings

func (iq *ImportQualifier) GetImportStrings() []string

func (*ImportQualifier) Qualifier

func (iq *ImportQualifier) Qualifier(p *types.Package) string

type Interface

type Interface struct {
	InterfaceName   string
	PkgName         string           // package name (should be the same as the package's package statement)
	PkgPath         string           // import path
	PkgDir          string           // local on-disk directory
	TypesInterface  *types.Interface // auxiliary information about a Interface from the go/types package
	TypesNamed      *types.Named     // auxiliary information about a Named from the go/types package
	Implementations []*Struct        // structs that implements this interface from explore packages
	Constructors    []*Constructor
}

func (*Interface) IsSupported

func (i *Interface) IsSupported() bool

func (*Interface) String

func (i *Interface) String() string

func (*Interface) TypeString

func (i *Interface) TypeString(qualifier types.Qualifier) string

type Package

type Package struct {
	PkgName    string
	PkgPath    string
	Targets    []*Func // funcs for fuzzing
	Funcs      []*Func
	Structs    []*Struct
	Interfaces []*Interface

	Fset *token.FileSet
}

type Struct

type Struct struct {
	StructName   string
	PkgName      string        // package name (should be the same as the package's package statement)
	PkgPath      string        // import path
	PkgDir       string        // local on-disk directory
	TypesStruct  *types.Struct // auxiliary information about a Struct from the go/types package
	TypesNamed   *types.Named  // auxiliary information about a Named from the go/types package
	Constructors []*Constructor

	AsPointer bool // detect that struct implement interface as pointer to this struct
}

func (*Struct) String

func (s *Struct) String() string

func (*Struct) TypeString

func (s *Struct) TypeString(qualifier types.Qualifier) string

type TypeContext

type TypeContext struct {
	ExistedFuncs        []*Func
	ExistedStructs      []*Struct
	ExistedInterfaces   []*Interface
	SupportedInterfaces map[*Interface]bool

	ValidConstructors map[*Constructor]bool
	// contains filtered or unexported fields
}

func NewTypeContext

func NewTypeContext(constructorPattern *regexp.Regexp) *TypeContext

func (*TypeContext) AddFunc

func (tc *TypeContext) AddFunc(f *Func)

func (*TypeContext) AddInterface

func (tc *TypeContext) AddInterface(i *Interface)

func (*TypeContext) AddStruct

func (tc *TypeContext) AddStruct(s *Struct)

func (*TypeContext) AddType

func (tc *TypeContext) AddType(t types.Type)

func (*TypeContext) IsSupported

func (tc *TypeContext) IsSupported(
	t types.Type,
) bool

type VariablesContext

type VariablesContext struct {
	Fabrics map[types.Type]*GeneratedFunc
	// contains filtered or unexported fields
}

func NewVariablesContext

func NewVariablesContext(importQualifier *ImportQualifier) *VariablesContext

func (*VariablesContext) CreateUniqueName

func (vc *VariablesContext) CreateUniqueName(wanted string) string

func (*VariablesContext) CreateUniqueNameForVariable

func (vc *VariablesContext) CreateUniqueNameForVariable(v *types.Var) string

Jump to

Keyboard shortcuts

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