st: github.com/nbio/st Index | Examples | Files | Directories

package st

import "github.com/nbio/st"

Package st, pronounced "ghost", is a tiny test framework for making short, useful assertions in your Go tests.

To abort a test immediately with t.Fatal, use Assert(t, have, want) and Refute(t, have, want)

To allow a test to continue, reporting failure at the end with t.Error, use Expect(t, have, want) and Reject(t, have, want)

Code:

f := func() {
    file, line := caller()
    fmt.Printf("%s:%d", file, line)
}
f() // the output will contain this line's number

Output:

st_test.go:16

Index

Examples

Package Files

st.go

func Assert Uses

func Assert(t Fatalf, have, want interface{})

Assert calls t.Fatal to abort the test immediately and prints a nice comparison message when have != want.

func Expect Uses

func Expect(t Errorf, have, want interface{}, iter ...int)

Expect calls t.Error and prints a nice comparison message when have != want. Especially useful in table-based tests when passing the loop index as iter.

func Refute Uses

func Refute(t Fatalf, have, want interface{})

Refute calls t.Fatal to abort the test immediately and prints a nice comparison message when have != want.

func Reject Uses

func Reject(t Errorf, have, want interface{}, iter ...int)

Reject calls t.Error and prints a nice comparison message when have == want. Especially useful in table-based tests when passing the loop index as iter.

type Errorf Uses

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

Errorf is satisfied by testing.T and testing.B.

type Fatalf Uses

type Fatalf interface {
    Fatalf(format string, args ...interface{})
}

Fatalf is satisfied by testing.T and testing.B.

Directories

PathSynopsis
readme

Package st imports 4 packages (graph) and is imported by 2 packages. Updated 2017-12-05. Refresh now. Tools for package owners.