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
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) }