You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2018/10/24 15:06:30 UTC

qpid-proton git commit: NO-JIRA: [go] Remove testing.TB.Helper(), only available from Go 1.9

Repository: qpid-proton
Updated Branches:
  refs/heads/master 90dbf46cc -> ded03b190


NO-JIRA: [go] Remove testing.TB.Helper(), only available from Go 1.9


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/ded03b19
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/ded03b19
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/ded03b19

Branch: refs/heads/master
Commit: ded03b190016780200b78df0c77612513b58ee0a
Parents: 90dbf46
Author: Alan Conway <ac...@redhat.com>
Authored: Tue Oct 23 20:48:13 2018 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Wed Oct 24 10:16:11 2018 -0400

----------------------------------------------------------------------
 go/src/qpid.apache.org/electron/common_test.go | 11 ++---
 go/src/qpid.apache.org/internal/test/test.go   | 54 ++++++++++-----------
 2 files changed, 31 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ded03b19/go/src/qpid.apache.org/electron/common_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/electron/common_test.go b/go/src/qpid.apache.org/electron/common_test.go
index 56c0e44..59ee616 100644
--- a/go/src/qpid.apache.org/electron/common_test.go
+++ b/go/src/qpid.apache.org/electron/common_test.go
@@ -82,9 +82,8 @@ func newPipe(t testing.TB, clientOpts, serverOpts []ConnectionOption) *pair {
 
 // AMQP pair linked by TCP socket
 func newSocketPair(t testing.TB, clientOpts, serverOpts []ConnectionOption) *pair {
-	t.Helper()
 	l, err := net.Listen("tcp4", ":0") // For systems with ipv6 disabled
-	test.FatalIf(t, err)
+	test.FatalIfN(1, t, err)
 	var srv Connection
 	var srvErr error
 	var wg sync.WaitGroup
@@ -95,9 +94,9 @@ func newSocketPair(t testing.TB, clientOpts, serverOpts []ConnectionOption) *pai
 	}()
 	addr := l.Addr()
 	cli, err := NewContainer("client").Dial(addr.Network(), addr.String(), clientOpts...)
-	test.FatalIf(t, err)
+	test.FatalIfN(1, t, err)
 	wg.Wait()
-	test.FatalIf(t, srvErr)
+	test.FatalIfN(1, t, srvErr)
 	return newPair(t, cli, srv)
 }
 
@@ -106,7 +105,7 @@ func (p *pair) close() { p.client.Connection().Close(nil); p.server.Close(nil) }
 // Return a client sender and server receiver
 func (p *pair) sender(opts ...LinkOption) (Sender, Receiver) {
 	snd, err := p.client.Sender(opts...)
-	test.FatalIf(p.t, err)
+	test.FatalIfN(1, p.t, err)
 	rcv := <-p.rchan
 	return snd, rcv
 }
@@ -114,7 +113,7 @@ func (p *pair) sender(opts ...LinkOption) (Sender, Receiver) {
 // Return a client receiver and server sender
 func (p *pair) receiver(opts ...LinkOption) (Receiver, Sender) {
 	rcv, err := p.client.Receiver(opts...)
-	test.FatalIf(p.t, err)
+	test.FatalIfN(1, p.t, err)
 	snd := <-p.schan
 	return rcv, snd
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ded03b19/go/src/qpid.apache.org/internal/test/test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/internal/test/test.go b/go/src/qpid.apache.org/internal/test/test.go
index 6429d01..c3508ae 100644
--- a/go/src/qpid.apache.org/internal/test/test.go
+++ b/go/src/qpid.apache.org/internal/test/test.go
@@ -28,46 +28,44 @@ import (
 	"testing"
 )
 
-// The testing.TB.Helper() function does not seem to work
-func decorate(msg string, callDepth int) string {
-	_, file, line, _ := runtime.Caller(callDepth + 1) // annotate with location of caller.
+// The testing.TB.Helper() is only available from Go 1.9.
+// Decorate messages with the correct file:line at callDepth before calling
+// before calling a testing.TB method.
+func decorate(method func(arg ...interface{}), callDepth int, msg string) {
+	_, file, line, _ := runtime.Caller(callDepth + 1)
 	_, file = path.Split(file)
-	return fmt.Sprintf("\n%s:%d: %v", file, line, msg)
+	method(fmt.Sprintf("\n%s:%d: %v", file, line, msg))
 }
 
-func message(err error, args ...interface{}) (msg string) {
-	if len(args) > 0 {
-		msg = fmt.Sprintf(args[0].(string), args[1:]...) + ": "
-	}
-	msg = msg + err.Error()
-	return
-}
-
-// ErrorIf calls t.Error() if err != nil, with optional format message
-func ErrorIf(t testing.TB, err error, format ...interface{}) error {
-	t.Helper()
+// Format a message and call method if err != nil
+func checkErr(method func(arg ...interface{}), callDepth int, err error, format ...interface{}) error {
 	if err != nil {
-		t.Error(message(err, format...))
+		var msg string
+		if len(format) > 0 {
+			msg = fmt.Sprintf("%v: %v", fmt.Sprintf(format[0].(string), format[1:]...), err)
+		} else {
+			msg = err.Error()
+		}
+		decorate(method, callDepth+1, msg)
 	}
 	return err
 }
 
-// ErrorIf calls t.Fatal() if err != nil, with optional format message
-func FatalIf(t testing.TB, err error, format ...interface{}) {
-	t.Helper()
-	if err != nil {
-		t.Fatal(message(err, format...))
-	}
+func ErrorIfN(callDepth int, t testing.TB, err error, format ...interface{}) error {
+	return checkErr(t.Error, callDepth+1, err, format...)
+}
+
+func ErrorIf(t testing.TB, err error, format ...interface{}) error {
+	return ErrorIfN(1, t, err, format...)
 }
 
-// Extend the methods on testing.TB
-type TB struct{ testing.TB }
+func FatalIfN(callDepth int, t testing.TB, err error, format ...interface{}) {
+	checkErr(t.Fatal, callDepth+1, err, format...)
+}
 
-func (t *TB) ErrorIf(err error, format ...interface{}) error {
-	t.Helper()
-	return ErrorIf(t, err, format...)
+func FatalIf(t testing.TB, err error, format ...interface{}) {
+	FatalIfN(1, t, err, format...)
 }
-func (t *TB) FatalIf(err error, format ...interface{}) { t.Helper(); FatalIf(t, err, format...) }
 
 // if reflect.DeepEqual(want, got) { return nil } else { return error("want != got" })
 func Differ(want interface{}, got interface{}) error {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org