diff options
author | Ondřej Surý <ondrej@sury.org> | 2012-04-06 15:14:11 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2012-04-06 15:14:11 +0200 |
commit | 505c19580e0f43fe5224431459cacb7c21edd93d (patch) | |
tree | 79e2634c253d60afc0cc0b2f510dc7dcbb48497b /test/interface | |
parent | 1336a7c91e596c423a49d1194ea42d98bca0d958 (diff) | |
download | golang-505c19580e0f43fe5224431459cacb7c21edd93d.tar.gz |
Imported Upstream version 1upstream/1
Diffstat (limited to 'test/interface')
-rw-r--r-- | test/interface/bigdata.go | 5 | ||||
-rw-r--r-- | test/interface/convert.go | 5 | ||||
-rw-r--r-- | test/interface/convert1.go | 5 | ||||
-rw-r--r-- | test/interface/convert2.go | 5 | ||||
-rw-r--r-- | test/interface/embed.go | 4 | ||||
-rw-r--r-- | test/interface/embed0.go | 4 | ||||
-rw-r--r-- | test/interface/embed1.go | 2 | ||||
-rw-r--r-- | test/interface/embed2.go | 4 | ||||
-rw-r--r-- | test/interface/explicit.go | 5 | ||||
-rw-r--r-- | test/interface/fail.go | 18 | ||||
-rw-r--r-- | test/interface/fake.go | 4 | ||||
-rw-r--r-- | test/interface/noeq.go | 40 | ||||
-rw-r--r-- | test/interface/pointer.go | 7 | ||||
-rw-r--r-- | test/interface/private.go | 3 | ||||
-rw-r--r-- | test/interface/private1.go | 4 | ||||
-rw-r--r-- | test/interface/receiver.go | 6 | ||||
-rw-r--r-- | test/interface/receiver1.go | 5 | ||||
-rw-r--r-- | test/interface/recursive.go | 4 | ||||
-rw-r--r-- | test/interface/recursive1.go | 17 | ||||
-rw-r--r-- | test/interface/recursive2.go | 22 | ||||
-rw-r--r-- | test/interface/returntype.go | 17 | ||||
-rw-r--r-- | test/interface/struct.go | 4 |
22 files changed, 149 insertions, 41 deletions
diff --git a/test/interface/bigdata.go b/test/interface/bigdata.go index 44f6ab127..0f2e9a990 100644 --- a/test/interface/bigdata.go +++ b/test/interface/bigdata.go @@ -1,11 +1,10 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out +// run // 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. -// check that big vs small, pointer vs not -// interface methods work. +// Test big vs. small, pointer vs. value interface methods. package main diff --git a/test/interface/convert.go b/test/interface/convert.go index 7f429f703..eb6fd1d55 100644 --- a/test/interface/convert.go +++ b/test/interface/convert.go @@ -1,11 +1,10 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out +// run // 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. -// Check uses of all the different interface -// conversion runtime functions. +// Test all the different interface conversion runtime functions. package main diff --git a/test/interface/convert1.go b/test/interface/convert1.go index 658b1a92f..4a3ec8a37 100644 --- a/test/interface/convert1.go +++ b/test/interface/convert1.go @@ -1,11 +1,10 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out +// run // 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. -// Check that static interface conversion of -// interface value nil succeeds. +// Test static interface conversion of interface value nil. package main diff --git a/test/interface/convert2.go b/test/interface/convert2.go index 658b1a92f..4a3ec8a37 100644 --- a/test/interface/convert2.go +++ b/test/interface/convert2.go @@ -1,11 +1,10 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out +// run // 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. -// Check that static interface conversion of -// interface value nil succeeds. +// Test static interface conversion of interface value nil. package main diff --git a/test/interface/embed.go b/test/interface/embed.go index 2fddee190..5c52ac023 100644 --- a/test/interface/embed.go +++ b/test/interface/embed.go @@ -1,10 +1,10 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out +// run // 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. -// Check methods derived from embedded interface values. +// Test methods derived from embedded interface values. package main diff --git a/test/interface/embed0.go b/test/interface/embed0.go index bbd81e760..e2ee20ade 100644 --- a/test/interface/embed0.go +++ b/test/interface/embed0.go @@ -1,10 +1,10 @@ -// true # used by embed1.go +// skip # used by embed1.go // 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. -// Check that embedded interface types can have local methods. +// Test that embedded interface types can have local methods. package p diff --git a/test/interface/embed1.go b/test/interface/embed1.go index 24e50471f..ee502a162 100644 --- a/test/interface/embed1.go +++ b/test/interface/embed1.go @@ -4,7 +4,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Check that embedded interface types can have local methods. +// Test that embedded interface types can have local methods. package main diff --git a/test/interface/embed2.go b/test/interface/embed2.go index c18a1fece..1636db78e 100644 --- a/test/interface/embed2.go +++ b/test/interface/embed2.go @@ -1,10 +1,10 @@ -// errchk $G -e $D/$F.go +// errorcheck // 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. -// Check methods derived from embedded interface and *interface values. +// Test methods derived from embedded interface and *interface values. package main diff --git a/test/interface/explicit.go b/test/interface/explicit.go index daae59b36..d19480a68 100644 --- a/test/interface/explicit.go +++ b/test/interface/explicit.go @@ -1,10 +1,11 @@ -// errchk $G -e $D/$F.go +// errorcheck // 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. -// Static error messages about interface conversions. +// Verify compiler messages about erroneous static interface conversions. +// Does not compile. package main diff --git a/test/interface/fail.go b/test/interface/fail.go index 3e741d3f9..72b854dc0 100644 --- a/test/interface/fail.go +++ b/test/interface/fail.go @@ -1,10 +1,10 @@ -// $G $D/$F.go && $L $F.$A && ! ./$A.out +// run // 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. -// Check that interface conversion fails when method is missing. +// Test that interface conversion fails when method is missing. package main @@ -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 ddb832542..861a64084 100644 --- a/test/interface/fake.go +++ b/test/interface/fake.go @@ -1,10 +1,10 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out +// run // 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. -// Interface comparisons using types hidden +// Test interface comparisons using types hidden // inside reflected-on structs. package main diff --git a/test/interface/noeq.go b/test/interface/noeq.go new file mode 100644 index 000000000..1c5166ede --- /dev/null +++ b/test/interface/noeq.go @@ -0,0 +1,40 @@ +// run + +// 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. + +// Test run-time error detection for 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/pointer.go b/test/interface/pointer.go index fe4d8e3ef..292705066 100644 --- a/test/interface/pointer.go +++ b/test/interface/pointer.go @@ -1,10 +1,11 @@ -// errchk $G $D/$F.go +// errorcheck // 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. -// Check that interface{M()} = *interface{M()} produces a compiler error. +// Test that interface{M()} = *interface{M()} produces a compiler error. +// Does not compile. package main @@ -33,5 +34,5 @@ func main() { print("call addinst\n") var x Inst = AddInst(new(Start)) // ERROR "pointer to interface" print("return from addinst\n") - var y *Inst = new(Start) // ERROR "pointer to interface" + var y *Inst = new(Start) // ERROR "pointer to interface|incompatible type" } diff --git a/test/interface/private.go b/test/interface/private.go index 37890c923..14dfc1ae5 100644 --- a/test/interface/private.go +++ b/test/interface/private.go @@ -4,6 +4,9 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Test that unexported methods are not visible outside the package. +// Does not compile. + package main import "./private1" diff --git a/test/interface/private1.go b/test/interface/private1.go index 3173fbef4..3281c38be 100644 --- a/test/interface/private1.go +++ b/test/interface/private1.go @@ -1,9 +1,11 @@ -// true # used by private.go +// skip # used by private.go // 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. +// Imported by private.go, which should not be able to see the private method. + package p type Exported interface { diff --git a/test/interface/receiver.go b/test/interface/receiver.go index f53daf8da..4511ab3b4 100644 --- a/test/interface/receiver.go +++ b/test/interface/receiver.go @@ -1,11 +1,11 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out +// run // 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. -// Implicit methods for embedded types. -// Mixed pointer and non-pointer receivers. +// Test Implicit methods for embedded types and +// mixed pointer and non-pointer receivers. package main diff --git a/test/interface/receiver1.go b/test/interface/receiver1.go index 51312d000..2b7ccdc1a 100644 --- a/test/interface/receiver1.go +++ b/test/interface/receiver1.go @@ -1,10 +1,11 @@ -// errchk $G $D/$F.go +// errorcheck // 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. -// Error messages about missing implicit methods. +// Verify compiler complains about missing implicit methods. +// Does not compile. package main diff --git a/test/interface/recursive.go b/test/interface/recursive.go index 1eb56e976..fcc88331e 100644 --- a/test/interface/recursive.go +++ b/test/interface/recursive.go @@ -1,4 +1,4 @@ -// $G $D/$F.go || echo BUG: should compile +// compile // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -6,7 +6,7 @@ // Check mutually recursive interfaces -package main +package recursive type I1 interface { foo() I2 diff --git a/test/interface/recursive1.go b/test/interface/recursive1.go new file mode 100644 index 000000000..cc3cdc37f --- /dev/null +++ b/test/interface/recursive1.go @@ -0,0 +1,17 @@ +// skip # 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. + +// Mutually recursive type definitions imported and used by recursive1.go. + +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..5129ceb02 --- /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. + +// Test 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..4d86f3918 100644 --- a/test/interface/returntype.go +++ b/test/interface/returntype.go @@ -1,10 +1,10 @@ -// $G $D/$F.go && $L $F.$A && (! ./$A.out || echo BUG: should not succeed) +// run // 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. -// Check methods with different return types. +// Test interface methods with different return types are distinct. package main @@ -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() +} diff --git a/test/interface/struct.go b/test/interface/struct.go index 40b7f4f91..f60819ca8 100644 --- a/test/interface/struct.go +++ b/test/interface/struct.go @@ -1,10 +1,10 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG interface6 +// run // 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. -// Interface values containing structures. +// Test interface values containing structures. package main |