gen

package
v0.0.5-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package gen provides a generator for creating assignment statements for input parameters of functions for every function found in a given folder

Index

Constants

View Source
const (
	DefaultPopulationSize   = 30
	DefaultTestCasesPerFunc = 18
	// Currently the best way to detect cycles is to count
	// the amount of times some struct is created
	DefaultAmountRecursion = 3
)

Default constants

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Version     string
	PackageName string
	Dir         string
	FileName    string
	// funcName, list of test cases
	TestCases map[string][]*testcase.TestCase
}

File file contains test cases for functions of a given file

func (*File) SuiteName

func (f *File) SuiteName() string

SuiteName returns the name of the test suite for this file

type Generator

type Generator struct {
	Version     string
	Dir         string
	PackageInfo *importer.PackageInfo
	Opts        *Options
	Deco        *decorator.Deco
}

Generator the generator

func New

func New(dir, version string, opts *Options) (*Generator, error)

New creates a new generator for generating assignment statements for function parameters

func (*Generator) GetNewOrganism

func (g *Generator) GetNewOrganism() *Organism

GetNewOrganism get a single organism

func (*Generator) GetTestCases

func (g *Generator) GetTestCases() []*Organism

GetTestCases retrieve test cases, start of recursions

func (*Generator) GetTestCasesForFunctionsInFile

func (g *Generator) GetTestCasesForFunctionsInFile(f *ast.File, pointer *importer.PkgResolverPointer) map[string][]*testcase.TestCase

GetTestCasesForFunctionsInFile convert given input ast file to a set of test cases per function test case contains a set of decl and assignment statement to generate test cases

func (*Generator) TestCasePrefix

func (g *Generator) TestCasePrefix(funcDecl *ast.FuncDecl) string

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 (*Generator) TypeToPrefix

func (g *Generator) TypeToPrefix(e ast.Expr) string

TypeToPrefix converts a function receiver type to a prefix

type Options

type Options struct {
	MaxRecursion     int
	OrganismAmount   int
	TestCasesPerFunc int
	ValGenerator     values.IGen
	// FIXME: Remove var generator as soon as IdentGen can be used everywhere
	VarGenerator variables.IGen
	IdentGen     ident.IGen
}

Options the options for the generator

func DefaultOpts

func DefaultOpts() *Options

DefaultOpts creates default generator options

type Organism

type Organism struct {
	Fitness float64
	// Create test cases for all files in a pkg
	Files []*File
}

Organism organism is a set of testcases for functions of files in a given directory

func (*Organism) UpdateAssertStmts

func (o *Organism) UpdateAssertStmts(printed string, firstRun bool)

UpdateAssertStmts sets an os assert statements based on printed runtime result

Jump to

Keyboard shortcuts

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