expect

package module
v0.0.0-...-1fe4c93 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: BSD-2-Clause Imports: 6 Imported by: 3

README

expect Travis-CI GoDoc Report card Sourcegraph

A simple assertion library that you probably shouldn't use.

Quickstart

Package expect contains various test assertion helpers.

func TestOpenFile(t *testing.T) {
        f, err := os.Open("notfound")
        expect.Nil(err)
        err = f.Close()
        expect.True(err == nil)
}

expect helpers can be called from any function called from the main testing goroutine.

% go test
--- FAIL: TestOpenFile (0.00s)
    check_test.go:12: expected: <nil>, got: open notfound: no such file or directory

Consult the documentation for more information.

How does this work?

Magic

No, seriously, how does this work?

*testing.T is recovered dynamically from the call stack. Read the blog post.

License

BSD-2-Clause

Documentation

Overview

package expect contains various test assertion helpers.

The functions this package recover the *testing.T value passed to the Test from the call stack. This implies that expect functions should not be called from a goroutine launched from a test. However, this restriction applies to calling t.Fatal/FailNow directly, so here we are.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Nil

func Nil(v interface{})

Nil fails the test if v is not nil.

func True

func True(v bool)

True fails the test if v is not true.

Types

This section is empty.

Jump to

Keyboard shortcuts

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