From 0c5d545ccdd01403d6ce865fb03774a6aff6032c Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 22 Oct 2019 14:55:17 +0200 Subject: [PATCH] test: add tests for runtime.itab.init We seem to lack any tests for some corner cases of itab.init (multiple methods with the same name, breaking itab.init doesn't seem to fail any tests). We also lack tests that fix text of panics. Add more tests for itab.init. Change-Id: Id6b536179ba6b0d45c3cb9dc1c66b9311d0ab85e Reviewed-on: https://go-review.googlesource.com/c/go/+/202451 Run-TryBot: Dmitry Vyukov TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- test/interface/embed3.dir/embed0.go | 21 ++++++++ test/interface/embed3.dir/embed1.go | 78 +++++++++++++++++++++++++++++ test/interface/embed3.go | 7 +++ 3 files changed, 106 insertions(+) create mode 100644 test/interface/embed3.dir/embed0.go create mode 100644 test/interface/embed3.dir/embed1.go create mode 100644 test/interface/embed3.go diff --git a/test/interface/embed3.dir/embed0.go b/test/interface/embed3.dir/embed0.go new file mode 100644 index 0000000000..614609e74a --- /dev/null +++ b/test/interface/embed3.dir/embed0.go @@ -0,0 +1,21 @@ +// Copyright 2019 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. + +package p + +type I1 interface { + Foo(int) +} + +type I2 interface { + foo(int) +} + +type M1 int + +func (M1) foo() {} + +type M2 int + +func (M2) foo(int) {} diff --git a/test/interface/embed3.dir/embed1.go b/test/interface/embed3.dir/embed1.go new file mode 100644 index 0000000000..d042482e94 --- /dev/null +++ b/test/interface/embed3.dir/embed1.go @@ -0,0 +1,78 @@ +// Copyright 2019 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. + +package main + +import "./embed0" + +type X1 struct{} + +func (X1) Foo() {} + +type X2 struct{} + +func (X2) foo() {} + +type X3 struct{} + +func (X3) foo(int) {} + +type X4 struct{ p.M1 } + +type X5 struct{ p.M1 } + +func (X5) foo(int) {} + +type X6 struct{ p.M2 } + +type X7 struct{ p.M2 } + +func (X7) foo() {} + +type X8 struct{ p.M2 } + +func (X8) foo(int) {} + +func main() { + var i1 interface{} = X1{} + check(func() { _ = i1.(p.I1) }, "interface conversion: main.X1 is not p.I1: missing method Foo") + + var i2 interface{} = X2{} + check(func() { _ = i2.(p.I2) }, "interface conversion: main.X2 is not p.I2: missing method foo") + + var i3 interface{} = X3{} + check(func() { _ = i3.(p.I2) }, "interface conversion: main.X3 is not p.I2: missing method foo") + + var i4 interface{} = X4{} + check(func() { _ = i4.(p.I2) }, "interface conversion: main.X4 is not p.I2: missing method foo") + + var i5 interface{} = X5{} + check(func() { _ = i5.(p.I2) }, "interface conversion: main.X5 is not p.I2: missing method foo") + + var i6 interface{} = X6{} + check(func() { _ = i6.(p.I2) }, "") + + var i7 interface{} = X7{} + check(func() { _ = i7.(p.I2) }, "") + + var i8 interface{} = X8{} + check(func() { _ = i8.(p.I2) }, "") +} + +func check(f func(), msg string) { + defer func() { + v := recover() + if v == nil { + if msg == "" { + return + } + panic("did not panic") + } + got := v.(error).Error() + if msg != got { + panic("want '" + msg + "', got '" + got + "'") + } + }() + f() +} diff --git a/test/interface/embed3.go b/test/interface/embed3.go new file mode 100644 index 0000000000..af6f134172 --- /dev/null +++ b/test/interface/embed3.go @@ -0,0 +1,7 @@ +// rundir + +// Copyright 2019 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. + +package ignored -- 2.50.0