From: Caio Marcelo de Oliveira Filho Date: Fri, 26 Feb 2016 19:09:54 +0000 (-0300) Subject: cmd/go: show position in error for wrong signature in test functions X-Git-Tag: go1.7beta1~1686 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5c72c6f889ad854ba16e4ed560e6ad10ebb6dcc4;p=gostls13.git cmd/go: show position in error for wrong signature in test functions Change-Id: Ie915dc2fc32a31d31f566ac931ccecb506559645 Reviewed-on: https://go-review.googlesource.com/19888 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/go/test.go b/src/cmd/go/test.go index e23f939255..1d39a72197 100644 --- a/src/cmd/go/test.go +++ b/src/cmd/go/test.go @@ -1352,14 +1352,16 @@ func (t *testFuncs) load(filename, pkg string, doImport, seen *bool) error { t.TestMain = &testFunc{pkg, name, ""} *doImport, *seen = true, true case isTest(name, "Test"): - if !isTestFunc(n, "T") { - return fmt.Errorf("wrong type for %s", name) + err := checkTestFunc(n, "T") + if err != nil { + return err } t.Tests = append(t.Tests, testFunc{pkg, name, ""}) *doImport, *seen = true, true case isTest(name, "Benchmark"): - if !isTestFunc(n, "B") { - return fmt.Errorf("wrong type for %s", name) + err := checkTestFunc(n, "B") + if err != nil { + return err } t.Benchmarks = append(t.Benchmarks, testFunc{pkg, name, ""}) *doImport, *seen = true, true @@ -1379,6 +1381,15 @@ func (t *testFuncs) load(filename, pkg string, doImport, seen *bool) error { return nil } +func checkTestFunc(fn *ast.FuncDecl, arg string) error { + if !isTestFunc(fn, arg) { + name := fn.Name.String() + pos := testFileSet.Position(fn.Pos()) + return fmt.Errorf("%s: wrong signature for %s, must be: func %s(%s *testing.%s)", pos, name, name, strings.ToLower(arg), arg) + } + return nil +} + type byOrder []*doc.Example func (x byOrder) Len() int { return len(x) }