gotcha

package module
v0.0.0-...-5841215 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2014 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Gotcha: Super Simple Assertions for Go

Don't want to have to run a code generator to write test assertions? Sick of dropping boilerplate test runner code in every test file? Gotcha is a super simple Assertion library that just works.

package mymath

import (
	"testing"
	. "github.com/anthonybishopric/gotcha"
)

func TestBasicAddition(t *testing.T) {
	Assert(t).AreEqual(1 + 1, 2, "expected addition to work")
}

Portable Implementation

The Assert() function takes an interface Failer, shown below:

type Failer interface {
	Fatalf(string, ...interface{})
}

So while the gotcha package will work with tests, it will also work with instances of log.Logger, and can be reused as mainline Assertions.

Simple Matcher

Flexible matching can be done by implementing the Matcher interface

type Matcher (interface{}) bool

These can be used together with the Matches() function


func ValidPassword(s interface{}) bool {
	 x := s.(string)
	 return len(x) > 6
}

Assert(t).Matches(password, ValidPassword)

Documentation

Overview

* package gotcha contains a set of common test assertions. It doesn't attempt to be any sort of fancy test library. Use the Assert() function to grab an Asserter, which has assertion methods

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equality

func Equality(l, r interface{}) bool

func Inequality

func Inequality(l, r interface{}) bool

Types

type Asserter

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

func Assert

func Assert(t Failer) *Asserter

func (*Asserter) AreEqual

func (a *Asserter) AreEqual(left, right interface{}, message string) *Asserter

func (*Asserter) AreNotEqual

func (a *Asserter) AreNotEqual(left, right interface{}, message string) *Asserter

func (*Asserter) EachMatch

func (a *Asserter) EachMatch(left []interface{}, right []interface{}, comparator Comparator, message string)

func (*Asserter) Fail

func (a *Asserter) Fail(message string)

func (*Asserter) IsFalse

func (a *Asserter) IsFalse(statement bool, message string) *Asserter

func (*Asserter) IsNil

func (a *Asserter) IsNil(subject interface{}, message string) *Asserter

func (*Asserter) IsNotNil

func (a *Asserter) IsNotNil(subject interface{}, message string) *Asserter

func (*Asserter) IsTrue

func (a *Asserter) IsTrue(statement bool, message string) *Asserter

func (*Asserter) Matches

func (a *Asserter) Matches(subject interface{}, matcher Matcher, message string)

type Comparator

type Comparator func(interface{}, interface{}) bool

type Failer

type Failer interface {
	Fatalf(string, ...interface{})
}

type Matcher

type Matcher func(interface{}) bool

Jump to

Keyboard shortcuts

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