is

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2015 License: MIT Imports: 9 Imported by: 0

README

is GoDoc Build Status Coverage Status Gitter

Is provides a quick, clean and simple framework for writing Go tests.

Installation

To install, simply execute:

go get gopkg.in/tylerb/is.v1

I am using gopkg.in to control releases.

Usage

Using Is is simple:

func TestSomething(t *testing.T) {
	is := is.New(t)

	expected := 10
	result, _ := awesomeFunction()
	is.Equal(expected,result)
}

If you'd like a bit more information when a test fails, you may use the Msg() method:

func TestSomething(t *testing.T) {
	is := is.New(t)

	expected := 10
	result, details := awesomeFunction()
	is.Msg("result details: %s", details).Equal(expected,result)
}

Contributing

If you would like to contribute, please:

  1. Create a GitHub issue regarding the contribution. Features and bugs should be discussed beforehand.
  2. Fork the repository.
  3. Create a pull request with your solution. This pull request should reference and close the issues (Fix #2).

All pull requests should:

  1. Pass gometalinter -t . with no warnings.
  2. Be go fmt formatted.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetOutput added in v1.1.1

func SetOutput(w io.Writer)

SetOutput changes the message output Writer from the default (os.Stdout). This may be useful if the application under test takes over the console, or if logging to a file is desired.

Types

type Is

type Is struct {
	TB testing.TB
	// contains filtered or unexported fields
}

Is provides methods that leverage the existing testing capabilities found in the Go test framework. The methods provided allow for a more natural, efficient and expressive approach to writing tests. The goal is to write fewer lines of code while improving communication of intent.

func New

func New(tb testing.TB) *Is

New creates a new instance of the Is object and stores a reference to the provided testing object.

func (*Is) Equal

func (is *Is) Equal(a interface{}, b interface{})

Equal performs a deep compare of the provided objects and fails if they are not equal.

Equal does not respect type differences. If the types are different and comparable (eg int32 and int64), but the values are the same, the objects are considered equal.

func (*Is) Err

func (is *Is) Err(e error)

Err checks the provided error object to determine if an error is present.

func (*Is) False

func (is *Is) False(b bool)

False checks the provided boolean to determine if is false.

func (*Is) Lax added in v1.1.1

func (is *Is) Lax() *Is

Lax returns a copy of this instance of Is which does not abort the test if a failure occurs. Use this to run a set of tests and see all the failures at once.

func (*Is) Msg

func (is *Is) Msg(format string, args ...interface{}) *Is

Msg defines a message to print in the event of a failure. This allows you to print out additional information about a failure if it happens.

func (*Is) Nil

func (is *Is) Nil(o interface{})

Nil checks the provided object to determine if it is nil.

func (*Is) NotEqual

func (is *Is) NotEqual(a interface{}, b interface{})

NotEqual performs a deep compare of the provided objects and fails if they are equal.

NotEqual does not respect type differences. If the types are different and comparable (eg int32 and int64), but the values are different, the objects are considered not equal.

func (*Is) NotErr

func (is *Is) NotErr(e error)

NotErr checks the provided error object to determine if an error is not present.

func (*Is) NotNil

func (is *Is) NotNil(o interface{})

NotNil checks the provided object to determine if it is not nil.

func (*Is) NotZero

func (is *Is) NotZero(o interface{})

NotZero checks the provided object to determine if it is not the zero value for the type of that object. The zero value is the same as what the object would contain when initialized but not assigned.

This method, for example, would be used to determine if a string is not empty, an array is not empty or a map is not empty. It could also be used to determine if a number is not 0.

In cases such as slice, map, array and chan, a nil value is treated the same as an object with len == 0

func (*Is) Strict added in v1.1.1

func (is *Is) Strict() *Is

Strict returns a copy of this instance of Is which aborts the test if a failure occurs. This is the default behavior, thus this method has no effect unless it is used to reverse a previous call to Lax.

func (*Is) True

func (is *Is) True(b bool)

True checks the provided boolean to determine if it is true.

func (*Is) Zero

func (is *Is) Zero(o interface{})

Zero checks the provided object to determine if it is the zero value for the type of that object. The zero value is the same as what the object would contain when initialized but not assigned.

This method, for example, would be used to determine if a string is empty, an array is empty or a map is empty. It could also be used to determine if a number is 0.

In cases such as slice, map, array and chan, a nil value is treated the same as an object with len == 0

Jump to

Keyboard shortcuts

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