runtime

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: 5 Imported by: 0

Documentation

Overview

Package runtime analyses runtime output and converts it into assert statements

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(mem []string, key string) bool

Contains check if memory contains key

func EndName

func EndName(funcName string, index int) string

EndName expected end tag for test case output

func StartName

func StartName(funcName string, index int) string

StartName expected start tag for test case output

Types

type AssertStmt

type AssertStmt struct {
	AssertStmtType AssertStmtType
	Expected       string
	Value          string
}

AssertStmt an assert statement

func (*AssertStmt) Replace

func (a *AssertStmt) Replace(key, val string)

Replace replaces key with value

func (*AssertStmt) Type

func (a *AssertStmt) Type() StmtType

Type retrieves the type of assert stmt

type AssertStmtType

type AssertStmtType string

AssertStmtType Type of assert statement

const (
	AssertStmtTypeEqualValues AssertStmtType = "EqualValues"
	AssertStmtTypeNil         AssertStmtType = "Nil"
	AssertStmtTypeNoError     AssertStmtType = "NoError"
	AssertStmtTypeError       AssertStmtType = "Error"
	AssertStmtTypeFalse       AssertStmtType = "False"
	AssertStmtTypeTrue        AssertStmtType = "True"
)

Used assert statement types

type AssignStmt

type AssignStmt struct {
	AssignStmtType AssignStmtType
	LeftHand       string
	RightHand      string
}

AssignStmt an assign statement

func (*AssignStmt) Replace

func (a *AssignStmt) Replace(key, val string)

Replace replaces key with value used to resolve map and array index values

func (*AssignStmt) Type

func (a *AssignStmt) Type() StmtType

Type retrieves the type of assert stmt

type AssignStmtType

type AssignStmtType string

AssignStmtType is the type of assign statement

const (
	AssignStmtTypeDefine AssignStmtType = ":="
	AssignSTmtTypeAssign AssignStmtType = "="
)

Different assign statement types

type Info

type Info struct {
	Panics      bool
	AssertStmts []Stmt
	SecondRun   []Stmt
	Printer     StmtPrinter
}

Info information about values on runtime

func NewInfo

func NewInfo(printer StmtPrinter) *Info

NewInfo creates new runtime info for given printer

func (*Info) AssertStmtsForTestCase

func (info *Info) AssertStmtsForTestCase(printed string, firstRun bool, funcName string, index int)

AssertStmtsForTestCase creates assert statements for a testcase

func (*Info) GetAssertStmts

func (info *Info) GetAssertStmts() []string

GetAssertStmts retrieve the assert statements

func (*Info) IsValid

func (info *Info) IsValid() bool

IsValid verifies that created runtime info is valid used when generating end result

type Output

type Output struct {
	Type       string  `json:"type"`
	VarName    string  `json:"var_name"`
	MapKeyType string  `json:"map_key_type"`
	Val        string  `json:"val"`
	ArrIdent   string  `json:"arr_ident"`
	Child      *Output `json:"child"`
}

Output JSON structure for runtime output

type OutputParser

type OutputParser struct {
	// contains filtered or unexported fields
}

OutputParser parses runtime output strings

func NewOutputParser

func NewOutputParser() *OutputParser

NewOutputParser creates a new output paraser

func (*OutputParser) AssertStmts

func (o *OutputParser) AssertStmts(data *Output, replacements []Replacement, typeCorrection TypeCorrections, resStmts []Stmt) []Stmt

AssertStmts new assert statement from runtime output

func (*OutputParser) CreateAssertStmts

func (o *OutputParser) CreateAssertStmts(runtimeOutput *Output, replacements []Replacement, typeCorrection TypeCorrections, resStmts []Stmt) []Stmt

CreateAssertStmts creates the eventual assert statement based on runtime output and corrections

func (*OutputParser) Parse

func (o *OutputParser) Parse(printed, funcName string, index int) ([]Stmt, bool)

Parse parses printed runtime output to statements

func (*OutputParser) ParseLine

func (o *OutputParser) ParseLine(jsonString string) []Stmt

ParseLine parses a line of output

type Replacement

type Replacement struct {
	Key string
	Val string
}

Replacement struct which contains keys and replacement values

type Stmt

type Stmt interface {
	Type() StmtType
	Replace(key, val string)
}

Stmt statement interface

type StmtPrinter

type StmtPrinter interface {
	fmt.Stringer
	PrintStmt(stmt Stmt) string
}

StmtPrinter printer for assert statements

func NewTestifySuitePrinter

func NewTestifySuitePrinter(receiver string) StmtPrinter

NewTestifySuitePrinter new testify suite

type StmtType

type StmtType string

StmtType indicates the type of statement

const (
	StmtTypeAssert StmtType = "assert"
	StmtTypeAssign StmtType = "assign"
)

Different statement types

type TestifySuitePrinter

type TestifySuitePrinter struct {
	Receiver string
}

TestifySuitePrinter printer for testify suites

func (*TestifySuitePrinter) PrintAssertStmt

func (t *TestifySuitePrinter) PrintAssertStmt(astmt *AssertStmt) string

PrintAssertStmt prints an assert statement for a testcase in a testify suite

func (*TestifySuitePrinter) PrintAssignStmt

func (t *TestifySuitePrinter) PrintAssignStmt(astmt *AssignStmt) string

PrintAssignStmt prints an assign stmt

func (*TestifySuitePrinter) PrintStmt

func (t *TestifySuitePrinter) PrintStmt(stmt Stmt) string

PrintStmt prints a statement

func (*TestifySuitePrinter) String

func (t *TestifySuitePrinter) String() string

type TypeCorrections

type TypeCorrections struct {
	Prefix string
	Suffix string
}

TypeCorrections struct containing information for printing corrections in types e.g. custom values X(int(3)) in order to make correct assert statements

Jump to

Keyboard shortcuts

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