]> Cypherpunks repositories - gostls13.git/commitdiff
doc/progs: test defer programs
authorAndrew Gerrand <adg@golang.org>
Thu, 5 Jan 2012 05:43:02 +0000 (16:43 +1100)
committerAndrew Gerrand <adg@golang.org>
Thu, 5 Jan 2012 05:43:02 +0000 (16:43 +1100)
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/5517044

doc/progs/defer.go
doc/progs/run

index f52278aef2947ac257816cb3a519d238464f1385..098cdf26b16e4c8428d52069a04bb94153fc494a 100644 (file)
@@ -18,6 +18,7 @@ func a() {
        i++
        return
 }
+
 // STOP OMIT
 
 func b() {
@@ -25,12 +26,14 @@ func b() {
                defer fmt.Print(i)
        }
 }
+
 // STOP OMIT
 
 func c() (i int) {
        defer func() { i++ }()
        return 1
 }
+
 // STOP OMIT
 
 // Intial version.
@@ -50,4 +53,12 @@ func CopyFile(dstName, srcName string) (written int64, err error) {
        src.Close()
        return
 }
+
 // STOP OMIT
+
+func main() {
+       a()
+       b()
+       fmt.Println()
+       fmt.Println(c())
+}
index 7ceec7466eff648e88dc3cda5bd3874ed2f79276..9cb6f8d79f15db887e853a46d3f493b90e3e49f0 100755 (executable)
@@ -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 sum "" "6"
 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
 rot13=nopqrstuvwxyzabcdefghijklm