FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

assertauto package - github.com/pierrre/assert/assertauto - Go Packages

  1. Discover Packages
  2. github.com/pierrre/assert
  3. assertauto

assertauto

package
v0.15.7 Latest Latest

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 14 Imported by: 0
Main Versions Licenses Imports Imported By

Details

Repository

Links

Documentation

Documentation

Overview

Package assertauto provides helpers to automatically update the expected values of test assertions.

It compares actual values with expected values that are stored in files.

Run the tests with the environment variable ASSERTAUTO_UPDATE=true to update the expected values.

The values are stored in the "_assertauto" directory relative to the tested package. Each test creates a file with the name of the test and the ".txt" extension. Values of the same tests are stored sequentially in the same file.

The directory can be changed with the environment variable ASSERTAUTO_DIRECTORY. It must be a local path (see filepath.IsLocal). When ASSERTAUTO_UPDATE=true, this directory is removed at startup.

Values are converted to string using DefaultValueStringer.

Concurrency: functions in this package must not be called concurrently with the same test name. Values for a given test name are stored sequentially in a single file, and their order is significant: each call consumes the next expected value (in read mode) or appends the next actual value (in update mode). Concurrent calls sharing a test name make that order non-deterministic, causing flaky results: in update mode the file content varies between runs, and in read mode a call may be matched against the wrong expected value. By default the test name is testing.TB.Name, so concurrent calls must use distinct subtests (e.g. via testing.T.Run) rather than sharing a single testing.TB across goroutines.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultValueStringer is the default value stringer.
	//
	// By default it uses [assert.ValueStringer].
	DefaultValueStringer atomicutil.Value[func(any) string]
	// DefaultDirectory is the default directory.
	// It can be set with the environment variable ASSERTAUTO_DIRECTORY.
	// It must be a local path (see [filepath.IsLocal]).
	//
	// By default it is "_assertauto".
	DefaultDirectory atomicutil.Value[string]
	// DefaultUpdate is the default update value.
	// It can be set with the environment variable ASSERTAUTO_UPDATE.
	// If the value is not a valid boolean, it panics during init().
	//
	// By default it is false.
	DefaultUpdate atomic.Bool
)

Functions

func AllocsPerRun added in v0.4.2

func AllocsPerRun(tb testing.TB, runs int, f func(), optfs ...Option) (float64, bool)

AllocsPerRun asserts that a function allocates a certain number of times per run.

If the race detector is enabled, this function skips the test with testing.TB.Skip because testing.AllocsPerRun reports inaccurate allocations under -race.

It must not be called concurrently with the same test name. See the package documentation for details.

func Equal

func Equal(tb testing.TB, v any, optfs ...Option) bool

Equal asserts that the value is equal to the expected value.

It must not be called concurrently with the same test name. See the package documentation for details.

Types

type Option added in v0.4.0

type Option func(*options)

Option is an option for assertauto.

func AssertOptions added in v0.4.0

func AssertOptions(opts ...assert.Option) Option

AssertOptions returns an Option that sets the assert options.

func ValueStringer added in v0.7.0

func ValueStringer(vs func(any) string) Option

ValueStringer returns an Option that sets the value stringer.

Directories

Path Synopsis
Package diff is a copy of https://pkg.go.dev/internal/diff.
Package diff is a copy of https://pkg.go.dev/internal/diff.

Back | FazBrowse Home | New Git URL