1
0
mirror of https://github.com/golang/go synced 2024-11-22 06:34:40 -07:00

doc/progs: test defer programs

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/5517044
This commit is contained in:
Andrew Gerrand 2012-01-05 16:43:02 +11:00
parent 2469a817ba
commit 8f1cb093ff
2 changed files with 13 additions and 0 deletions

View File

@ -18,6 +18,7 @@ func a() {
i++ i++
return return
} }
// STOP OMIT // STOP OMIT
func b() { func b() {
@ -25,12 +26,14 @@ func b() {
defer fmt.Print(i) defer fmt.Print(i)
} }
} }
// STOP OMIT // STOP OMIT
func c() (i int) { func c() (i int) {
defer func() { i++ }() defer func() { i++ }()
return 1 return 1
} }
// STOP OMIT // STOP OMIT
// Intial version. // Intial version.
@ -50,4 +53,12 @@ func CopyFile(dstName, srcName string) (written int64, err error) {
src.Close() src.Close()
return return
} }
// STOP OMIT // STOP OMIT
func main() {
a()
b()
fmt.Println()
fmt.Println(c())
}

View File

@ -95,6 +95,8 @@ testit helloworld3 "" "hello, world can't open file; err=no such file or directo
testit echo "hello, world" "hello, world" testit echo "hello, world" "hello, world"
testit sum "" "6" testit sum "" "6"
testit strings "" "" testit strings "" ""
testit defer "" "0 3210 2"
testit defer2 "" "Calling g. Printing in g 0 Printing in g 1 Printing in g 2 Printing in g 3 Panicking! Defer in g 3 Defer in g 2 Defer in g 1 Defer in g 0 Recovered in f 4 Returned normally from f."
alphabet=abcdefghijklmnopqrstuvwxyz alphabet=abcdefghijklmnopqrstuvwxyz
rot13=nopqrstuvwxyzabcdefghijklm rot13=nopqrstuvwxyzabcdefghijklm