Skip to content

anthonybishopric/gotcha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Super Simple Assertions for Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages