From: Russ Cox Date: Mon, 15 Dec 2008 16:56:17 +0000 (-0800) Subject: add test for once X-Git-Tag: weekly.2009-11-06~2510 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8fb837d96dfee662580b5247072fe0a599fc8ae0;p=gostls13.git add test for once R=r DELTA=31 (31 added, 0 deleted, 0 changed) OCL=21043 CL=21175 --- diff --git a/src/lib/Makefile b/src/lib/Makefile index 32e2918307..7221a9c3e6 100644 --- a/src/lib/Makefile +++ b/src/lib/Makefile @@ -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 index 0000000000..21a889dd3c --- /dev/null +++ b/src/lib/once_test.go @@ -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); + } +}