mint: github.com/otiai10/mint Index | Examples | Files

package mint

import "github.com/otiai10/mint"

Index

Examples

Package Files

because.go comparer.go exit.go log.go mint.go result.go testee.go

func Because Uses

func Because(t *testing.T, context string, wrapper func(*testing.T))

Because is context printer.

func Log Uses

func Log(args ...interface{})

Log only output if -v flag is given. This is because the standard "t.Testing.Log" method decorates its caller: runtime.Caller(3) automatically.

func When Uses

func When(t *testing.T, context string, wrapper func(*testing.T))

When is an alternative of `Because`

type Comparer Uses

type Comparer interface {
    Compare(a, b interface{}) bool
}

type Mint Uses

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

Mint (mint.Mint) is wrapper for *testing.T blending testing type to omit repeated `t`.

func Blend Uses

func Blend(t *testing.T) *Mint

Blend provides (blended) *mint.Mint. You can save writing "t" repeatedly.

Code:

// get blended mint
m := mint.Blend(t)
m.Expect(100).ToBe(100)
m.Expect(100).Not().ToBe(200)

func (*Mint) Expect Uses

func (m *Mint) Expect(actual interface{}) *Testee

Expect provides "*Testee". The blended mint is merely a proxy to instantiate testee.

type Result Uses

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

Result provide the results of assertion for `Dry` option.

func (Result) Message Uses

func (r Result) Message() string

Message returns failure message.

func (Result) NG Uses

func (r Result) NG() bool

NG is the opposite alias for OK().

func (Result) OK Uses

func (r Result) OK() bool

OK returns whether result is ok or not.

type Testee Uses

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

Testee is holder of interfaces which user want to assert and also has its result.

func Expect Uses

func Expect(t *testing.T, actual interface{}) *Testee

Expect provides "*mint.Testee". It has assertion methods such as "ToBe".

Code:

mint.Expect(t, 100).ToBe(100)
mint.Expect(t, 100).TypeOf("int")

func (*Testee) Deeply Uses

func (testee *Testee) Deeply() *Testee

Deeply makes following assertions use `reflect.DeepEqual`. You had better use this to compare reference type objects.

Code:

map0 := &map[int]string{
    3:  "three",
    5:  "five",
    10: "ten",
}
map1 := &map[int]string{
    3:  "three",
    5:  "five",
    10: "ten",
}
mint.Expect(t, map0).Not().ToBe(map1)
mint.Expect(t, map0).Deeply().ToBe(map1)

func (*Testee) Dry Uses

func (testee *Testee) Dry() *Testee

Dry makes the testee NOT to call "Fail()". Use this if you want to fail test in a purpose.

Code:

result := mint.Expect(t, 100).Dry().ToBe(100)
if !result.OK() {
    t.Fail()
}

func (*Testee) Exit Uses

func (testee *Testee) Exit(expectedCode int) Result

Exit ...

func (*Testee) In Uses

func (testee *Testee) In(expecteds ...interface{}) Result

In can assert the testee is in given array.

Code:

mint.Expect(t, 100).In(10, 100, 1000)

func (*Testee) Log Uses

func (testee *Testee) Log(args ...interface{})

Log only output if -v flag is given. This is because the standard "t.Testing.Log" method decorates its caller: runtime.Caller(3) automatically.

func (*Testee) Match Uses

func (testee *Testee) Match(expression string) Result

Match can assert the testee to match with specified regular expression. It uses `regexp.MustCompile`, it's due to caller to make sure it's valid regexp. OS will exit with code 1, when the assertion fail. If you don't want to exit, see "Dry()".

Code:

mint.Expect(t, "3.05.00dev").Match("[0-9].[0-9]{2}(.[0-9a-z]+)?")

func (*Testee) Not Uses

func (testee *Testee) Not() *Testee

Not makes following assertion conversed.

Code:

mint.Expect(t, 100).Not().ToBe(200)
mint.Expect(t, 100).Not().TypeOf("string")

func (*Testee) ToBe Uses

func (testee *Testee) ToBe(expected interface{}) Result

ToBe can assert the testee to equal the parameter of this func. OS will exit with code 1, when the assertion fail. If you don't want to exit, see "Dry()".

Code:

mint.Expect(t, 100).ToBe(100)

func (*Testee) TypeOf Uses

func (testee *Testee) TypeOf(typeName string) Result

TypeOf can assert the type of testee to equal the parameter of this func. OS will exit with code 1, when the assertion fail. If you don't want to exit, see "Dry()".

Code:

mint.Expect(t, 100).TypeOf("int")

Package mint imports 8 packages (graph). Updated 2019-05-14. Refresh now. Tools for package owners.