-
-
Save kofiasare/d6e9f03902f2018935d353dc2f59fd8e to your computer and use it in GitHub Desktop.
A simple test helper for Go. See http://openmymind.net/Testing-In-Go/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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