ts

package
v1.13.12 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

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

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

PropVal returns property value of an object.

Types

type Expecting

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

Expecting represents a expecting object.

func StartExpecting

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

StartExpecting starts expecting with a capture mode.

func (*Expecting) Call

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

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

func (*Expecting) Close

func (p *Expecting) Close() error

Close stops expecting.

func (*Expecting) Expect

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

Expect expects stdout ouput is equal to text.

func (*Expecting) ExpectErr

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

ExpectErr expects stderr ouput is equal to text.

func (*Expecting) NoPanic

func (p *Expecting) NoPanic()

NoPanic indicates that no panic occurs.

func (*Expecting) Panic

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

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

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

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

TestCase represents a test case.

func (*TestCase) Call

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

Call calls a function.

func (*TestCase) Equal

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

Equal checks current output value.

func (*TestCase) Init

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

Init sets output parameters.

func (*TestCase) Next

func (p *TestCase) Next() *TestCase

Next sets current output value to next output parameter.

func (*TestCase) Panic

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

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

PropEqual checks property of current output value.

func (*TestCase) With

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

With sets current output value to check.

type Testing

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

Testing represents a testing object.

func New

func New(t *testing.T) *Testing

New creates a testing object.

func (*Testing) Call

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

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

func (*Testing) Case

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

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

func (*Testing) Init

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

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

func (*Testing) New

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