mint

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2020 License: MIT Imports: 7 Imported by: 0

README

mint

Build Status codecov GoDoc

The very minimum assertion for Go.

package your_test

import (
    "testing"
    "pkg/your"
    . "github.com/otiai10/mint"
)

func TestFoo(t *testing.T) {

    foo := your.Foo()
    Expect(t, foo).ToBe(1234)
    Expect(t, foo).TypeOf("int")
    Expect(t, foo).Not().ToBe(nil)
    Expect(t, func() { yourFunc() }).Exit(1)

    // If assertion failed, exit 1 with message.
    Expect(t, foo).ToBe("foobarbuz")

    // You can run assertions without os.Exit
    res := Expect(t, foo).Dry().ToBe("bar")
    // res.OK() == false

    // You can omit repeated `t`.
    m := mint.Blend(t)
    m.Expect(foo).ToBe(1234)
}

features

  • Simple syntax
  • Loosely coupled
  • Plain implementation

tests

go test ./...

use cases

Projects bellow use mint

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Because

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

Because is context printer.

func Log

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

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

When is an alternative of `Because`

Types

type Comparer

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

type Mint

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

func Blend(t *testing.T) *Mint

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

func (*Mint) Expect

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

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

type Result

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

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

func (Result) Message

func (r Result) Message() string

Message returns failure message.

func (Result) NG

func (r Result) NG() bool

NG is the opposite alias for OK().

func (Result) OK

func (r Result) OK() bool

OK returns whether result is ok or not.

type Testee

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

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

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

func (*Testee) Deeply

func (testee *Testee) Deeply() *Testee

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

func (*Testee) Dry

func (testee *Testee) Dry() *Testee

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

func (*Testee) Exit

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

Exit ...

func (*Testee) In

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

In can assert the testee is in given array.

func (*Testee) Log

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

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()".

func (*Testee) Not

func (testee *Testee) Not() *Testee

Not makes following assertion conversed.

func (*Testee) ToBe

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()".

func (*Testee) TypeOf

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()".

Jump to

Keyboard shortcuts

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