Categorygithub.com/nowk/assert
repositorypackage
2.0.0+incompatible
Repository: https://github.com/nowk/assert.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

Assert

Build Status GoDoc

Simple test assertions for Go. This is a fork of a fork of a fork of bmizerany/assert with improved support for things like nil pointers, etc.


This is a fully refactored version and no longer tracks it's birthed forks.
  • Removes some additional assertions that were from the previous forks.
  • Exposes some of the internal API to allow for extending within your project.
  • New failure messages

Installation

$ go get gopkg.in/nowk/assert.v2

API

Equality

func Equal(t Testing, exp interface{}, got interface{}, m ...interface{})

func NotEqual(t Testing, exp interface{}, got interface{}, m ...interface{})

Truth

func True(t Testing, got interface{}, m ...interface{})

func False(t Testing, got interface{}, m ...interface{})

Nil

func Nil(t Testing, got interface{}, m ...interface{})

func NotNil(t Testing, got interface{}, m ...interface{})

TypeOf

func TypeOf(t Testing, exp string, got interface{}, m ...interface{})

Panic

func Panic(t Testing, exp string, fn func(), m ...interface{})

Testing is an interface to allow for use across multiple testing libraries.

type Testing interface {
  Errorf(string, ...interface{})
  Fail()
  FailNow()
}

Currently tested are the core testing and gocheck.

Example

package main

import "gopkg.in/nowk/assert.v2"

type CoolStruct struct{}

func TestThings(t *testing.T) {
  myString := "cool"

  assert.Equal(t, "cool", myString, "myString should be equal")
  assert.NotEqual(t, "nope", myString)

  var myStruct CoolStruct
  assert.Nil(t, myStruct)
}

See assert_test.go for more usage examples.

Output

You can add extra information to test failures by passing in any number of extra arguments:

assert.Equal(t, "foo", "bar", "when did foo ever equal bar?")
% go test
--- FAIL: TestImportantFeature (0.00 seconds)
	assert.go:18: /Users/tyson/go/src/github.com/foo/bar/main_test.go:31
	assert.go:38: ! Expected `foo` to equal `bar`
	assert.go:38: - \"foo\" != \"bar\"
	assert.go:40: - when did foo ever equal bar?
FAIL
exit status 1
FAIL	github.com/foo/bar	0.017s

License

Copyright Blake Mizerany and Keith Rarick. Licensed under the MIT license. Additional modifications by Stovepipe Studios.