source

package
v3.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package source provides utilities for handling source-code.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = fmt.Errorf("failed to find variable for update of golden value")

ErrNotFound indicates that UpdateExpectedValue failed to find the variable to update, likely because it is not a package level variable.

View Source
var Update bool

Update is a shim for testing, and for compatibility with the old -update-golden flag.

Functions

func CallExprArgs

func CallExprArgs(stackIndex int) ([]ast.Expr, error)

CallExprArgs returns the ast.Expr slice for the args of an ast.CallExpr at the index in the call stack.

func FormatNode

func FormatNode(node ast.Node) (string, error)

FormatNode using go/format.Node and return the result as a string

func FormattedCallExprArg

func FormattedCallExprArg(stackIndex int, argPos int) (string, error)

FormattedCallExprArg returns the argument from an ast.CallExpr at the index in the call stack. The argument is formatted using FormatNode.

func GoVersionLessThan

func GoVersionLessThan(major, minor int64) bool

GoVersionLessThan returns true if runtime.Version() is semantically less than version major.minor. Returns false if a release version can not be parsed from runtime.Version().

func IsUpdate added in v3.5.1

func IsUpdate() bool

IsUpdate is returns true if the -update flag is set. It indicates the user running the tests would like to update any golden values.

func UpdateExpectedValue added in v3.3.0

func UpdateExpectedValue(stackIndex int, x, y interface{}) error

UpdateExpectedValue looks for a package-level variable with a name that starts with expected in the arguments to the caller. If the variable is found, the value of the variable will be updated to value of the other argument to the caller.

func UpdateVariable added in v3.3.0

func UpdateVariable(
	filename string,
	fileset *token.FileSet,
	astFile *ast.File,
	ident *ast.Ident,
	value string,
) error

UpdateVariable writes to filename the contents of astFile with the value of the variable updated to value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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