internal

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package goparse contains logic for parsing Go files. Specifically it parses source and test files into domain models for generating tests.

Package gotests contains the core logic for generating table-driven tests.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyFile = errors.New("file is empty")

ErrEmptyFile represents an empty file error.

Functions

func IsFileExist

func IsFileExist(path string) bool

Types

type Expression

type Expression struct {
	Value      string
	IsStar     bool
	IsVariadic bool
	IsWriter   bool
	Underlying string
}

func (*Expression) String

func (e *Expression) String() string

type Field

type Field struct {
	Name  string
	Type  *Expression
	Index int
}

func (*Field) IsBasicType

func (f *Field) IsBasicType() bool

func (*Field) IsNamed

func (f *Field) IsNamed() bool

func (*Field) IsStruct

func (f *Field) IsStruct() bool

func (*Field) IsWriter

func (f *Field) IsWriter() bool

func (*Field) ShortName

func (f *Field) ShortName() string

type Function

type Function struct {
	Name         string
	IsExported   bool
	Receiver     *Receiver
	Parameters   []*Field
	Results      []*Field
	ReturnsError bool
}

func (*Function) FullName

func (f *Function) FullName() string

func (*Function) IsNaked

func (f *Function) IsNaked() bool

func (*Function) OnlyReturnsError

func (f *Function) OnlyReturnsError() bool

func (*Function) OnlyReturnsOneValue

func (f *Function) OnlyReturnsOneValue() bool

func (*Function) ReturnsMultiple

func (f *Function) ReturnsMultiple() bool

func (*Function) TestName

func (f *Function) TestName() string

func (*Function) TestParameters

func (f *Function) TestParameters() []*Field

func (*Function) TestResults

func (f *Function) TestResults() []*Field

type GeneratedTest

type GeneratedTest struct {
	Path      string      // The test file's absolute path.
	Functions []*Function // The functions with new test methods.
}

A GeneratedTest contains information about a test file with generated tests.

func GenerateTests

func GenerateTests(srcPath string, opt *Options) ([]*GeneratedTest, error)

GenerateTests generates table-driven tests for the function and method signatures defined in the target source path file(s). The source path parameter can be either a Go source file or directory containing Go files.

type Header struct {
	Comments []string
	Package  string
	Imports  []*Import
	Code     []byte
}

type Import

type Import struct {
	Name, Path string
}

type Options

type Options struct {
	Only           *regexp.Regexp         // Includes only functions that match.
	Exclude        *regexp.Regexp         // Excludes functions that match.
	Exported       bool                   // Include only exported methods
	PrintInputs    bool                   // Print function parameters in error messages
	Subtests       bool                   // Print tests using Go 1.7 subtests
	Parallel       bool                   // Print tests that runs the subtests in parallel.
	Importer       func() types.Importer  // A custom importer.
	Template       string                 // Name of custom template set
	TemplateDir    string                 // Path to custom template set
	TemplateParams map[string]interface{} // Custom external parameters
}

Options provides custom filters and parameters for generating tests.

type Parser

type Parser struct {
	// The importer to resolve packages from import paths.
	Importer types.Importer
}

Parser can parse Go files.

func (*Parser) Parse

func (p *Parser) Parse(srcPath string, files []Path) (*Result, error)

Parse parses a given Go file at srcPath, along any files that share the same package, into a domain model for generating tests.

type Path

type Path string

func Files

func Files(srcPath string) ([]Path, error)

Files returns all the Golang files for the given path. Ignores hidden files.

func (Path) IsTestPath

func (p Path) IsTestPath() bool

func (Path) TestPath

func (p Path) TestPath() string

type Receiver

type Receiver struct {
	*Field
	Fields []*Field
}

type Result

type Result struct {
	// The package name and imports of a Go file.
	Header *Header
	// All the functions and methods in a Go file.
	Funcs []*Function
}

Result representats a parsed Go file.

Jump to

Keyboard shortcuts

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