Skip to content

Instantly share code, notes, and snippets.

@karlseguin
Last active February 20, 2018 19:42
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save karlseguin/5128442 to your computer and use it in GitHub Desktop.
Save karlseguin/5128442 to your computer and use it in GitHub Desktop.
A simple test helper for Go. See http://openmymind.net/Testing-In-Go/
package tests
import (
"testing"
)
type S struct {
t *testing.T
}
type SR struct {
t *testing.T
expected []interface{}
}
func Spec(t *testing.T) (*S) {
return &S{t:t}
}
func (s *S) Expect(expected ... interface{}) (sr *SR) {
return &SR{t: s.t, expected: expected,}
}
func (sr *SR) ToEqual(actuals ... interface{}) {
for index, actual := range(actuals) {
if sr.expected[index] != actual {
sr.t.Errorf("expected %+v to equal %+v", sr.expected[index], actual)
}
}
}
func (sr *SR) ToNotEqual(actuals ... interface{}) {
for index, actual := range(actuals) {
if sr.expected[index] == actual {
sr.t.Errorf("expected %+v to not equal %+v", sr.expected[index], actual)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment