convert low-level (used by testing) packages to

whole-package compilation.  new Makefiles,
tests now in separate package

	bytes
	flag
	fmt
	io
	math
	once
	os
	reflect
	strconv
	sync
	time
	utf8

delete import "xxx" in package xxx.

inside package xxx, xxx is not declared
anymore so s/xxx.//g

delete file and package level forward declarations.

note the new internal_test.go and sync
and strconv to provide public access to
internals during testing.  the installed version
of the package omits that file and thus does
not open the internals to all clients.

R=r
OCL=33065
CL=33097
This commit is contained in:
Russ Cox 2009-08-12 13:18:37 -07:00
parent dd5f32330c
commit 3b864e4195
81 changed files with 330 additions and 1081 deletions

View file

@ -2,61 +2,11 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile
D=
include $(GOROOT)/src/Make.$(GOARCH) include $(GOROOT)/src/Make.$(GOARCH)
AR=gopack
default: packages TARG=bytes
GOFILES=\
buffer.go\
bytes.go\
clean: include $(GOROOT)/src/Make.pkg
rm -rf *.[$(OS)] *.a [$(OS)].out _obj
test: packages
gotest
coverage: packages
gotest
6cov -g $$(pwd) | grep -v '_test\.go:'
%.$O: %.go
$(GC) -I_obj $*.go
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
O1=\
buffer.$O\
bytes.$O\
phases: a1
_obj$D/bytes.a: phases
a1: $(O1)
$(AR) grc _obj$D/bytes.a buffer.$O bytes.$O
rm -f $(O1)
newpkg: clean
mkdir -p _obj$D
$(AR) grc _obj$D/bytes.a
$(O1): newpkg
$(O2): a1
nuke: clean
rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/bytes.a
packages: _obj$D/bytes.a
install: packages
test -d $(GOROOT)/pkg && mkdir -p $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D
cp _obj$D/bytes.a $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/bytes.a

View file

@ -7,7 +7,6 @@ package bytes
// Simple byte buffer for marshaling data. // Simple byte buffer for marshaling data.
import ( import (
"bytes";
"os"; "os";
) )

View file

@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package bytes package bytes_test
import ( import (
"bytes"; . "bytes";
"rand"; "rand";
"testing"; "testing";
) )

View file

@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package bytes package bytes_test
import ( import (
"bytes"; . "bytes";
"strings"; "strings";
"testing"; "testing";
) )
@ -85,7 +85,7 @@ var explodetests = []ExplodeTest {
} }
func TestExplode(t *testing.T) { func TestExplode(t *testing.T) {
for _, tt := range(explodetests) { for _, tt := range(explodetests) {
a := explode(strings.Bytes(tt.s), tt.n); a := Split(strings.Bytes(tt.s), nil, tt.n);
result := arrayOfString(a); result := arrayOfString(a);
if !eq(result, tt.a) { if !eq(result, tt.a) {
t.Errorf(`Explode("%s", %d) = %v; want %v`, tt.s, tt.n, result, tt.a); t.Errorf(`Explode("%s", %d) = %v; want %v`, tt.s, tt.n, result, tt.a);

View file

@ -2,59 +2,10 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile
D=
include $(GOROOT)/src/Make.$(GOARCH) include $(GOROOT)/src/Make.$(GOARCH)
AR=gopack
default: packages TARG=flag
GOFILES=\
flag.go\
clean: include $(GOROOT)/src/Make.pkg
rm -rf *.[$(OS)] *.a [$(OS)].out _obj
test: packages
gotest
coverage: packages
gotest
6cov -g `pwd` | grep -v '_test\.go:'
%.$O: %.go
$(GC) -I_obj $*.go
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
O1=\
flag.$O\
phases: a1
_obj$D/flag.a: phases
a1: $(O1)
$(AR) grc _obj$D/flag.a flag.$O
rm -f $(O1)
newpkg: clean
mkdir -p _obj$D
$(AR) grc _obj$D/flag.a
$(O1): newpkg
$(O2): a1
nuke: clean
rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/flag.a
packages: _obj$D/flag.a
install: packages
test -d $(GOROOT)/pkg && mkdir -p $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D
cp _obj$D/flag.a $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/flag.a

View file

@ -8,7 +8,7 @@
Usage: Usage:
1) Define flags using flag.String(), Bool(), Int(), etc. Example: 1) Define flags using flag.String(), Bool(), Int(), etc. Example:
import flag "flag" import "flag"
var ip *int = flag.Int("flagname", 1234, "help message for flagname") var ip *int = flag.Int("flagname", 1234, "help message for flagname")
If you like, you can bind the flag to a variable using the Var() functions. If you like, you can bind the flag to a variable using the Var() functions.
var flagvar int var flagvar int

View file

@ -2,21 +2,21 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package flag package flag_test
import ( import (
"flag"; . "flag";
"fmt"; "fmt";
"testing"; "testing";
) )
var ( var (
test_bool = flag.Bool("test_bool", false, "bool value"); test_bool = Bool("test_bool", false, "bool value");
test_int = flag.Int("test_int", 0, "int value"); test_int = Int("test_int", 0, "int value");
test_int64 = flag.Int64("test_int64", 0, "int64 value"); test_int64 = Int64("test_int64", 0, "int64 value");
test_uint = flag.Uint("test_uint", 0, "uint value"); test_uint = Uint("test_uint", 0, "uint value");
test_uint64 = flag.Uint64("test_uint64", 0, "uint64 value"); test_uint64 = Uint64("test_uint64", 0, "uint64 value");
test_string = flag.String("test_string", "0", "string value"); test_string = String("test_string", "0", "string value");
) )
func boolString(s string) string { func boolString(s string) string {
@ -27,9 +27,9 @@ func boolString(s string) string {
} }
func TestEverything(t *testing.T) { func TestEverything(t *testing.T) {
m := make(map[string] *flag.Flag); m := make(map[string] *Flag);
desired := "0"; desired := "0";
visitor := func(f *flag.Flag) { visitor := func(f *Flag) {
if len(f.Name) > 5 && f.Name[0:5] == "test_" { if len(f.Name) > 5 && f.Name[0:5] == "test_" {
m[f.Name] = f; m[f.Name] = f;
ok := false; ok := false;
@ -40,36 +40,36 @@ func TestEverything(t *testing.T) {
ok = true; ok = true;
} }
if !ok { if !ok {
t.Error("flag.Visit: bad value", f.Value.String(), "for", f.Name); t.Error("Visit: bad value", f.Value.String(), "for", f.Name);
} }
} }
}; };
flag.VisitAll(visitor); VisitAll(visitor);
if len(m) != 6 { if len(m) != 6 {
t.Error("flag.VisitAll misses some flags"); t.Error("VisitAll misses some flags");
for k, v := range m { for k, v := range m {
t.Log(k, *v) t.Log(k, *v)
} }
} }
m = make(map[string] *flag.Flag); m = make(map[string] *Flag);
flag.Visit(visitor); Visit(visitor);
if len(m) != 0 { if len(m) != 0 {
t.Errorf("flag.Visit sees unset flags"); t.Errorf("Visit sees unset flags");
for k, v := range m { for k, v := range m {
t.Log(k, *v) t.Log(k, *v)
} }
} }
// Now set all flags // Now set all flags
flag.Set("test_bool", "true"); Set("test_bool", "true");
flag.Set("test_int", "1"); Set("test_int", "1");
flag.Set("test_int64", "1"); Set("test_int64", "1");
flag.Set("test_uint", "1"); Set("test_uint", "1");
flag.Set("test_uint64", "1"); Set("test_uint64", "1");
flag.Set("test_string", "1"); Set("test_string", "1");
desired = "1"; desired = "1";
flag.Visit(visitor); Visit(visitor);
if len(m) != 6 { if len(m) != 6 {
t.Error("flag.Visit fails after set"); t.Error("Visit fails after set");
for k, v := range m { for k, v := range m {
t.Log(k, *v) t.Log(k, *v)
} }

View file

@ -2,67 +2,11 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile
D=
include $(GOROOT)/src/Make.$(GOARCH) include $(GOROOT)/src/Make.$(GOARCH)
AR=gopack
default: packages TARG=fmt
GOFILES=\
format.go\
print.go\
clean: include $(GOROOT)/src/Make.pkg
rm -rf *.[$(OS)] *.a [$(OS)].out _obj
test: packages
gotest
coverage: packages
gotest
6cov -g `pwd` | grep -v '_test\.go:'
%.$O: %.go
$(GC) -I_obj $*.go
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
O1=\
format.$O\
O2=\
print.$O\
phases: a1 a2
_obj$D/fmt.a: phases
a1: $(O1)
$(AR) grc _obj$D/fmt.a format.$O
rm -f $(O1)
a2: $(O2)
$(AR) grc _obj$D/fmt.a print.$O
rm -f $(O2)
newpkg: clean
mkdir -p _obj$D
$(AR) grc _obj$D/fmt.a
$(O1): newpkg
$(O2): a1
$(O3): a2
nuke: clean
rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/fmt.a
packages: _obj$D/fmt.a
install: packages
test -d $(GOROOT)/pkg && mkdir -p $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D
cp _obj$D/fmt.a $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/fmt.a

View file

@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package fmt package fmt_test
import ( import (
"fmt"; . "fmt";
"io"; "io";
"math"; "math";
"strings"; "strings";

View file

@ -74,7 +74,6 @@ package fmt
import ( import (
"fmt";
"io"; "io";
"os"; "os";
"reflect"; "reflect";
@ -198,9 +197,6 @@ func (p *pp) Write(b []byte) (ret int, err os.Error) {
return len(b), nil; return len(b), nil;
} }
func (p *pp) doprintf(format string, v *reflect.StructValue);
func (p *pp) doprint(v *reflect.StructValue, addspace, addnewline bool);
// These routines end in 'f' and take a format string. // These routines end in 'f' and take a format string.
// Fprintf formats according to a format specifier and writes to w. // Fprintf formats according to a format specifier and writes to w.

View file

@ -2,69 +2,12 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile
D=
include $(GOROOT)/src/Make.$(GOARCH) include $(GOROOT)/src/Make.$(GOARCH)
AR=gopack
default: packages TARG=io
GOFILES=\
io.go\
pipe.go\
utils.go\
clean: include $(GOROOT)/src/Make.pkg
rm -rf *.[$(OS)] *.a [$(OS)].out _obj
test: packages
gotest
coverage: packages
gotest
6cov -g $$(pwd) | grep -v '_test\.go:'
%.$O: %.go
$(GC) -I_obj $*.go
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
O1=\
io.$O\
pipe.$O\
O2=\
utils.$O\
phases: a1 a2
_obj$D/io.a: phases
a1: $(O1)
$(AR) grc _obj$D/io.a io.$O pipe.$O
rm -f $(O1)
a2: $(O2)
$(AR) grc _obj$D/io.a utils.$O
rm -f $(O2)
newpkg: clean
mkdir -p _obj$D
$(AR) grc _obj$D/io.a
$(O1): newpkg
$(O2): a1
$(O3): a2
nuke: clean
rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/io.a
packages: _obj$D/io.a
install: packages
test -d $(GOROOT)/pkg && mkdir -p $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D
cp _obj$D/io.a $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/io.a

View file

@ -8,7 +8,6 @@
package io package io
import ( import (
"io";
"os"; "os";
"sync"; "sync";
) )

View file

@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package io package io_test
import ( import (
"fmt"; "fmt";
"io"; . "io";
"os"; "os";
"strings"; "strings";
"testing"; "testing";
@ -84,6 +84,11 @@ func TestPipe2(t *testing.T) {
} }
} }
type pipeReturn struct {
n int;
err os.Error;
}
// Test a large write that requires multiple reads to satisfy. // Test a large write that requires multiple reads to satisfy.
func writer(w WriteCloser, buf []byte, c chan pipeReturn) { func writer(w WriteCloser, buf []byte, c chan pipeReturn) {
n, err := w.Write(buf); n, err := w.Write(buf);
@ -156,10 +161,10 @@ func (p pipeTest) String() string {
var pipeTests = []pipeTest { var pipeTests = []pipeTest {
pipeTest{ true, nil, false }, pipeTest{ true, nil, false },
pipeTest{ true, nil, true }, pipeTest{ true, nil, true },
pipeTest{ true, io.ErrShortWrite, true }, pipeTest{ true, ErrShortWrite, true },
pipeTest{ false, nil, false }, pipeTest{ false, nil, false },
pipeTest{ false, nil, true }, pipeTest{ false, nil, true },
pipeTest{ false, io.ErrShortWrite, true }, pipeTest{ false, ErrShortWrite, true },
} }
func delayClose(t *testing.T, cl closer, ch chan int, tt pipeTest) { func delayClose(t *testing.T, cl closer, ch chan int, tt pipeTest) {

View file

@ -8,7 +8,6 @@ package io
import ( import (
"bytes"; "bytes";
"io";
"os"; "os";
) )

View file

@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package io package io_test
import ( import (
"io"; . "io";
"os"; "os";
"strings"; "strings";
"testing"; "testing";

View file

@ -2,97 +2,27 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile
D=
include $(GOROOT)/src/Make.$(GOARCH) include $(GOROOT)/src/Make.$(GOARCH)
AR=gopack
default: packages TARG=math
GOFILES=\
asin.go\
atan.go\
atan2.go\
const.go\
exp.go\
fabs.go\
floor.go\
fmod.go\
hypot.go\
log.go\
pow.go\
pow10.go\
runtime.go\
sin.go\
sinh.go\
sqrt.go\
tan.go\
tanh.go\
clean: include $(GOROOT)/src/Make.pkg
rm -rf *.[$(OS)] *.a [$(OS)].out _obj
test: packages
gotest
coverage: packages
gotest
6cov -g `pwd` | grep -v '_test\.go:'
%.$O: %.go
$(GC) -I_obj $*.go
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
O1=\
const.$O\
fabs.$O\
hypot.$O\
pow10.$O\
runtime.$O\
O2=\
atan.$O\
exp.$O\
floor.$O\
fmod.$O\
log.$O\
sin.$O\
sqrt.$O\
tan.$O\
O3=\
asin.$O\
atan2.$O\
pow.$O\
sinh.$O\
O4=\
tanh.$O\
phases: a1 a2 a3 a4
_obj$D/math.a: phases
a1: $(O1)
$(AR) grc _obj$D/math.a const.$O fabs.$O hypot.$O pow10.$O runtime.$O
rm -f $(O1)
a2: $(O2)
$(AR) grc _obj$D/math.a atan.$O exp.$O floor.$O fmod.$O log.$O sin.$O sqrt.$O tan.$O
rm -f $(O2)
a3: $(O3)
$(AR) grc _obj$D/math.a asin.$O atan2.$O pow.$O sinh.$O
rm -f $(O3)
a4: $(O4)
$(AR) grc _obj$D/math.a tanh.$O
rm -f $(O4)
newpkg: clean
mkdir -p _obj$D
$(AR) grc _obj$D/math.a
$(O1): newpkg
$(O2): a1
$(O3): a2
$(O4): a3
$(O5): a4
nuke: clean
rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/math.a
packages: _obj$D/math.a
install: packages
test -d $(GOROOT)/pkg && mkdir -p $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D
cp _obj$D/math.a $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/math.a

View file

@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package math package math_test
import ( import (
"math"; . "math";
"testing"; "testing";
) )

View file

@ -4,7 +4,6 @@
package math package math
import "math"
/* /*
* asin(arg) and acos(arg) return the arcsin, arccos, * asin(arg) and acos(arg) return the arcsin, arccos,

View file

@ -4,7 +4,6 @@
package math package math
import "math"
/* /*
* floating-point arctangent * floating-point arctangent

View file

@ -4,7 +4,6 @@
package math package math
import "math"
// Atan returns the arc tangent of y/x, using // Atan returns the arc tangent of y/x, using
// the signs of the two to determine the quadrant // the signs of the two to determine the quadrant

View file

@ -4,7 +4,6 @@
package math package math
import "math"
// The original C code, the long comment, and the constants // The original C code, the long comment, and the constants
// below are from FreeBSD's /usr/src/lib/msun/src/e_exp.c // below are from FreeBSD's /usr/src/lib/msun/src/e_exp.c

View file

@ -4,7 +4,6 @@
package math package math
import "math"
// Floor returns the greatest integer value less than or equal to x. // Floor returns the greatest integer value less than or equal to x.
func Floor(x float64) float64 { func Floor(x float64) float64 {

View file

@ -4,7 +4,6 @@
package math package math
import "math"
/* /*
* floating-point mod func without infinity or NaN checking * floating-point mod func without infinity or NaN checking

View file

@ -4,7 +4,6 @@
package math package math
import "math"
// The original C code, the long comment, and the constants // The original C code, the long comment, and the constants
// below are from FreeBSD's /usr/src/lib/msun/src/e_log.c // below are from FreeBSD's /usr/src/lib/msun/src/e_log.c
@ -33,19 +32,17 @@ import "math"
// = 2s + 2/3 s**3 + 2/5 s**5 + ....., // = 2s + 2/3 s**3 + 2/5 s**5 + .....,
// = 2s + s*R // = 2s + s*R
// We use a special Reme algorithm on [0,0.1716] to generate // We use a special Reme algorithm on [0,0.1716] to generate
// a polynomial of degree 14 to approximate R The maximum error // a polynomial of degree 14 to approximate R. The maximum error
// of this polynomial approximation is bounded by 2**-58.45. In // of this polynomial approximation is bounded by 2**-58.45. In
// other words, // other words,
// 2 4 6 8 10 12 14 // 2 4 6 8 10 12 14
// R(z) ~ L1*s +L2*s +L3*s +L4*s +L5*s +L6*s +L7*s // R(z) ~ L1*s +L2*s +L3*s +L4*s +L5*s +L6*s +L7*s
// (the values of L1 to L7 are listed in the program) // (the values of L1 to L7 are listed in the program) and
// and
// | 2 14 | -58.45 // | 2 14 | -58.45
// | L1*s +...+L7*s - R(z) | <= 2 // | L1*s +...+L7*s - R(z) | <= 2
// | | // | |
// Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. // Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
// In order to guarantee error in log below 1ulp, we compute log // In order to guarantee error in log below 1ulp, we compute log by
// by
// log(1+f) = f - s*(f - R) (if f is not too large) // log(1+f) = f - s*(f - R) (if f is not too large)
// log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy) // log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy)
// //

View file

@ -4,7 +4,6 @@
package math package math
import "math"
// Pow returns x**y, the base-x exponential of y. // Pow returns x**y, the base-x exponential of y.
func Pow(x, y float64) float64 { func Pow(x, y float64) float64 {

View file

@ -4,7 +4,6 @@
package math package math
import "math"
func sinus(x float64, quad int) float64 { func sinus(x float64, quad int) float64 {
// Coefficients are #3370 from Hart & Cheney (18.80D). // Coefficients are #3370 from Hart & Cheney (18.80D).

View file

@ -4,7 +4,6 @@
package math package math
import "math"
/* /*
* Sinh(x) returns the hyperbolic sine of x * Sinh(x) returns the hyperbolic sine of x

View file

@ -4,7 +4,6 @@
package math package math
import "math"
/* /*
* sqrt returns the square root of its floating * sqrt returns the square root of its floating

View file

@ -4,7 +4,6 @@
package math package math
import "math"
/* /*
* floating point tangent * floating point tangent

View file

@ -4,7 +4,6 @@
package math package math
import "math"
/* /*
* tanh(x) computes the hyperbolic tangent of its floating * tanh(x) computes the hyperbolic tangent of its floating

View file

@ -2,59 +2,10 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile
D=
include $(GOROOT)/src/Make.$(GOARCH) include $(GOROOT)/src/Make.$(GOARCH)
AR=gopack
default: packages TARG=once
GOFILES=\
once.go\
clean: include $(GOROOT)/src/Make.pkg
rm -rf *.[$(OS)] *.a [$(OS)].out _obj
test: packages
gotest
coverage: packages
gotest
6cov -g `pwd` | grep -v '_test\.go:'
%.$O: %.go
$(GC) -I_obj $*.go
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
O1=\
once.$O\
phases: a1
_obj$D/once.a: phases
a1: $(O1)
$(AR) grc _obj$D/once.a once.$O
rm -f $(O1)
newpkg: clean
mkdir -p _obj$D
$(AR) grc _obj$D/once.a
$(O1): newpkg
$(O2): a1
nuke: clean
rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/once.a
packages: _obj$D/once.a
install: packages
test -d $(GOROOT)/pkg && mkdir -p $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D
cp _obj$D/once.a $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/once.a

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package once package once_test
import ( import (
"once"; "once";
@ -14,7 +14,7 @@ func call() {
ncall++ ncall++
} }
func TestOnce(t *testing.T) { func TestDo(t *testing.T) {
ncall = 0; ncall = 0;
once.Do(call); once.Do(call);
if ncall != 1 { if ncall != 1 {

View file

@ -2,92 +2,21 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m dir_${GOOS}_${GOARCH}.go env.go error.go file.go path.go stat_${GOOS}_${GOARCH}.go time.go types.go exec.go proc.go getwd.go sys_${GOOS}.go >Makefile
D=
include $(GOROOT)/src/Make.$(GOARCH) include $(GOROOT)/src/Make.$(GOARCH)
AR=gopack
default: packages TARG=os
GOFILES=\
dir_$(GOOS)_$(GOARCH).go\
env.go\
error.go\
exec.go\
file.go\
getwd.go\
path.go\
proc.go\
stat_$(GOOS)_$(GOARCH).go\
sys_$(GOOS).go\
time.go\
types.go\
clean: include $(GOROOT)/src/Make.pkg
rm -rf *.[$(OS)] *.a [$(OS)].out _obj
test: packages
gotest
coverage: packages
gotest
6cov -g $$(pwd) | grep -v '_test\.go:'
%.$O: %.go
$(GC) -I_obj $*.go
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
O1=\
error.$O\
types.$O\
O2=\
proc.$O\
stat_$(GOOS)_$(GOARCH).$O\
time.$O\
O3=\
env.$O\
file.$O\
O4=\
dir_$(GOOS)_$(GOARCH).$O\
exec.$O\
getwd.$O\
path.$O\
sys_$(GOOS).$O\
phases: a1 a2 a3 a4
_obj$D/os.a: phases
a1: $(O1)
$(AR) grc _obj$D/os.a error.$O types.$O
rm -f $(O1)
a2: $(O2)
$(AR) grc _obj$D/os.a proc.$O stat_$(GOOS)_$(GOARCH).$O time.$O
rm -f $(O2)
a3: $(O3)
$(AR) grc _obj$D/os.a env.$O file.$O
rm -f $(O3)
a4: $(O4)
$(AR) grc _obj$D/os.a dir_$(GOOS)_$(GOARCH).$O exec.$O getwd.$O path.$O sys_$(GOOS).$O
rm -f $(O4)
newpkg: clean
mkdir -p _obj$D
$(AR) grc _obj$D/os.a
$(O1): newpkg
$(O2): a1
$(O3): a2
$(O4): a3
$(O5): a4
nuke: clean
rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/os.a
packages: _obj$D/os.a
install: packages
test -d $(GOROOT)/pkg && mkdir -p $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D
cp _obj$D/os.a $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/os.a

View file

@ -5,7 +5,6 @@
package os package os
import ( import (
"os";
"syscall"; "syscall";
"unsafe"; "unsafe";
) )
@ -14,7 +13,11 @@ const (
blockSize = 4096 // TODO(r): use statfs blockSize = 4096 // TODO(r): use statfs
) )
// Negative count means read until EOF. // Readdirnames reads the contents of the directory associated with file and
// returns an array of up to count names, in directory order. Subsequent
// calls on the same file will yield further names.
// A negative count means to read until EOF.
// Readdirnames returns the array and an Error, if any.
func (file *File) Readdirnames(count int) (names []string, err Error) { func (file *File) Readdirnames(count int) (names []string, err Error) {
// If this file has no dirinfo, create one. // If this file has no dirinfo, create one.
if file.dirinfo == nil { if file.dirinfo == nil {

View file

@ -5,7 +5,6 @@
package os package os
import ( import (
"os";
"syscall"; "syscall";
"unsafe"; "unsafe";
) )
@ -14,7 +13,6 @@ const (
blockSize = 4096 // TODO(r): use statfs blockSize = 4096 // TODO(r): use statfs
) )
// Negative count means read until EOF.
func (file *File) Readdirnames(count int) (names []string, err Error) { func (file *File) Readdirnames(count int) (names []string, err Error) {
// If this file has no dirinfo, create one. // If this file has no dirinfo, create one.
if file.dirinfo == nil { if file.dirinfo == nil {

View file

@ -9,7 +9,6 @@
package os package os
import ( import (
"os";
"syscall"; "syscall";
"unsafe"; "unsafe";
) )
@ -27,7 +26,6 @@ func clen(n []byte) int {
return len(n) return len(n)
} }
// Negative count means read until EOF.
func (file *File) Readdirnames(count int) (names []string, err Error) { func (file *File) Readdirnames(count int) (names []string, err Error) {
// If this file has no dirinfo, create one. // If this file has no dirinfo, create one.
if file.dirinfo == nil { if file.dirinfo == nil {

View file

@ -5,7 +5,6 @@
package os package os
import ( import (
"os";
"syscall"; "syscall";
"unsafe"; "unsafe";
) )
@ -23,7 +22,6 @@ func clen(n []byte) int {
return len(n) return len(n)
} }
// Negative count means read until EOF.
func (file *File) Readdirnames(count int) (names []string, err Error) { func (file *File) Readdirnames(count int) (names []string, err Error) {
// If this file has no dirinfo, create one. // If this file has no dirinfo, create one.
if file.dirinfo == nil { if file.dirinfo == nil {

View file

@ -8,7 +8,6 @@ package os
import ( import (
"once"; "once";
"os";
) )
// ENOENV is the Error indicating that an environment variable does not exist. // ENOENV is the Error indicating that an environment variable does not exist.

View file

@ -5,7 +5,6 @@
package os package os
import ( import (
"os";
"syscall"; "syscall";
) )

View file

@ -7,7 +7,6 @@
package os package os
import ( import (
"os";
"syscall"; "syscall";
) )
@ -257,13 +256,6 @@ func Lstat(name string) (dir *Dir, err Error) {
return dirFromStat(name, new(Dir), &stat, &stat), nil return dirFromStat(name, new(Dir), &stat, &stat), nil
} }
// Readdirnames reads the contents of the directory associated with file and
// returns an array of up to count names, in directory order. Subsequent
// calls on the same file will yield further names.
// A negative count means to read until EOF.
// Readdirnames returns the array and an Error, if any.
func (file *File) Readdirnames(count int) (names []string, err Error)
// Readdir reads the contents of the directory associated with file and // Readdir reads the contents of the directory associated with file and
// returns an array of up to count Dir structures, as would be returned // returns an array of up to count Dir structures, as would be returned
// by Stat, in directory order. Subsequent calls on the same file will yield further Dirs. // by Stat, in directory order. Subsequent calls on the same file will yield further Dirs.

View file

@ -5,7 +5,6 @@
package os package os
import ( import (
"os";
"syscall" "syscall"
) )

View file

@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package os package os_test
import ( import (
"bytes"; "bytes";
"fmt"; "fmt";
"io"; "io";
"os"; . "os";
"strings"; "strings";
"testing"; "testing";
) )

View file

@ -4,7 +4,6 @@
package os package os
import "os"
// MkdirAll creates a directory named path, // MkdirAll creates a directory named path,
// along with any necessary parents, and returns nil, // along with any necessary parents, and returns nil,

View file

@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package os package os_test
import ( import (
"os"; . "os";
"testing"; "testing";
) )

View file

@ -8,7 +8,6 @@ package os
import ( import (
"syscall"; "syscall";
"os";
"unsafe"; "unsafe";
) )

View file

@ -6,8 +6,7 @@
package os package os
import syscall "syscall" import "syscall"
import os "os"
func isSymlink(stat *syscall.Stat_t) bool { func isSymlink(stat *syscall.Stat_t) bool {
return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK

View file

@ -6,8 +6,7 @@
package os package os
import syscall "syscall" import "syscall"
import os "os"
func isSymlink(stat *syscall.Stat_t) bool { func isSymlink(stat *syscall.Stat_t) bool {
return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK

View file

@ -10,10 +10,7 @@
package os package os
import ( import "syscall"
"os";
"syscall";
)
func isSymlink(stat *syscall.Stat_t) bool { func isSymlink(stat *syscall.Stat_t) bool {
return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK

View file

@ -6,8 +6,7 @@
package os package os
import syscall "syscall" import "syscall"
import os "os"
func isSymlink(stat *syscall.Stat_t) bool { func isSymlink(stat *syscall.Stat_t) bool {
return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK

View file

@ -6,10 +6,7 @@
package os package os
import ( import "syscall"
"os";
"syscall";
)
func Hostname() (name string, err Error) { func Hostname() (name string, err Error) {
var errno int; var errno int;

View file

@ -6,7 +6,6 @@
package os package os
import "os"
// Hostname returns the host name reported by the kernel. // Hostname returns the host name reported by the kernel.
func Hostname() (name string, err Error) { func Hostname() (name string, err Error) {

View file

@ -4,10 +4,7 @@
package os package os
import ( import "syscall"
"os";
"syscall"
)
// Time returns the current time, in whole seconds and // Time returns the current time, in whole seconds and

View file

@ -2,77 +2,12 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile
D=
include $(GOROOT)/src/Make.$(GOARCH) include $(GOROOT)/src/Make.$(GOARCH)
AR=gopack
default: packages TARG=reflect
GOFILES=\
deepequal.go\
type.go\
value.go\
clean: include $(GOROOT)/src/Make.pkg
rm -rf *.[$(OS)] *.a [$(OS)].out _obj
test: packages
gotest
coverage: packages
gotest
6cov -g $$(pwd) | grep -v '_test\.go:'
%.$O: %.go
$(GC) -I_obj $*.go
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
O1=\
type.$O\
O2=\
value.$O\
O3=\
deepequal.$O\
tostring.$O\
phases: a1 a2 a3
_obj$D/reflect.a: phases
a1: $(O1)
$(AR) grc _obj$D/reflect.a type.$O
rm -f $(O1)
a2: $(O2)
$(AR) grc _obj$D/reflect.a value.$O
rm -f $(O2)
a3: $(O3)
$(AR) grc _obj$D/reflect.a deepequal.$O tostring.$O
rm -f $(O3)
newpkg: clean
mkdir -p _obj$D
$(AR) grc _obj$D/reflect.a
$(O1): newpkg
$(O2): a1
$(O3): a2
$(O4): a3
nuke: clean
rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/reflect.a
packages: _obj$D/reflect.a
install: packages
test -d $(GOROOT)/pkg && mkdir -p $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D
cp _obj$D/reflect.a $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/reflect.a

View file

@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package reflect package reflect_test
import ( import (
"io"; "io";
"os"; "os";
"reflect"; . "reflect";
"testing"; "testing";
"unsafe"; "unsafe";
) )
@ -50,14 +50,14 @@ var typeTests = []pair {
pair { struct { x float64 }{}, "float64" }, pair { struct { x float64 }{}, "float64" },
pair { struct { x int8 }{}, "int8" }, pair { struct { x int8 }{}, "int8" },
pair { struct { x (**int8) }{}, "**int8" }, pair { struct { x (**int8) }{}, "**int8" },
pair { struct { x (**reflect.integer) }{}, "**reflect.integer" }, pair { struct { x (**integer) }{}, "**reflect_test.integer" },
pair { struct { x ([32]int32) }{}, "[32]int32" }, pair { struct { x ([32]int32) }{}, "[32]int32" },
pair { struct { x ([]int8) }{}, "[]int8" }, pair { struct { x ([]int8) }{}, "[]int8" },
pair { struct { x (map[string]int32) }{}, "map[string] int32" }, pair { struct { x (map[string]int32) }{}, "map[string] int32" },
pair { struct { x (chan<-string) }{}, "chan<- string" }, pair { struct { x (chan<-string) }{}, "chan<- string" },
pair { struct { x struct {c chan *int32; d float32} }{}, "struct { c chan *int32; d float32 }" }, pair { struct { x struct {c chan *int32; d float32} }{}, "struct { c chan *int32; d float32 }" },
pair { struct { x (func(a int8, b int32)) }{}, "func(int8, int32)" }, pair { struct { x (func(a int8, b int32)) }{}, "func(int8, int32)" },
pair { struct { x struct {c func(chan *reflect.integer, *int8)} }{}, "struct { c func(chan *reflect.integer, *int8) }" }, pair { struct { x struct {c func(chan *integer, *int8)} }{}, "struct { c func(chan *reflect_test.integer, *int8) }" },
pair { struct { x struct {a int8; b int32} }{}, "struct { a int8; b int32 }" }, pair { struct { x struct {a int8; b int32} }{}, "struct { a int8; b int32 }" },
pair { struct { x struct {a int8; b int8; c int32} }{}, "struct { a int8; b int8; c int32 }" }, pair { struct { x struct {a int8; b int8; c int32} }{}, "struct { a int8; b int8; c int32 }" },
pair { struct { x struct {a int8; b int8; c int8; d int32} }{}, "struct { a int8; b int8; c int8; d int32 }" }, pair { struct { x struct {a int8; b int8; c int8; d int32} }{}, "struct { a int8; b int8; c int8; d int32 }" },
@ -85,12 +85,12 @@ var valueTests = []pair {
pair { (*int8)(nil), "*int8(0)" }, pair { (*int8)(nil), "*int8(0)" },
pair { (**int8)(nil), "**int8(0)" }, pair { (**int8)(nil), "**int8(0)" },
pair { ([5]int32){}, "[5]int32{0, 0, 0, 0, 0}" }, pair { ([5]int32){}, "[5]int32{0, 0, 0, 0, 0}" },
pair { (**reflect.integer)(nil), "**reflect.integer(0)" }, pair { (**integer)(nil), "**reflect_test.integer(0)" },
pair { (map[string]int32)(nil), "map[string] int32{<can't iterate on maps>}" }, pair { (map[string]int32)(nil), "map[string] int32{<can't iterate on maps>}" },
pair { (chan<-string)(nil), "chan<- string" }, pair { (chan<-string)(nil), "chan<- string" },
pair { (struct {c chan *int32; d float32}){}, "struct { c chan *int32; d float32 }{chan *int32, 0}" }, pair { (struct {c chan *int32; d float32}){}, "struct { c chan *int32; d float32 }{chan *int32, 0}" },
pair { (func(a int8, b int32))(nil), "func(int8, int32)(0)" }, pair { (func(a int8, b int32))(nil), "func(int8, int32)(0)" },
pair { (struct {c func(chan *reflect.integer, *int8)}){}, "struct { c func(chan *reflect.integer, *int8) }{func(chan *reflect.integer, *int8)(0)}" }, pair { (struct {c func(chan *integer, *int8)}){}, "struct { c func(chan *reflect_test.integer, *int8) }{func(chan *reflect_test.integer, *int8)(0)}" },
pair { (struct {a int8; b int32}){}, "struct { a int8; b int32 }{0, 0}" }, pair { (struct {a int8; b int32}){}, "struct { a int8; b int32 }{0, 0}" },
pair { (struct {a int8; b int8; c int32}){}, "struct { a int8; b int8; c int32 }{0, 0, 0}" }, pair { (struct {a int8; b int8; c int32}){}, "struct { a int8; b int8; c int32 }{0, 0, 0}" },
} }
@ -112,35 +112,35 @@ func TestValue(t *testing.T) {
for i, tt := range valueTests { for i, tt := range valueTests {
v := NewValue(tt.i); v := NewValue(tt.i);
switch v := v.(type) { switch v := v.(type) {
case *reflect.IntValue: case *IntValue:
v.Set(132); v.Set(132);
case *reflect.Int8Value: case *Int8Value:
v.Set(8); v.Set(8);
case *reflect.Int16Value: case *Int16Value:
v.Set(16); v.Set(16);
case *reflect.Int32Value: case *Int32Value:
v.Set(32); v.Set(32);
case *reflect.Int64Value: case *Int64Value:
v.Set(64); v.Set(64);
case *reflect.UintValue: case *UintValue:
v.Set(132); v.Set(132);
case *reflect.Uint8Value: case *Uint8Value:
v.Set(8); v.Set(8);
case *reflect.Uint16Value: case *Uint16Value:
v.Set(16); v.Set(16);
case *reflect.Uint32Value: case *Uint32Value:
v.Set(32); v.Set(32);
case *reflect.Uint64Value: case *Uint64Value:
v.Set(64); v.Set(64);
case *reflect.FloatValue: case *FloatValue:
v.Set(3200.0); v.Set(3200.0);
case *reflect.Float32Value: case *Float32Value:
v.Set(32.1); v.Set(32.1);
case *reflect.Float64Value: case *Float64Value:
v.Set(64.2); v.Set(64.2);
case *reflect.StringValue: case *StringValue:
v.Set("stringy cheese"); v.Set("stringy cheese");
case *reflect.BoolValue: case *BoolValue:
v.Set(true); v.Set(true);
} }
s := valueToString(v); s := valueToString(v);
@ -157,8 +157,8 @@ var valueToStringTests = []pair {
pair { 123.4, "123.4" }, pair { 123.4, "123.4" },
pair { byte(123), "123" }, pair { byte(123), "123" },
pair { "abc", "abc" }, pair { "abc", "abc" },
pair { T{123, 456.75, "hello", &_i}, "reflect.T{123, 456.75, hello, *int(&7)}" }, pair { T{123, 456.75, "hello", &_i}, "reflect_test.T{123, 456.75, hello, *int(&7)}" },
pair { new(chan *T), "*chan *reflect.T(&chan *reflect.T)" }, pair { new(chan *T), "*chan *reflect_test.T(&chan *reflect_test.T)" },
pair { [10]int{1,2,3,4,5,6,7,8,9,10}, "[10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}" }, pair { [10]int{1,2,3,4,5,6,7,8,9,10}, "[10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}" },
pair { &[10]int{1,2,3,4,5,6,7,8,9,10}, "*[10]int(&[10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})" }, pair { &[10]int{1,2,3,4,5,6,7,8,9,10}, "*[10]int(&[10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})" },
pair { []int{1,2,3,4,5,6,7,8,9,10}, "[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}" }, pair { []int{1,2,3,4,5,6,7,8,9,10}, "[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}" },
@ -771,7 +771,7 @@ func (p Point) Dist(scale int) int {
func TestMethod(t *testing.T) { func TestMethod(t *testing.T) {
// Non-curried method of type. // Non-curried method of type.
p := Point{3, 4}; p := Point{3, 4};
i := reflect.Typeof(p).Method(0).Func.Call([]Value{NewValue(p), NewValue(10)})[0].(*IntValue).Get(); i := Typeof(p).Method(0).Func.Call([]Value{NewValue(p), NewValue(10)})[0].(*IntValue).Get();
if i != 250 { if i != 250 {
t.Errorf("Type Method returned %d; want 250", i); t.Errorf("Type Method returned %d; want 250", i);
} }
@ -812,7 +812,7 @@ func TestInterfaceSet(t *testing.T) {
if q := s.P.(*Point); q != p { if q := s.P.(*Point); q != p {
t.Errorf("i: have %p want %p", q, p); t.Errorf("i: have %p want %p", q, p);
} }
i := pv.Method(0).Call([]Value{NewValue(10)})[0].(*IntValue).Get(); i := pv.Method(0).Call([]Value{NewValue(10)})[0].(*IntValue).Get();
if i != 250 { if i != 250 {
t.Errorf("Interface Method returned %d; want 250", i); t.Errorf("Interface Method returned %d; want 250", i);
@ -907,7 +907,7 @@ func TestFieldByIndex(t *testing.T) {
} }
if test.value != 0 { if test.value != 0 {
v := reflect.NewValue(test.s).(*reflect.StructValue).FieldByIndex(test.index); v := NewValue(test.s).(*StructValue).FieldByIndex(test.index);
if v != nil { if v != nil {
if x, ok := v.Interface().(int); ok { if x, ok := v.Interface().(int); ok {
if x != test.value { if x != test.value {
@ -945,9 +945,9 @@ func TestFieldByName(t *testing.T) {
} else if len(test.index) > 0 { } else if len(test.index) > 0 {
t.Errorf("%s.%s not found", s.Name(), test.name); t.Errorf("%s.%s not found", s.Name(), test.name);
} }
if test.value != 0 { if test.value != 0 {
v := reflect.NewValue(test.s).(*reflect.StructValue).FieldByName(test.name); v := NewValue(test.s).(*StructValue).FieldByName(test.name);
if v != nil { if v != nil {
if x, ok := v.Interface().(int); ok { if x, ok := v.Interface().(int); ok {
if x != test.value { if x != test.value {

View file

@ -6,7 +6,6 @@
package reflect package reflect
import "reflect"
// During deepValueEqual, must keep track of checks that are // During deepValueEqual, must keep track of checks that are
// in progress. The comparison algorithm assumes that all // in progress. The comparison algorithm assumes that all

View file

@ -2,15 +2,14 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Reflection library.
// Formatting of reflection types and values for debugging. // Formatting of reflection types and values for debugging.
// Not defined as methods so they do not need to be linked into most binaries; // Not defined as methods so they do not need to be linked into most binaries;
// the functions are not used by the library itself, only in tests. // the functions are not used by the library itself, only in tests.
package reflect package reflect_test
import ( import (
"reflect"; . "reflect";
"strconv"; "strconv";
) )
@ -113,7 +112,7 @@ func valueToString(val Value) string {
v := val; v := val;
return typ.String() + "(" + strconv.Itoa64(int64(v.Get())) + ")"; return typ.String() + "(" + strconv.Itoa64(int64(v.Get())) + ")";
default: default:
panicln("reflect.valueToString: can't print type ", typ.String()); panicln("valueToString: can't print type ", typ.String());
} }
return "reflect.valueToString: can't happen"; return "valueToString: can't happen";
} }

View file

@ -226,11 +226,6 @@ type StructType struct {
* The compiler does not know about the data structures and methods below. * The compiler does not know about the data structures and methods below.
*/ */
type Type interface
type addr unsafe.Pointer
type FuncValue struct
func newFuncValue(typ Type, addr addr, canSet bool) *FuncValue
// Method represents a single method. // Method represents a single method.
type Method struct { type Method struct {
PkgPath string; // empty for uppercase Name PkgPath string; // empty for uppercase Name
@ -281,8 +276,6 @@ type Type interface {
uncommon() *uncommonType; uncommon() *uncommonType;
} }
func toType(i interface{}) Type
func (t *uncommonType) uncommon() *uncommonType { func (t *uncommonType) uncommon() *uncommonType {
return t; return t;
} }

View file

@ -5,14 +5,13 @@
package reflect package reflect
import ( import (
"reflect";
"runtime"; "runtime";
"unsafe"; "unsafe";
) )
const ptrSize = uintptr(unsafe.Sizeof((*byte)(nil))) const ptrSize = uintptr(unsafe.Sizeof((*byte)(nil)))
const cannotSet = "cannot set value obtained via unexported struct field" const cannotSet = "cannot set value obtained via unexported struct field"
type addr unsafe.Pointer
// TODO: This will have to go away when // TODO: This will have to go away when
// the new gc goes in. // the new gc goes in.
@ -72,8 +71,6 @@ type Value interface {
getAddr() addr; getAddr() addr;
} }
func MakeZero(typ Type) Value
type value struct { type value struct {
typ Type; typ Type;
addr addr; addr addr;
@ -92,11 +89,6 @@ func (v *value) getAddr() addr {
return v.addr; return v.addr;
} }
func (v *value) Method(i int) *FuncValue
type InterfaceValue struct
type StructValue struct
func (v *value) Interface() interface{} { func (v *value) Interface() interface{} {
if typ, ok := v.typ.(*InterfaceType); ok { if typ, ok := v.typ.(*InterfaceType); ok {
// There are two different representations of interface values, // There are two different representations of interface values,
@ -117,9 +109,6 @@ func (v *value) CanSet() bool {
return v.canSet; return v.canSet;
} }
func newValue(typ Type, addr addr, canSet bool) Value
func NewValue(i interface{}) Value
/* /*
* basic types * basic types
*/ */
@ -420,7 +409,6 @@ type UnsafePointerValue struct {
// Get returns the underlying uintptr value. // Get returns the underlying uintptr value.
// Get returns uintptr, not unsafe.Pointer, so that // Get returns uintptr, not unsafe.Pointer, so that
// programs that do not import "unsafe" cannot // programs that do not import "unsafe" cannot
// obtain a value of unsafe.Pointer type from "reflect".
func (v *UnsafePointerValue) Get() uintptr { func (v *UnsafePointerValue) Get() uintptr {
return uintptr(*(*unsafe.Pointer)(v.addr)); return uintptr(*(*unsafe.Pointer)(v.addr));
} }

View file

@ -2,79 +2,15 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile
D=
include $(GOROOT)/src/Make.$(GOARCH) include $(GOROOT)/src/Make.$(GOARCH)
AR=gopack
default: packages TARG=strconv
GOFILES=\
atof.go\
atoi.go\
decimal.go\
ftoa.go\
itoa.go\
quote.go\
clean: include $(GOROOT)/src/Make.pkg
rm -rf *.[$(OS)] *.a [$(OS)].out _obj
test: packages
gotest
coverage: packages
gotest
6cov -g $$(pwd) | grep -v '_test\.go:'
%.$O: %.go
$(GC) -I_obj $*.go
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
O1=\
decimal.$O\
itoa.$O\
quote.$O\
O2=\
atoi.$O\
ftoa.$O\
O3=\
atof.$O\
phases: a1 a2 a3
_obj$D/strconv.a: phases
a1: $(O1)
$(AR) grc _obj$D/strconv.a decimal.$O itoa.$O quote.$O
rm -f $(O1)
a2: $(O2)
$(AR) grc _obj$D/strconv.a atoi.$O ftoa.$O
rm -f $(O2)
a3: $(O3)
$(AR) grc _obj$D/strconv.a atof.$O
rm -f $(O3)
newpkg: clean
mkdir -p _obj$D
$(AR) grc _obj$D/strconv.a
$(O1): newpkg
$(O2): a1
$(O3): a2
$(O4): a3
nuke: clean
rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/strconv.a
packages: _obj$D/strconv.a
install: packages
test -d $(GOROOT)/pkg && mkdir -p $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D
cp _obj$D/strconv.a $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/strconv.a

View file

@ -15,7 +15,6 @@ package strconv
import ( import (
"math"; "math";
"os"; "os";
"strconv";
) )
var optimize = true // can change for testing var optimize = true // can change for testing

View file

@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package strconv package strconv_test
import ( import (
"fmt"; "fmt";
"os"; "os";
"reflect"; "reflect";
"strconv"; . "strconv";
"testing" "testing";
) )
type atofTest struct { type atofTest struct {
@ -104,36 +105,35 @@ func init() {
} }
func testAtof(t *testing.T, opt bool) { func testAtof(t *testing.T, opt bool) {
oldopt := strconv.optimize; oldopt := SetOptimize(opt);
strconv.optimize = opt;
for i := 0; i < len(atoftests); i++ { for i := 0; i < len(atoftests); i++ {
test := &atoftests[i]; test := &atoftests[i];
out, err := strconv.Atof64(test.in); out, err := Atof64(test.in);
outs := strconv.Ftoa64(out, 'g', -1); outs := Ftoa64(out, 'g', -1);
if outs != test.out || !reflect.DeepEqual(err, test.err) { if outs != test.out || !reflect.DeepEqual(err, test.err) {
t.Errorf("strconv.Atof64(%v) = %v, %v want %v, %v\n", t.Errorf("Atof64(%v) = %v, %v want %v, %v\n",
test.in, out, err, test.out, test.err); test.in, out, err, test.out, test.err);
} }
if float64(float32(out)) == out { if float64(float32(out)) == out {
out32, err := strconv.Atof32(test.in); out32, err := Atof32(test.in);
outs := strconv.Ftoa32(out32, 'g', -1); outs := Ftoa32(out32, 'g', -1);
if outs != test.out || !reflect.DeepEqual(err, test.err) { if outs != test.out || !reflect.DeepEqual(err, test.err) {
t.Errorf("strconv.Atof32(%v) = %v, %v want %v, %v # %v\n", t.Errorf("Atof32(%v) = %v, %v want %v, %v # %v\n",
test.in, out32, err, test.out, test.err, out); test.in, out32, err, test.out, test.err, out);
} }
} }
if FloatSize == 64 || float64(float32(out)) == out { if FloatSize == 64 || float64(float32(out)) == out {
outf, err := strconv.Atof(test.in); outf, err := Atof(test.in);
outs := strconv.Ftoa(outf, 'g', -1); outs := Ftoa(outf, 'g', -1);
if outs != test.out || !reflect.DeepEqual(err, test.err) { if outs != test.out || !reflect.DeepEqual(err, test.err) {
t.Errorf("strconv.Ftoa(%v) = %v, %v want %v, %v # %v\n", t.Errorf("Ftoa(%v) = %v, %v want %v, %v # %v\n",
test.in, outf, err, test.out, test.err, out); test.in, outf, err, test.out, test.err, out);
} }
} }
} }
strconv.optimize = oldopt; SetOptimize(oldopt);
} }
func TestAtof(t *testing.T) { func TestAtof(t *testing.T) {

View file

@ -3,10 +3,8 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package strconv package strconv
import (
"os"; import "os"
"strconv"
)
type NumError struct { type NumError struct {
Num string; Num string;
@ -25,7 +23,7 @@ func computeIntsize() uint {
} }
return siz return siz
} }
var intsize = computeIntsize(); var IntSize = computeIntsize();
// Return the first number n such that n*base >= 1<<64. // Return the first number n such that n*base >= 1<<64.
func cutoff64(base int) uint64 { func cutoff64(base int) uint64 {
@ -189,9 +187,9 @@ func Atoi(s string) (i int, err os.Error) {
i = int(i1); i = int(i1);
if int64(i) != i1 { if int64(i) != i1 {
if i1 < 0 { if i1 < 0 {
return -1<<(intsize-1), &NumError{s, os.ERANGE} return -1<<(IntSize-1), &NumError{s, os.ERANGE}
} }
return 1<<(intsize-1) - 1, &NumError{s, os.ERANGE} return 1<<(IntSize-1) - 1, &NumError{s, os.ERANGE}
} }
return i, nil return i, nil
} }

View file

@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package strconv package strconv_test
import ( import (
"fmt"; "fmt";
"os"; "os";
"reflect"; "reflect";
"strconv"; . "strconv";
"testing" "testing";
) )
type atoui64Test struct { type atoui64Test struct {
@ -151,9 +151,9 @@ func init() {
func TestAtoui64(t *testing.T) { func TestAtoui64(t *testing.T) {
for i := range atoui64tests { for i := range atoui64tests {
test := &atoui64tests[i]; test := &atoui64tests[i];
out, err := strconv.Atoui64(test.in); out, err := Atoui64(test.in);
if test.out != out || !reflect.DeepEqual(test.err, err) { if test.out != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("strconv.Atoui64(%q) = %v, %v want %v, %v\n", t.Errorf("Atoui64(%q) = %v, %v want %v, %v\n",
test.in, out, err, test.out, test.err); test.in, out, err, test.out, test.err);
} }
} }
@ -162,31 +162,31 @@ func TestAtoui64(t *testing.T) {
func TestAtoi64(t *testing.T) { func TestAtoi64(t *testing.T) {
for i := range atoi64tests { for i := range atoi64tests {
test := &atoi64tests[i]; test := &atoi64tests[i];
out, err := strconv.Atoi64(test.in); out, err := Atoi64(test.in);
if test.out != out || !reflect.DeepEqual(test.err, err) { if test.out != out || !reflect.DeepEqual(test.err, err) {
t.Errorf("strconv.Atoi64(%q) = %v, %v want %v, %v\n", t.Errorf("Atoi64(%q) = %v, %v want %v, %v\n",
test.in, out, err, test.out, test.err); test.in, out, err, test.out, test.err);
} }
} }
} }
func TestAtoui(t *testing.T) { func TestAtoui(t *testing.T) {
switch intsize { switch IntSize {
case 32: case 32:
for i := range atoui32tests { for i := range atoui32tests {
test := &atoui32tests[i]; test := &atoui32tests[i];
out, err := strconv.Atoui(test.in); out, err := Atoui(test.in);
if test.out != uint32(out) || !reflect.DeepEqual(test.err, err) { if test.out != uint32(out) || !reflect.DeepEqual(test.err, err) {
t.Errorf("strconv.Atoui(%q) = %v, %v want %v, %v\n", t.Errorf("Atoui(%q) = %v, %v want %v, %v\n",
test.in, out, err, test.out, test.err); test.in, out, err, test.out, test.err);
} }
} }
case 64: case 64:
for i := range atoui64tests { for i := range atoui64tests {
test := &atoui64tests[i]; test := &atoui64tests[i];
out, err := strconv.Atoui(test.in); out, err := Atoui(test.in);
if test.out != uint64(out) || !reflect.DeepEqual(test.err, err) { if test.out != uint64(out) || !reflect.DeepEqual(test.err, err) {
t.Errorf("strconv.Atoui(%q) = %v, %v want %v, %v\n", t.Errorf("Atoui(%q) = %v, %v want %v, %v\n",
test.in, out, err, test.out, test.err); test.in, out, err, test.out, test.err);
} }
} }
@ -194,22 +194,22 @@ func TestAtoui(t *testing.T) {
} }
func TestAtoi(t *testing.T) { func TestAtoi(t *testing.T) {
switch intsize { switch IntSize {
case 32: case 32:
for i := range atoi32tests { for i := range atoi32tests {
test := &atoi32tests[i]; test := &atoi32tests[i];
out, err := strconv.Atoi(test.in); out, err := Atoi(test.in);
if test.out != int32(out) || !reflect.DeepEqual(test.err, err) { if test.out != int32(out) || !reflect.DeepEqual(test.err, err) {
t.Errorf("strconv.Atoi(%q) = %v, %v want %v, %v\n", t.Errorf("Atoi(%q) = %v, %v want %v, %v\n",
test.in, out, err, test.out, test.err); test.in, out, err, test.out, test.err);
} }
} }
case 64: case 64:
for i := range atoi64tests { for i := range atoi64tests {
test := &atoi64tests[i]; test := &atoi64tests[i];
out, err := strconv.Atoi(test.in); out, err := Atoi(test.in);
if test.out != int64(out) || !reflect.DeepEqual(test.err, err) { if test.out != int64(out) || !reflect.DeepEqual(test.err, err) {
t.Errorf("strconv.Atoi(%q) = %v, %v want %v, %v\n", t.Errorf("Atoi(%q) = %v, %v want %v, %v\n",
test.in, out, err, test.out, test.err); test.in, out, err, test.out, test.err);
} }
} }

View file

@ -20,16 +20,6 @@ type decimal struct {
nd int; // number of digits used nd int; // number of digits used
dp int; // decimal point dp int; // decimal point
}; };
func (a *decimal) String() string;
func (a *decimal) Assign(v uint64);
func (a *decimal) Shift(k int) *decimal;
func (a *decimal) Round(nd int) *decimal;
func (a *decimal) RoundUp(nd int) *decimal;
func (a *decimal) RoundDown(nd int) *decimal;
func (a *decimal) RoundedInteger() uint64;
func digitZero(dst []byte) int;
func (a *decimal) String() string { func (a *decimal) String() string {
n := 10 + a.nd; n := 10 + a.nd;

View file

@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package strconv package strconv_test
import ( import (
"fmt"; "fmt";
"strconv"; . "strconv";
"testing"; "testing";
) )
@ -33,7 +33,7 @@ func TestDecimalShift(t *testing.T) {
ok := true; ok := true;
for i := 0; i < len(shifttests); i++ { for i := 0; i < len(shifttests); i++ {
test := &shifttests[i]; test := &shifttests[i];
s := strconv.newDecimal(test.i).Shift(test.shift).String(); s := NewDecimal(test.i).Shift(test.shift).String();
if s != test.out { if s != test.out {
t.Errorf("Decimal %v << %v = %v, want %v\n", t.Errorf("Decimal %v << %v = %v, want %v\n",
test.i, test.shift, s, test.out); test.i, test.shift, s, test.out);
@ -69,17 +69,17 @@ var roundtests = []roundTest {
func TestDecimalRound(t *testing.T) { func TestDecimalRound(t *testing.T) {
for i := 0; i < len(roundtests); i++ { for i := 0; i < len(roundtests); i++ {
test := &roundtests[i]; test := &roundtests[i];
s := strconv.newDecimal(test.i).RoundDown(test.nd).String(); s := NewDecimal(test.i).RoundDown(test.nd).String();
if s != test.down { if s != test.down {
t.Errorf("Decimal %v RoundDown %d = %v, want %v\n", t.Errorf("Decimal %v RoundDown %d = %v, want %v\n",
test.i, test.nd, s, test.down); test.i, test.nd, s, test.down);
} }
s = strconv.newDecimal(test.i).Round(test.nd).String(); s = NewDecimal(test.i).Round(test.nd).String();
if s != test.round { if s != test.round {
t.Errorf("Decimal %v Round %d = %v, want %v\n", t.Errorf("Decimal %v Round %d = %v, want %v\n",
test.i, test.nd, s, test.down); test.i, test.nd, s, test.down);
} }
s = strconv.newDecimal(test.i).RoundUp(test.nd).String(); s = NewDecimal(test.i).RoundUp(test.nd).String();
if s != test.up { if s != test.up {
t.Errorf("Decimal %v RoundUp %d = %v, want %v\n", t.Errorf("Decimal %v RoundUp %d = %v, want %v\n",
test.i, test.nd, s, test.up); test.i, test.nd, s, test.up);
@ -109,11 +109,10 @@ var roundinttests = []roundIntTest {
func TestDecimalRoundedInteger(t *testing.T) { func TestDecimalRoundedInteger(t *testing.T) {
for i := 0; i < len(roundinttests); i++ { for i := 0; i < len(roundinttests); i++ {
test := roundinttests[i]; test := roundinttests[i];
// TODO: should be able to use int := here. int := NewDecimal(test.i).Shift(test.shift).RoundedInteger();
int1 := strconv.newDecimal(test.i).Shift(test.shift).RoundedInteger(); if int != test.int {
if int1 != test.int {
t.Errorf("Decimal %v >> %v RoundedInteger = %v, want %v\n", t.Errorf("Decimal %v >> %v RoundedInteger = %v, want %v\n",
test.i, test.shift, int1, test.int); test.i, test.shift, int, test.int);
} }
} }
} }

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package strconv package strconv_test
import ( import (
"bufio"; "bufio";
"fmt"; "fmt";
@ -144,6 +144,5 @@ func TestFp(t *testing.T) {
t.Error("testfp.txt:", lineno, ": ", a[0], " ", a[1], " ", a[2], " (", v, ") ", t.Error("testfp.txt:", lineno, ": ", a[0], " ", a[1], " ", a[2], " (", v, ") ",
"want ", a[3], " got ", s); "want ", a[3], " got ", s);
} }
//else print("testfp.txt:", lineno, ": worked! ", s, "\n");
} }
} }

View file

@ -10,10 +10,7 @@
package strconv package strconv
import ( import "math"
"math";
"strconv";
)
// TODO: move elsewhere? // TODO: move elsewhere?
type floatInfo struct { type floatInfo struct {
@ -24,13 +21,6 @@ type floatInfo struct {
var float32info = floatInfo{ 23, 8, -127 } var float32info = floatInfo{ 23, 8, -127 }
var float64info = floatInfo{ 52, 11, -1023 } var float64info = floatInfo{ 52, 11, -1023 }
func fmtB(neg bool, mant uint64, exp int, flt *floatInfo) string
func fmtE(neg bool, d *decimal, prec int) string
func fmtF(neg bool, d *decimal, prec int) string
func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string
func max(a, b int) int
func roundShortest(d *decimal, mant uint64, exp int, flt *floatInfo)
func floatsize() int { func floatsize() int {
// Figure out whether float is float32 or float64. // Figure out whether float is float32 or float64.
// 1e-35 is representable in both, but 1e-70 // 1e-35 is representable in both, but 1e-70

View file

@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package strconv package strconv_test
import ( import (
"math"; "math";
"strconv"; . "strconv";
"testing" "testing";
) )
type ftoaTest struct { type ftoaTest struct {
@ -100,17 +100,17 @@ var ftoatests = []ftoaTest {
} }
func TestFtoa(t *testing.T) { func TestFtoa(t *testing.T) {
if strconv.FloatSize != 32 { if FloatSize != 32 {
panic("floatsize: ", strconv.FloatSize); panic("floatsize: ", FloatSize);
} }
for i := 0; i < len(ftoatests); i++ { for i := 0; i < len(ftoatests); i++ {
test := &ftoatests[i]; test := &ftoatests[i];
s := strconv.Ftoa64(test.f, test.fmt, test.prec); s := Ftoa64(test.f, test.fmt, test.prec);
if s != test.s { if s != test.s {
t.Error("test", test.f, string(test.fmt), test.prec, "want", test.s, "got", s); t.Error("test", test.f, string(test.fmt), test.prec, "want", test.s, "got", s);
} }
if float64(float32(test.f)) == test.f && test.fmt != 'b' { if float64(float32(test.f)) == test.f && test.fmt != 'b' {
s := strconv.Ftoa32(float32(test.f), test.fmt, test.prec); s := Ftoa32(float32(test.f), test.fmt, test.prec);
if s != test.s { if s != test.s {
t.Error("test32", test.f, string(test.fmt), test.prec, "want", test.s, "got", s); t.Error("test32", test.f, string(test.fmt), test.prec, "want", test.s, "got", s);
} }

View file

@ -0,0 +1,18 @@
// 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.
// export access to strconv internals for tests
package strconv
func NewDecimal(i uint64) *decimal {
return newDecimal(i);
}
func SetOptimize(b bool) bool {
old := optimize;
optimize = b;
return old;
}

View file

@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package strconv package strconv_test
import ( import (
"fmt"; "fmt";
"os"; "os";
"strconv"; . "strconv";
"testing"; "testing";
) )
@ -61,62 +61,62 @@ var itob64tests = []itob64Test {
func TestItoa(t *testing.T) { func TestItoa(t *testing.T) {
for i, test := range itob64tests { for i, test := range itob64tests {
s := strconv.Itob64(test.in, test.base); s := Itob64(test.in, test.base);
if s != test.out { if s != test.out {
t.Errorf("strconv.Itob64(%v, %v) = %v want %v\n", t.Errorf("Itob64(%v, %v) = %v want %v\n",
test.in, test.base, s, test.out); test.in, test.base, s, test.out);
} }
if test.in >= 0 { if test.in >= 0 {
s := strconv.Uitob64(uint64(test.in), test.base); s := Uitob64(uint64(test.in), test.base);
if s != test.out { if s != test.out {
t.Errorf("strconv.Uitob64(%v, %v) = %v want %v\n", t.Errorf("Uitob64(%v, %v) = %v want %v\n",
test.in, test.base, s, test.out); test.in, test.base, s, test.out);
} }
} }
if int64(int(test.in)) == test.in { if int64(int(test.in)) == test.in {
s := strconv.Itob(int(test.in), test.base); s := Itob(int(test.in), test.base);
if s != test.out { if s != test.out {
t.Errorf("strconv.Itob(%v, %v) = %v want %v\n", t.Errorf("Itob(%v, %v) = %v want %v\n",
test.in, test.base, s, test.out); test.in, test.base, s, test.out);
} }
if test.in >= 0 { if test.in >= 0 {
s := strconv.Uitob(uint(test.in), test.base); s := Uitob(uint(test.in), test.base);
if s != test.out { if s != test.out {
t.Errorf("strconv.Uitob(%v, %v) = %v want %v\n", t.Errorf("Uitob(%v, %v) = %v want %v\n",
test.in, test.base, s, test.out); test.in, test.base, s, test.out);
} }
} }
} }
if test.base == 10 { if test.base == 10 {
s := strconv.Itoa64(test.in); s := Itoa64(test.in);
if s != test.out { if s != test.out {
t.Errorf("strconv.Itoa64(%v) = %v want %v\n", t.Errorf("Itoa64(%v) = %v want %v\n",
test.in, s, test.out); test.in, s, test.out);
} }
if test.in >= 0 { if test.in >= 0 {
s := strconv.Uitob64(uint64(test.in), test.base); s := Uitob64(uint64(test.in), test.base);
if s != test.out { if s != test.out {
t.Errorf("strconv.Uitob64(%v, %v) = %v want %v\n", t.Errorf("Uitob64(%v, %v) = %v want %v\n",
test.in, test.base, s, test.out); test.in, test.base, s, test.out);
} }
} }
if int64(int(test.in)) == test.in { if int64(int(test.in)) == test.in {
s := strconv.Itoa(int(test.in)); s := Itoa(int(test.in));
if s != test.out { if s != test.out {
t.Errorf("strconv.Itoa(%v) = %v want %v\n", t.Errorf("Itoa(%v) = %v want %v\n",
test.in, s, test.out); test.in, s, test.out);
} }
if test.in >= 0 { if test.in >= 0 {
s := strconv.Uitoa(uint(test.in)); s := Uitoa(uint(test.in));
if s != test.out { if s != test.out {
t.Errorf("strconv.Uitoa(%v) = %v want %v\n", t.Errorf("Uitoa(%v) = %v want %v\n",
test.in, s, test.out); test.in, s, test.out);
} }
} }
@ -141,31 +141,31 @@ var uitob64tests = []uitob64Test {
func TestUitoa(t *testing.T) { func TestUitoa(t *testing.T) {
for i, test := range uitob64tests { for i, test := range uitob64tests {
s := strconv.Uitob64(test.in, test.base); s := Uitob64(test.in, test.base);
if s != test.out { if s != test.out {
t.Errorf("strconv.Uitob64(%v, %v) = %v want %v\n", t.Errorf("Uitob64(%v, %v) = %v want %v\n",
test.in, test.base, s, test.out); test.in, test.base, s, test.out);
} }
if uint64(uint(test.in)) == test.in { if uint64(uint(test.in)) == test.in {
s := strconv.Uitob(uint(test.in), test.base); s := Uitob(uint(test.in), test.base);
if s != test.out { if s != test.out {
t.Errorf("strconv.Uitob(%v, %v) = %v want %v\n", t.Errorf("Uitob(%v, %v) = %v want %v\n",
test.in, test.base, s, test.out); test.in, test.base, s, test.out);
} }
} }
if test.base == 10 { if test.base == 10 {
s := strconv.Uitoa64(test.in); s := Uitoa64(test.in);
if s != test.out { if s != test.out {
t.Errorf("strconv.Uitoa64(%v) = %v want %v\n", t.Errorf("Uitoa64(%v) = %v want %v\n",
test.in, s, test.out); test.in, s, test.out);
} }
if uint64(uint(test.in)) == test.in { if uint64(uint(test.in)) == test.in {
s := strconv.Uitoa(uint(test.in)); s := Uitoa(uint(test.in));
if s != test.out { if s != test.out {
t.Errorf("strconv.Uitoa(%v) = %v want %v\n", t.Errorf("Uitoa(%v) = %v want %v\n",
test.in, s, test.out); test.in, s, test.out);
} }
} }

View file

@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package strconv package strconv_test
import ( import (
"os"; "os";
"strconv"; . "strconv";
"testing"; "testing";
) )

View file

@ -2,60 +2,13 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m asm_${GOARCH}.s mutex.go >Makefile
D=
include $(GOROOT)/src/Make.$(GOARCH) include $(GOROOT)/src/Make.$(GOARCH)
AR=gopack
default: packages TARG=sync
GOFILES=\
mutex.go\
clean: OFILES=\
rm -rf *.[$(OS)] *.a [$(OS)].out _obj
test: packages
gotest
coverage: packages
gotest
6cov -g `pwd` | grep -v '_test\.go:'
%.$O: %.go
$(GC) -I_obj $*.go
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
O1=\
asm_$(GOARCH).$O\ asm_$(GOARCH).$O\
mutex.$O\
include $(GOROOT)/src/Make.pkg
phases: a1
_obj$D/sync.a: phases
a1: $(O1)
$(AR) grc _obj$D/sync.a asm_$(GOARCH).$O mutex.$O
rm -f $(O1)
newpkg: clean
mkdir -p _obj$D
$(AR) grc _obj$D/sync.a
$(O1): newpkg
$(O2): a1
nuke: clean
rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/sync.a
packages: _obj$D/sync.a
install: packages
test -d $(GOROOT)/pkg && mkdir -p $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D
cp _obj$D/sync.a $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/sync.a

View file

@ -0,0 +1,15 @@
// 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.
// expose internals for testing
package sync
func Semacquire(s *int32) {
semacquire(s)
}
func Semrelease(s *int32) {
semrelease(s)
}

View file

@ -4,17 +4,17 @@
// GOMAXPROCS=10 gotest // GOMAXPROCS=10 gotest
package sync package sync_test
import ( import (
"sync"; . "sync";
"testing" "testing"
) )
func HammerSemaphore(s *int32, cdone chan bool) { func HammerSemaphore(s *int32, cdone chan bool) {
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
semacquire(s); Semacquire(s);
semrelease(s); Semrelease(s);
} }
cdone <- true; cdone <- true;
} }

View file

@ -2,76 +2,13 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile
D=
include $(GOROOT)/src/Make.$(GOARCH) include $(GOROOT)/src/Make.$(GOARCH)
AR=gopack
default: packages TARG=time
GOFILES=\
sleep.go\
tick.go\
time.go\
zoneinfo.go\
clean: include $(GOROOT)/src/Make.pkg
rm -rf *.[$(OS)] *.a [$(OS)].out _obj
test: packages
gotest
coverage: packages
gotest
6cov -g `pwd` | grep -v '_test\.go:'
%.$O: %.go
$(GC) -I_obj $*.go
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
O1=\
sleep.$O\
zoneinfo.$O\
O2=\
time.$O\
O3=\
tick.$O\
phases: a1 a2 a3
_obj$D/time.a: phases
a1: $(O1)
$(AR) grc _obj$D/time.a sleep.$O zoneinfo.$O
rm -f $(O1)
a2: $(O2)
$(AR) grc _obj$D/time.a time.$O
rm -f $(O2)
a3: $(O3)
$(AR) grc _obj$D/time.a tick.$O
rm -f $(O3)
newpkg: clean
mkdir -p _obj$D
$(AR) grc _obj$D/time.a
$(O1): newpkg
$(O2): a1
$(O3): a2
$(O4): a3
nuke: clean
rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/time.a
packages: _obj$D/time.a
install: packages
test -d $(GOROOT)/pkg && mkdir -p $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D
cp _obj$D/time.a $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/time.a

View file

@ -6,7 +6,6 @@ package time
import ( import (
"syscall"; "syscall";
"time";
"unsafe"; "unsafe";
) )

View file

@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package time package time_test
import ( import (
"testing"; "testing";
"time"; . "time";
) )
func TestTick(t *testing.T) { func TestTick(t *testing.T) {

View file

@ -8,7 +8,6 @@ package time
import ( import (
"os"; "os";
"time"
) )
// Seconds reports the number of seconds since the Unix epoch, // Seconds reports the number of seconds since the Unix epoch,

View file

@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package time package time_test
import ( import (
"os"; "os";
"testing"; "testing";
"time"; . "time";
) )
func init() { func init() {

View file

@ -2,59 +2,10 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile
D=
include $(GOROOT)/src/Make.$(GOARCH) include $(GOROOT)/src/Make.$(GOARCH)
AR=gopack
default: packages TARG=utf8
GOFILES=\
utf8.go\
clean: include $(GOROOT)/src/Make.pkg
rm -rf *.[$(OS)] *.a [$(OS)].out _obj
test: packages
gotest
coverage: packages
gotest
6cov -g `pwd` | grep -v '_test\.go:'
%.$O: %.go
$(GC) -I_obj $*.go
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
O1=\
utf8.$O\
phases: a1
_obj$D/utf8.a: phases
a1: $(O1)
$(AR) grc _obj$D/utf8.a utf8.$O
rm -f $(O1)
newpkg: clean
mkdir -p _obj$D
$(AR) grc _obj$D/utf8.a
$(O1): newpkg
$(O2): a1
nuke: clean
rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/utf8.a
packages: _obj$D/utf8.a
install: packages
test -d $(GOROOT)/pkg && mkdir -p $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D
cp _obj$D/utf8.a $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/utf8.a

View file

@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package utf8 package utf8_test
import ( import (
"bytes"; "bytes";
"fmt"; "fmt";
"strings"; "strings";
"testing"; "testing";
"utf8"; . "utf8";
) )
type Utf8Map struct { type Utf8Map struct {
@ -56,19 +56,19 @@ func TestFullRune(t *testing.T) {
for i := 0; i < len(utf8map); i++ { for i := 0; i < len(utf8map); i++ {
m := utf8map[i]; m := utf8map[i];
b := makeBytes(m.str); b := makeBytes(m.str);
if !utf8.FullRune(b) { if !FullRune(b) {
t.Errorf("FullRune(%q) (rune %04x) = false, want true", b, m.rune); t.Errorf("FullRune(%q) (rune %04x) = false, want true", b, m.rune);
} }
s := m.str; s := m.str;
if !utf8.FullRuneInString(s) { if !FullRuneInString(s) {
t.Errorf("FullRuneInString(%q) (rune %04x) = false, want true", s, m.rune); t.Errorf("FullRuneInString(%q) (rune %04x) = false, want true", s, m.rune);
} }
b1 := b[0:len(b)-1]; b1 := b[0:len(b)-1];
if utf8.FullRune(b1) { if FullRune(b1) {
t.Errorf("FullRune(%q) = true, want false", b1); t.Errorf("FullRune(%q) = true, want false", b1);
} }
s1 := string(b1); s1 := string(b1);
if utf8.FullRuneInString(s1) { if FullRuneInString(s1) {
t.Errorf("FullRune(%q) = true, want false", s1); t.Errorf("FullRune(%q) = true, want false", s1);
} }
} }
@ -79,7 +79,7 @@ func TestEncodeRune(t *testing.T) {
m := utf8map[i]; m := utf8map[i];
b := makeBytes(m.str); b := makeBytes(m.str);
var buf [10]byte; var buf [10]byte;
n := utf8.EncodeRune(m.rune, &buf); n := EncodeRune(m.rune, &buf);
b1 := buf[0:n]; b1 := buf[0:n];
if !bytes.Equal(b, b1) { if !bytes.Equal(b, b1) {
t.Errorf("EncodeRune(0x%04x) = %q want %q", m.rune, b1, b); t.Errorf("EncodeRune(0x%04x) = %q want %q", m.rune, b1, b);
@ -91,23 +91,23 @@ func TestDecodeRune(t *testing.T) {
for i := 0; i < len(utf8map); i++ { for i := 0; i < len(utf8map); i++ {
m := utf8map[i]; m := utf8map[i];
b := makeBytes(m.str); b := makeBytes(m.str);
rune, size := utf8.DecodeRune(b); rune, size := DecodeRune(b);
if rune != m.rune || size != len(b) { if rune != m.rune || size != len(b) {
t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b, rune, size, m.rune, len(b)); t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b, rune, size, m.rune, len(b));
} }
s := m.str; s := m.str;
rune, size = utf8.DecodeRuneInString(s); rune, size = DecodeRuneInString(s);
if rune != m.rune || size != len(b) { if rune != m.rune || size != len(b) {
t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", s, rune, size, m.rune, len(b)); t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", s, rune, size, m.rune, len(b));
} }
// there's an extra byte that bytes left behind - make sure trailing byte works // there's an extra byte that bytes left behind - make sure trailing byte works
rune, size = utf8.DecodeRune(b[0:cap(b)]); rune, size = DecodeRune(b[0:cap(b)]);
if rune != m.rune || size != len(b) { if rune != m.rune || size != len(b) {
t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b, rune, size, m.rune, len(b)); t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b, rune, size, m.rune, len(b));
} }
s = m.str+"\x00"; s = m.str+"\x00";
rune, size = utf8.DecodeRuneInString(s); rune, size = DecodeRuneInString(s);
if rune != m.rune || size != len(b) { if rune != m.rune || size != len(b) {
t.Errorf("DecodeRuneInString(%q) = 0x%04x, %d want 0x%04x, %d", s, rune, size, m.rune, len(b)); t.Errorf("DecodeRuneInString(%q) = 0x%04x, %d want 0x%04x, %d", s, rune, size, m.rune, len(b));
} }
@ -117,12 +117,12 @@ func TestDecodeRune(t *testing.T) {
if wantsize >= len(b) { if wantsize >= len(b) {
wantsize = 0; wantsize = 0;
} }
rune, size = utf8.DecodeRune(b[0:len(b)-1]); rune, size = DecodeRune(b[0:len(b)-1]);
if rune != RuneError || size != wantsize { if rune != RuneError || size != wantsize {
t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b[0:len(b)-1], rune, size, RuneError, wantsize); t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b[0:len(b)-1], rune, size, RuneError, wantsize);
} }
s = m.str[0:len(m.str)-1]; s = m.str[0:len(m.str)-1];
rune, size = utf8.DecodeRuneInString(s); rune, size = DecodeRuneInString(s);
if rune != RuneError || size != wantsize { if rune != RuneError || size != wantsize {
t.Errorf("DecodeRuneInString(%q) = 0x%04x, %d want 0x%04x, %d", s, rune, size, RuneError, wantsize); t.Errorf("DecodeRuneInString(%q) = 0x%04x, %d want 0x%04x, %d", s, rune, size, RuneError, wantsize);
} }
@ -133,12 +133,12 @@ func TestDecodeRune(t *testing.T) {
} else { } else {
b[len(b)-1] = 0x7F; b[len(b)-1] = 0x7F;
} }
rune, size = utf8.DecodeRune(b); rune, size = DecodeRune(b);
if rune != RuneError || size != 1 { if rune != RuneError || size != 1 {
t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b, rune, size, RuneError, 1); t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b, rune, size, RuneError, 1);
} }
s = string(b); s = string(b);
rune, size = utf8.DecodeRune(b); rune, size = DecodeRune(b);
if rune != RuneError || size != 1 { if rune != RuneError || size != 1 {
t.Errorf("DecodeRuneInString(%q) = 0x%04x, %d want 0x%04x, %d", s, rune, size, RuneError, 1); t.Errorf("DecodeRuneInString(%q) = 0x%04x, %d want 0x%04x, %d", s, rune, size, RuneError, 1);
} }
@ -158,10 +158,10 @@ var runecounttests = []RuneCountTest {
func TestRuneCount(t *testing.T) { func TestRuneCount(t *testing.T) {
for i := 0; i < len(runecounttests); i++ { for i := 0; i < len(runecounttests); i++ {
tt := runecounttests[i]; tt := runecounttests[i];
if out := utf8.RuneCountInString(tt.in); out != tt.out { if out := RuneCountInString(tt.in); out != tt.out {
t.Errorf("RuneCountInString(%q) = %d, want %d", tt.in, out, tt.out); t.Errorf("RuneCountInString(%q) = %d, want %d", tt.in, out, tt.out);
} }
if out := utf8.RuneCount(makeBytes(tt.in)); out != tt.out { if out := RuneCount(makeBytes(tt.in)); out != tt.out {
t.Errorf("RuneCount(%q) = %d, want %d", tt.in, out, tt.out); t.Errorf("RuneCount(%q) = %d, want %d", tt.in, out, tt.out);
} }
} }