Skip to content

Instantly share code, notes, and snippets.

@mdwhatcott
Last active June 22, 2022 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdwhatcott/54bd7da72d1cbb473a61a2acdc429bfb to your computer and use it in GitHub Desktop.
Save mdwhatcott/54bd7da72d1cbb473a61a2acdc429bfb to your computer and use it in GitHub Desktop.
The tiniest testing library
package assert
import (
"reflect"
"testing"
)
// That allows assertions as in: assert.That(t, actual).Equals(expected)
func That(t *testing.T, actual interface{}) *assertion {
return &assertion{t: t, actual: actual}
}
type assertion struct {
t *testing.T
actual interface{}
}
func (this *assertion) IsNil() { this.t.Helper(); this.Equals(nil) }
func (this *assertion) IsTrue() { this.t.Helper(); this.Equals(true) }
func (this *assertion) IsFalse() { this.t.Helper(); this.Equals(false) }
func (this *assertion) Equals(expected interface{}) {
this.t.Helper()
if !reflect.DeepEqual(this.actual, expected) {
this.t.Errorf("\n"+
"Expected: %#v\n"+
"Actual: %#v",
expected,
this.actual,
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment