Commit efcf639f by Ian Lance Taylor Committed by Ian Lance Taylor

Update to current Go testsuite.

	* go.test/go-test.exp (filecmp): New procedure.
	(errchk): Handle quoted square brackets.
	(go-gc-tests): Set go_compile_args. Handle various new test
	lines.  Skip a few new tests.
	* lib/go-torture.exp (go-torture-execute): Use go_compile_args.

From-SVN: r183502
parent d1cab3a6
2012-01-24 Ian Lance Taylor <iant@google.com>
* go.test/go-test.exp (filecmp): New procedure.
(errchk): Handle quoted square brackets.
(go-gc-tests): Set go_compile_args. Handle various new test
lines. Skip a few new tests.
* lib/go-torture.exp (go-torture-execute): Use go_compile_args.
2012-01-24 Richard Sandiford <rdsandiford@googlemail.com> 2012-01-24 Richard Sandiford <rdsandiford@googlemail.com>
* lib/target-supports.exp (proc check_effective_target_vect_perm) * lib/target-supports.exp (proc check_effective_target_vect_perm)
......
// errchk $G -e $D/$F.go
// Copyright 2011 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 main
// Test that error messages say what the source file says
// (uint8 vs byte, int32 vs. rune).
import (
"fmt"
"unicode/utf8"
)
func f(byte) {}
func g(uint8) {}
func main() {
var x float64
f(x) // ERROR "byte"
g(x) // ERROR "uint8"
// Test across imports.
var ff fmt.Formatter
var fs fmt.State
ff.Format(fs, x) // ERROR "rune"
utf8.RuneStart(x) // ERROR "byte"
}
// $G $D/$F.go && $L $F.$A && ./$A.out
// Copyright 2011 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 main
// Test that dynamic interface checks treat byte=uint8
// and rune=int or rune=int32.
func main() {
var x interface{}
x = byte(1)
switch x.(type) {
case uint8:
// ok
default:
println("byte != uint8")
}
x = uint8(2)
switch x.(type) {
case byte:
// ok
default:
println("uint8 != byte")
}
rune32 := false
x = rune(3)
switch x.(type) {
case int:
// ok
case int32:
// must be new code
rune32 = true
default:
println("rune != int and rune != int32")
}
if rune32 {
x = int32(4)
} else {
x = int(5)
}
switch x.(type) {
case rune:
// ok
default:
println("int (or int32) != rune")
}
}
...@@ -63,6 +63,11 @@ var tests = []struct { ...@@ -63,6 +63,11 @@ var tests = []struct {
{"byte i", append([]byte{0, 1, 2}, []byte{3}...), []byte{0, 1, 2, 3}}, {"byte i", append([]byte{0, 1, 2}, []byte{3}...), []byte{0, 1, 2, 3}},
{"byte j", append([]byte{0, 1, 2}, []byte{3, 4, 5}...), []byte{0, 1, 2, 3, 4, 5}}, {"byte j", append([]byte{0, 1, 2}, []byte{3, 4, 5}...), []byte{0, 1, 2, 3, 4, 5}},
{"bytestr a", append([]byte{}, "0"...), []byte("0")},
{"bytestr b", append([]byte{}, "0123"...), []byte("0123")},
{"bytestr c", append([]byte("012"), "3"...), []byte("0123")},
{"bytestr d", append([]byte("012"), "345"...), []byte("012345")},
{"int16 a", append([]int16{}), []int16{}}, {"int16 a", append([]int16{}), []int16{}},
{"int16 b", append([]int16{}, 0), []int16{0}}, {"int16 b", append([]int16{}, 0), []int16{0}},
......
...@@ -2,23 +2,24 @@ ...@@ -2,23 +2,24 @@
# 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.
include ../../src/Make.inc include ../../../src/Make.inc
ALL=\ ALL=\
parser\ parser\
peano\ peano\
tree\ tree\
tree2\
all: $(addsuffix .out, $(ALL)) all: $(addsuffix .out, $(ALL))
%.$O: %.go stats.go %.$O: %.go stats.go
$(GC) $*.go stats.go $(GC) $(GCFLAGS) $(GCIMPORTS) $*.go stats.go
%.out: %.$O %.out: %.$O
$(LD) -o $@ $*.$O $(LD) -o $@ $*.$O
%.bench: %.out %.bench: %.out
./$*.out time ./$*.out
bench: $(addsuffix .bench, $(ALL)) bench: $(addsuffix .bench, $(ALL))
......
...@@ -12,27 +12,27 @@ import ( ...@@ -12,27 +12,27 @@ import (
"go/ast" "go/ast"
"go/parser" "go/parser"
"go/token" "go/token"
"log"
"net/http"
_ "net/http/pprof"
"os" "os"
"path" "path"
"runtime" "runtime"
"strings" "strings"
"time" "time"
"http"
_ "http/pprof"
"log"
) )
var serve = flag.String("serve", "", "serve http on this address at end") var serve = flag.String("serve", "", "serve http on this address at end")
func isGoFile(dir *os.FileInfo) bool { func isGoFile(dir os.FileInfo) bool {
return dir.IsRegular() && return !dir.IsDir() &&
!strings.HasPrefix(dir.Name, ".") && // ignore .files !strings.HasPrefix(dir.Name(), ".") && // ignore .files
path.Ext(dir.Name) == ".go" path.Ext(dir.Name()) == ".go"
} }
func isPkgFile(dir *os.FileInfo) bool { func isPkgFile(dir os.FileInfo) bool {
return isGoFile(dir) && return isGoFile(dir) &&
!strings.HasSuffix(dir.Name, "_test.go") // ignore test files !strings.HasSuffix(dir.Name(), "_test.go") // ignore test files
} }
func pkgName(filename string) string { func pkgName(filename string) string {
...@@ -49,7 +49,7 @@ func parseDir(dirpath string) map[string]*ast.Package { ...@@ -49,7 +49,7 @@ func parseDir(dirpath string) map[string]*ast.Package {
_, pkgname := path.Split(dirpath) _, pkgname := path.Split(dirpath)
// filter function to select the desired .go files // filter function to select the desired .go files
filter := func(d *os.FileInfo) bool { filter := func(d os.FileInfo) bool {
if isPkgFile(d) { if isPkgFile(d) {
// Some directories contain main packages: Only accept // Some directories contain main packages: Only accept
// files that belong to the expected package so that // files that belong to the expected package so that
...@@ -57,7 +57,7 @@ func parseDir(dirpath string) map[string]*ast.Package { ...@@ -57,7 +57,7 @@ func parseDir(dirpath string) map[string]*ast.Package {
// found" errors. // found" errors.
// Additionally, accept the special package name // Additionally, accept the special package name
// fakePkgName if we are looking at cmd documentation. // fakePkgName if we are looking at cmd documentation.
name := pkgName(dirpath + "/" + d.Name) name := pkgName(dirpath + "/" + d.Name())
return name == pkgname return name == pkgname
} }
return false return false
...@@ -66,17 +66,13 @@ func parseDir(dirpath string) map[string]*ast.Package { ...@@ -66,17 +66,13 @@ func parseDir(dirpath string) map[string]*ast.Package {
// get package AST // get package AST
pkgs, err := parser.ParseDir(token.NewFileSet(), dirpath, filter, parser.ParseComments) pkgs, err := parser.ParseDir(token.NewFileSet(), dirpath, filter, parser.ParseComments)
if err != nil { if err != nil {
println("parse", dirpath, err.String()) println("parse", dirpath, err.Error())
panic("fail") panic("fail")
} }
return pkgs return pkgs
} }
func main() { func main() {
runtime.GOMAXPROCS(4)
go func() {}()
go func() {}()
go func() {}()
st := &runtime.MemStats st := &runtime.MemStats
packages = append(packages, packages...) packages = append(packages, packages...)
packages = append(packages, packages...) packages = append(packages, packages...)
...@@ -86,7 +82,7 @@ func main() { ...@@ -86,7 +82,7 @@ func main() {
flag.Parse() flag.Parse()
var lastParsed []map[string]*ast.Package var lastParsed []map[string]*ast.Package
var t0 int64 var t0 time.Time
pkgroot := runtime.GOROOT() + "/src/pkg/" pkgroot := runtime.GOROOT() + "/src/pkg/"
for pass := 0; pass < 2; pass++ { for pass := 0; pass < 2; pass++ {
// Once the heap is grown to full size, reset counters. // Once the heap is grown to full size, reset counters.
...@@ -95,7 +91,7 @@ func main() { ...@@ -95,7 +91,7 @@ func main() {
// the average look much better than it actually is. // the average look much better than it actually is.
st.NumGC = 0 st.NumGC = 0
st.PauseTotalNs = 0 st.PauseTotalNs = 0
t0 = time.Nanoseconds() t0 = time.Now()
for i := 0; i < *n; i++ { for i := 0; i < *n; i++ {
parsed := make([]map[string]*ast.Package, *p) parsed := make([]map[string]*ast.Package, *p)
...@@ -109,7 +105,7 @@ func main() { ...@@ -109,7 +105,7 @@ func main() {
runtime.GC() runtime.GC()
runtime.GC() runtime.GC()
} }
t1 := time.Nanoseconds() t1 := time.Now()
fmt.Printf("Alloc=%d/%d Heap=%d Mallocs=%d PauseTime=%.3f/%d = %.3f\n", fmt.Printf("Alloc=%d/%d Heap=%d Mallocs=%d PauseTime=%.3f/%d = %.3f\n",
st.Alloc, st.TotalAlloc, st.Alloc, st.TotalAlloc,
...@@ -124,7 +120,7 @@ func main() { ...@@ -124,7 +120,7 @@ func main() {
} }
*/ */
// Standard gotest benchmark output, collected by build dashboard. // Standard gotest benchmark output, collected by build dashboard.
gcstats("BenchmarkParser", *n, t1-t0) gcstats("BenchmarkParser", *n, t1.Sub(t0))
if *serve != "" { if *serve != "" {
log.Fatal(http.ListenAndServe(*serve, nil)) log.Fatal(http.ListenAndServe(*serve, nil))
...@@ -132,23 +128,20 @@ func main() { ...@@ -132,23 +128,20 @@ func main() {
} }
} }
var packages = []string{ var packages = []string{
"archive/tar", "archive/tar",
"asn1", "encoding/asn1",
"big", "math/big",
"bufio", "bufio",
"bytes", "bytes",
"cmath", "math/cmplx",
"compress/flate", "compress/flate",
"compress/gzip", "compress/gzip",
"compress/zlib", "compress/zlib",
"container/heap", "container/heap",
"container/list", "container/list",
"container/ring", "container/ring",
"container/vector",
"crypto/aes", "crypto/aes",
"crypto/block",
"crypto/blowfish", "crypto/blowfish",
"crypto/hmac", "crypto/hmac",
"crypto/md4", "crypto/md4",
...@@ -167,20 +160,14 @@ var packages = []string{ ...@@ -167,20 +160,14 @@ var packages = []string{
"debug/macho", "debug/macho",
"debug/elf", "debug/elf",
"debug/gosym", "debug/gosym",
"debug/proc", "exp/ebnf",
"ebnf",
"encoding/ascii85", "encoding/ascii85",
"encoding/base64", "encoding/base64",
"encoding/binary", "encoding/binary",
"encoding/git85", "encoding/git85",
"encoding/hex", "encoding/hex",
"encoding/pem", "encoding/pem",
"exec", "os/exec",
"exp/datafmt",
"exp/draw",
"exp/eval",
"exp/iterable",
"expvar",
"flag", "flag",
"fmt", "fmt",
"go/ast", "go/ast",
...@@ -189,18 +176,18 @@ var packages = []string{ ...@@ -189,18 +176,18 @@ var packages = []string{
"go/printer", "go/printer",
"go/scanner", "go/scanner",
"go/token", "go/token",
"gob", "encoding/gob",
"hash", "hash",
"hash/adler32", "hash/adler32",
"hash/crc32", "hash/crc32",
"hash/crc64", "hash/crc64",
"http", "net/http",
"image", "image",
"image/jpeg", "image/jpeg",
"image/png", "image/png",
"io", "io",
"io/ioutil", "io/ioutil",
"json", "encoding/json",
"log", "log",
"math", "math",
"mime", "mime",
...@@ -209,29 +196,29 @@ var packages = []string{ ...@@ -209,29 +196,29 @@ var packages = []string{
"os/signal", "os/signal",
"patch", "patch",
"path", "path",
"rand", "math/rand",
"reflect", "reflect",
"regexp", "regexp",
"rpc", "net/rpc",
"runtime", "runtime",
"scanner", "text/scanner",
"sort", "sort",
"smtp", "net/smtp",
"strconv", "strconv",
"strings", "strings",
"sync", "sync",
"syscall", "syscall",
"syslog", "log/syslog",
"tabwriter", "text/tabwriter",
"template", "text/template",
"testing", "testing",
"testing/iotest", "testing/iotest",
"testing/quick", "testing/quick",
"testing/script", "testing/script",
"time", "time",
"unicode", "unicode",
"utf8", "unicode/utf8",
"utf16", "unicode/utf16",
"websocket", "websocket",
"xml", "encoding/xml",
} }
...@@ -12,31 +12,25 @@ import ( ...@@ -12,31 +12,25 @@ import (
"time" "time"
) )
type Number struct { type Number struct {
next *Number next *Number
} }
// ------------------------------------- // -------------------------------------
// Peano primitives // Peano primitives
func zero() *Number { return nil } func zero() *Number { return nil }
func is_zero(x *Number) bool { return x == nil } func is_zero(x *Number) bool { return x == nil }
func add1(x *Number) *Number { func add1(x *Number) *Number {
e := new(Number) e := new(Number)
e.next = x e.next = x
return e return e
} }
func sub1(x *Number) *Number { return x.next } func sub1(x *Number) *Number { return x.next }
func add(x, y *Number) *Number { func add(x, y *Number) *Number {
if is_zero(y) { if is_zero(y) {
return x return x
...@@ -45,7 +39,6 @@ func add(x, y *Number) *Number { ...@@ -45,7 +39,6 @@ func add(x, y *Number) *Number {
return add(add1(x), sub1(y)) return add(add1(x), sub1(y))
} }
func mul(x, y *Number) *Number { func mul(x, y *Number) *Number {
if is_zero(x) || is_zero(y) { if is_zero(x) || is_zero(y) {
return zero() return zero()
...@@ -54,7 +47,6 @@ func mul(x, y *Number) *Number { ...@@ -54,7 +47,6 @@ func mul(x, y *Number) *Number {
return add(mul(x, sub1(y)), x) return add(mul(x, sub1(y)), x)
} }
func fact(n *Number) *Number { func fact(n *Number) *Number {
if is_zero(n) { if is_zero(n) {
return add1(zero()) return add1(zero())
...@@ -63,7 +55,6 @@ func fact(n *Number) *Number { ...@@ -63,7 +55,6 @@ func fact(n *Number) *Number {
return mul(fact(sub1(n)), n) return mul(fact(sub1(n)), n)
} }
// ------------------------------------- // -------------------------------------
// Helpers to generate/count Peano integers // Helpers to generate/count Peano integers
...@@ -75,7 +66,6 @@ func gen(n int) *Number { ...@@ -75,7 +66,6 @@ func gen(n int) *Number {
return zero() return zero()
} }
func count(x *Number) int { func count(x *Number) int {
if is_zero(x) { if is_zero(x) {
return 0 return 0
...@@ -84,7 +74,6 @@ func count(x *Number) int { ...@@ -84,7 +74,6 @@ func count(x *Number) int {
return count(sub1(x)) + 1 return count(sub1(x)) + 1
} }
func check(x *Number, expected int) { func check(x *Number, expected int) {
var c = count(x) var c = count(x)
if c != expected { if c != expected {
...@@ -92,7 +81,6 @@ func check(x *Number, expected int) { ...@@ -92,7 +81,6 @@ func check(x *Number, expected int) {
} }
} }
// ------------------------------------- // -------------------------------------
// Test basic functionality // Test basic functionality
...@@ -117,19 +105,17 @@ func verify() { ...@@ -117,19 +105,17 @@ func verify() {
check(fact(gen(5)), 120) check(fact(gen(5)), 120)
} }
// ------------------------------------- // -------------------------------------
// Factorial // Factorial
func main() { func main() {
t0 := time.Nanoseconds() t0 := time.Now()
verify() verify()
for i := 0; i <= 9; i++ { for i := 0; i <= 9; i++ {
print(i, "! = ", count(fact(gen(i))), "\n") print(i, "! = ", count(fact(gen(i))), "\n")
} }
runtime.GC() runtime.GC()
t1 := time.Nanoseconds() t1 := time.Now()
gcstats("BenchmarkPeano", 1, t1-t0) gcstats("BenchmarkPeano", 1, t1.Sub(t0))
} }
...@@ -8,12 +8,13 @@ import ( ...@@ -8,12 +8,13 @@ import (
"fmt" "fmt"
"runtime" "runtime"
"sort" "sort"
"time"
) )
func gcstats(name string, n int, t int64) { func gcstats(name string, n int, t time.Duration) {
st := &runtime.MemStats st := &runtime.MemStats
fmt.Printf("garbage.%sMem Alloc=%d/%d Heap=%d NextGC=%d Mallocs=%d\n", name, st.Alloc, st.TotalAlloc, st.Sys, st.NextGC, st.Mallocs) fmt.Printf("garbage.%sMem Alloc=%d/%d Heap=%d NextGC=%d Mallocs=%d\n", name, st.Alloc, st.TotalAlloc, st.Sys, st.NextGC, st.Mallocs)
fmt.Printf("garbage.%s %d %d ns/op\n", name, n, t/int64(n)) fmt.Printf("garbage.%s %d %d ns/op\n", name, n, t.Nanoseconds()/int64(n))
fmt.Printf("garbage.%sLastPause 1 %d ns/op\n", name, st.PauseNs[(st.NumGC-1)%uint32(len(st.PauseNs))]) fmt.Printf("garbage.%sLastPause 1 %d ns/op\n", name, st.PauseNs[(st.NumGC-1)%uint32(len(st.PauseNs))])
fmt.Printf("garbage.%sPause %d %d ns/op\n", name, st.NumGC, int64(st.PauseTotalNs)/int64(st.NumGC)) fmt.Printf("garbage.%sPause %d %d ns/op\n", name, st.NumGC, int64(st.PauseTotalNs)/int64(st.NumGC))
nn := int(st.NumGC) nn := int(st.NumGC)
...@@ -22,13 +23,14 @@ func gcstats(name string, n int, t int64) { ...@@ -22,13 +23,14 @@ func gcstats(name string, n int, t int64) {
} }
t1, t2, t3, t4, t5 := tukey5(st.PauseNs[0:nn]) t1, t2, t3, t4, t5 := tukey5(st.PauseNs[0:nn])
fmt.Printf("garbage.%sPause5: %d %d %d %d %d\n", name, t1, t2, t3, t4, t5) fmt.Printf("garbage.%sPause5: %d %d %d %d %d\n", name, t1, t2, t3, t4, t5)
// fmt.Printf("garbage.%sScan: %v\n", name, st.ScanDist) // fmt.Printf("garbage.%sScan: %v\n", name, st.ScanDist)
} }
type T []uint64 type T []uint64
func (t T) Len() int { return len(t) }
func (t T) Swap(i, j int) { t[i], t[j] = t[j], t[i] } func (t T) Len() int { return len(t) }
func (t T) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t T) Less(i, j int) bool { return t[i] < t[j] } func (t T) Less(i, j int) bool { return t[i] < t[j] }
func tukey5(raw []uint64) (lo, q1, q2, q3, hi uint64) { func tukey5(raw []uint64) (lo, q1, q2, q3, hi uint64) {
......
...@@ -68,7 +68,7 @@ const minDepth = 4 ...@@ -68,7 +68,7 @@ const minDepth = 4
func main() { func main() {
flag.Parse() flag.Parse()
t0 := time.Nanoseconds() t0 := time.Now()
maxDepth := *n maxDepth := *n
if minDepth+2 > *n { if minDepth+2 > *n {
...@@ -93,8 +93,8 @@ func main() { ...@@ -93,8 +93,8 @@ func main() {
} }
fmt.Printf("long lived tree of depth %d\t check: %d\n", maxDepth, longLivedTree.itemCheck()) fmt.Printf("long lived tree of depth %d\t check: %d\n", maxDepth, longLivedTree.itemCheck())
t1 := time.Nanoseconds() t1 := time.Now()
// Standard gotest benchmark output, collected by build dashboard. // Standard gotest benchmark output, collected by build dashboard.
gcstats("BenchmarkTree", *n, t1-t0) gcstats("BenchmarkTree", *n, t1.Sub(t0))
} }
// Copyright 2012 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 main
import (
"flag"
"fmt"
"log"
"os"
"runtime"
"runtime/pprof"
"unsafe"
)
const BranchingFactor = 4
type Object struct {
child [BranchingFactor]*Object
}
var (
cpus = flag.Int("cpus", 1, "number of cpus to use")
heapsize = flag.Int64("heapsize", 100*1024*1024, "size of the heap in bytes")
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
lastPauseNs uint64 = 0
lastFree uint64 = 0
heap *Object
calls [20]int
numobjects int64
)
func buildHeap() {
objsize := int64(unsafe.Sizeof(Object{}))
heap, _ = buildTree(float64(objsize), float64(*heapsize), 0)
fmt.Printf("*** built heap: %.0f MB; (%d objects * %d bytes)\n",
float64(*heapsize)/1048576, numobjects, objsize)
}
func buildTree(objsize, size float64, depth int) (*Object, float64) {
calls[depth]++
x := &Object{}
numobjects++
subtreeSize := (size - objsize) / BranchingFactor
alloc := objsize
for i := 0; i < BranchingFactor && alloc < size; i++ {
c, n := buildTree(objsize, subtreeSize, depth+1)
x.child[i] = c
alloc += n
}
return x, alloc
}
func gc() {
runtime.GC()
runtime.UpdateMemStats()
pause := runtime.MemStats.PauseTotalNs
inuse := runtime.MemStats.Alloc
free := runtime.MemStats.TotalAlloc - inuse
fmt.Printf("gc pause: %8.3f ms; collect: %8.0f MB; heapsize: %8.0f MB\n",
float64(pause-lastPauseNs)/1e6,
float64(free-lastFree)/1048576,
float64(inuse)/1048576)
lastPauseNs = pause
lastFree = free
}
func main() {
flag.Parse()
buildHeap()
runtime.GOMAXPROCS(*cpus)
runtime.UpdateMemStats()
lastPauseNs = runtime.MemStats.PauseTotalNs
lastFree = runtime.MemStats.TotalAlloc - runtime.MemStats.Alloc
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
for i := 0; i < 10; i++ {
gc()
}
}
include $(GOROOT)/src/Make.inc
TARG=go1
GOFILES=\
dummy.go\
include $(GOROOT)/src/Make.pkg
This source diff could not be displayed because it is too large. You can view the blob instead.
package main
import target "go1"
import "testing"
import "regexp"
var tests = []testing.InternalTest{
}
var benchmarks = []testing.InternalBenchmark{
{"go1.BenchmarkBinaryTree17", target.BenchmarkBinaryTree17},
{"go1.BenchmarkFannkuch11", target.BenchmarkFannkuch11},
{"go1.BenchmarkGobDecode", target.BenchmarkGobDecode},
{"go1.BenchmarkGobEncode", target.BenchmarkGobEncode},
{"go1.BenchmarkGzip", target.BenchmarkGzip},
{"go1.BenchmarkGunzip", target.BenchmarkGunzip},
{"go1.BenchmarkJSONEncode", target.BenchmarkJSONEncode},
{"go1.BenchmarkJSONDecode", target.BenchmarkJSONDecode},
{"go1.BenchmarkRevcomp25M", target.BenchmarkRevcomp25M},
{"go1.BenchmarkTemplate", target.BenchmarkTemplate},
}
var examples = []testing.InternalExample{}
var matchPat string
var matchRe *regexp.Regexp
func matchString(pat, str string) (result bool, err error) {
if matchRe == nil || matchPat != pat {
matchPat = pat
matchRe, err = regexp.Compile(matchPat)
if err != nil {
return
}
}
return matchRe.MatchString(str), nil
}
func main() {
testing.Main(matchString, tests, benchmarks, examples)
}
// Copyright 2011 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.
// This benchmark, taken from the shootout, tests garbage collector
// performance by generating and discarding large binary trees.
package go1
import "testing"
type binaryNode struct {
item int
left, right *binaryNode
}
func bottomUpTree(item, depth int) *binaryNode {
if depth <= 0 {
return &binaryNode{item: item}
}
return &binaryNode{item, bottomUpTree(2*item-1, depth-1), bottomUpTree(2*item, depth-1)}
}
func (n *binaryNode) itemCheck() int {
if n.left == nil {
return n.item
}
return n.item + n.left.itemCheck() - n.right.itemCheck()
}
const minDepth = 4
func binarytree(n int) {
maxDepth := n
if minDepth+2 > n {
maxDepth = minDepth + 2
}
stretchDepth := maxDepth + 1
check := bottomUpTree(0, stretchDepth).itemCheck()
//fmt.Printf("stretch tree of depth %d\t check: %d\n", stretchDepth, check)
longLivedTree := bottomUpTree(0, maxDepth)
for depth := minDepth; depth <= maxDepth; depth += 2 {
iterations := 1 << uint(maxDepth-depth+minDepth)
check = 0
for i := 1; i <= iterations; i++ {
check += bottomUpTree(i, depth).itemCheck()
check += bottomUpTree(-i, depth).itemCheck()
}
//fmt.Printf("%d\t trees of depth %d\t check: %d\n", iterations*2, depth, check)
}
longLivedTree.itemCheck()
//fmt.Printf("long lived tree of depth %d\t check: %d\n", maxDepth, longLivedTree.itemCheck())
}
func BenchmarkBinaryTree17(b *testing.B) {
for i := 0; i < b.N; i++ {
binarytree(17)
}
}
package go1
// Nothing to see here: everything is in the _test files.
// Copyright 2011 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.
// This benchmark, taken from the shootout, tests array indexing
// and array bounds elimination performance.
package go1
import "testing"
func fannkuch(n int) int {
if n < 1 {
return 0
}
n1 := n - 1
perm := make([]int, n)
perm1 := make([]int, n)
count := make([]int, n)
for i := 0; i < n; i++ {
perm1[i] = i // initial (trivial) permutation
}
r := n
didpr := 0
flipsMax := 0
for {
if didpr < 30 {
didpr++
}
for ; r != 1; r-- {
count[r-1] = r
}
if perm1[0] != 0 && perm1[n1] != n1 {
flips := 0
for i := 1; i < n; i++ { // perm = perm1
perm[i] = perm1[i]
}
k := perm1[0] // cache perm[0] in k
for { // k!=0 ==> k>0
for i, j := 1, k-1; i < j; i, j = i+1, j-1 {
perm[i], perm[j] = perm[j], perm[i]
}
flips++
// Now exchange k (caching perm[0]) and perm[k]... with care!
j := perm[k]
perm[k] = k
k = j
if k == 0 {
break
}
}
if flipsMax < flips {
flipsMax = flips
}
}
for ; r < n; r++ {
// rotate down perm[0..r] by one
perm0 := perm1[0]
for i := 0; i < r; i++ {
perm1[i] = perm1[i+1]
}
perm1[r] = perm0
count[r]--
if count[r] > 0 {
break
}
}
if r == n {
return flipsMax
}
}
return 0
}
func BenchmarkFannkuch11(b *testing.B) {
for i := 0; i < b.N; i++ {
fannkuch(11)
}
}
// Copyright 2011 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 go1
// Not a benchmark; input for revcomp.
var fasta25m = fasta(25e6)
func fasta(n int) []byte {
out := make(fastaBuffer, 0, 11*n)
iub := []fastaAcid{
{prob: 0.27, sym: 'a'},
{prob: 0.12, sym: 'c'},
{prob: 0.12, sym: 'g'},
{prob: 0.27, sym: 't'},
{prob: 0.02, sym: 'B'},
{prob: 0.02, sym: 'D'},
{prob: 0.02, sym: 'H'},
{prob: 0.02, sym: 'K'},
{prob: 0.02, sym: 'M'},
{prob: 0.02, sym: 'N'},
{prob: 0.02, sym: 'R'},
{prob: 0.02, sym: 'S'},
{prob: 0.02, sym: 'V'},
{prob: 0.02, sym: 'W'},
{prob: 0.02, sym: 'Y'},
}
homosapiens := []fastaAcid{
{prob: 0.3029549426680, sym: 'a'},
{prob: 0.1979883004921, sym: 'c'},
{prob: 0.1975473066391, sym: 'g'},
{prob: 0.3015094502008, sym: 't'},
}
alu := []byte(
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA")
out.WriteString(">ONE Homo sapiens alu\n")
fastaRepeat(&out, alu, 2*n)
out.WriteString(">TWO IUB ambiguity codes\n")
fastaRandom(&out, iub, 3*n)
out.WriteString(">THREE Homo sapiens frequency\n")
fastaRandom(&out, homosapiens, 5*n)
return out
}
type fastaBuffer []byte
func (b *fastaBuffer) Flush() {
panic("flush")
}
func (b *fastaBuffer) WriteString(s string) {
p := b.NextWrite(len(s))
copy(p, s)
}
func (b *fastaBuffer) NextWrite(n int) []byte {
p := *b
if len(p)+n > cap(p) {
b.Flush()
p = *b
}
out := p[len(p) : len(p)+n]
*b = p[:len(p)+n]
return out
}
const fastaLine = 60
func fastaRepeat(out *fastaBuffer, alu []byte, n int) {
buf := append(alu, alu...)
off := 0
for n > 0 {
m := n
if m > fastaLine {
m = fastaLine
}
buf1 := out.NextWrite(m + 1)
copy(buf1, buf[off:])
buf1[m] = '\n'
if off += m; off >= len(alu) {
off -= len(alu)
}
n -= m
}
}
const (
fastaLookupSize = 4096
fastaLookupScale float64 = fastaLookupSize - 1
)
var fastaRand uint32 = 42
type fastaAcid struct {
sym byte
prob float64
cprob float64
next *fastaAcid
}
func fastaComputeLookup(acid []fastaAcid) *[fastaLookupSize]*fastaAcid {
var lookup [fastaLookupSize]*fastaAcid
var p float64
for i := range acid {
p += acid[i].prob
acid[i].cprob = p * fastaLookupScale
if i > 0 {
acid[i-1].next = &acid[i]
}
}
acid[len(acid)-1].cprob = 1.0 * fastaLookupScale
j := 0
for i := range lookup {
for acid[j].cprob < float64(i) {
j++
}
lookup[i] = &acid[j]
}
return &lookup
}
func fastaRandom(out *fastaBuffer, acid []fastaAcid, n int) {
const (
IM = 139968
IA = 3877
IC = 29573
)
lookup := fastaComputeLookup(acid)
for n > 0 {
m := n
if m > fastaLine {
m = fastaLine
}
buf := out.NextWrite(m + 1)
f := fastaLookupScale / IM
myrand := fastaRand
for i := 0; i < m; i++ {
myrand = (myrand*IA + IC) % IM
r := float64(int(myrand)) * f
a := lookup[int(r)]
for a.cprob < r {
a = a.next
}
buf[i] = a.sym
}
fastaRand = myrand
buf[m] = '\n'
n -= m
}
}
// Copyright 2011 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.
// This benchmark tests gob encoding and decoding performance.
package go1
import (
"bytes"
"encoding/gob"
"encoding/json"
"io/ioutil"
"log"
"reflect"
"testing"
)
var (
gobbytes []byte
gobdata *JSONResponse
)
func gobinit() {
// gobinit is called after json's init,
// because it uses jsondata.
gobdata = gobResponse(&jsondata)
var buf bytes.Buffer
if err := gob.NewEncoder(&buf).Encode(gobdata); err != nil {
panic(err)
}
gobbytes = buf.Bytes()
var r JSONResponse
if err := gob.NewDecoder(bytes.NewBuffer(gobbytes)).Decode(&r); err != nil {
panic(err)
}
if !reflect.DeepEqual(gobdata, &r) {
log.Printf("%v\n%v", jsondata, r)
b, _ := json.Marshal(&jsondata)
br, _ := json.Marshal(&r)
log.Printf("%s\n%s\n", b, br)
panic("gob: encode+decode lost data")
}
}
// gob turns [] into null, so make a copy of the data structure like that
func gobResponse(r *JSONResponse) *JSONResponse {
return &JSONResponse{gobNode(r.Tree), r.Username}
}
func gobNode(n *JSONNode) *JSONNode {
n1 := new(JSONNode)
*n1 = *n
if len(n1.Kids) == 0 {
n1.Kids = nil
} else {
for i, k := range n1.Kids {
n1.Kids[i] = gobNode(k)
}
}
return n1
}
func gobdec() {
if gobbytes == nil {
panic("gobdata not initialized")
}
var r JSONResponse
if err := gob.NewDecoder(bytes.NewBuffer(gobbytes)).Decode(&r); err != nil {
panic(err)
}
_ = r
}
func gobenc() {
if err := gob.NewEncoder(ioutil.Discard).Encode(&gobdata); err != nil {
panic(err)
}
}
func BenchmarkGobDecode(b *testing.B) {
b.SetBytes(int64(len(gobbytes)))
for i := 0; i < b.N; i++ {
gobdec()
}
}
func BenchmarkGobEncode(b *testing.B) {
b.SetBytes(int64(len(gobbytes)))
for i := 0; i < b.N; i++ {
gobenc()
}
}
// Copyright 2011 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.
// This benchmark tests gzip and gunzip performance.
package go1
import (
"bytes"
gz "compress/gzip"
"io"
"io/ioutil"
"testing"
)
var (
jsongunz = bytes.Repeat(jsonbytes, 10)
jsongz []byte
)
func init() {
var buf bytes.Buffer
c, err := gz.NewWriter(&buf)
if err != nil {
panic(err)
}
c.Write(jsongunz)
c.Close()
jsongz = buf.Bytes()
}
func gzip() {
c, err := gz.NewWriter(ioutil.Discard)
if err != nil {
panic(err)
}
if _, err := c.Write(jsongunz); err != nil {
panic(err)
}
if err := c.Close(); err != nil {
panic(err)
}
}
func gunzip() {
r, err := gz.NewReader(bytes.NewBuffer(jsongz))
if err != nil {
panic(err)
}
if _, err := io.Copy(ioutil.Discard, r); err != nil {
panic(err)
}
r.Close()
}
func BenchmarkGzip(b *testing.B) {
b.SetBytes(int64(len(jsongunz)))
for i := 0; i < b.N; i++ {
gzip()
}
}
func BenchmarkGunzip(b *testing.B) {
b.SetBytes(int64(len(jsongunz)))
for i := 0; i < b.N; i++ {
gunzip()
}
}
// Copyright 2011 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.
// This benchmark tests JSON encoding and decoding performance.
package go1
import (
"compress/bzip2"
"encoding/base64"
"encoding/json"
"io"
"io/ioutil"
"strings"
"testing"
)
var (
jsonbytes []byte
jsondata JSONResponse
)
func init() {
var r io.Reader
r = strings.NewReader(jsonbz2_base64)
r = base64.NewDecoder(base64.StdEncoding, r)
r = bzip2.NewReader(r)
b, err := ioutil.ReadAll(r)
if err != nil {
panic(err)
}
jsonbytes = b
if err := json.Unmarshal(jsonbytes, &jsondata); err != nil {
panic(err)
}
gobinit()
}
type JSONResponse struct {
Tree *JSONNode `json:"tree"`
Username string `json:"username"`
}
type JSONNode struct {
Name string `json:"name"`
Kids []*JSONNode `json:"kids"`
CLWeight float64 `json:"cl_weight"`
Touches int `json:"touches"`
MinT int64 `json:"min_t"`
MaxT int64 `json:"max_t"`
MeanT int64 `json:"mean_t"`
}
func jsondec() {
var r JSONResponse
if err := json.Unmarshal(jsonbytes, &r); err != nil {
panic(err)
}
_ = r
}
func jsonenc() {
buf, err := json.Marshal(&jsondata)
if err != nil {
panic(err)
}
_ = buf
}
func BenchmarkJSONEncode(b *testing.B) {
b.SetBytes(int64(len(jsonbytes)))
for i := 0; i < b.N; i++ {
jsonenc()
}
}
func BenchmarkJSONDecode(b *testing.B) {
b.SetBytes(int64(len(jsonbytes)))
for i := 0; i < b.N; i++ {
jsondec()
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
// Copyright 2011 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.
// This benchmark, taken from the shootout, tests array indexing
// and array bounds elimination performance.
package go1
import (
"bufio"
"bytes"
"io/ioutil"
"testing"
)
var revCompTable = [256]uint8{
'A': 'T', 'a': 'T',
'C': 'G', 'c': 'G',
'G': 'C', 'g': 'C',
'T': 'A', 't': 'A',
'U': 'A', 'u': 'A',
'M': 'K', 'm': 'K',
'R': 'Y', 'r': 'Y',
'W': 'W', 'w': 'W',
'S': 'S', 's': 'S',
'Y': 'R', 'y': 'R',
'K': 'M', 'k': 'M',
'V': 'B', 'v': 'B',
'H': 'D', 'h': 'D',
'D': 'H', 'd': 'H',
'B': 'V', 'b': 'V',
'N': 'N', 'n': 'N',
}
func revcomp(data []byte) {
in := bufio.NewReader(bytes.NewBuffer(data))
out := ioutil.Discard
buf := make([]byte, 1024*1024)
line, err := in.ReadSlice('\n')
for err == nil {
out.Write(line)
// Accumulate reversed complement in buf[w:]
nchar := 0
w := len(buf)
for {
line, err = in.ReadSlice('\n')
if err != nil || line[0] == '>' {
break
}
line = line[0 : len(line)-1]
nchar += len(line)
if len(line)+nchar/60+128 >= w {
nbuf := make([]byte, len(buf)*5)
copy(nbuf[len(nbuf)-len(buf):], buf)
w += len(nbuf) - len(buf)
buf = nbuf
}
// This loop is the bottleneck.
for _, c := range line {
w--
buf[w] = revCompTable[c]
}
}
// Copy down to beginning of buffer, inserting newlines.
// The loop left room for the newlines and 128 bytes of padding.
i := 0
for j := w; j < len(buf); j += 60 {
n := copy(buf[i:i+60], buf[j:])
buf[i+n] = '\n'
i += n + 1
}
out.Write(buf[0:i])
}
}
func BenchmarkRevcomp25M(b *testing.B) {
b.SetBytes(int64(len(fasta25m)))
for i := 0; i < b.N; i++ {
revcomp(fasta25m)
}
}
// Copyright 2011 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.
// This benchmark tests text/template throughput,
// converting a large data structure with a simple template.
package go1
import (
"bytes"
"io/ioutil"
"strings"
"testing"
"text/template"
)
// After removing \t and \n this generates identical output to
// json.Marshal, making it easy to test for correctness.
const tmplText = `
{
"tree":{{template "node" .Tree}},
"username":"{{.Username}}"
}
{{define "node"}}
{
"name":"{{.Name}}",
"kids":[
{{range $i, $k := .Kids}}
{{if $i}}
,
{{end}}
{{template "node" $k}}
{{end}}
],
"cl_weight":{{.CLWeight}},
"touches":{{.Touches}},
"min_t":{{.MinT}},
"max_t":{{.MaxT}},
"mean_t":{{.MeanT}}
}
{{end}}
`
func stripTabNL(r rune) rune {
if r == '\t' || r == '\n' {
return -1
}
return r
}
var tmpl = template.Must(template.New("main").Parse(strings.Map(stripTabNL, tmplText)))
func init() {
var buf bytes.Buffer
if err := tmpl.Execute(&buf, &jsondata); err != nil {
panic(err)
}
if !bytes.Equal(buf.Bytes(), jsonbytes) {
println(buf.Len(), len(jsonbytes))
panic("wrong output")
}
}
func tmplexec() {
if err := tmpl.Execute(ioutil.Discard, &jsondata); err != nil {
panic(err)
}
}
func BenchmarkTemplate(b *testing.B) {
b.SetBytes(int64(len(jsonbytes)))
for i := 0; i < b.N; i++ {
tmplexec()
}
}
...@@ -2,7 +2,7 @@ ...@@ -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.
include ../../src/Make.inc include ../../../src/Make.inc
all: all:
@echo "make clean or timing" @echo "make clean or timing"
......
...@@ -49,20 +49,20 @@ const ( ...@@ -49,20 +49,20 @@ const (
) )
var complement = [...]int{ var complement = [...]int{
red | red<<2: red, red | red<<2: red,
red | yellow<<2: blue, red | yellow<<2: blue,
red | blue<<2: yellow, red | blue<<2: yellow,
yellow | red<<2: blue, yellow | red<<2: blue,
yellow | yellow<<2: yellow, yellow | yellow<<2: yellow,
yellow | blue<<2: red, yellow | blue<<2: red,
blue | red<<2: yellow, blue | red<<2: yellow,
blue | yellow<<2: red, blue | yellow<<2: red,
blue | blue<<2: blue, blue | blue<<2: blue,
} }
var colname = [...]string{ var colname = [...]string{
blue: "blue", blue: "blue",
red: "red", red: "red",
yellow: "yellow", yellow: "yellow",
} }
......
...@@ -70,7 +70,7 @@ const ( ...@@ -70,7 +70,7 @@ const (
IA = 3877 IA = 3877
IC = 29573 IC = 29573
LookupSize = 4096 LookupSize = 4096
LookupScale float64 = LookupSize - 1 LookupScale float64 = LookupSize - 1
) )
...@@ -178,7 +178,6 @@ func main() { ...@@ -178,7 +178,6 @@ func main() {
Random(homosapiens, 5**n) Random(homosapiens, 5**n)
} }
type buffer []byte type buffer []byte
func (b *buffer) Flush() { func (b *buffer) Flush() {
......
...@@ -43,7 +43,6 @@ import ( ...@@ -43,7 +43,6 @@ import (
var max_solutions = flag.Int("n", 2100, "maximum number of solutions") var max_solutions = flag.Int("n", 2100, "maximum number of solutions")
func boolInt(b bool) int8 { func boolInt(b bool) int8 {
if b { if b {
return 1 return 1
...@@ -115,7 +114,6 @@ var piece_def = [10][4]int8{ ...@@ -115,7 +114,6 @@ var piece_def = [10][4]int8{
[4]int8{E, E, E, SW}, [4]int8{E, E, E, SW},
} }
/* To minimize the amount of work done in the recursive solve function below, /* To minimize the amount of work done in the recursive solve function below,
* I'm going to allocate enough space for all legal rotations of each piece * I'm going to allocate enough space for all legal rotations of each piece
* at each position on the board. That's 10 pieces x 50 board positions x * at each position on the board. That's 10 pieces x 50 board positions x
...@@ -138,7 +136,6 @@ func rotate(dir int8) int8 { return (dir + 2) % PIVOT } ...@@ -138,7 +136,6 @@ func rotate(dir int8) int8 { return (dir + 2) % PIVOT }
/* Returns the direction flipped on the horizontal axis */ /* Returns the direction flipped on the horizontal axis */
func flip(dir int8) int8 { return (PIVOT - dir) % PIVOT } func flip(dir int8) int8 { return (PIVOT - dir) % PIVOT }
/* Returns the new cell index from the specified cell in the /* Returns the new cell index from the specified cell in the
* specified direction. The index is only valid if the * specified direction. The index is only valid if the
* starting cell and direction have been checked by the * starting cell and direction have been checked by the
...@@ -322,7 +319,6 @@ func record_piece(piece int, minimum int8, first_empty int8, piece_mask uint64) ...@@ -322,7 +319,6 @@ func record_piece(piece int, minimum int8, first_empty int8, piece_mask uint64)
piece_counts[piece][minimum]++ piece_counts[piece][minimum]++
} }
/* Fill the entire board going cell by cell. If any cells are "trapped" /* Fill the entire board going cell by cell. If any cells are "trapped"
* they will be left alone. * they will be left alone.
*/ */
...@@ -351,7 +347,6 @@ func fill_contiguous_space(board []int8, index int8) { ...@@ -351,7 +347,6 @@ func fill_contiguous_space(board []int8, index int8) {
} }
} }
/* To thin the number of pieces, I calculate if any of them trap any empty /* To thin the number of pieces, I calculate if any of them trap any empty
* cells at the edges. There are only a handful of exceptions where the * cells at the edges. There are only a handful of exceptions where the
* the board can be solved with the trapped cells. For example: piece 8 can * the board can be solved with the trapped cells. For example: piece 8 can
...@@ -382,7 +377,6 @@ func has_island(cell []int8, piece int) bool { ...@@ -382,7 +377,6 @@ func has_island(cell []int8, piece int) bool {
return true return true
} }
/* Calculate all six rotations of the specified piece at the specified index. /* Calculate all six rotations of the specified piece at the specified index.
* We calculate only half of piece 3's rotations. This is because any solution * We calculate only half of piece 3's rotations. This is because any solution
* found has an identical solution rotated 180 degrees. Thus we can reduce the * found has an identical solution rotated 180 degrees. Thus we can reduce the
...@@ -417,7 +411,6 @@ func calc_pieces() { ...@@ -417,7 +411,6 @@ func calc_pieces() {
} }
} }
/* Calculate all 32 possible states for a 5-bit row and all rows that will /* Calculate all 32 possible states for a 5-bit row and all rows that will
* create islands that follow any of the 32 possible rows. These pre- * create islands that follow any of the 32 possible rows. These pre-
* calculated 5-bit rows will be used to find islands in a partially solved * calculated 5-bit rows will be used to find islands in a partially solved
...@@ -530,7 +523,6 @@ func calc_rows() { ...@@ -530,7 +523,6 @@ func calc_rows() {
} }
} }
/* Calculate islands while solving the board. /* Calculate islands while solving the board.
*/ */
func boardHasIslands(cell int8) int8 { func boardHasIslands(cell int8) int8 {
...@@ -545,7 +537,6 @@ func boardHasIslands(cell int8) int8 { ...@@ -545,7 +537,6 @@ func boardHasIslands(cell int8) int8 {
return bad_even_triple[current_triple] return bad_even_triple[current_triple]
} }
/* The recursive solve algorithm. Try to place each permutation in the upper- /* The recursive solve algorithm. Try to place each permutation in the upper-
* leftmost empty cell. Mark off available pieces as it goes along. * leftmost empty cell. Mark off available pieces as it goes along.
* Because the board is a bit mask, the piece number and bit mask must be saved * Because the board is a bit mask, the piece number and bit mask must be saved
......
...@@ -125,39 +125,39 @@ func (sys System) advance(dt float64) { ...@@ -125,39 +125,39 @@ func (sys System) advance(dt float64) {
var ( var (
jupiter = Body{ jupiter = Body{
x: 4.84143144246472090e+00, x: 4.84143144246472090e+00,
y: -1.16032004402742839e+00, y: -1.16032004402742839e+00,
z: -1.03622044471123109e-01, z: -1.03622044471123109e-01,
vx: 1.66007664274403694e-03 * daysPerYear, vx: 1.66007664274403694e-03 * daysPerYear,
vy: 7.69901118419740425e-03 * daysPerYear, vy: 7.69901118419740425e-03 * daysPerYear,
vz: -6.90460016972063023e-05 * daysPerYear, vz: -6.90460016972063023e-05 * daysPerYear,
mass: 9.54791938424326609e-04 * solarMass, mass: 9.54791938424326609e-04 * solarMass,
} }
saturn = Body{ saturn = Body{
x: 8.34336671824457987e+00, x: 8.34336671824457987e+00,
y: 4.12479856412430479e+00, y: 4.12479856412430479e+00,
z: -4.03523417114321381e-01, z: -4.03523417114321381e-01,
vx: -2.76742510726862411e-03 * daysPerYear, vx: -2.76742510726862411e-03 * daysPerYear,
vy: 4.99852801234917238e-03 * daysPerYear, vy: 4.99852801234917238e-03 * daysPerYear,
vz: 2.30417297573763929e-05 * daysPerYear, vz: 2.30417297573763929e-05 * daysPerYear,
mass: 2.85885980666130812e-04 * solarMass, mass: 2.85885980666130812e-04 * solarMass,
} }
uranus = Body{ uranus = Body{
x: 1.28943695621391310e+01, x: 1.28943695621391310e+01,
y: -1.51111514016986312e+01, y: -1.51111514016986312e+01,
z: -2.23307578892655734e-01, z: -2.23307578892655734e-01,
vx: 2.96460137564761618e-03 * daysPerYear, vx: 2.96460137564761618e-03 * daysPerYear,
vy: 2.37847173959480950e-03 * daysPerYear, vy: 2.37847173959480950e-03 * daysPerYear,
vz: -2.96589568540237556e-05 * daysPerYear, vz: -2.96589568540237556e-05 * daysPerYear,
mass: 4.36624404335156298e-05 * solarMass, mass: 4.36624404335156298e-05 * solarMass,
} }
neptune = Body{ neptune = Body{
x: 1.53796971148509165e+01, x: 1.53796971148509165e+01,
y: -2.59193146099879641e+01, y: -2.59193146099879641e+01,
z: 1.79258772950371181e-01, z: 1.79258772950371181e-01,
vx: 2.68067772490389322e-03 * daysPerYear, vx: 2.68067772490389322e-03 * daysPerYear,
vy: 1.62824170038242295e-03 * daysPerYear, vy: 1.62824170038242295e-03 * daysPerYear,
vz: -9.51592254519715870e-05 * daysPerYear, vz: -9.51592254519715870e-05 * daysPerYear,
mass: 5.15138902046611451e-05 * solarMass, mass: 5.15138902046611451e-05 * solarMass,
} }
sun = Body{ sun = Body{
......
...@@ -38,9 +38,9 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -38,9 +38,9 @@ POSSIBILITY OF SUCH DAMAGE.
package main package main
import ( import (
"big"
"flag" "flag"
"fmt" "fmt"
"math/big"
) )
var n = flag.Int("n", 27, "number of digits") var n = flag.Int("n", 27, "number of digits")
......
...@@ -39,8 +39,8 @@ import ( ...@@ -39,8 +39,8 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"runtime"
"regexp" "regexp"
"runtime"
) )
var variants = []string{ var variants = []string{
......
...@@ -52,7 +52,7 @@ func f(i int, in <-chan int, out chan<- int) { ...@@ -52,7 +52,7 @@ func f(i int, in <-chan int, out chan<- int) {
fmt.Printf("%d\n", i) fmt.Printf("%d\n", i)
os.Exit(0) os.Exit(0)
} }
out <- n-1 out <- n - 1
} }
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
set -e set -e
eval $(gomake --no-print-directory -f ../../src/Make.inc go-env) eval $(gomake --no-print-directory -f ../../../src/Make.inc go-env)
PATH=.:$PATH PATH=.:$PATH
havegccgo=false havegccgo=false
......
...@@ -101,6 +101,46 @@ func main() { ...@@ -101,6 +101,46 @@ func main() {
} }
h(a, b) h(a, b)
m()
}
type I interface {
M(_ int, y int)
}
type TI struct{}
func (TI) M(x int, y int) {
if x != y {
println("invalid M call:", x, y)
panic("bad M")
}
}
var fp = func(_ int, y int) {}
func init() {
fp = fp1
}
func fp1(x, y int) {
if x != y {
println("invalid fp1 call:", x, y)
panic("bad fp1")
}
}
func m() {
var i I
i = TI{}
i.M(1, 1)
i.M(2, 2)
fp(1, 1)
fp(2, 2)
} }
// useless but legal // useless but legal
...@@ -120,3 +160,4 @@ func _() { ...@@ -120,3 +160,4 @@ func _() {
func ff() { func ff() {
var _ int = 1 var _ int = 1
} }
// echo bug395 is broken # takes 90+ seconds to break
// # $G $D/$F.go || echo bug395
// Copyright 2011 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.
// Issue 1909
// Would OOM due to exponential recursion on Foo's expanded methodset in nodefmt
package test
type Foo interface {
Bar() interface {
Foo
}
Baz() interface {
Foo
}
Bug() interface {
Foo
}
}
...@@ -82,5 +82,4 @@ func main() { ...@@ -82,5 +82,4 @@ func main() {
// However, the result of the bug linked to at the top is that we'll // However, the result of the bug linked to at the top is that we'll
// end up panicking with: "throw: bad g->status in ready". // end up panicking with: "throw: bad g->status in ready".
recver(cmux) recver(cmux)
print("PASS\n")
} }
...@@ -279,5 +279,4 @@ func main() { ...@@ -279,5 +279,4 @@ func main() {
<-sync <-sync
} }
} }
print("PASS\n")
} }
...@@ -48,4 +48,11 @@ func main() { ...@@ -48,4 +48,11 @@ func main() {
case x := <-cs: // ERROR "receive" case x := <-cs: // ERROR "receive"
_ = x _ = x
} }
for _ = range cs {// ERROR "receive"
}
close(c)
close(cs)
close(cr) // ERROR "receive"
} }
// $G $D/$F.go && $L $F.$A && ./$A.out
// Copyright 2011 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.
// Test select when discarding a value.
package main
import "runtime"
func recv1(c <-chan int) {
<-c
}
func recv2(c <-chan int) {
select {
case <-c:
}
}
func recv3(c <-chan int) {
c2 := make(chan int)
select {
case <-c:
case <-c2:
}
}
func send1(recv func(<-chan int)) {
c := make(chan int)
go recv(c)
runtime.Gosched()
c <- 1
}
func send2(recv func(<-chan int)) {
c := make(chan int)
go recv(c)
runtime.Gosched()
select {
case c <- 1:
}
}
func send3(recv func(<-chan int)) {
c := make(chan int)
go recv(c)
runtime.Gosched()
c2 := make(chan int)
select {
case c <- 1:
case c2 <- 1:
}
}
func main() {
send1(recv1)
send2(recv1)
send3(recv1)
send1(recv2)
send2(recv2)
send3(recv2)
send1(recv3)
send2(recv3)
send3(recv3)
}
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
package main package main
import "runtime"
var c = make(chan int) var c = make(chan int)
func check(a []int) { func check(a []int) {
...@@ -77,6 +79,8 @@ func h() { ...@@ -77,6 +79,8 @@ func h() {
func newfunc() func(int) int { return func(x int) int { return x } } func newfunc() func(int) int { return func(x int) int { return x } }
func main() { func main() {
var fail bool
go f() go f()
check([]int{1, 4, 5, 4}) check([]int{1, 4, 5, 4})
...@@ -88,13 +92,26 @@ func main() { ...@@ -88,13 +92,26 @@ func main() {
go h() go h()
check([]int{100, 200, 101, 201, 500, 101, 201, 500}) check([]int{100, 200, 101, 201, 500, 101, 201, 500})
runtime.UpdateMemStats()
n0 := runtime.MemStats.Mallocs
x, y := newfunc(), newfunc() x, y := newfunc(), newfunc()
if x(1) != 1 || y(2) != 2 { if x(1) != 1 || y(2) != 2 {
println("newfunc returned broken funcs") println("newfunc returned broken funcs")
panic("fail") fail = true
}
runtime.UpdateMemStats()
if n0 != runtime.MemStats.Mallocs {
println("newfunc allocated unexpectedly")
fail = true
} }
ff(1) ff(1)
if fail {
panic("fail")
}
} }
func ff(x int) { func ff(x int) {
......
// $G $D/$F.go && $L $F.$A && ./$A.out
// 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 main
import "unsafe"
var global bool
func use(b bool) { global = b }
func stringptr(s string) uintptr { return *(*uintptr)(unsafe.Pointer(&s)) }
func isfalse(b bool) {
if b {
// stack will explain where
panic("wanted false, got true")
}
}
func istrue(b bool) {
if !b {
// stack will explain where
panic("wanted true, got false")
}
}
type T *int
func main() {
var a []int
var b map[string]int
var c string = "hello"
var d string = "hel" // try to get different pointer
d = d + "lo"
if stringptr(c) == stringptr(d) {
panic("compiler too smart -- got same string")
}
var e = make(chan int)
var ia interface{} = a
var ib interface{} = b
var ic interface{} = c
var id interface{} = d
var ie interface{} = e
// these comparisons are okay because
// string compare is okay and the others
// are comparisons where the types differ.
isfalse(ia == ib)
isfalse(ia == ic)
isfalse(ia == id)
isfalse(ib == ic)
isfalse(ib == id)
istrue(ic == id)
istrue(ie == ie)
istrue(ia != ib)
istrue(ia != ic)
istrue(ia != id)
istrue(ib != ic)
istrue(ib != id)
isfalse(ic != id)
isfalse(ie != ie)
// these are not okay, because there is no comparison on slices or maps.
//isfalse(a == ib)
//isfalse(a == ic)
//isfalse(a == id)
//isfalse(b == ic)
//isfalse(b == id)
istrue(c == id)
istrue(e == ie)
//isfalse(ia == b)
isfalse(ia == c)
isfalse(ia == d)
isfalse(ib == c)
isfalse(ib == d)
istrue(ic == d)
istrue(ie == e)
//istrue(a != ib)
//istrue(a != ic)
//istrue(a != id)
//istrue(b != ic)
//istrue(b != id)
isfalse(c != id)
isfalse(e != ie)
//istrue(ia != b)
istrue(ia != c)
istrue(ia != d)
istrue(ib != c)
istrue(ib != d)
isfalse(ic != d)
isfalse(ie != e)
// 6g used to let this go through as true.
var g uint64 = 123
var h int64 = 123
var ig interface{} = g
var ih interface{} = h
isfalse(ig == ih)
istrue(ig != ih)
// map of interface should use == on interface values,
// not memory.
var m = make(map[interface{}]int)
m[ic] = 1
m[id] = 2
if m[c] != 2 {
println("m[c] = ", m[c])
panic("bad m[c]")
}
// non-interface comparisons
{
c := make(chan int)
c1 := (<-chan int)(c)
c2 := (chan<- int)(c)
istrue(c == c1)
istrue(c == c2)
istrue(c1 == c)
istrue(c2 == c)
isfalse(c != c1)
isfalse(c != c2)
isfalse(c1 != c)
isfalse(c2 != c)
d := make(chan int)
isfalse(c == d)
isfalse(d == c)
isfalse(d == c1)
isfalse(d == c2)
isfalse(c1 == d)
isfalse(c2 == d)
istrue(c != d)
istrue(d != c)
istrue(d != c1)
istrue(d != c2)
istrue(c1 != d)
istrue(c2 != d)
}
// named types vs not
{
var x = new(int)
var y T
var z T = x
isfalse(x == y)
istrue(x == z)
isfalse(y == z)
isfalse(y == x)
istrue(z == x)
isfalse(z == y)
istrue(x != y)
isfalse(x != z)
istrue(y != z)
istrue(y != x)
isfalse(z != x)
istrue(z != y)
}
// structs
{
var x = struct {
x int
y string
}{1, "hi"}
var y = struct {
x int
y string
}{2, "bye"}
var z = struct {
x int
y string
}{1, "hi"}
isfalse(x == y)
isfalse(y == x)
isfalse(y == z)
isfalse(z == y)
istrue(x == z)
istrue(z == x)
istrue(x != y)
istrue(y != x)
istrue(y != z)
istrue(z != y)
isfalse(x != z)
isfalse(z != x)
var m = make(map[struct {
x int
y string
}]int)
m[x] = 10
m[y] = 20
m[z] = 30
istrue(m[x] == 30)
istrue(m[y] == 20)
istrue(m[z] == 30)
istrue(m[x] != 10)
isfalse(m[x] != 30)
isfalse(m[y] != 20)
isfalse(m[z] != 30)
isfalse(m[x] == 10)
var m1 = make(map[struct {
x int
y string
}]struct {
x int
y string
})
m1[x] = x
m1[y] = y
m1[z] = z
istrue(m1[x] == z)
istrue(m1[y] == y)
istrue(m1[z] == z)
istrue(m1[x] == x)
isfalse(m1[x] != z)
isfalse(m1[y] != y)
isfalse(m1[z] != z)
isfalse(m1[x] != x)
var ix, iy, iz interface{} = x, y, z
isfalse(ix == iy)
isfalse(iy == ix)
isfalse(iy == iz)
isfalse(iz == iy)
istrue(ix == iz)
istrue(iz == ix)
isfalse(x == iy)
isfalse(y == ix)
isfalse(y == iz)
isfalse(z == iy)
istrue(x == iz)
istrue(z == ix)
isfalse(ix == y)
isfalse(iy == x)
isfalse(iy == z)
isfalse(iz == y)
istrue(ix == z)
istrue(iz == x)
istrue(ix != iy)
istrue(iy != ix)
istrue(iy != iz)
istrue(iz != iy)
isfalse(ix != iz)
isfalse(iz != ix)
istrue(x != iy)
istrue(y != ix)
istrue(y != iz)
istrue(z != iy)
isfalse(x != iz)
isfalse(z != ix)
istrue(ix != y)
istrue(iy != x)
istrue(iy != z)
istrue(iz != y)
isfalse(ix != z)
isfalse(iz != x)
}
// arrays
{
var x = [2]string{"1", "hi"}
var y = [2]string{"2", "bye"}
var z = [2]string{"1", "hi"}
isfalse(x == y)
isfalse(y == x)
isfalse(y == z)
isfalse(z == y)
istrue(x == z)
istrue(z == x)
istrue(x != y)
istrue(y != x)
istrue(y != z)
istrue(z != y)
isfalse(x != z)
isfalse(z != x)
var m = make(map[[2]string]int)
m[x] = 10
m[y] = 20
m[z] = 30
istrue(m[x] == 30)
istrue(m[y] == 20)
istrue(m[z] == 30)
isfalse(m[x] != 30)
isfalse(m[y] != 20)
isfalse(m[z] != 30)
var ix, iy, iz interface{} = x, y, z
isfalse(ix == iy)
isfalse(iy == ix)
isfalse(iy == iz)
isfalse(iz == iy)
istrue(ix == iz)
istrue(iz == ix)
isfalse(x == iy)
isfalse(y == ix)
isfalse(y == iz)
isfalse(z == iy)
istrue(x == iz)
istrue(z == ix)
isfalse(ix == y)
isfalse(iy == x)
isfalse(iy == z)
isfalse(iz == y)
istrue(ix == z)
istrue(iz == x)
istrue(ix != iy)
istrue(iy != ix)
istrue(iy != iz)
istrue(iz != iy)
isfalse(ix != iz)
isfalse(iz != ix)
istrue(x != iy)
istrue(y != ix)
istrue(y != iz)
istrue(z != iy)
isfalse(x != iz)
isfalse(z != ix)
istrue(ix != y)
istrue(iy != x)
istrue(iy != z)
istrue(iz != y)
isfalse(ix != z)
isfalse(iz != x)
}
shouldPanic(p1)
shouldPanic(p2)
shouldPanic(p3)
shouldPanic(p4)
}
func p1() {
var a []int
var ia interface{} = a
use(ia == ia)
}
func p2() {
var b []int
var ib interface{} = b
use(ib == ib)
}
func p3() {
var a []int
var ia interface{} = a
var m = make(map[interface{}]int)
m[ia] = 1
}
func p4() {
var b []int
var ib interface{} = b
var m = make(map[interface{}]int)
m[ib] = 1
}
func shouldPanic(f func()) {
defer func() {
if recover() == nil {
panic("function should panic")
}
}()
f()
}
// $G $D/$F.go && $L $F.$A && ! ./$A.out
// 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 main
func use(bool) { }
func main() {
var a []int
var ia interface{} = a
use(ia == ia)
}
// $G $D/$F.go && $L $F.$A && ! ./$A.out
// 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 main
func use(bool) { }
func main() {
var b []int
var ib interface{} = b
use(ib == ib)
}
// $G $D/$F.go && $L $F.$A && ! ./$A.out
// 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 main
func main() {
var a []int
var ia interface{} = a
var m = make(map[interface{}] int)
m[ia] = 1
}
// $G $D/$F.go && $L $F.$A && ! ./$A.out
// 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 main
func main() {
var b []int
var ib interface{} = b
var m = make(map[interface{}] int)
m[ib] = 1
}
...@@ -31,6 +31,18 @@ func eq(a []*R) { ...@@ -31,6 +31,18 @@ func eq(a []*R) {
} }
} }
func teq(t *T, n int) {
for i := 0; i < n; i++ {
if t == nil || t.i != i {
panic("bad")
}
t = t.next
}
if t != nil {
panic("bad")
}
}
type P struct { type P struct {
a, b int a, b int
} }
...@@ -46,6 +58,9 @@ func main() { ...@@ -46,6 +58,9 @@ func main() {
var tp *T var tp *T
tp = &T{0, 7.2, "hi", &t} tp = &T{0, 7.2, "hi", &t}
tl := &T{i: 0, next: &T{i: 1, next: &T{i: 2, next: &T{i: 3, next: &T{i: 4}}}}}
teq(tl, 5)
a1 := []int{1, 2, 3} a1 := []int{1, 2, 3}
if len(a1) != 3 { if len(a1) != 3 {
panic("a1") panic("a1")
...@@ -93,6 +108,7 @@ func main() { ...@@ -93,6 +108,7 @@ func main() {
} }
eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)}) eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)})
eq([]*R{{0}, {1}, {2}, {3}, {4}, {5}})
p1 := NewP(1, 2) p1 := NewP(1, 2)
p2 := NewP(1, 2) p2 := NewP(1, 2)
......
// errchk $G -e $D/$F.go
// Copyright 2011 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 main
var m map[int][3]int
func f() [3]int
func fp() *[3]int
var mp map[int]*[3]int
var (
_ = [3]int{1, 2, 3}[:] // ERROR "slice of unaddressable value"
_ = m[0][:] // ERROR "slice of unaddressable value"
_ = f()[:] // ERROR "slice of unaddressable value"
// these are okay because they are slicing a pointer to an array
_ = (&[3]int{1, 2, 3})[:]
_ = mp[0][:]
_ = fp()[:]
)
type T struct {
i int
f float64
s string
next *T
}
var (
_ = &T{0, 0, "", nil} // ok
_ = &T{i: 0, f: 0, s: "", next: {}} // ERROR "missing type in composite literal|omit types within composite literal"
_ = &T{0, 0, "", {}} // ERROR "missing type in composite literal|omit types within composite literal"
)
// errchk $G -e $D/$F.go
// Copyright 2011 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 main
type Tbyte []byte
type Trune []rune
type Tint64 []int64
type Tstring string
func main() {
s := "hello"
sb := []byte("hello")
sr := []rune("hello")
si := []int64{'h', 'e', 'l', 'l', 'o'}
ts := Tstring(s)
tsb := Tbyte(sb)
tsr := Trune(sr)
tsi := Tint64(si)
_ = string(s)
_ = []byte(s)
_ = []rune(s)
_ = []int64(s) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
_ = Tstring(s)
_ = Tbyte(s)
_ = Trune(s)
_ = Tint64(s) // ERROR "cannot convert.*Tint64|invalid type conversion"
_ = string(sb)
_ = []byte(sb)
_ = []rune(sb) // ERROR "cannot convert.*\[\]rune|invalid type conversion"
_ = []int64(sb) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
_ = Tstring(sb)
_ = Tbyte(sb)
_ = Trune(sb) // ERROR "cannot convert.*Trune|invalid type conversion"
_ = Tint64(sb) // ERROR "cannot convert.*Tint64|invalid type conversion"
_ = string(sr)
_ = []byte(sr) // ERROR "cannot convert.*\[\]byte|invalid type conversion"
_ = []rune(sr)
_ = []int64(sr) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
_ = Tstring(sr)
_ = Tbyte(sr) // ERROR "cannot convert.*Tbyte|invalid type conversion"
_ = Trune(sr)
_ = Tint64(sr) // ERROR "cannot convert.*Tint64|invalid type conversion"
_ = string(si) // ERROR "cannot convert.* string|invalid type conversion"
_ = []byte(si) // ERROR "cannot convert.*\[\]byte|invalid type conversion"
_ = []rune(si) // ERROR "cannot convert.*\[\]rune|invalid type conversion"
_ = []int64(si)
_ = Tstring(si) // ERROR "cannot convert.*Tstring|invalid type conversion"
_ = Tbyte(si) // ERROR "cannot convert.*Tbyte|invalid type conversion"
_ = Trune(si) // ERROR "cannot convert.*Trune|invalid type conversion"
_ = Tint64(si)
_ = string(ts)
_ = []byte(ts)
_ = []rune(ts)
_ = []int64(ts) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
_ = Tstring(ts)
_ = Tbyte(ts)
_ = Trune(ts)
_ = Tint64(ts) // ERROR "cannot convert.*Tint64|invalid type conversion"
_ = string(tsb)
_ = []byte(tsb)
_ = []rune(tsb) // ERROR "cannot convert.*\[\]rune|invalid type conversion"
_ = []int64(tsb) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
_ = Tstring(tsb)
_ = Tbyte(tsb)
_ = Trune(tsb) // ERROR "cannot convert.*Trune|invalid type conversion"
_ = Tint64(tsb) // ERROR "cannot convert.*Tint64|invalid type conversion"
_ = string(tsr)
_ = []byte(tsr) // ERROR "cannot convert.*\[\]byte|invalid type conversion"
_ = []rune(tsr)
_ = []int64(tsr) // ERROR "cannot convert.*\[\]int64|invalid type conversion"
_ = Tstring(tsr)
_ = Tbyte(tsr) // ERROR "cannot convert.*Tbyte|invalid type conversion"
_ = Trune(tsr)
_ = Tint64(tsr) // ERROR "cannot convert.*Tint64|invalid type conversion"
_ = string(tsi) // ERROR "cannot convert.* string|invalid type conversion"
_ = []byte(tsi) // ERROR "cannot convert.*\[\]byte|invalid type conversion"
_ = []rune(tsi) // ERROR "cannot convert.*\[\]rune|invalid type conversion"
_ = []int64(tsi)
_ = Tstring(tsi) // ERROR "cannot convert.*Tstring|invalid type conversion"
_ = Tbyte(tsi) // ERROR "cannot convert.*Tbyte|invalid type conversion"
_ = Trune(tsi) // ERROR "cannot convert.*Trune|invalid type conversion"
_ = Tint64(tsi)
}
// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go &&
// $G tmp.go && $L tmp.$A && ./$A.out
// rm -f tmp.go
// Copyright 2011 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.
// Test source files and strings containing \r and \r\n.
package main
import (
"fmt"
"strings"
)
func main() {
prog = strings.Replace(prog, "BQ", "`", -1)
prog = strings.Replace(prog, "CR", "\r", -1)
fmt.Print(prog)
}
var prog = `
package main
CR
import "fmt"
var CR s = "hello\n" + CR
" world"CR
var t = BQhelloCR
worldBQ
var u = BQhCReCRlCRlCRoCR
worldBQ
var golden = "hello\n world"
func main() {
if s != golden {
fmt.Printf("s=%q, want %q", s, golden)
}
if t != golden {
fmt.Printf("t=%q, want %q", t, golden)
}
if u != golden {
fmt.Printf("u=%q, want %q", u, golden)
}
}
`
...@@ -15,8 +15,8 @@ var ( ...@@ -15,8 +15,8 @@ var (
_ = sum() _ = sum()
_ = sum(1.0, 2.0) _ = sum(1.0, 2.0)
_ = sum(1.5) // ERROR "integer" _ = sum(1.5) // ERROR "integer"
_ = sum("hello") // ERROR "string.*as type int|incompatible" _ = sum("hello") // ERROR ".hello. .type string. as type int|incompatible"
_ = sum([]int{1}) // ERROR "slice literal.*as type int|incompatible" _ = sum([]int{1}) // ERROR "\[\]int literal.*as type int|incompatible"
) )
type T []T type T []T
......
// $G $D/$F.go && $L $F.$A && ./$A.out // $G $D/$F.go && $L $F.$A && ./$A.out 2>&1 | cmp - $D/$F.out
// Copyright 2010 The Go Authors. All rights reserved. // Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
......
printing: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
42 true false true +1.500000e+000 world 0x0 [0/0]0x0 0x0 0x0 255
// $G $D/$F.go && $L $F.$A && ./$A.out
// Copyright 2011 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.
//line foo/bar.y:4
package main
//line foo/bar.y:60
func main() {
//line foo/bar.y:297
f, l := 0, 0
//line yacctab:1
f, l = 1, 1
//line yaccpar:1
f, l = 2, 1
//line foo/bar.y:82
f, l = 3, 82
//line foo/bar.y:90
f, l = 3, 90
//line foo/bar.y:92
f, l = 3, 92
//line foo/bar.y:100
f, l = 3, 100
//line foo/bar.y:104
l = 104
//line foo/bar.y:112
l = 112
//line foo/bar.y:117
l = 117
//line foo/bar.y:121
l = 121
//line foo/bar.y:125
l = 125
//line foo/bar.y:133
l = 133
//line foo/bar.y:146
l = 146
//line foo/bar.y:148
//line foo/bar.y:153
//line foo/bar.y:155
l = 155
//line foo/bar.y:160
//line foo/bar.y:164
//line foo/bar.y:173
//line foo/bar.y:178
//line foo/bar.y:180
//line foo/bar.y:185
//line foo/bar.y:195
//line foo/bar.y:197
//line foo/bar.y:202
//line foo/bar.y:204
//line foo/bar.y:208
//line foo/bar.y:211
//line foo/bar.y:213
//line foo/bar.y:215
//line foo/bar.y:217
//line foo/bar.y:221
//line foo/bar.y:229
//line foo/bar.y:236
//line foo/bar.y:238
//line foo/bar.y:240
//line foo/bar.y:244
//line foo/bar.y:249
//line foo/bar.y:253
//line foo/bar.y:257
//line foo/bar.y:262
//line foo/bar.y:267
//line foo/bar.y:272
if l == f {
//line foo/bar.y:277
panic("aie!")
//line foo/bar.y:281
}
//line foo/bar.y:285
return
//line foo/bar.y:288
//line foo/bar.y:290
}
//line foo/bar.y:293
//line foo/bar.y:295
// $G $D/$F.go $D/z*.go && $L $F.$A && ./$A.out
// 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 main
func main() {
F1()
F2()
F3()
F4()
F5()
F6()
F7()
F8()
F9()
F10()
F11()
F12()
F13()
F14()
F15()
F16()
F17()
F18()
F19()
F20()
}
//line x1.go:4
package main
func F1() {}
//line x10.go:4
package main
func F10() {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment