mirror of
https://github.com/golang/go
synced 2024-11-21 21:04:41 -07:00
testing: add wrapper methods so the godoc output lists all methods
To be deleted when godoc catches up. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5504079
This commit is contained in:
parent
4a8ea4ae94
commit
416afcb411
@ -6,8 +6,9 @@ include ../../Make.inc
|
|||||||
|
|
||||||
TARG=testing
|
TARG=testing
|
||||||
GOFILES=\
|
GOFILES=\
|
||||||
benchmark.go\
|
benchmark.go\
|
||||||
example.go\
|
example.go\
|
||||||
testing.go\
|
testing.go\
|
||||||
|
wrapper.go\
|
||||||
|
|
||||||
include ../../Make.pkg
|
include ../../Make.pkg
|
||||||
|
@ -90,7 +90,7 @@ func Short() bool {
|
|||||||
// If addFileLine is true, it also prefixes the string with the file and line of the call site.
|
// If addFileLine is true, it also prefixes the string with the file and line of the call site.
|
||||||
func decorate(s string, addFileLine bool) string {
|
func decorate(s string, addFileLine bool) string {
|
||||||
if addFileLine {
|
if addFileLine {
|
||||||
_, file, line, ok := runtime.Caller(3) // decorate + log + public function.
|
_, file, line, ok := runtime.Caller(4) // decorate + log + public function.
|
||||||
if ok {
|
if ok {
|
||||||
// Truncate file name at last file name separator.
|
// Truncate file name at last file name separator.
|
||||||
if index := strings.LastIndex(file, "/"); index >= 0 {
|
if index := strings.LastIndex(file, "/"); index >= 0 {
|
||||||
|
105
src/pkg/testing/wrapper.go
Normal file
105
src/pkg/testing/wrapper.go
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
// Copyright 2009 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// This file contains wrappers so t.Errorf etc. have documentation.
|
||||||
|
// TODO: delete when godoc shows exported methods for unexported embedded fields.
|
||||||
|
// TODO: need to change the argument to runtime.Caller in testing.go from 4 to 3 at that point.
|
||||||
|
|
||||||
|
package testing
|
||||||
|
|
||||||
|
// Fail marks the function as having failed but continues execution.
|
||||||
|
func (b *B) Fail() {
|
||||||
|
b.common.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failed returns whether the function has failed.
|
||||||
|
func (b *B) Failed() bool {
|
||||||
|
return b.common.Failed()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FailNow marks the function as having failed and stops its execution.
|
||||||
|
// Execution will continue at the next Test.
|
||||||
|
func (b *B) FailNow() {
|
||||||
|
b.common.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log formats its arguments using default formatting, analogous to Println(),
|
||||||
|
// and records the text in the error log.
|
||||||
|
func (b *B) Log(args ...interface{}) {
|
||||||
|
b.common.Log(args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logf formats its arguments according to the format, analogous to Printf(),
|
||||||
|
// and records the text in the error log.
|
||||||
|
func (b *B) Logf(format string, args ...interface{}) {
|
||||||
|
b.common.Logf(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error is equivalent to Log() followed by Fail().
|
||||||
|
func (b *B) Error(args ...interface{}) {
|
||||||
|
b.common.Error(args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errorf is equivalent to Logf() followed by Fail().
|
||||||
|
func (b *B) Errorf(format string, args ...interface{}) {
|
||||||
|
b.common.Errorf(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatal is equivalent to Log() followed by FailNow().
|
||||||
|
func (b *B) Fatal(args ...interface{}) {
|
||||||
|
b.common.Fatal(args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatalf is equivalent to Logf() followed by FailNow().
|
||||||
|
func (b *B) Fatalf(format string, args ...interface{}) {
|
||||||
|
b.common.Fatalf(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fail marks the function as having failed but continues execution.
|
||||||
|
func (t *T) Fail() {
|
||||||
|
t.common.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failed returns whether the function has failed.
|
||||||
|
func (t *T) Failed() bool {
|
||||||
|
return t.common.Failed()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FailNow marks the function as having failed and stops its execution.
|
||||||
|
// Execution will continue at the next Test.
|
||||||
|
func (t *T) FailNow() {
|
||||||
|
t.common.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log formats its arguments using default formatting, analogous to Println(),
|
||||||
|
// and records the text in the error log.
|
||||||
|
func (t *T) Log(args ...interface{}) {
|
||||||
|
t.common.Log(args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logf formats its arguments according to the format, analogous to Printf(),
|
||||||
|
// and records the text in the error log.
|
||||||
|
func (t *T) Logf(format string, args ...interface{}) {
|
||||||
|
t.common.Logf(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error is equivalent to Log() followed by Fail().
|
||||||
|
func (t *T) Error(args ...interface{}) {
|
||||||
|
t.common.Error(args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errorf is equivalent to Logf() followed by Fail().
|
||||||
|
func (t *T) Errorf(format string, args ...interface{}) {
|
||||||
|
t.common.Errorf(format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatal is equivalent to Log() followed by FailNow().
|
||||||
|
func (t *T) Fatal(args ...interface{}) {
|
||||||
|
t.common.Fatal(args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatalf is equivalent to Logf() followed by FailNow().
|
||||||
|
func (t *T) Fatalf(format string, args ...interface{}) {
|
||||||
|
t.common.Fatalf(format, args...)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user