]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: show position in error for wrong signature in test functions
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Fri, 26 Feb 2016 19:09:54 +0000 (16:09 -0300)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 26 Feb 2016 20:13:44 +0000 (20:13 +0000)
Change-Id: Ie915dc2fc32a31d31f566ac931ccecb506559645
Reviewed-on: https://go-review.googlesource.com/19888
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/test.go

index e23f939255324b934e2361bcc7ed6846695f595e..1d39a7219705dd81c4522b91a51454f13ceb4d6f 100644 (file)
@@ -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) }