func (a *A) Use(args ...interface{}) {
	if len(args) == 0 {
		return
	}
	argIndex := make([]int, 0, len(args))
	values := make([]interface{}, 0, len(args))
	for i := range args {
		if args[i] == nil {
			continue
		}
		val := reflect.ValueOf(args[i])
		if val.Kind() != reflect.Ptr {
			continue
		}
		val = val.Elem()
		if !val.IsValid() {
			continue
		}
		argIndex = append(argIndex, i)
		values = append(values, args[i])
	}
	if len(argIndex) == 0 {
		return
	}
	f, err := a.parser.ParseArgs("Use", 1, argIndex)
	if err != nil {
		return
	}
	for i, arg := range f.Args {
		expr, ok := arg.(*ast.UnaryExpr)
		if !ok || expr.Op != token.AND {
			continue
		}
		if !assertion.IsVar(expr.X) {
			continue
		}
		buf := &bytes.Buffer{}
		printer.Fprint(buf, f.FileSet, expr.X)
		a.vars[buf.String()] = values[i]
	}
	a.parser.AddExcluded(f.Caller)
}
Use saves args in context and prints related args automatically in assertion method when referenced.

Sample code.

func TestSomething(t *testing.T) {
a := assert.New(t)
v1 := 123
v2 := []string{"wrong", "right"}
v3 := v2[0]
v4 := "not related"
a.Use(&v1, &v2, &v3, &v4)
}

Output:

Assertion failed:
v1 == 123 && v3 == "right"
Referenced variables are assigned in following statements:
v1 := 123
v3 := v2[0]
Related variables:
v1 = (int)123
v3 = (string)wrong
package assert
import (
	"bytes"
	"go/ast"
	"go/printer"
	"go/token"
	"reflect"
	"testing"
	"github.com/huandu/go-assert/internal/assertion"
)
type A struct {
	*testing.T
	vars   map[string]interface{}
	parser *assertion.Parser
}
func New(t *testing.T) *A {
	return &A{
		T:      t,
		vars:   make(map[string]interface{}),
		parser: new(assertion.Parser),
	}
}
func (a *A) Assert(expr interface{}) {
	assertion.Assert(a.T, expr, &assertion.Trigger{
		Parser:   a.parser,
		FuncName: "Assert",
		Skip:     1,
		Args:     []int{0},
		Vars:     a.vars,
	})
}
func (a *A) NilError(result ...interface{}) {
	assertion.AssertNilError(a.T, result, &assertion.Trigger{
		Parser:   a.parser,
		FuncName: "NilError",
		Skip:     1,
		Args:     []int{-1},
		Vars:     a.vars,
	})
}
func (a *A) NonNilError(result ...interface{}) {
	assertion.AssertNonNilError(a.T, result, &assertion.Trigger{
		Parser:   a.parser,
		FuncName: "NonNilError",
		Skip:     1,
		Args:     []int{-1},
		Vars:     a.vars,
	})
}
func (a *A) Equal(v1, v2 interface{}) {
	assertion.AssertEqual(a.T, v1, v2, &assertion.Trigger{
		Parser:   a.parser,
		FuncName: "Equal",
		Skip:     1,
		Args:     []int{0, 1},
		Vars:     a.vars,
	})
}
func (a *A) NotEqual(v1, v2 interface{}) {
	assertion.AssertNotEqual(a.T, v1, v2, &assertion.Trigger{
		Parser:   a.parser,
		FuncName: "NotEqual",
		Skip:     1,
		Args:     []int{0, 1},
		Vars:     a.vars,
	})
}