checkers

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSuiteExtraAssertCallMode = SuiteExtraAssertCallModeRemove

Variables

View Source
var DefaultExpectedVarPattern = regexp.MustCompile(
	`(^(exp(ected)?|want(ed)?)([A-Z]\w*)?$)|(^(\w*[a-z])?(Exp(ected)?|Want(ed)?)$)`)

DefaultExpectedVarPattern matches variables with "expected" or "wanted" prefix or suffix in the name.

Functions

func All

func All() []string

All returns all checkers names sorted by checker's priority.

func EnabledByDefault

func EnabledByDefault() []string

EnabledByDefault returns checkers enabled by default sorted by checker's priority.

func IsEnabledByDefault

func IsEnabledByDefault(name string) bool

IsEnabledByDefault returns true if a checker is enabled by default. Returns false if there is no such checker in the registry. For pre-validation use Get or IsKnown.

func IsKnown

func IsKnown(name string) bool

IsKnown checks if there is a checker with that name.

func SortByPriority

func SortByPriority(checkers []string)

SortByPriority mutates the input checkers names by sorting them in checker priority order. Ignores unknown checkers. For pre-validation use Get or IsKnown.

Types

type AdvancedChecker

type AdvancedChecker interface {
	Checker
	Check(pass *analysis.Pass, inspector *inspector.Inspector) []analysis.Diagnostic
}

AdvancedChecker implements complex Check logic different from trivial CallMeta check.

type BlankImport added in v1.1.0

type BlankImport struct{}

BlankImport detects useless blank imports of testify's packages. These imports are useless since testify doesn't do any magic with init() function.

The checker detects situations like

import (
	"testing"

	_ "github.com/stretchr/testify"
	_ "github.com/stretchr/testify/assert"
	_ "github.com/stretchr/testify/http"
	_ "github.com/stretchr/testify/mock"
	_ "github.com/stretchr/testify/require"
	_ "github.com/stretchr/testify/suite"
)

and requires

import (
	"testing"
)

func NewBlankImport added in v1.1.0

func NewBlankImport() BlankImport

NewBlankImport constructs BlankImport checker.

func (BlankImport) Check added in v1.1.0

func (checker BlankImport) Check(pass *analysis.Pass, _ *inspector.Inspector) (diagnostics []analysis.Diagnostic)

func (BlankImport) Name added in v1.1.0

func (BlankImport) Name() string

type BoolCompare

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

BoolCompare detects situations like

assert.Equal(t, false, result)
assert.EqualValues(t, false, result)
assert.Exactly(t, false, result)
assert.NotEqual(t, true, result)
assert.NotEqualValues(t, true, result)
assert.False(t, !result)
assert.True(t, result == true)
...

and requires

assert.False(t, result)
assert.True(t, result)

func NewBoolCompare

func NewBoolCompare() *BoolCompare

NewBoolCompare constructs BoolCompare checker.

func (BoolCompare) Check

func (checker BoolCompare) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (BoolCompare) Name

func (BoolCompare) Name() string

func (*BoolCompare) SetIgnoreCustomTypes added in v1.2.0

func (checker *BoolCompare) SetIgnoreCustomTypes(v bool) *BoolCompare

type CallMeta

type CallMeta struct {
	// Call stores the original AST call expression.
	Call *ast.CallExpr
	// Range contains start and end position of assertion call.
	analysis.Range
	// IsPkg true if this is package (not object) call.
	IsPkg bool
	// IsAssert true if this is "testify/assert" package (or object) call.
	IsAssert bool
	// Selector is the AST expression of "assert.Equal".
	Selector *ast.SelectorExpr
	// SelectorXStr is a string representation of Selector's left part – value before point, e.g. "assert".
	SelectorXStr string
	// Fn stores meta info about assertion function itself.
	Fn FnMeta
	// Args stores assertion call arguments but without `t *testing.T` argument.
	// E.g [42, result, "helpful comment"].
	Args []ast.Expr
	// ArgsRaw stores assertion call initial arguments.
	// E.g [t, 42, result, "helpful comment"].
	ArgsRaw []ast.Expr
}

CallMeta stores meta info about assertion function/method call, for example

assert.Equal(t, 42, result, "helpful comment")

func NewCallMeta added in v1.0.0

func NewCallMeta(pass *analysis.Pass, ce *ast.CallExpr) *CallMeta

NewCallMeta returns meta information about testify assertion call. Returns nil if ast.CallExpr is not testify call.

func (CallMeta) String added in v1.0.0

func (c CallMeta) String() string

type Checker

type Checker interface {
	Name() string
}

Checker describes named checker.

func Get

func Get(name string) (Checker, bool)

Get returns new checker instance by checker's name.

type Compares

type Compares struct{}

Compares detects situations like

assert.True(t, a == b)
assert.True(t, a != b)
assert.True(t, a > b)
assert.True(t, a >= b)
assert.True(t, a < b)
assert.True(t, a <= b)
assert.False(t, a == b)
...

and requires

assert.Equal(t, a, b)
assert.NotEqual(t, a, b)
assert.Greater(t, a, b)
assert.GreaterOrEqual(t, a, b)
assert.Less(t, a, b)
assert.LessOrEqual(t, a, b)

If `a` and `b` are pointers then `assert.Same`/`NotSame` is required instead, due to the inappropriate recursive nature of `assert.Equal` (based on `reflect.DeepEqual`).

func NewCompares

func NewCompares() Compares

NewCompares constructs Compares checker.

func (Compares) Check

func (checker Compares) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (Compares) Name

func (Compares) Name() string

type Contains added in v1.5.0

type Contains struct{}

Contains detects situations like

assert.True(t, strings.Contains(a, "abc123"))
assert.False(t, !strings.Contains(a, "abc123"))

assert.False(t, strings.Contains(a, "abc123"))
assert.True(t, !strings.Contains(a, "abc123"))

and requires

assert.Contains(t, a, "abc123")
assert.NotContains(t, a, "abc123")

func NewContains added in v1.5.0

func NewContains() Contains

NewContains constructs Contains checker.

func (Contains) Check added in v1.5.0

func (checker Contains) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (Contains) Name added in v1.5.0

func (Contains) Name() string

type Empty

type Empty struct{}

Empty detects situations like

assert.Len(t, arr, 0)
assert.Equal(t, 0, len(arr))
assert.EqualValues(t, 0, len(arr))
assert.Exactly(t, 0, len(arr))
assert.LessOrEqual(t, len(arr), 0)
assert.GreaterOrEqual(t, 0, len(arr))
assert.Less(t, len(arr), 0)
assert.Greater(t, 0, len(arr))
assert.Less(t, len(arr), 1)
assert.Greater(t, 1, len(arr))
assert.Zero(t, len(arr))
assert.Empty(t, len(arr))

assert.NotEqual(t, 0, len(arr))
assert.NotEqualValues(t, 0, len(arr))
assert.Less(t, 0, len(arr))
assert.Greater(t, len(arr), 0)
assert.Positive(t, len(arr))
assert.NotZero(t, len(arr))
assert.NotEmpty(t, len(arr))

and requires

assert.Empty(t, arr)
assert.NotEmpty(t, arr)

func NewEmpty

func NewEmpty() Empty

NewEmpty constructs Empty checker.

func (Empty) Check

func (checker Empty) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (Empty) Name

func (Empty) Name() string

type EncodedCompare added in v1.5.0

type EncodedCompare struct{}

EncodedCompare detects situations like

assert.Equal(t, `{"foo": "bar"}`, body)
assert.EqualValues(t, `{"foo": "bar"}`, body)
assert.Exactly(t, `{"foo": "bar"}`, body)
assert.Equal(t, expectedJSON, resultJSON)
assert.Equal(t, expBodyConst, w.Body.String())
assert.Equal(t, fmt.Sprintf(`{"value":"%s"}`, hexString), result)
assert.Equal(t, "{}", json.RawMessage(resp))
assert.Equal(t, expJSON, strings.Trim(string(resultJSONBytes), "\n")) // + Replace, ReplaceAll, TrimSpace

assert.Equal(t, expectedYML, conf)

and requires

assert.JSONEq(t, `{"foo": "bar"}`, body)
assert.YAMLEq(t, expectedYML, conf)

func NewEncodedCompare added in v1.5.0

func NewEncodedCompare() EncodedCompare

NewEncodedCompare constructs EncodedCompare checker.

func (EncodedCompare) Check added in v1.5.0

func (checker EncodedCompare) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (EncodedCompare) Name added in v1.5.0

func (EncodedCompare) Name() string

type ErrorIsAs

type ErrorIsAs struct{}

ErrorIsAs detects situations like

assert.Error(t, err, errSentinel)
assert.NoError(t, err, errSentinel)
assert.True(t, errors.Is(err, errSentinel))
assert.False(t, errors.Is(err, errSentinel))
assert.True(t, errors.As(err, &target))

and requires

assert.ErrorIs(t, err, errSentinel)
assert.NotErrorIs(t, err, errSentinel)
assert.ErrorAs(t, err, &target)

Also ErrorIsAs repeats go vet's "errorsas" check logic.

func NewErrorIsAs

func NewErrorIsAs() ErrorIsAs

NewErrorIsAs constructs ErrorIsAs checker.

func (ErrorIsAs) Check

func (checker ErrorIsAs) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (ErrorIsAs) Name

func (ErrorIsAs) Name() string

type ErrorNil

type ErrorNil struct{}

ErrorNil detects situations like

assert.Nil(t, err)
assert.Empty(t, err)
assert.Zero(t, err)
assert.Equal(t, nil, err)
assert.EqualValues(t, nil, err)
assert.Exactly(t, nil, err)
assert.ErrorIs(t, err, nil)

assert.NotNil(t, err)
assert.NotEmpty(t, err)
assert.NotZero(t, err)
assert.NotEqual(t, nil, err)
assert.NotEqualValues(t, nil, err)
assert.NotErrorIs(t, err, nil)

and requires

assert.NoError(t, err)
assert.Error(t, err)

func NewErrorNil

func NewErrorNil() ErrorNil

NewErrorNil constructs ErrorNil checker.

func (ErrorNil) Check

func (checker ErrorNil) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (ErrorNil) Name

func (ErrorNil) Name() string

type ExpectedActual

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

ExpectedActual detects situations like

assert.Equal(t, result, expected)
assert.EqualExportedValues(t, resultObj, User{Name: "Anton"})
assert.EqualValues(t, result, 42)
assert.Exactly(t, result, int64(42))
assert.JSONEq(t, result, `{"version": 3}`)
assert.InDelta(t, result, 42.42, 1.0)
assert.InDeltaMapValues(t, result, map[string]float64{"score": 0.99}, 1.0)
assert.InDeltaSlice(t, result, []float64{0.98, 0.99}, 1.0)
assert.InEpsilon(t, result, 42.42, 0.0001)
assert.InEpsilonSlice(t, result, []float64{0.9801, 0.9902}, 0.0001)
assert.IsType(t, result, (*User)(nil))
assert.NotEqual(t, result, "expected")
assert.NotEqualValues(t, result, "expected")
assert.NotSame(t, resultPtr, &value)
assert.Same(t, resultPtr, &value)
assert.WithinDuration(t, resultTime, time.Date(2023, 01, 12, 11, 46, 33, 0, nil), time.Second)
assert.YAMLEq(t, result, "version: '3'")

and requires

assert.Equal(t, expected, result)
assert.EqualExportedValues(t, User{Name: "Anton"}, resultObj)
assert.EqualValues(t, 42, result)
...

func NewExpectedActual

func NewExpectedActual() *ExpectedActual

NewExpectedActual constructs ExpectedActual checker using DefaultExpectedVarPattern.

func (ExpectedActual) Check

func (checker ExpectedActual) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (ExpectedActual) Name

func (ExpectedActual) Name() string

func (*ExpectedActual) SetExpVarPattern

func (checker *ExpectedActual) SetExpVarPattern(p *regexp.Regexp) *ExpectedActual

type FloatCompare

type FloatCompare struct{}

FloatCompare detects situations like

assert.Equal(t, 42.42, result)
assert.EqualValues(t, 42.42, result)
assert.Exactly(t, 42.42, result)
assert.True(t, result == 42.42)
assert.False(t, result != 42.42)

and requires

assert.InEpsilon(t, 42.42, result, 0.0001) // Or assert.InDelta

func NewFloatCompare

func NewFloatCompare() FloatCompare

NewFloatCompare constructs FloatCompare checker.

func (FloatCompare) Check

func (checker FloatCompare) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (FloatCompare) Name

func (FloatCompare) Name() string

type FnMeta

type FnMeta struct {
	// Range contains start and end position of function Name.
	analysis.Range
	// Name is a function name.
	Name string
	// NameFTrimmed is a function name without "f" suffix.
	NameFTrimmed string
	// IsFmt is true if function is formatted, e.g. "Equalf".
	IsFmt bool
	// Signature represents assertion signature.
	Signature *types.Signature
}

FnMeta stores meta info about assertion function itself, for example "Equal".

type Formatter added in v1.4.0

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

Formatter detects situations like

assert.ElementsMatch(t, certConfig.Org, csr.Subject.Org, "organizations not equal")
assert.Error(t, err, fmt.Sprintf("Profile %s should not be valid", test.profile))
assert.Errorf(t, err, fmt.Sprintf("test %s", test.testName))
assert.Truef(t, targetTs.Equal(ts), "the timestamp should be as expected (%s) but was %s", targetTs)
...

and requires

assert.ElementsMatchf(t, certConfig.Org, csr.Subject.Org, "organizations not equal")
assert.Errorf(t, err, "Profile %s should not be valid", test.profile)
assert.Errorf(t, err, "test %s", test.testName)
assert.Truef(t, targetTs.Equal(ts), "the timestamp should be as expected (%s) but was %s", targetTs, ts)

func NewFormatter added in v1.4.0

func NewFormatter() *Formatter

NewFormatter constructs Formatter checker.

func (Formatter) Check added in v1.4.0

func (checker Formatter) Check(pass *analysis.Pass, call *CallMeta) (result *analysis.Diagnostic)

func (Formatter) Name added in v1.4.0

func (Formatter) Name() string

func (*Formatter) SetCheckFormatString added in v1.4.0

func (checker *Formatter) SetCheckFormatString(v bool) *Formatter

func (*Formatter) SetRequireFFuncs added in v1.4.0

func (checker *Formatter) SetRequireFFuncs(v bool) *Formatter

type GoRequire added in v1.0.0

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

GoRequire takes idea from go vet's "testinggoroutine" check and detects usage of require package's functions or assert.FailNow in the non-test goroutines

go func() {
	conn, err = lis.Accept()
	require.NoError(t, err)

	if assert.Error(err) {
		assert.FailNow(t, msg)
	}
}()

func NewGoRequire added in v1.0.0

func NewGoRequire() *GoRequire

NewGoRequire constructs GoRequire checker.

func (GoRequire) Check added in v1.0.0

func (checker GoRequire) Check(pass *analysis.Pass, inspector *inspector.Inspector) (diagnostics []analysis.Diagnostic)

Check should be consistent with https://cs.opensource.google/go/x/tools/+/master:go/analysis/passes/testinggoroutine/testinggoroutine.go

But due to the fact that the Check covers cases missed by go vet, the implementation turned out to be terribly complicated.

In simple words, the algorithm is as follows:

  • we walk along the call tree and store the status, whether we are in the test goroutine or not;
  • if we are in a test goroutine, then require is allowed, otherwise not;
  • when we encounter the launch of a subtest or `go` statement, the status changes;
  • in order to correctly handle the return to the correct status when exiting the current function, we have to store a stack of statuses (inGoroutineRunningTestFunc).

Other test functions called in the test function are also analyzed to make a verdict about the current function. This leads to recursion, which the cache of processed functions (processedFuncs) helps reduce the impact of. Also, because of this, we have to pre-collect a list of test function declarations (testsDecls).

func (GoRequire) Name added in v1.0.0

func (GoRequire) Name() string

func (*GoRequire) SetIgnoreHTTPHandlers added in v1.3.0

func (checker *GoRequire) SetIgnoreHTTPHandlers(v bool) *GoRequire

type Len

type Len struct{}

Len detects situations like

assert.Equal(t, 3, len(arr))
assert.EqualValues(t, 3, len(arr))
assert.Exactly(t, 3, len(arr))
assert.True(t, len(arr) == 3)

and requires

assert.Len(t, arr, 3)

func NewLen

func NewLen() Len

NewLen constructs Len checker.

func (Len) Check

func (checker Len) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (Len) Name

func (Len) Name() string

type NegativePositive added in v1.3.0

type NegativePositive struct{}

NegativePositive detects situations like

assert.Less(t, a, 0)
assert.Greater(t, 0, a)
assert.True(t, a < 0)
assert.True(t, 0 > a)
assert.False(t, a >= 0)
assert.False(t, 0 <= a)

assert.Greater(t, a, 0)
assert.Less(t, 0, a)
assert.True(t, a > 0)
assert.True(t, 0 < a)
assert.False(t, a <= 0)
assert.False(t, 0 >= a)

and requires

assert.Negative(t, value)
assert.Positive(t, value)

Typed zeros (like `int8(0)`, ..., `uint64(0)`) are also supported.

func NewNegativePositive added in v1.3.0

func NewNegativePositive() NegativePositive

NewNegativePositive constructs NegativePositive checker.

func (NegativePositive) Check added in v1.3.0

func (checker NegativePositive) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (NegativePositive) Name added in v1.3.0

func (NegativePositive) Name() string

type NilCompare added in v1.0.0

type NilCompare struct{}

NilCompare detects situations like

assert.Equal(t, nil, value)
assert.EqualValues(t, nil, value)
assert.Exactly(t, nil, value)

assert.NotEqual(t, nil, value)
assert.NotEqualValues(t, nil, value)

and requires

assert.Nil(t, value)
assert.NotNil(t, value)

func NewNilCompare added in v1.0.0

func NewNilCompare() NilCompare

NewNilCompare constructs NilCompare checker.

func (NilCompare) Check added in v1.0.0

func (checker NilCompare) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (NilCompare) Name added in v1.0.0

func (NilCompare) Name() string

type Regexp added in v1.5.0

type Regexp struct{}

Regexp detects situations like

assert.Regexp(t, regexp.MustCompile(`\[.*\] DEBUG \(.*TestNew.*\): message`), out)
assert.NotRegexp(t, regexp.MustCompile(`\[.*\] TRACE message`), out)

and requires

assert.Regexp(t, `\[.*\] DEBUG \(.*TestNew.*\): message`, out)
assert.NotRegexp(t, `\[.*\] TRACE message`, out)

func NewRegexp added in v1.5.0

func NewRegexp() Regexp

NewRegexp constructs Regexp checker.

func (Regexp) Check added in v1.5.0

func (checker Regexp) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (Regexp) Name added in v1.5.0

func (Regexp) Name() string

type RegularChecker

type RegularChecker interface {
	Checker
	Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic
}

RegularChecker check assertion call presented in CallMeta form.

type RequireError

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

RequireError detects error assertions like

assert.Error(t, err) // s.Error(err), s.Assert().Error(err)
assert.ErrorIs(t, err, io.EOF)
assert.ErrorAs(t, err, &target)
assert.EqualError(t, err, "end of file")
assert.ErrorContains(t, err, "end of file")
assert.NoError(t, err)
assert.NotErrorIs(t, err, io.EOF)

and requires

require.Error(t, err) // s.Require().Error(err), s.Require().Error(err)
require.ErrorIs(t, err, io.EOF)
require.ErrorAs(t, err, &target)
...

RequireError ignores: - assertions in the `if` condition; - assertions in the bool expression; - the entire `if-else[-if]` block, if there is an assertion in any `if` condition; - the last assertion in the block, if there are no methods/functions calls after it; - assertions in an explicit goroutine (including `http.Handler`); - assertions in an explicit testing cleanup function or suite teardown methods; - sequence of NoError assertions.

func NewRequireError

func NewRequireError() *RequireError

NewRequireError constructs RequireError checker.

func (RequireError) Check

func (checker RequireError) Check(pass *analysis.Pass, inspector *inspector.Inspector) []analysis.Diagnostic

func (RequireError) Name

func (RequireError) Name() string

func (*RequireError) SetFnPattern added in v1.0.0

func (checker *RequireError) SetFnPattern(p *regexp.Regexp) *RequireError

type SuiteBrokenParallel added in v1.4.0

type SuiteBrokenParallel struct{}

SuiteBrokenParallel detects unsupported t.Parallel() call in suite tests

func (s *MySuite) SetupTest() {
	s.T().Parallel()
}

// And other hooks...

func (s *MySuite) TestSomething() {
	s.T().Parallel()

	for _, tt := range cases {
		s.Run(tt.name, func() {
			s.T().Parallel()
		})

		s.T().Run(tt.name, func(t *testing.T) {
			t.Parallel()
		})
	}
}

func NewSuiteBrokenParallel added in v1.4.0

func NewSuiteBrokenParallel() SuiteBrokenParallel

NewSuiteBrokenParallel constructs SuiteBrokenParallel checker.

func (SuiteBrokenParallel) Check added in v1.4.0

func (checker SuiteBrokenParallel) Check(pass *analysis.Pass, insp *inspector.Inspector) (diagnostics []analysis.Diagnostic)

func (SuiteBrokenParallel) Name added in v1.4.0

func (SuiteBrokenParallel) Name() string

type SuiteDontUsePkg

type SuiteDontUsePkg struct{}

SuiteDontUsePkg detects situations like

func (s *MySuite) TestSomething() {
	assert.Equal(s.T(), 42, value)
}

and requires

func (s *MySuite) TestSomething() {
	s.Equal(42, value)
}

func NewSuiteDontUsePkg

func NewSuiteDontUsePkg() SuiteDontUsePkg

NewSuiteDontUsePkg constructs SuiteDontUsePkg checker.

func (SuiteDontUsePkg) Check

func (checker SuiteDontUsePkg) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (SuiteDontUsePkg) Name

func (SuiteDontUsePkg) Name() string

type SuiteExtraAssertCall

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

SuiteExtraAssertCall detects situations like

func (s *MySuite) TestSomething() {
	s.Assert().Equal(42, value)
}

and requires

func (s *MySuite) TestSomething() {
	s.Equal(42, value)
}

or vice versa (depending on the configurable mode).

func NewSuiteExtraAssertCall

func NewSuiteExtraAssertCall() *SuiteExtraAssertCall

NewSuiteExtraAssertCall constructs SuiteExtraAssertCall checker.

func (SuiteExtraAssertCall) Check

func (checker SuiteExtraAssertCall) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (SuiteExtraAssertCall) Name

func (*SuiteExtraAssertCall) SetMode

type SuiteExtraAssertCallMode

type SuiteExtraAssertCallMode int

SuiteExtraAssertCallMode reflects different modes of work of SuiteExtraAssertCall checker.

const (
	SuiteExtraAssertCallModeRemove SuiteExtraAssertCallMode = iota
	SuiteExtraAssertCallModeRequire
)

type SuiteSubtestRun added in v1.4.0

type SuiteSubtestRun struct{}

SuiteSubtestRun detects situations like

s.T().Run("subtest", func(t *testing.T) {
	assert.Equal(t, 42, result)
})

and requires

s.Run("subtest", func() {
	s.Equal(42, result)
})

func NewSuiteSubtestRun added in v1.4.0

func NewSuiteSubtestRun() SuiteSubtestRun

NewSuiteSubtestRun constructs SuiteSubtestRun checker.

func (SuiteSubtestRun) Check added in v1.4.0

func (checker SuiteSubtestRun) Check(pass *analysis.Pass, insp *inspector.Inspector) (diagnostics []analysis.Diagnostic)

func (SuiteSubtestRun) Name added in v1.4.0

func (SuiteSubtestRun) Name() string

type SuiteTHelper

type SuiteTHelper struct{}

SuiteTHelper requires t.Helper() call in suite helpers:

func (s *RoomSuite) assertRoomRound(roundID RoundID) {
	s.T().Helper()
	s.Equal(roundID, s.getRoom().CurrentRound.ID)
}

func NewSuiteTHelper

func NewSuiteTHelper() SuiteTHelper

NewSuiteTHelper constructs SuiteTHelper checker.

func (SuiteTHelper) Check

func (checker SuiteTHelper) Check(pass *analysis.Pass, inspector *inspector.Inspector) (diagnostics []analysis.Diagnostic)

func (SuiteTHelper) Name

func (SuiteTHelper) Name() string

type UselessAssert added in v1.1.0

type UselessAssert struct{}

UselessAssert detects useless asserts like

assert.Contains(t, tt.value, tt.value)
assert.ElementsMatch(t, tt.value, tt.value)
assert.Equal(t, tt.value, tt.value)
assert.EqualExportedValues(t, tt.value, tt.value)
...

assert.True(t, num > num)
assert.True(t, num < num)
assert.True(t, num >= num)
assert.True(t, num <= num)
assert.True(t, num == num)
assert.True(t, num != num)

assert.False(t, num > num)
assert.False(t, num < num)
assert.False(t, num >= num)
assert.False(t, num <= num)
assert.False(t, num == num)
assert.False(t, num != num)

assert.Empty(t, "")
assert.False(t, false)
assert.Implements(t, (*any)(nil), new(Conn))
assert.Negative(t, -42)
assert.Nil(t, nil)
assert.NoError(t, nil)
assert.NotEmpty(t, "value")
assert.NotZero(t, 42)
assert.NotZero(t, "value")
assert.Positive(t, 42)
assert.True(t, true)
assert.Zero(t, 0)
assert.Zero(t, "")
assert.Zero(t, nil)

func NewUselessAssert added in v1.1.0

func NewUselessAssert() UselessAssert

NewUselessAssert constructs UselessAssert checker.

func (UselessAssert) Check added in v1.1.0

func (checker UselessAssert) Check(pass *analysis.Pass, call *CallMeta) *analysis.Diagnostic

func (UselessAssert) Name added in v1.1.0

func (UselessAssert) Name() string

Directories

Path Synopsis
Package printf is a patched fork of https://github.com/golang/tools/blob/b6235391adb3b7f8bcfc4df81055e8f023de2688/go/analysis/passes/printf/printf.go#L538
Package printf is a patched fork of https://github.com/golang/tools/blob/b6235391adb3b7f8bcfc4df81055e8f023de2688/go/analysis/passes/printf/printf.go#L538

Jump to

Keyboard shortcuts

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