ts

package
v1.13.10 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Package ts provides Go packages testing utilities. See https://github.com/qiniu/x/wiki/How-to-write-a-TestCase for details.

Index

Constants

View Source
const (
	// CapStdout - capture stdout
	CapStdout = 1
	// CapStderr - capture stderr
	CapStderr = 2
	// CapOutput - capture stdout and stderr
	CapOutput = CapStdout | CapStderr
)

Variables

This section is empty.

Functions

func Error

func Error(t *testing.T, args ...interface{})

Error is equivalent to Log() followed by Fail().

func Errorf

func Errorf(t *testing.T, format string, args ...interface{})

Errorf is equivalent to Logf() followed by Fail().

func Fatal

func Fatal(t *testing.T, args ...interface{})

Fatal is equivalent to Log() followed by FailNow().

func Fatalf

func Fatalf(t *testing.T, format string, args ...interface{})

Fatalf is equivalent to Logf() followed by FailNow().

func Log

func Log(t *testing.T, args ...interface{})

Log formats its arguments using default formatting, analogous to Print(), and records the text in the error log.

func Logf

func Logf(t *testing.T, format string, args ...interface{})

Logf formats its arguments according to the format, analogous to Printf(), and records the text in the error log.

func PropVal added in v1.10.6

func PropVal(o reflect.Value, prop string) reflect.Value

PropVal returns property value of an object.

Types

type Expecting added in v1.10.9

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

Expecting represents a expecting object.

func StartExpecting added in v1.10.9

func StartExpecting(t *testing.T, mode int) *Expecting

StartExpecting starts expecting with a capture mode.

func (*Expecting) Call added in v1.10.9

func (p *Expecting) Call(fn interface{}, args ...interface{}) (e *Expecting)

Call creates a test case, and then calls a function.

func (*Expecting) Close added in v1.10.9

func (p *Expecting) Close() error

Close stops expecting.

func (*Expecting) Expect added in v1.10.9

func (p *Expecting) Expect(text interface{}) *Expecting

Expect expects stdout ouput is equal to text.

func (*Expecting) ExpectErr added in v1.10.9

func (p *Expecting) ExpectErr(text interface{}) *Expecting

ExpectErr expects stderr ouput is equal to text.

func (*Expecting) NoPanic added in v1.11.5

func (p *Expecting) NoPanic()

NoPanic indicates that no panic occurs.

func (*Expecting) Panic added in v1.10.9

func (p *Expecting) Panic(panicMsg ...interface{}) *Expecting

Panic checks if function call panics or not. Panic(v) means function call panics with `v`. If v == nil, it means we don't care any detail information about panic. Panic() indicates that no panic occurs.

type Frame added in v1.11.2

type Frame uintptr

Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.

func (Frame) Format added in v1.11.2

func (f Frame) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface.

%n    <funcname>
%v    <file>:<line>

Format accepts flags that alter the printing of some verbs, as follows:

%+v   equivalent to <funcname>\n\t<file>:<line>

type TestCase added in v1.10.6

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

TestCase represents a test case.

func (*TestCase) Call added in v1.10.6

func (p *TestCase) Call(fn interface{}, args ...interface{}) (e *TestCase)

Call calls a function.

func (*TestCase) Equal added in v1.10.6

func (p *TestCase) Equal(vals ...interface{}) *TestCase

Equal checks current output value.

func (*TestCase) Init added in v1.10.8

func (p *TestCase) Init(result ...interface{}) *TestCase

Init sets output parameters.

func (*TestCase) Next added in v1.10.7

func (p *TestCase) Next() *TestCase

Next sets current output value to next output parameter.

func (*TestCase) Panic added in v1.10.9

func (p *TestCase) Panic(panicMsg ...interface{}) *TestCase

Panic checks if function call panics or not. Panic() means the function call doesn't panic at all, and Panic(v) means function call panics with `v`. If v == nil, it means we don't care any detail information about panic.

func (*TestCase) PropEqual added in v1.10.6

func (p *TestCase) PropEqual(prop string, v interface{}) *TestCase

PropEqual checks property of current output value.

func (*TestCase) With added in v1.10.6

func (p *TestCase) With(i int) *TestCase

With sets current output value to check.

type Testing added in v1.10.6

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

Testing represents a testing object.

func New added in v1.10.6

func New(t *testing.T) *Testing

New creates a testing object.

func (*Testing) Call added in v1.10.6

func (p *Testing) Call(fn interface{}, args ...interface{}) *TestCase

Call creates a test case without name, and calls a function.

func (*Testing) Case added in v1.10.6

func (p *Testing) Case(name string, result ...interface{}) *TestCase

Case creates a test case with name and sets its output parameters.

func (*Testing) Init added in v1.13.0

func (p *Testing) Init(result ...interface{}) *TestCase

Init creates a test case without name and sets its output parameters.

func (*Testing) New added in v1.10.8

func (p *Testing) New(name string) *TestCase

New creates a test case.

Jump to

Keyboard shortcuts

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