summaryrefslogtreecommitdiff
path: root/test/closure.go
diff options
context:
space:
mode:
authorLuuk van Dijk <lvd@golang.org>2012-01-10 21:47:22 +0100
committerLuuk van Dijk <lvd@golang.org>2012-01-10 21:47:22 +0100
commit9877ea283e9f5b8b09533efc9f1a580cf666a36c (patch)
treea0be4828b117b18923796a539d2b27e9d1248881 /test/closure.go
parent66bd2583d2f12ab021bc90187aad97febc2749a7 (diff)
downloadgo-9877ea283e9f5b8b09533efc9f1a580cf666a36c.tar.gz
gc: test that asserts closures are not wrapped when they don't have closure vars.
R=rsc, bradfitz CC=golang-dev http://codereview.appspot.com/5529060
Diffstat (limited to 'test/closure.go')
-rw-r--r--test/closure.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/test/closure.go b/test/closure.go
index 191514def..97da1dd23 100644
--- a/test/closure.go
+++ b/test/closure.go
@@ -6,6 +6,8 @@
package main
+import "runtime"
+
var c = make(chan int)
func check(a []int) {
@@ -77,6 +79,8 @@ func h() {
func newfunc() func(int) int { return func(x int) int { return x } }
func main() {
+ var fail bool
+
go f()
check([]int{1, 4, 5, 4})
@@ -88,13 +92,26 @@ func main() {
go h()
check([]int{100, 200, 101, 201, 500, 101, 201, 500})
+ runtime.UpdateMemStats()
+ n0 := runtime.MemStats.Mallocs
+
x, y := newfunc(), newfunc()
if x(1) != 1 || y(2) != 2 {
println("newfunc returned broken funcs")
- panic("fail")
+ fail = true
+ }
+
+ runtime.UpdateMemStats()
+ if n0 != runtime.MemStats.Mallocs {
+ println("newfunc allocated unexpectedly")
+ fail = true
}
ff(1)
+
+ if fail {
+ panic("fail")
+ }
}
func ff(x int) {