]> Cypherpunks repositories - gostls13.git/commitdiff
add test for once
authorRuss Cox <rsc@golang.org>
Mon, 15 Dec 2008 16:56:17 +0000 (08:56 -0800)
committerRuss Cox <rsc@golang.org>
Mon, 15 Dec 2008 16:56:17 +0000 (08:56 -0800)
R=r
DELTA=31  (31 added, 0 deleted, 0 changed)
OCL=21043
CL=21175

src/lib/Makefile
src/lib/once_test.go [new file with mode: 0644]

index 32e2918307d53ef44b84b9e6e49508812553ec9d..7221a9c3e642c0e76329082d660b0a6f8487ec0a 100644 (file)
@@ -37,6 +37,7 @@ FILES=\
 TEST=\
        bignum\
        bufio\
+       once\
        sort\
        strings\
        utf8\
diff --git a/src/lib/once_test.go b/src/lib/once_test.go
new file mode 100644 (file)
index 0000000..21a889d
--- /dev/null
@@ -0,0 +1,31 @@
+// 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.
+
+package once
+
+import (
+       "once";
+       "testing";
+)
+
+var ncall int;
+func Call() {
+       ncall++
+}
+
+export func TestOnce(t *testing.T) {
+       ncall = 0;
+       once.Do(&Call);
+       if ncall != 1 {
+               t.Fatalf("once.Do(&Call) didn't Call(): ncall=%d", ncall);
+       }
+       once.Do(&Call);
+       if ncall != 1 {
+               t.Fatalf("second once.Do(&Call) did Call(): ncall=%d", ncall);
+       }
+       once.Do(&Call);
+       if ncall != 1 {
+               t.Fatalf("third once.Do(&Call) did Call(): ncall=%d", ncall);
+       }
+}