package source

import "gotest.tools/v3/internal/source"

Package source provides utilities for handling source-code.

Index

Variables

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.

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

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

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

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.

Source Files

bazel.go defers.go source.go update.go version.go

Version
v3.5.2 (latest)
Published
Sep 5, 2024
Platform
linux/amd64
Imports
13 packages
Last checked
2 months ago

Tools for package owners.