2008-12-15 09:56:17 -07:00
|
|
|
// 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.
|
|
|
|
|
2009-08-12 14:18:37 -06:00
|
|
|
package once_test
|
2008-12-15 09:56:17 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"once";
|
|
|
|
"testing";
|
|
|
|
)
|
|
|
|
|
2009-10-06 20:40:35 -06:00
|
|
|
var ncall int
|
|
|
|
|
2009-01-16 13:47:24 -07:00
|
|
|
func call() {
|
2009-10-06 20:40:35 -06:00
|
|
|
ncall++;
|
2008-12-15 09:56:17 -07:00
|
|
|
}
|
|
|
|
|
2009-08-12 14:18:37 -06:00
|
|
|
func TestDo(t *testing.T) {
|
2008-12-15 09:56:17 -07:00
|
|
|
ncall = 0;
|
2009-01-30 15:39:31 -07:00
|
|
|
once.Do(call);
|
2008-12-15 09:56:17 -07:00
|
|
|
if ncall != 1 {
|
2009-01-30 15:39:31 -07:00
|
|
|
t.Fatalf("once.Do(call) didn't call(): ncall=%d", ncall);
|
2008-12-15 09:56:17 -07:00
|
|
|
}
|
2009-01-30 15:39:31 -07:00
|
|
|
once.Do(call);
|
2008-12-15 09:56:17 -07:00
|
|
|
if ncall != 1 {
|
2009-01-30 15:39:31 -07:00
|
|
|
t.Fatalf("second once.Do(call) did call(): ncall=%d", ncall);
|
2008-12-15 09:56:17 -07:00
|
|
|
}
|
2009-01-30 15:39:31 -07:00
|
|
|
once.Do(call);
|
2008-12-15 09:56:17 -07:00
|
|
|
if ncall != 1 {
|
2009-01-30 15:39:31 -07:00
|
|
|
t.Fatalf("third once.Do(call) did call(): ncall=%d", ncall);
|
2008-12-15 09:56:17 -07:00
|
|
|
}
|
|
|
|
}
|