tt

package module
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: Apache-2.0 Imports: 10 Imported by: 13

README

tt

Simple and colorful test tools

CircleCI Status Appveyor codecov Build Status Go Report Card GoDoc Release

Installation/Update

go get -u github.com/vcaesar/tt

Usage:

Look at an example
package tt

import (
	"fmt"
	"testing"

	"github.com/vcaesar/tt"
	"github.com/vcaesar/tt/example"
)

func TestAdd(t *testing.T) {
	fmt.Println(add.Add(1, 1))

	tt.Expect(t, "1", add.Add(1, 1))
	tt.Expect(t, "2", add.Add(1, 1))

	tt.Equal(t, 1, add.Add(1, 1))
	tt.Equal(t, 2, add.Add(1, 1))

	at := tt.New(t)
	at.Expect("2", add.Add(1, 1))
	at.Equal(2, add.Add(1, 1))
}

func Benchmark1(b *testing.B) {
	at := tt.New(b)
	fn := func() {
		at.Equal(2, add.Add(1, 1))
	}

	tt.BM(b, fn)
	// at.BM(b, fn)
}

func Benchmark2(b *testing.B) {
	at := tt.New(b)
	for i := 0; i < b.N; i++ {
		at.Equal(2, Add(1, 1))
	}
}

Thanks

Testify, the code has some inspiration.

Documentation

Index

Constants

View Source
const (
	// Version get the tt version
	Version = "v0.20.0.77, Sierra Nevada!"
)

Variables

View Source
var (
	// Type type must
	Type bool
)

Functions

func BM

func BM(b *testing.B, fn func())

BM func Benchmark1(b *testing.B, fn func())

func Blue

func Blue(message string) string

Blue returns a blue string

func Bold

func Bold(message string) string

Bold returns a blod string

func Bool

func Bool(t TestingT, actual interface{}, args ...interface{}) bool

Bool asserts that true and objects are equal.

func CallerInfo

func CallerInfo() (callers []string)

CallerInfo returns an array of strings containing the file and line number, and each stack frame leading from the current test, when the assert call that failed.

func DEqual

func DEqual(t TestingT, expect, actual interface{}, args ...interface{}) bool

DEqual asserts that two objects are deep equal.

tt.DEqual(t *testing.T, 1, 1)

func Drop

func Drop(api, use string, info ...string) bool

Drop set drop tag and println log

func Empty

func Empty(t TestingT, actual interface{}, args ...interface{}) bool

Empty asserts that empty and objects are equal.

func Equal

func Equal(t TestingT, expect, actual interface{}, args ...interface{}) bool

Equal asserts that two objects are equal.

tt.Equal(t *testing.T, 1, 1)

func Err

func Err(s string, v ...interface{}) error

Err dbg fatal error log

func Error

func Error(t TestingT, actual interface{}, args ...interface{}) bool

Error asserts that equal error.

func Expect

func Expect(t TestingT, expect string, actual interface{}, args ...interface{}) bool

Expect asserts that string and objects are equal.

tt.Expect(t *testing.T, "1", 1)

func False

func False(t TestingT, actual interface{}, args ...interface{}) bool

False asserts that flase and objects are equal.

func Fmt

func Fmt(equal, expect string, call int, info ...string) (err string)

Fmt return error string

func FmtErr

func FmtErr(call int, info ...string) string

FmtErr return error string

func IsType

func IsType(t TestingT, expect string, actual interface{}, args ...interface{}) bool

IsType asserts that two objects type are equal

func IsTypes added in v0.20.0

func IsTypes(expect string, actual interface{}) bool

IsTypes return bool when actual is expect type

func Log

func Log(s string, v ...interface{}) error

Log dbg println log

func Nil

func Nil(t TestingT, actual interface{}, args ...interface{}) bool

Nil asserts that nil and objects are equal.

func Not

func Not(t TestingT, expect, actual interface{}, args ...interface{}) bool

Not asserts that two objects are not equal.

tt.NotEqual(t *testing.T, 1, 1)

func NotEmpty

func NotEmpty(t TestingT, actual interface{}, args ...interface{}) bool

NotEmpty asserts that empty and objects are not equal.

func NotEqual

func NotEqual(t TestingT, expect, actual interface{}, args ...interface{}) bool

NotEqual asserts that two objects are not equal.

tt.NotEqual(t *testing.T, 1, 1)

func NotErr

func NotErr(call int, info ...string) string

NotErr return not equal error string

func NotExpect

func NotExpect(t TestingT, expect string, actual interface{}, args ...interface{}) bool

NotExpect asserts that string and objects are not equal.

tt.NotExpect(t *testing.T, "1", 1)

func NotNil

func NotNil(t TestingT, actual interface{}, args ...interface{}) bool

NotNil asserts that not equal nil.

tt.NotNil(t *testing.T, 1)

func NotZero

func NotZero(t TestingT, actual interface{}, args ...interface{}) bool

NotZero asserts that zero and objects are not equal.

func Pprof

func Pprof(tm ...int) bool

Pprof use: Mem: pprof -http=:8090 http://127.0.0.1:6060/debug/pprof/heap

go tool pprof http://localhost:6060/debug/pprof/heap

CPU:

debug/pprof/profile

set time:

debug/pprof/profile\?seconds\=10

pprof -http=:8090 http://127.0.0.1:6060/debug/pprof/profile\?seconds\=10

debug/pprof/block debug/pprof/mutex

func Red

func Red(message string) string

Red returns a red string

func RedBold

func RedBold(message string) string

RedBold returns a red bold string

func True

func True(t TestingT, actual interface{}, args ...interface{}) bool

True asserts that true and objects are equal.

func TypeF

func TypeF()

TypeF make Type false

func TypeOf

func TypeOf(expect, actual interface{}) bool

TypeOf equal two interface{} type

func UnUsed

func UnUsed(v string, info ...string) bool

UnUsed not used tag and println log

func Yellow

func Yellow(message string) string

Yellow returns a yellow string

func Zero

func Zero(t TestingT, actual interface{}, args ...interface{}) bool

Zero asserts that zero and objects are equal.

Types

type Assertions

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

Assertions provides assertion methods around the TestingT interface.

func New

func New(t TestingT) *Assertions

New makes a new Assertions object for the specified TestingT.

func (*Assertions) BM

func (at *Assertions) BM(b *testing.B, fn func())

BM is the encapsulation of the benchmark function

func Benchmark1(b *testing.B, fn func())

func (*Assertions) Bool

func (at *Assertions) Bool(actual interface{}, args ...interface{}) bool

Bool asserts that true and objects are equal.

func (*Assertions) Empty

func (at *Assertions) Empty(actual interface{}, args ...interface{}) bool

Empty asserts that empty and objects are equal.

func (*Assertions) Equal

func (at *Assertions) Equal(expect, actual interface{}, args ...interface{}) bool

Equal asserts that two objects are equal.

func (*Assertions) Error

func (at *Assertions) Error(actual interface{}, args ...interface{}) bool

Error asserts that not equal error.

at.Error(t *testing.T, err)

func (*Assertions) Expect

func (at *Assertions) Expect(expect string, actual interface{}, args ...interface{}) bool

Expect asserts that string and objects are equal.

func (*Assertions) False

func (at *Assertions) False(actual interface{}, args ...interface{}) bool

False asserts that flase and objects are equal.

func (*Assertions) IsType

func (at *Assertions) IsType(expect string, actual interface{}, args ...interface{}) bool

IsType asserts that two objects type are equal

func (*Assertions) Nil

func (at *Assertions) Nil(actual interface{}, args ...interface{}) bool

Nil asserts that nil and objects are equal.

func (*Assertions) Not

func (at *Assertions) Not(expect, actual interface{}, args ...interface{}) bool

Not asserts that two objects are not equal.

func (Assertions) NotEmpty

func (at Assertions) NotEmpty(actual interface{}, args ...interface{}) bool

NotEmpty asserts that empty and objects are not equal.

func (*Assertions) NotEqual

func (at *Assertions) NotEqual(expect, actual interface{}, args ...interface{}) bool

NotEqual asserts that two objects are not equal.

func (*Assertions) NotExpect

func (at *Assertions) NotExpect(expect string, actual interface{}, args ...interface{}) bool

NotExpect asserts that string and objects are not equal.

func (*Assertions) NotNil

func (at *Assertions) NotNil(actual interface{}, args ...interface{}) bool

NotNil asserts that not equal nil.

at.NotNil(t *testing.T, 1)

func (*Assertions) NotZero

func (at *Assertions) NotZero(actual interface{}, args ...interface{}) bool

NotZero asserts that zero and objects are not equal.

func (*Assertions) True

func (at *Assertions) True(actual interface{}, args ...interface{}) bool

True asserts that true and objects are equal.

func (*Assertions) Zero

func (at *Assertions) Zero(actual interface{}, args ...interface{}) bool

Zero asserts that zero and objects are equal.

type TestingT

type TestingT interface {
	Errorf(format string, args ...interface{})
}

TestingT is an interface wrapper around *testing.T

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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