Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Sep 17, 2017
1 parent a7cf99a commit d96158d
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ func trace() string {
return "\r\t" + strings.Repeat(" ", len(fmt.Sprintf("%s:", trace2))) + "\r\t" + trace3
}

func message(empty string, msgs ...interface{}) string {
msg := fmt.Sprintln(msgs...)
if len(msg) == 0 {
msg = empty + "\n"
func message(msgs ...interface{}) string {
if len(msgs) == 0 {
return "\n"
}
return msg
return ": " + fmt.Sprintln(msgs...)
}

func printable(s string) string {
Expand All @@ -50,39 +49,39 @@ func printable(s string) string {

func That(t *testing.T, condition bool, msgs ...interface{}) {
if !condition {
t.Errorf("%s: %s", trace(), message("bad assertion", msgs...))
t.Errorf("%s%s", trace(), message(msgs...))
}
}

func Error(t *testing.T, err, expected error, msgs ...interface{}) {
if err != expected {
t.Errorf("%s: %s error: %v\nexpected: %v\n", trace(), message("", msgs...), err, expected)
t.Errorf("%s%s error: %v\nexpected: %v\n", trace(), message(msgs...), err, expected)
}
}

func Float(t *testing.T, output, expected float64, msgs ...interface{}) {
if math.Abs(output-expected) > 1e-10 {
t.Errorf("%s: %s output: %f\nexpected: %f\n", trace(), message("", msgs...), output, expected)
t.Errorf("%s%s output: %f\nexpected: %f\n", trace(), message(msgs...), output, expected)
}
}

func String(t *testing.T, output, expected string, msgs ...interface{}) {
if output != expected {
t.Errorf("%s: %s output: %s\nexpected: %s\n", trace(), message("", msgs...), printable(output), printable(expected))
t.Errorf("%s%s output: %s\nexpected: %s\n", trace(), message(msgs...), printable(output), printable(expected))
}
}

func Bytes(t *testing.T, output, expected []byte, msgs ...interface{}) {
if !bytes.Equal(output, expected) {
t.Errorf("%s: %s output: %s\nexpected: %s\n", trace(), message("", msgs...), printable(string(output)), printable(string(expected)))
t.Errorf("%s%s output: %s\nexpected: %s\n", trace(), message(msgs...), printable(string(output)), printable(string(expected)))
}
}

func Minify(t *testing.T, input string, err error, output, expected string, msgs ...interface{}) {
if err != nil {
t.Errorf("%s: %s given: %s\n error: %v\n", trace(), message("", msgs...), printable(input), err)
t.Errorf("%s%s given: %s\n error: %v\n", trace(), message(msgs...), printable(input), err)
}
if output != expected {
t.Errorf("%s: %s given: %s\n output: %s\nexpected: %s\n", trace(), message("", msgs...), printable(input), printable(output), printable(expected))
t.Errorf("%s%s given: %s\n output: %s\nexpected: %s\n", trace(), message(msgs...), printable(input), printable(output), printable(expected))
}
}

0 comments on commit d96158d

Please sign in to comment.