From d96158d52942c0e992a1b200b38d3c0cbf24b21e Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Sun, 17 Sep 2017 17:40:20 +0200 Subject: [PATCH] Update --- test.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/test.go b/test.go index 6344b28..c092727 100644 --- a/test.go +++ b/test.go @@ -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 { @@ -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)) } }