diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-04-26 09:55:32 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-04-26 09:55:32 +0200 |
commit | 7b15ed9ef455b6b66c6b376898a88aef5d6a9970 (patch) | |
tree | 3ef530baa80cdf29436ba981f5783be6b4d2202b /test | |
parent | 50104cc32a498f7517a51c8dc93106c51c7a54b4 (diff) | |
download | golang-7b15ed9ef455b6b66c6b376898a88aef5d6a9970.tar.gz |
Imported Upstream version 2011.04.13upstream/2011.04.13
Diffstat (limited to 'test')
47 files changed, 659 insertions, 209 deletions
diff --git a/test/bench/regex-dna-parallel.go b/test/bench/regex-dna-parallel.go index e8e62b806..1335e4d34 100644 --- a/test/bench/regex-dna-parallel.go +++ b/test/bench/regex-dna-parallel.go @@ -89,7 +89,7 @@ func countMatches(pat string, bytes []byte) int { func main() { runtime.GOMAXPROCS(4) - bytes, err := ioutil.ReadFile("/dev/stdin") + bytes, err := ioutil.ReadAll(os.Stdin) if err != nil { fmt.Fprintf(os.Stderr, "can't read input: %s\n", err) os.Exit(2) diff --git a/test/bench/regex-dna.go b/test/bench/regex-dna.go index dc31db768..042d7f283 100644 --- a/test/bench/regex-dna.go +++ b/test/bench/regex-dna.go @@ -87,7 +87,7 @@ func countMatches(pat string, bytes []byte) int { } func main() { - bytes, err := ioutil.ReadFile("/dev/stdin") + bytes, err := ioutil.ReadAll(os.Stdin) if err != nil { fmt.Fprintf(os.Stderr, "can't read input: %s\n", err) os.Exit(2) diff --git a/test/bugs/bug322.dir/main.go b/test/bugs/bug322.dir/main.go index a99ed3bc2..0ab5b32e4 100644 --- a/test/bugs/bug322.dir/main.go +++ b/test/bugs/bug322.dir/main.go @@ -19,8 +19,9 @@ func main() { t.M() t.PM() - var i1 I = t - i1.M() + // This is still an error. + // var i1 I = t + // i1.M() // This combination is illegal because // PM requires a pointer receiver. @@ -42,6 +43,5 @@ func main() { These should not be errors anymore: bug322.dir/main.go:19: implicit assignment of unexported field 'x' of lib.T in method receiver -bug322.dir/main.go:22: implicit assignment of unexported field 'x' of lib.T in assignment -bug322.dir/main.go:31: implicit assignment of unexported field 'x' of lib.T in method receiver -*/
\ No newline at end of file +bug322.dir/main.go:32: implicit assignment of unexported field 'x' of lib.T in method receiver +*/ diff --git a/test/bugs/bug324.dir/main.go b/test/bugs/bug324.dir/main.go index 37f2a59e4..4c1a18d9c 100644 --- a/test/bugs/bug324.dir/main.go +++ b/test/bugs/bug324.dir/main.go @@ -40,7 +40,7 @@ func main() { // x = px // this assignment unexpectedly compiles and then executes - x = px.(Exported) // ERROR "does not implement" + x = px.(Exported) // this is a legitimate call, but because of the previous assignment, // it invokes the method private in p! diff --git a/test/bugs/bug324.go b/test/bugs/bug324.go index 8b4e29200..e188515d7 100644 --- a/test/bugs/bug324.go +++ b/test/bugs/bug324.go @@ -1,4 +1,4 @@ -// $G $D/$F.dir/p.go && errchk $G $D/$F.dir/main.go +// $G $D/$F.dir/p.go && $G $D/$F.dir/main.go && $L main.$A && ! ./$A.out || echo BUG: should fail // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/chan/perm.go b/test/chan/perm.go index c725829d1..038ff94e3 100644 --- a/test/chan/perm.go +++ b/test/chan/perm.go @@ -22,21 +22,18 @@ func main() { c <- 0 // ok <-c // ok - //TODO(rsc): uncomment when this syntax is valid for receive+check closed - // x, ok := <-c // ok - // _, _ = x, ok + x, ok := <-c // ok + _, _ = x, ok cr <- 0 // ERROR "send" <-cr // ok - //TODO(rsc): uncomment when this syntax is valid for receive+check closed - // x, ok = <-cr // ok - // _, _ = x, ok + x, ok = <-cr // ok + _, _ = x, ok cs <- 0 // ok <-cs // ERROR "receive" - ////TODO(rsc): uncomment when this syntax is valid for receive+check closed - //// x, ok = <-cs // ERROR "receive" - //// _, _ = x, ok + x, ok = <-cs // ERROR "receive" + _, _ = x, ok select { case c <- 0: // ok diff --git a/test/chan/select3.go b/test/chan/select3.go index 47941063c..b4e8f8e4b 100644 --- a/test/chan/select3.go +++ b/test/chan/select3.go @@ -88,12 +88,16 @@ func main() { ch <- 7 }) - // receiving (a small number of times) from a closed channel never blocks + // receiving from a closed channel never blocks testBlock(never, func() { for i := 0; i < 10; i++ { if <-closedch != 0 { panic("expected zero value when reading from closed channel") } + if x, ok := <-closedch; x != 0 || ok { + println("closedch:", x, ok) + panic("expected 0, false from closed channel") + } } }) @@ -191,12 +195,24 @@ func main() { case <-closedch: } }) + testBlock(never, func() { + select { + case x := <-closedch: + _ = x + } + }) + testBlock(never, func() { + select { + case x, ok := <-closedch: + _, _ = x, ok + } + }) testPanic(always, func() { select { case closedch <- 7: } }) - + // select should not get confused if it sees itself testBlock(always, func() { c := make(chan int) diff --git a/test/closedchan.go b/test/closedchan.go index 46d9d0f5d..95314b334 100644 --- a/test/closedchan.go +++ b/test/closedchan.go @@ -4,7 +4,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Test close(c), closed(c). +// Test close(c), receive of closed channel. // // TODO(rsc): Doesn't check behavior of close(c) when there // are blocked senders/receivers. @@ -14,10 +14,11 @@ package main type Chan interface { Send(int) Nbsend(int) bool - Recv() int + Recv() (int) Nbrecv() (int, bool) + Recv2() (int, bool) + Nbrecv2() (int, bool, bool) Close() - Closed() bool Impl() string } @@ -52,12 +53,23 @@ func (c XChan) Nbrecv() (int, bool) { panic("nbrecv") } -func (c XChan) Close() { - close(c) +func (c XChan) Recv2() (int, bool) { + x, ok := <-c + return x, ok +} + +func (c XChan) Nbrecv2() (int, bool, bool) { + select { + case x, ok := <-c: + return x, ok, true + default: + return 0, false, false + } + panic("nbrecv2") } -func (c XChan) Closed() bool { - return closed(c) +func (c XChan) Close() { + close(c) } func (c XChan) Impl() string { @@ -101,12 +113,26 @@ func (c SChan) Nbrecv() (int, bool) { panic("nbrecv") } -func (c SChan) Close() { - close(c) +func (c SChan) Recv2() (int, bool) { + select { + case x, ok := <-c: + return x, ok + } + panic("recv") } -func (c SChan) Closed() bool { - return closed(c) +func (c SChan) Nbrecv2() (int, bool, bool) { + select { + default: + return 0, false, false + case x, ok := <-c: + return x, ok, true + } + panic("nbrecv") +} + +func (c SChan) Close() { + close(c) } func (c SChan) Impl() string { @@ -156,12 +182,28 @@ func (c SSChan) Nbrecv() (int, bool) { panic("nbrecv") } -func (c SSChan) Close() { - close(c) +func (c SSChan) Recv2() (int, bool) { + select { + case <-dummy: + case x, ok := <-c: + return x, ok + } + panic("recv") } -func (c SSChan) Closed() bool { - return closed(c) +func (c SSChan) Nbrecv2() (int, bool, bool) { + select { + case <-dummy: + default: + return 0, false, false + case x, ok := <-c: + return x, ok, true + } + panic("nbrecv") +} + +func (c SSChan) Close() { + close(c) } func (c SSChan) Impl() string { @@ -179,29 +221,23 @@ func shouldPanic(f func()) { } func test1(c Chan) { - // not closed until the close signal (a zero value) has been received. - if c.Closed() { - println("test1: Closed before Recv zero:", c.Impl()) - } - for i := 0; i < 3; i++ { // recv a close signal (a zero value) if x := c.Recv(); x != 0 { - println("test1: recv on closed got non-zero:", x, c.Impl()) + println("test1: recv on closed:", x, c.Impl()) } - - // should now be closed. - if !c.Closed() { - println("test1: not closed after recv zero", c.Impl()) + if x, ok := c.Recv2(); x != 0 || ok { + println("test1: recv2 on closed:", x, ok, c.Impl()) } - // should work with ,ok: received a value without blocking, so ok == true. - x, ok := c.Nbrecv() - if !ok { - println("test1: recv on closed got not ok", c.Impl()) + // should work with select: received a value without blocking, so selected == true. + x, selected := c.Nbrecv() + if x != 0 || !selected { + println("test1: recv on closed nb:", x, selected, c.Impl()) } - if x != 0 { - println("test1: recv ,ok on closed got non-zero:", x, c.Impl()) + x, ok, selected := c.Nbrecv2() + if x != 0 || ok || !selected { + println("test1: recv2 on closed nb:", x, ok, selected, c.Impl()) } } @@ -221,11 +257,6 @@ func test1(c Chan) { } func testasync1(c Chan) { - // not closed until the close signal (a zero value) has been received. - if c.Closed() { - println("testasync1: Closed before Recv zero:", c.Impl()) - } - // should be able to get the last value via Recv if x := c.Recv(); x != 1 { println("testasync1: Recv did not get 1:", x, c.Impl()) @@ -235,19 +266,31 @@ func testasync1(c Chan) { } func testasync2(c Chan) { - // not closed until the close signal (a zero value) has been received. - if c.Closed() { - println("testasync2: Closed before Recv zero:", c.Impl()) + // should be able to get the last value via Recv2 + if x, ok := c.Recv2(); x != 1 || !ok { + println("testasync1: Recv did not get 1, true:", x, ok, c.Impl()) } + test1(c) +} + +func testasync3(c Chan) { // should be able to get the last value via Nbrecv - if x, ok := c.Nbrecv(); !ok || x != 1 { - println("testasync2: Nbrecv did not get 1, true:", x, ok, c.Impl()) + if x, selected := c.Nbrecv(); x != 1 || !selected { + println("testasync2: Nbrecv did not get 1, true:", x, selected, c.Impl()) } test1(c) } +func testasync4(c Chan) { + // should be able to get the last value via Nbrecv2 + if x, ok, selected := c.Nbrecv2(); x != 1 || !ok || !selected { + println("testasync2: Nbrecv did not get 1, true, true:", x, ok, selected, c.Impl()) + } + test1(c) +} + func closedsync() chan int { c := make(chan int) close(c) @@ -261,15 +304,27 @@ func closedasync() chan int { return c } +var mks = []func(chan int) Chan { + func(c chan int) Chan { return XChan(c) }, + func(c chan int) Chan { return SChan(c) }, + func(c chan int) Chan { return SSChan(c) }, +} + +var testcloseds = []func(Chan) { + testasync1, + testasync2, + testasync3, + testasync4, +} + func main() { - test1(XChan(closedsync())) - test1(SChan(closedsync())) - test1(SSChan(closedsync())) - - testasync1(XChan(closedasync())) - testasync1(SChan(closedasync())) - testasync1(SSChan(closedasync())) - testasync2(XChan(closedasync())) - testasync2(SChan(closedasync())) - testasync2(SSChan(closedasync())) + for _, mk := range mks { + test1(mk(closedsync())) + } + + for _, testclosed := range testcloseds { + for _, mk := range mks { + testclosed(mk(closedasync())) + } + } } diff --git a/test/cmp6.go b/test/cmp6.go index 4c0601187..b3ea8ffeb 100644 --- a/test/cmp6.go +++ b/test/cmp6.go @@ -25,8 +25,8 @@ func main() { var c2 <-chan int var c3 chan int - use(c1 == c2) // ERROR "invalid operation" - use(c2 == c1) // ERROR "invalid operation" + use(c1 == c2) // ERROR "invalid operation|incompatible" + use(c2 == c1) // ERROR "invalid operation|incompatible" use(c1 == c3) use(c2 == c2) use(c3 == c1) @@ -37,13 +37,13 @@ func main() { var p2 T2 var p3 *int - use(p1 == p2) // ERROR "invalid operation" - use(p2 == p1) // ERROR "invalid operation" + use(p1 == p2) // ERROR "invalid operation|incompatible" + use(p2 == p1) // ERROR "invalid operation|incompatible" use(p1 == p3) use(p2 == p2) use(p3 == p1) use(p3 == p2) // Comparison of structs should have a good message - use(t3 == t3) // ERROR "struct" + use(t3 == t3) // ERROR "struct|expected" } diff --git a/test/ddd1.go b/test/ddd1.go index fcd32c282..a0bc73814 100644 --- a/test/ddd1.go +++ b/test/ddd1.go @@ -15,7 +15,7 @@ var ( _ = sum() _ = sum(1.0, 2.0) _ = sum(1.5) // ERROR "integer" - _ = sum("hello") // ERROR "convert|incompatible" + _ = sum("hello") // ERROR "string.*as type int|incompatible" _ = sum([]int{1}) // ERROR "slice literal.*as type int|incompatible" ) @@ -35,7 +35,6 @@ func bad(args ...int) { ch := make(chan int) close(ch...) // ERROR "[.][.][.]" _ = len(args...) // ERROR "[.][.][.]" - _ = closed(ch...) // ERROR "[.][.][.]" _ = new(int...) // ERROR "[.][.][.]" n := 10 _ = make([]byte, n...) // ERROR "[.][.][.]" diff --git a/test/env.go b/test/env.go index 16b207644..28113bcb0 100644 --- a/test/env.go +++ b/test/env.go @@ -6,7 +6,10 @@ package main -import os "os" +import ( + "os" + "runtime" +) func main() { ga, e0 := os.Getenverror("GOARCH") @@ -14,8 +17,8 @@ func main() { print("$GOARCH: ", e0.String(), "\n") os.Exit(1) } - if ga != "amd64" && ga != "386" && ga != "arm" { - print("$GOARCH=", ga, "\n") + if ga != runtime.GOARCH { + print("$GOARCH=", ga, "!= runtime.GOARCH=", runtime.GOARCH, "\n") os.Exit(1) } xxx, e1 := os.Getenverror("DOES_NOT_EXIST") diff --git a/test/fixedbugs/bug016.go b/test/fixedbugs/bug016.go index 1cdd8df08..4fbfd48fd 100644 --- a/test/fixedbugs/bug016.go +++ b/test/fixedbugs/bug016.go @@ -8,7 +8,7 @@ package main func main() { var i int = 100 - i = i << -3 // ERROR "overflows" + i = i << -3 // ERROR "overflows|negative" } /* diff --git a/test/fixedbugs/bug055.go b/test/fixedbugs/bug055.go index 0326d828f..861739610 100644 --- a/test/fixedbugs/bug055.go +++ b/test/fixedbugs/bug055.go @@ -7,16 +7,21 @@ package main func main() { - var i int; - var j int; - if true {} - { return } - i = 0; - if true {} else i++; - type s struct {}; - i = 0; - type s2 int; - var k = func (a int) int { return a+1 }(3); - _, _ = j, k; -ro: ; + var i int + var j int + if true { + } + { + return + } + i = 0 + if true { + } else { + i++ + } + type s struct{} + i = 0 + type s2 int + var k = func(a int) int { return a + 1 }(3) + _, _ = j, k } diff --git a/test/fixedbugs/bug069.go b/test/fixedbugs/bug069.go index bf7316313..9038387ac 100644 --- a/test/fixedbugs/bug069.go +++ b/test/fixedbugs/bug069.go @@ -7,15 +7,14 @@ package main func main() { - //TODO(rsc): uncomment when this syntax is valid for receive+check closed - // c := make(chan int); - // ok := false; - // var i int; - // - // i, ok = <-c; // works - // _, _ = i, ok; - // - // ca := new([2]chan int); - // i, ok = <-(ca[0]); // fails: c.go:11: bad shape across assignment - cr=1 cl=2 - // _, _ = i, ok; + c := make(chan int); + ok := false; + var i int; + + i, ok = <-c; // works + _, _ = i, ok; + + ca := new([2]chan int); + i, ok = <-(ca[0]); // fails: c.go:11: bad shape across assignment - cr=1 cl=2 + _, _ = i, ok; } diff --git a/test/fixedbugs/bug076.go b/test/fixedbugs/bug076.go index 065cecc01..2ca518d76 100644 --- a/test/fixedbugs/bug076.go +++ b/test/fixedbugs/bug076.go @@ -1,4 +1,4 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out +// $G $D/$F.go && $L $F.$A // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -7,12 +7,16 @@ package main func f() { -exit: ; +exit: + ; + goto exit } func main() { -exit: ; // this should be legal (labels not properly scoped?) +exit: + ; // this should be legal (labels not properly scoped?) + goto exit } /* diff --git a/test/fixedbugs/bug077.go b/test/fixedbugs/bug077.go index 08028ab10..2cbf96d98 100644 --- a/test/fixedbugs/bug077.go +++ b/test/fixedbugs/bug077.go @@ -7,7 +7,8 @@ package main func main() { - var exit int; + var exit int exit: - _ = exit; + _ = exit + goto exit } diff --git a/test/fixedbugs/bug081.go b/test/fixedbugs/bug081.go index 8d3d538c8..026ce8002 100644 --- a/test/fixedbugs/bug081.go +++ b/test/fixedbugs/bug081.go @@ -6,7 +6,7 @@ package main -const x x = 2 // ERROR "loop" +const x x = 2 // ERROR "loop|type" /* bug081.go:3: first constant must evaluate an expression diff --git a/test/fixedbugs/bug091.go b/test/fixedbugs/bug091.go index cfbb09cd8..c2ede7153 100644 --- a/test/fixedbugs/bug091.go +++ b/test/fixedbugs/bug091.go @@ -7,18 +7,19 @@ package main func f1() { - exit: - print("hi\n"); +exit: + print("hi\n") + goto exit } func f2() { - const c = 1234; + const c = 1234 } func f3() { - i := c; // ERROR "undef" + i := c // ERROR "undef" } func main() { - f3(); + f3() } diff --git a/test/fixedbugs/bug137.go b/test/fixedbugs/bug137.go index 152792411..9d43f431b 100644 --- a/test/fixedbugs/bug137.go +++ b/test/fixedbugs/bug137.go @@ -8,16 +8,21 @@ package main func main() { L1: -L2: for i := 0; i < 10; i++ { - print(i); - break L2; +L2: + for i := 0; i < 10; i++ { + print(i) + break L2 } -L3: ; -L4: for i := 0; i < 10; i++ { - print(i); - break L4; +L3: + ; +L4: + for i := 0; i < 10; i++ { + print(i) + break L4 } + goto L1 + goto L3 } /* diff --git a/test/fixedbugs/bug140.go b/test/fixedbugs/bug140.go index 298081663..e27b370e7 100644 --- a/test/fixedbugs/bug140.go +++ b/test/fixedbugs/bug140.go @@ -7,8 +7,17 @@ package main func main() { - if true {} else L1: ; - if true {} else L2: main() ; + if true { + } else { + L1: + } + if true { + } else { + L2: + main() + } + goto L1 + goto L2 } /* diff --git a/test/fixedbugs/bug177.go b/test/fixedbugs/bug177.go index 84ff59d2f..aec382388 100644 --- a/test/fixedbugs/bug177.go +++ b/test/fixedbugs/bug177.go @@ -5,23 +5,26 @@ // license that can be found in the LICENSE file. package main + import "reflect" -type S1 struct { i int } -type S2 struct { S1 } + +type S1 struct{ i int } +type S2 struct{ S1 } + func main() { - typ := reflect.Typeof(S2{}).(*reflect.StructType); - f := typ.Field(0); + typ := reflect.Typeof(S2{}) + f := typ.Field(0) if f.Name != "S1" || f.Anonymous != true { - println("BUG: ", f.Name, f.Anonymous); - return; + println("BUG: ", f.Name, f.Anonymous) + return } - f, ok := typ.FieldByName("S1"); + f, ok := typ.FieldByName("S1") if !ok { - println("BUG: missing S1"); - return; + println("BUG: missing S1") + return } if !f.Anonymous { - println("BUG: S1 is not anonymous"); - return; + println("BUG: S1 is not anonymous") + return } } diff --git a/test/fixedbugs/bug178.go b/test/fixedbugs/bug178.go index 4f586342b..205961024 100644 --- a/test/fixedbugs/bug178.go +++ b/test/fixedbugs/bug178.go @@ -9,19 +9,25 @@ package main func main() { L: for i := 0; i < 1; i++ { -L1: + L1: for { - break L; + break L } - panic("BUG: not reached - break"); + panic("BUG: not reached - break") } L2: for i := 0; i < 1; i++ { -L3: + L3: for { - continue L2; + continue L2 } - panic("BUG: not reached - continue"); + panic("BUG: not reached - continue") + } + if false { + goto L1 + } + if false { + goto L3 } } diff --git a/test/fixedbugs/bug179.go b/test/fixedbugs/bug179.go index 67548733c..3347613d8 100644 --- a/test/fixedbugs/bug179.go +++ b/test/fixedbugs/bug179.go @@ -10,16 +10,18 @@ func main() { L: for { for { - break L2; // ERROR "L2" - continue L2; // ERROR "L2" + break L2 // ERROR "L2" + continue L2 // ERROR "L2" } } L1: - x := 1; - _ = x; + x := 1 + _ = x for { - break L1; // ERROR "L1" - continue L1; // ERROR "L1" + break L1 // ERROR "L1" + continue L1 // ERROR "L1" } + + goto L } diff --git a/test/fixedbugs/bug196.go b/test/fixedbugs/bug196.go index 8cb9c9990..ea8ab0dc1 100644 --- a/test/fixedbugs/bug196.go +++ b/test/fixedbugs/bug196.go @@ -13,12 +13,11 @@ var i int func multi() (int, int) { return 1, 2 } func xxx() { - //TODO(rsc): uncomment when this syntax is valid for receive+check closed - // var c chan int - // x, ok := <-c + var c chan int + x, ok := <-c var m map[int]int - x, ok := m[1] + x, ok = m[1] var i interface{} var xx int diff --git a/test/fixedbugs/bug234.go b/test/fixedbugs/bug234.go index 9affad043..562109a05 100644 --- a/test/fixedbugs/bug234.go +++ b/test/fixedbugs/bug234.go @@ -7,17 +7,17 @@ package main func main() { - //TODO(rsc): uncomment when this syntax is valid for receive+check closed - // c := make(chan int, 1) - // c <- 100 - // x, ok := <-c - // if x != 100 || !ok { - // println("x=", x, " ok=", ok, " want 100, true") - // panic("fail") - // } - // x, ok = <-c - // if x != 0 || ok { - // println("x=", x, " ok=", ok, " want 0, false") - // panic("fail") - // } + c := make(chan int, 1) + c <- 100 + x, ok := <-c + if x != 100 || !ok { + println("x=", x, " ok=", ok, " want 100, true") + panic("fail") + } + close(c) + x, ok = <-c + if x != 0 || ok { + println("x=", x, " ok=", ok, " want 0, false") + panic("fail") + } } diff --git a/test/fixedbugs/bug242.go b/test/fixedbugs/bug242.go index ad1cef8df..839dccd37 100644 --- a/test/fixedbugs/bug242.go +++ b/test/fixedbugs/bug242.go @@ -101,13 +101,11 @@ func main() { c := make(chan byte, 1) c <- 'C' - //TODO(rsc): uncomment when this syntax is valid for receive+check closed // 15 16 - // *f(), p1 = <-e1(c, 16) - *f(), p1 = <-e1(c, 16), true // delete uncommenting above + *f(), p1 = <-e1(c, 16) + close(c) // 17 18 - // *f(), p2 = <-e1(c, 18) - *f(), p2, _ = 0, false, e1(c, 18) // delete when uncommenting above + *f(), p2 = <-e1(c, 18) a[17] += '0' if !p1 || p2 { println("bad chan check", i, p1, p2) diff --git a/test/fixedbugs/bug243.go b/test/fixedbugs/bug243.go index 236c14402..0c531968e 100644 --- a/test/fixedbugs/bug243.go +++ b/test/fixedbugs/bug243.go @@ -6,12 +6,14 @@ package main -import ( - "net" -) +import "os" + +// Issue 481: closures and var declarations +// with multiple variables assigned from one +// function call. func main() { - var listen, _ = net.Listen("tcp", "127.0.0.1:0") + var listen, _ = Listen("tcp", "127.0.0.1:0") go func() { for { @@ -20,6 +22,31 @@ func main() { } }() - var conn, _ = net.Dial("tcp", "", listen.Addr().String()) + var conn, _ = Dial("tcp", "", listen.Addr().String()) _ = conn } + +// Simulated net interface to exercise bug +// without involving a real network. +type T chan int + +var global T + +func Listen(x, y string) (T, string) { + global = make(chan int) + return global, y +} + +func (t T) Addr() os.Error { + return os.ErrorString("stringer") +} + +func (t T) Accept() (int, string) { + return <-t, "" +} + +func Dial(x, y, z string) (int, string) { + global <- 1 + return 0, "" +} + diff --git a/test/fixedbugs/bug252.go b/test/fixedbugs/bug252.go index 5615f84fa..a2c1dab9d 100644 --- a/test/fixedbugs/bug252.go +++ b/test/fixedbugs/bug252.go @@ -7,9 +7,9 @@ package main func f(args ...int) { - g(args) // ERROR "[.][.][.]" + g(args) } func g(args ...interface{}) { - f(args) // ERROR "[.][.][.]" + f(args) // ERROR "cannot use|incompatible" } diff --git a/test/fixedbugs/bug274.go b/test/fixedbugs/bug274.go index 621f31eed..348aed429 100644 --- a/test/fixedbugs/bug274.go +++ b/test/fixedbugs/bug274.go @@ -24,6 +24,7 @@ func main() { case 1: L1: // ERROR "statement" default: - L2: // correct since no semicolon is required before a '}' + // correct since no semicolon is required before a '}' + L2: // GCCGO_ERROR "not used" } } diff --git a/test/fixedbugs/bug323.go b/test/fixedbugs/bug323.go index bfb528318..23e2be660 100644 --- a/test/fixedbugs/bug323.go +++ b/test/fixedbugs/bug323.go @@ -15,6 +15,6 @@ func (t T) Meth2() {} func main() { t := &T{} p := P(t) - p.Meth() // ERROR "undefined \(type P" - p.Meth2() // ERROR "undefined \(type P" -}
\ No newline at end of file + p.Meth() // ERROR "undefined" + p.Meth2() // ERROR "undefined" +} diff --git a/test/fixedbugs/bug325.go b/test/fixedbugs/bug325.go index 23dbc8b3c..b86740fff 100644 --- a/test/fixedbugs/bug325.go +++ b/test/fixedbugs/bug325.go @@ -11,4 +11,5 @@ import "unsafe" func main() { var x unsafe.Pointer println(*x) // ERROR "invalid indirect.*unsafe.Pointer" + var _ = (unsafe.Pointer)(nil).foo // ERROR "foo" } diff --git a/test/fixedbugs/bug326.go b/test/fixedbugs/bug326.go new file mode 100644 index 000000000..efdd0ef71 --- /dev/null +++ b/test/fixedbugs/bug326.go @@ -0,0 +1,41 @@ +// errchk $G $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 p + +import "os" + +func f() (_ int, err os.Error) { + return +} + +func g() (x int, _ os.Error) { + return +} + +func h() (_ int, _ os.Error) { + return +} + +func i() (int, os.Error) { + return // ERROR "not enough arguments to return" +} + +func f1() (_ int, err os.Error) { + return 1, nil +} + +func g1() (x int, _ os.Error) { + return 1, nil +} + +func h1() (_ int, _ os.Error) { + return 1, nil +} + +func ii() (int, os.Error) { + return 1, nil +} diff --git a/test/fixedbugs/bug327.go b/test/fixedbugs/bug327.go new file mode 100644 index 000000000..4ba5f6072 --- /dev/null +++ b/test/fixedbugs/bug327.go @@ -0,0 +1,24 @@ +// $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. + +// Conversion between identical interfaces. +// Issue 1647. + +// The compiler used to not realize this was a no-op, +// so it generated a call to the non-existent function runtime.convE2E. + +package main + +type ( + a interface{} + b interface{} +) + +func main() { + x := a(1) + z := b(x) + _ = z +} diff --git a/test/func6.go b/test/func6.go new file mode 100644 index 000000000..1356b6aa8 --- /dev/null +++ b/test/func6.go @@ -0,0 +1,14 @@ +// $G $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 + +func main() { + if func() bool { return true }() {} // 6g used to say this was a syntax error + if (func() bool { return true })() {} + if (func() bool { return true }()) {} +} + diff --git a/test/gc2.go b/test/gc2.go new file mode 100644 index 000000000..c5c6cbe4b --- /dev/null +++ b/test/gc2.go @@ -0,0 +1,41 @@ +// $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. + +// Check that buffered channels are garbage collected properly. +// An interesting case because they have finalizers and used to +// have self loops that kept them from being collected. +// (Cyclic data with finalizers is never finalized, nor collected.) + +package main + +import ( + "fmt" + "os" + "runtime" +) + +func main() { + const N = 10000 + st := runtime.MemStats + for i := 0; i < N; i++ { + c := make(chan int, 10) + _ = c + if i%100 == 0 { + for j := 0; j < 4; j++ { + runtime.GC() + runtime.Gosched() + runtime.GC() + runtime.Gosched() + } + } + } + + obj := runtime.MemStats.HeapObjects - st.HeapObjects + if obj > N/5 { + fmt.Println("too many objects left:", obj) + os.Exit(1) + } +} diff --git a/test/golden.out b/test/golden.out index cc699d450..f76db3e50 100644 --- a/test/golden.out +++ b/test/golden.out @@ -161,9 +161,10 @@ panic: interface conversion: interface is main.T, not main.T =========== bugs/bug322.go bugs/bug322.dir/main.go:19: implicit assignment of unexported field 'x' of lib.T in method receiver -bugs/bug322.dir/main.go:22: implicit assignment of unexported field 'x' of lib.T in assignment -bugs/bug322.dir/main.go:31: implicit assignment of unexported field 'x' of lib.T in method receiver +bugs/bug322.dir/main.go:32: implicit assignment of unexported field 'x' of lib.T in method receiver BUG: fails incorrectly =========== bugs/bug324.go -BUG: errchk: command succeeded unexpectedly +main.Implementation.private() +p.Implementation.private() +BUG: should fail diff --git a/test/init.go b/test/init.go index b6c8c9706..74c2d5c26 100644 --- a/test/init.go +++ b/test/init.go @@ -12,7 +12,7 @@ func init() { } func main() { - init() // ERROR "undefined: init" + init() // ERROR "undefined.*init" runtime.init() // ERROR "unexported.*runtime\.init" - var _ = init // ERROR "undefined: init" + var _ = init // ERROR "undefined.*init" } diff --git a/test/interface/fake.go b/test/interface/fake.go index 5cf3be052..de8505d8d 100644 --- a/test/interface/fake.go +++ b/test/interface/fake.go @@ -46,34 +46,34 @@ func main() { x.t = add("abc", "def") x.u = 1 x.v = 2 - x.w = 1<<28 - x.x = 2<<28 + x.w = 1 << 28 + x.x = 2 << 28 x.y = 0x12345678 x.z = x.y // check mem and string v := reflect.NewValue(x) - i := v.(*reflect.StructValue).Field(0) - j := v.(*reflect.StructValue).Field(1) + i := v.Field(0) + j := v.Field(1) assert(i.Interface() == j.Interface()) - s := v.(*reflect.StructValue).Field(2) - t := v.(*reflect.StructValue).Field(3) + s := v.Field(2) + t := v.Field(3) assert(s.Interface() == t.Interface()) // make sure different values are different. // make sure whole word is being compared, // not just a single byte. - i = v.(*reflect.StructValue).Field(4) - j = v.(*reflect.StructValue).Field(5) + i = v.Field(4) + j = v.Field(5) assert(i.Interface() != j.Interface()) - i = v.(*reflect.StructValue).Field(6) - j = v.(*reflect.StructValue).Field(7) + i = v.Field(6) + j = v.Field(7) assert(i.Interface() != j.Interface()) - i = v.(*reflect.StructValue).Field(8) - j = v.(*reflect.StructValue).Field(9) + i = v.Field(8) + j = v.Field(9) assert(i.Interface() == j.Interface()) } diff --git a/test/interface/private.go b/test/interface/private.go new file mode 100644 index 000000000..37890c923 --- /dev/null +++ b/test/interface/private.go @@ -0,0 +1,32 @@ +// $G $D/${F}1.go && errchk $G $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 + +import "./private1" + +type Exported interface { + private() +} + +type Implementation struct{} + +func (p *Implementation) private() {} + +func main() { + var x Exported + x = new(Implementation) + x.private() + + var px p.Exported + px = p.X + + px.private() // ERROR "private" + + px = new(Implementation) // ERROR "private" + + x = px // ERROR "private" +} diff --git a/test/interface/private1.go b/test/interface/private1.go new file mode 100644 index 000000000..3173fbef4 --- /dev/null +++ b/test/interface/private1.go @@ -0,0 +1,18 @@ +// true # used by private.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 p + +type Exported interface { + private() +} + +type Implementation struct{} + +func (p *Implementation) private() {} + +var X = new(Implementation) + diff --git a/test/ken/cplx3.go b/test/ken/cplx3.go index 83acc15ff..979e53f56 100644 --- a/test/ken/cplx3.go +++ b/test/ken/cplx3.go @@ -25,9 +25,9 @@ func main() { println(c) var a interface{} - switch c := reflect.NewValue(a).(type) { - case *reflect.ComplexValue: - v := c.Get() + switch c := reflect.NewValue(a); c.Kind() { + case reflect.Complex64, reflect.Complex128: + v := c.Complex() _, _ = complex128(v), true } } diff --git a/test/label.go b/test/label.go new file mode 100644 index 000000000..e3d853266 --- /dev/null +++ b/test/label.go @@ -0,0 +1,60 @@ +// 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. + +// Pass 1 label errors. + +package main + +var x int + +func f() { +L1: // ERROR "label .*L1.* defined and not used" + for { + } +L2: // ERROR "label .*L2.* defined and not used" + select { + } +L3: // ERROR "label .*L3.* defined and not used" + switch { + } +L4: // ERROR "label .*L4.* defined and not used" + if true { + } +L5: // ERROR "label .*L5.* defined and not used" + f() +L6: // GCCGO_ERROR "previous" + f() +L6: // ERROR "label .*L6.* already defined" + f() + if x == 20 { + goto L6 + } + +L7: + for { + break L7 + } + +L8: + for { + if x == 21 { + continue L8 + } + } + +L9: + switch { + case true: + break L9 + defalt: // ERROR "label .*defalt.* defined and not used" + } + +L10: + select { + default: + break L10 + } +} diff --git a/test/label1.go b/test/label1.go new file mode 100644 index 000000000..656daaeea --- /dev/null +++ b/test/label1.go @@ -0,0 +1,85 @@ +// 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. + +// Pass 2 label errors. + +package main + +var x int + +func f() { +L1: + for { + if x == 0 { + break L1 + } + if x == 1 { + continue L1 + } + goto L1 + } + +L2: + select { + default: + if x == 0 { + break L2 + } + if x == 1 { + continue L2 // ERROR "invalid continue label .*L2" + } + goto L2 + } + +L3: + switch { + case x > 10: + if x == 11 { + break L3 + } + if x == 12 { + continue L3 // ERROR "invalid continue label .*L3" + } + goto L3 + } + +L4: + if true { + if x == 13 { + break L4 // ERROR "invalid break label .*L4" + } + if x == 14 { + continue L4 // ERROR "invalid continue label .*L4" + } + if x == 15 { + goto L4 + } + } + +L5: + f() + if x == 16 { + break L5 // ERROR "invalid break label .*L5" + } + if x == 17 { + continue L5 // ERROR "invalid continue label .*L5" + } + if x == 18 { + goto L5 + } + + for { + if x == 19 { + break L1 // ERROR "invalid break label .*L1" + } + if x == 20 { + continue L1 // ERROR "invalid continue label .*L1" + } + if x == 21 { + goto L1 + } + } +} diff --git a/test/named1.go b/test/named1.go index 1776313f0..7e7aab9c1 100644 --- a/test/named1.go +++ b/test/named1.go @@ -43,10 +43,6 @@ func main() { _, b = m[2] // ERROR "cannot .* bool.*type Bool" m[2] = 1, b // ERROR "cannot use.*type Bool.*as type bool" - ////TODO(rsc): uncomment when this syntax is valid for receive+check closed - //// _, b = <-c // ERROR "cannot .* bool.*type Bool" - //// _ = b - var inter interface{} _, b = inter.(Map) // ERROR "cannot .* bool.*type Bool" _ = b @@ -57,8 +53,9 @@ func main() { _, b = minter.(Map) // ERROR "cannot .* bool.*type Bool" _ = b - asBool(closed(c)) // ERROR "cannot use.*type bool.*as type Bool" - b = closed(c) // ERROR "cannot use.*type bool.*type Bool" + _, bb := <-c + asBool(bb) // ERROR "cannot use.*type bool.*as type Bool" + _, b = <-c // ERROR "cannot .* bool.*type Bool" _ = b asString(String(slice)) // ERROR "cannot .*type Slice.*type String" @@ -5,6 +5,8 @@ eval $(gomake --no-print-directory -f ../src/Make.inc go-env) +export E= + case X"$GOARCH" in Xamd64) export A=6 @@ -97,6 +99,7 @@ do echo $i >>pass.out fi echo $(awk 'NR==1{print $2}' $TMP2FILE) $D/$F >>times.out + rm -f $F.$A $A.out ) done done | # clean up some stack noise egrep -v '^(r[0-9a-z]+|[cfg]s) +0x' | diff --git a/test/syntax/chan.go b/test/syntax/chan.go index 48beb1e70..ff3577502 100644 --- a/test/syntax/chan.go +++ b/test/syntax/chan.go @@ -8,9 +8,9 @@ package main type xyz struct { ch chan -} // ERROR "unexpected } in channel type" +} // ERROR "unexpected .*}.* in channel type" -func Foo(y chan) { // ERROR "unexpected \) in channel type" +func Foo(y chan) { // ERROR "unexpected .*\).* in channel type" } func Bar(x chan, y int) { // ERROR "unexpected comma in channel type" diff --git a/test/syntax/if.go b/test/syntax/if.go index 913d41885..a3b51f0c0 100644 --- a/test/syntax/if.go +++ b/test/syntax/if.go @@ -6,6 +6,9 @@ package main +func x() { +} + func main() { if { // ERROR "missing condition" } |