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/closure.go | |
parent | 6c7ca6e4d4e26e4c8cbe0d183966011b3b088a0a (diff) | |
download | golang-4cecda6c347bd6902b960c6a35a967add7070b0d.tar.gz |
Imported Upstream version 2012.01.27upstream-weekly/2012.01.27
Diffstat (limited to 'test/closure.go')
-rw-r--r-- | test/closure.go | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/test/closure.go b/test/closure.go index 3033c02ed..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) { @@ -76,8 +78,9 @@ 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}) @@ -89,17 +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 == y { - println("newfunc returned same func") - panic("fail") - } 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) { |