diff options
| author | Ondřej Surý <ondrej@sury.org> | 2012-01-30 15:38:19 +0100 |
|---|---|---|
| committer | Ondřej Surý <ondrej@sury.org> | 2012-01-30 15:38:19 +0100 |
| commit | 4cecda6c347bd6902b960c6a35a967add7070b0d (patch) | |
| tree | a462e224ff41ec9f3eb1a0b6e815806f9e8804ad /test/interface | |
| parent | 6c7ca6e4d4e26e4c8cbe0d183966011b3b088a0a (diff) | |
| download | golang-4cecda6c347bd6902b960c6a35a967add7070b0d.tar.gz | |
Imported Upstream version 2012.01.27upstream-weekly/2012.01.27
Diffstat (limited to 'test/interface')
| -rw-r--r-- | test/interface/fail.go | 16 | ||||
| -rw-r--r-- | test/interface/fake.go | 40 | ||||
| -rw-r--r-- | test/interface/noeq.go | 39 | ||||
| -rw-r--r-- | test/interface/recursive1.go | 15 | ||||
| -rw-r--r-- | test/interface/recursive2.go | 22 | ||||
| -rw-r--r-- | test/interface/returntype.go | 15 |
6 files changed, 124 insertions, 23 deletions
diff --git a/test/interface/fail.go b/test/interface/fail.go index 3e741d3f9..0c20bcf75 100644 --- a/test/interface/fail.go +++ b/test/interface/fail.go @@ -1,4 +1,4 @@ -// $G $D/$F.go && $L $F.$A && ! ./$A.out +// $G $D/$F.go && $L $F.$A && ./$A.out // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -13,6 +13,10 @@ type I interface { } func main() { + shouldPanic(p1) +} + +func p1() { var s *S var i I var e interface {} @@ -21,6 +25,14 @@ func main() { _ = i } -// hide S down here to avoid static warning type S struct { } + +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("function should panic") + } + }() + f() +} diff --git a/test/interface/fake.go b/test/interface/fake.go index bdc5b9072..ddb832542 100644 --- a/test/interface/fake.go +++ b/test/interface/fake.go @@ -12,20 +12,20 @@ package main import "reflect" type T struct { - f float32 - g float32 + F float32 + G float32 - s string - t string + S string + T string - u uint32 - v uint32 + U uint32 + V uint32 - w uint32 - x uint32 + W uint32 + X uint32 - y uint32 - z uint32 + Y uint32 + Z uint32 } func add(s, t string) string { @@ -40,16 +40,16 @@ func assert(b bool) { func main() { var x T - x.f = 1.0 - x.g = x.f - x.s = add("abc", "def") - x.t = add("abc", "def") - x.u = 1 - x.v = 2 - x.w = 1 << 28 - x.x = 2 << 28 - x.y = 0x12345678 - x.z = x.y + x.F = 1.0 + x.G = x.F + x.S = add("abc", "def") + x.T = add("abc", "def") + x.U = 1 + x.V = 2 + x.W = 1 << 28 + x.X = 2 << 28 + x.Y = 0x12345678 + x.Z = x.Y // check mem and string v := reflect.ValueOf(x) diff --git a/test/interface/noeq.go b/test/interface/noeq.go new file mode 100644 index 000000000..3c2ea5975 --- /dev/null +++ b/test/interface/noeq.go @@ -0,0 +1,39 @@ +// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: interface/noeq + +// Copyright 2011 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. + +// Interface values containing types that cannot be compared for equality. + +package main + +func main() { + cmp(1) + + var ( + m map[int]int + s struct{ x []int } + f func() + ) + noCmp(m) + noCmp(s) + noCmp(f) +} + +func cmp(x interface{}) bool { + return x == x +} + +func noCmp(x interface{}) { + shouldPanic(func() { cmp(x) }) +} + +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("function should panic") + } + }() + f() +} diff --git a/test/interface/recursive1.go b/test/interface/recursive1.go new file mode 100644 index 000000000..2c93a2836 --- /dev/null +++ b/test/interface/recursive1.go @@ -0,0 +1,15 @@ +// true # used by recursive2 + +// Copyright 2012 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 { + F() I2 +} + +type I2 interface { + I1 +} diff --git a/test/interface/recursive2.go b/test/interface/recursive2.go new file mode 100644 index 000000000..a7f9ab5db --- /dev/null +++ b/test/interface/recursive2.go @@ -0,0 +1,22 @@ +// $G $D/recursive1.go && $G $D/$F.go + +// Copyright 2012 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. + +// Check that the mutually recursive types in recursive1.go made it +// intact and with the same meaning, by assigning to or using them. + +package main + +import "./recursive1" + +func main() { + var i1 p.I1 + var i2 p.I2 + i1 = i2 + i2 = i1 + i1 = i2.F() + i2 = i1.F() + _, _ = i1, i2 +} diff --git a/test/interface/returntype.go b/test/interface/returntype.go index c526b3b0e..5cf083617 100644 --- a/test/interface/returntype.go +++ b/test/interface/returntype.go @@ -1,4 +1,4 @@ -// $G $D/$F.go && $L $F.$A && (! ./$A.out || echo BUG: should not succeed) +// $G $D/$F.go && $L $F.$A && ./$A.out // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -18,8 +18,21 @@ type I1 interface { Name() int8 } type I2 interface { Name() int64 } func main() { + shouldPanic(p1) +} + +func p1() { var i1 I1 var s *S i1 = s print(i1.(I2).Name()) } + +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("function should panic") + } + }() + f() +} |
