staticcase

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeFailFileSuffix

func ChangeFailFileSuffix(dir string, oldSuffix, newSuffix string) error

func CheckEmptyFileAndThenRemove

func CheckEmptyFileAndThenRemove(filePath string, shouldPrintLog bool) error

func CheckValueExis

func CheckValueExis(ctx context.Context, p *ssa.Function, globalValue, globalName string) bool

func CreatMiddleCode

func CreatMiddleCode(ctx context.Context) (int, error)

func FixGoFile

func FixGoFile(path string) error

func GenerateBaseTest

func GenerateBaseTest(ctx context.Context) error

func GenerateTest

func GenerateTest(dir string, shouldPrintLog bool) error

func GenerateTestForPlugin

func GenerateTestForPlugin(opt atgconstant.Options) error

GenerateTestForPlugin the test for the plugin. It is firstly generate the test with the _smart_unit_test_[random_number].go If there is the _smart_unit_test.go file. We merge these two file. If there is no _smart_unit_test.go file, we remove the random number.

func GetAllMock

func GetAllMock(ctx context.Context, useMockType int) map[string]map[string]int

func GetBaseMockByTempleType

func GetBaseMockByTempleType(ctx context.Context, useMockType int) map[string]map[string]int

func GetFunctions

func GetFunctions(sr *goparser.Result, opt *Options) ([]*models.Function, error)

We have two scenarios 1. generate the middle code: using the funcsMap 2. generate the final code: using the rowData

func GetGlobalValueBuilder

func GetGlobalValueBuilder(ctx context.Context) ([]string, []string)

func GetSpecialValueBuilder

func GetSpecialValueBuilder(ctx context.Context) map[string][]string

func Init

func Init(option *atgconstant.Options) (context.Context, error)

func NewTestsuiteEntry

func NewTestsuiteEntry(ctx context.Context, targetFile string, lock atghelper.RWLocker) *testsuiteEntry

func PickStructField

func PickStructField(ctx context.Context) []string

func PluginCmd

func PluginCmd(opt atgconstant.Options) error

func ReNameFileToGo

func ReNameFileToGo(path, oldSuffix, newSuffix string, isTemp bool, shouldPrintLog bool) error

func RecordFinalSuite

func RecordFinalSuite(ctx context.Context, filePath string, funcData map[string]string, useMockMap map[string]map[string]int, useMockType int) (code []byte, err error)

func RemoveGeneratedFile

func RemoveGeneratedFile(opt atgconstant.Options)

we are going to remove Vector_middle_code_test.go, path_BridgeVector.go, middle_code_fail_test.txt _final_code_fail_test.txt.

func ReportInternalError

func ReportInternalError(option atgconstant.Options, err error, panicInfo string)

Plugin doesn't need to report the message. Only the debug mode, we can see the message.

func Run

func Run(done func(), option atgconstant.Options) int

func RunForPlugin

func RunForPlugin(option atgconstant.Options) error

func RunSplitFunction

func RunSplitFunction(done func(), option atgconstant.Options)

func RunSplitFunctionTask

func RunSplitFunctionTask(filePath string, functionName string, useMockType int)

func UpdateSmartUnit

func UpdateSmartUnit(path string) error

func Work

func Work(path string, functionList string, useMockType int) error

func WorkForPlugin

func WorkForPlugin(opt atgconstant.Options) error

func WorkForSplitFunction

func WorkForSplitFunction(path string, useMockType int) error

func WorkOnFile

func WorkOnFile(option atgconstant.Options) error

func WorkToChangeGo

func WorkToChangeGo(dir string, shouldPrintLog bool) error

Types

type GeneratedTest

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

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 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
	Ctx             context.Context           // Context of the smart unit
	TestCaseNum     int                       // Test case number
	Uid             string                    // uuid for each function
	TestMode        string                    // type of render test
	RecordRow       map[string]string         // rowData on each function
	Builder         []string                  // global value builder
	MiddleBuilder   []string                  // global value builder
	FilePath        string                    // realpath
	Parallel        bool                      // Print tests that runs the subtests in parallel.
	Named           bool                      // Create Map instead of slice
	Importer        func() types.Importer     // A custom importer.  // TODO: remoeve it because I don't know to use it
	Template        string                    // Name of custom template set
	TemplateDir     string                    // Path to custom template set
	TemplateParams  map[string]interface{}    // Custom external parameters
	TemplateData    [][]byte                  // Data slice for templates
	ExistTestImport []*instrumentation.Import // Imports from exist test file for template
	UseMockType     int                       // whether to user mock pkg in cases
	UseMockMap      map[string]map[string]int // Data for function for mock
}

Options provides custom filters and parameters for generating tests.

Directories

Path Synopsis
internal
goparser
This file may have been modified by Bytedance Ltd.
This file may have been modified by Bytedance Ltd.
models
This file may have been modified by Bytedance Ltd.
This file may have been modified by Bytedance Ltd.
output
Package goparse contains logic for parsing Go files.
Package goparse contains logic for parsing Go files.
render
This file may have been modified by Bytedance Ltd.
This file may have been modified by Bytedance Ltd.
render/bindata
Code generated for package bindata by go-bindata DO NOT EDIT.
Code generated for package bindata by go-bindata DO NOT EDIT.
Code generated by "esc -include=.*\.tmpl -o=tmpl.go -pkg=templates ./"; DO NOT EDIT.
Code generated by "esc -include=.*\.tmpl -o=tmpl.go -pkg=templates ./"; DO NOT EDIT.

Jump to

Keyboard shortcuts

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