assert

package
v1.1.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

README

assert

提供了一些常用的断言函数。

Install

go get github.com/go-spring/spring-base@v1.1.0-rc2 

Import

import "github.com/go-spring/spring-base/assert"

Example

assert.True(t, true)
assert.Nil(t, nil)
assert.Equal(t, 0, "0")
assert.NotEqual(t, "0", 0)
assert.Same(t, 0, "0")
assert.NotSame(t, "0", "0")
assert.Panic(g, func() {}, "an error")
assert.Matches(g, "there's no error", "an error")
assert.Error(g, errors.New("there's no error"), "an error")
assert.TypeOf(g, new(int), (*int)(nil))
assert.Implements(g, errors.New("error"), (*error)(nil))

Documentation

Overview

Package assert 提供了一些常用的断言函数。

Package assert is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(cases Cases) error

Check 用于检查参数有效性。

func Equal

func Equal(t T, got interface{}, expect interface{}, msg ...string)

Equal asserts that got and expect are equal.

func Error

func Error(t T, got error, expr string, msg ...string)

Error asserts that a got error string matches a given regular expression.

func False

func False(t T, got bool, msg ...string)

False asserts that got is false.

func Implements

func Implements(t T, got interface{}, expect interface{}, msg ...string)

Implements asserts that got implements expect.

func Matches

func Matches(t T, got string, expr string, msg ...string)

Matches asserts that a got value matches a given regular expression.

func Nil

func Nil(t T, got interface{}, msg ...string)

Nil asserts that got is nil.

func NotEqual

func NotEqual(t T, got interface{}, expect interface{}, msg ...string)

NotEqual asserts that got and expect are not equal.

func NotNil

func NotNil(t T, got interface{}, msg ...string)

NotNil asserts that got is not nil.

func NotSame

func NotSame(t T, got interface{}, expect interface{}, msg ...string)

NotSame asserts that got and expect are not same.

func Panic

func Panic(t T, fn func(), expr string, msg ...string)

Panic asserts that function fn() would panic. It fails if the panic message does not match the regular expression.

func Same

func Same(t T, got interface{}, expect interface{}, msg ...string)

Same asserts that got and expect are same.

func True

func True(t T, got bool, msg ...string)

True asserts that got is true.

func TypeOf

func TypeOf(t T, got interface{}, expect interface{}, msg ...string)

TypeOf asserts that got and expect are same type.

Types

type Cases

type Cases = []struct {
	Condition bool
	Message   string
}

type MockT

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

MockT is a mock of T interface.

func NewMockT

func NewMockT(ctrl *gomock.Controller) *MockT

NewMockT creates a new mock instance.

func (*MockT) EXPECT

func (m *MockT) EXPECT() *MockTMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockT) Fail

func (m *MockT) Fail()

Fail mocks base method.

func (*MockT) Helper

func (m *MockT) Helper()

Helper mocks base method.

func (*MockT) Log

func (m *MockT) Log(args ...interface{})

Log mocks base method.

type MockTMockRecorder

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

MockTMockRecorder is the mock recorder for MockT.

func (*MockTMockRecorder) Fail

func (mr *MockTMockRecorder) Fail() *gomock.Call

Fail indicates an expected call of Fail.

func (*MockTMockRecorder) Helper

func (mr *MockTMockRecorder) Helper() *gomock.Call

Helper indicates an expected call of Helper.

func (*MockTMockRecorder) Log

func (mr *MockTMockRecorder) Log(args ...interface{}) *gomock.Call

Log indicates an expected call of Log.

type T

type T interface {
	Helper()
	Fail()
	Log(args ...interface{})
}

T testing.T 的简化接口。

Jump to

Keyboard shortcuts

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