diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/errchk | 16 | ||||
-rw-r--r-- | test/fixedbugs/bug140.go | 4 | ||||
-rw-r--r-- | test/fixedbugs/bug178.go | 12 | ||||
-rw-r--r-- | test/fixedbugs/bug238.go | 1 | ||||
-rw-r--r-- | test/fixedbugs/bug243.go | 3 | ||||
-rw-r--r-- | test/fixedbugs/bug274.go | 2 | ||||
-rw-r--r-- | test/fixedbugs/bug344.go | 6 | ||||
-rw-r--r-- | test/fixedbugs/bug345.dir/io.go | 15 | ||||
-rw-r--r-- | test/fixedbugs/bug345.dir/main.go | 28 | ||||
-rw-r--r-- | test/fixedbugs/bug345.go | 7 | ||||
-rw-r--r-- | test/fixedbugs/bug346.go | 19 | ||||
-rw-r--r-- | test/golden.out | 3 | ||||
-rw-r--r-- | test/goprint.go | 14 | ||||
-rw-r--r-- | test/goto.go | 535 | ||||
-rwxr-xr-x | test/run | 6 | ||||
-rw-r--r-- | test/sizeof.go | 23 |
16 files changed, 674 insertions, 20 deletions
diff --git a/test/errchk b/test/errchk index fbb021ce4..e89d75950 100755 --- a/test/errchk +++ b/test/errchk @@ -81,6 +81,19 @@ sub chk { next; } $regexp = $1; + + # Turn relative line number in message into absolute line number. + if($regexp =~ /LINE(([+-])([0-9]+))?/) { + my $n = $line; + if(defined($1)) { + if($2 eq "+") { + $n += int($3); + } else { + $n -= int($3); + } + } + $regexp = "$`$file:$n$'"; + } @errmsg = grep { /$file:$line[:[]/ } @out; @out = grep { !/$file:$line[:[]/ } @out; @@ -93,6 +106,9 @@ sub chk { if(@match == 0) { bug(); print STDERR "errchk: $file:$line: error message does not match '$regexp'\n"; + foreach my $l (@errmsg) { + print STDERR "> $l"; + } next; } } diff --git a/test/fixedbugs/bug140.go b/test/fixedbugs/bug140.go index e27b370e7..441c57a48 100644 --- a/test/fixedbugs/bug140.go +++ b/test/fixedbugs/bug140.go @@ -10,14 +10,14 @@ func main() { if true { } else { L1: + goto L1 } if true { } else { + goto L2 L2: main() } - goto L1 - goto L2 } /* diff --git a/test/fixedbugs/bug178.go b/test/fixedbugs/bug178.go index 205961024..a7ff09dae 100644 --- a/test/fixedbugs/bug178.go +++ b/test/fixedbugs/bug178.go @@ -14,6 +14,9 @@ L: break L } panic("BUG: not reached - break") + if false { + goto L1 + } } L2: @@ -23,11 +26,8 @@ L2: continue L2 } panic("BUG: not reached - continue") - } - if false { - goto L1 - } - if false { - goto L3 + if false { + goto L3 + } } } diff --git a/test/fixedbugs/bug238.go b/test/fixedbugs/bug238.go index 7e8660d37..4d5a905f0 100644 --- a/test/fixedbugs/bug238.go +++ b/test/fixedbugs/bug238.go @@ -19,4 +19,3 @@ const h bool = false const i int = 2 const j float64 = 5 -func main() { println(a, b, c, d, e, f, g) } diff --git a/test/fixedbugs/bug243.go b/test/fixedbugs/bug243.go index 0c531968e..95514cfd6 100644 --- a/test/fixedbugs/bug243.go +++ b/test/fixedbugs/bug243.go @@ -38,7 +38,7 @@ func Listen(x, y string) (T, string) { } func (t T) Addr() os.Error { - return os.ErrorString("stringer") + return os.NewError("stringer") } func (t T) Accept() (int, string) { @@ -49,4 +49,3 @@ func Dial(x, y, z string) (int, string) { global <- 1 return 0, "" } - diff --git a/test/fixedbugs/bug274.go b/test/fixedbugs/bug274.go index 348aed429..81ee9e5b8 100644 --- a/test/fixedbugs/bug274.go +++ b/test/fixedbugs/bug274.go @@ -25,6 +25,6 @@ func main() { L1: // ERROR "statement" default: // correct since no semicolon is required before a '}' - L2: // GCCGO_ERROR "not used" + L2: // ERROR "not used" } } diff --git a/test/fixedbugs/bug344.go b/test/fixedbugs/bug344.go index 2a20dcf6f..d217b3bd3 100644 --- a/test/fixedbugs/bug344.go +++ b/test/fixedbugs/bug344.go @@ -1,4 +1,4 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: bug344 +// 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 @@ -14,7 +14,9 @@ func main() { i := 42 a := []*int{&i, &i, &i, &i} x := a[0] - goto start + goto start // ERROR "goto start jumps into block" + z := 1 + _ = z for _, x = range a { start: fmt.Sprint(*x) diff --git a/test/fixedbugs/bug345.dir/io.go b/test/fixedbugs/bug345.dir/io.go new file mode 100644 index 000000000..1d695c304 --- /dev/null +++ b/test/fixedbugs/bug345.dir/io.go @@ -0,0 +1,15 @@ +// 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 io + +type Writer interface { + WrongWrite() +} + +type SectionReader struct { + X int +} + +func SR(*SectionReader) {} diff --git a/test/fixedbugs/bug345.dir/main.go b/test/fixedbugs/bug345.dir/main.go new file mode 100644 index 000000000..5bdc713f4 --- /dev/null +++ b/test/fixedbugs/bug345.dir/main.go @@ -0,0 +1,28 @@ +// 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 ( + "bufio" + "./io" + goio "io" +) + +func main() { + // The errors here complain that io.X != io.X + // for different values of io so they should be + // showing the full import path, which for the + // "./io" import is really ..../go/test/io. + // For example: + // + // main.go:25: cannot use w (type "/Users/rsc/g/go/test/fixedbugs/bug345.dir/io".Writer) as type "io".Writer in function argument: + // io.Writer does not implement io.Writer (missing Write method) + // main.go:27: cannot use &x (type *"io".SectionReader) as type *"/Users/rsc/g/go/test/fixedbugs/bug345.dir/io".SectionReader in function argument + + var w io.Writer + bufio.NewWriter(w) // ERROR "test/io" + var x goio.SectionReader + io.SR(&x) // ERROR "test/io" +} diff --git a/test/fixedbugs/bug345.go b/test/fixedbugs/bug345.go new file mode 100644 index 000000000..874710ce8 --- /dev/null +++ b/test/fixedbugs/bug345.go @@ -0,0 +1,7 @@ +// $G $D/$F.dir/io.go && errchk $G -e $D/$F.dir/main.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 ignored diff --git a/test/fixedbugs/bug346.go b/test/fixedbugs/bug346.go new file mode 100644 index 000000000..31284c31a --- /dev/null +++ b/test/fixedbugs/bug346.go @@ -0,0 +1,19 @@ +// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: issue2056 + +// 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 "os" + +func main() { + x := 4 + a, b, c, d := func(i int) (p int, q int, r int, s int) { return 1, i, 3, x }(2) + + if a != 1 || b != 2 || c != 3 || d != 4 { + println("abcd: expected 1 2 3 4 got", a, b, c, d) + os.Exit(1) + } +} diff --git a/test/golden.out b/test/golden.out index 4400e41dd..655ceda56 100644 --- a/test/golden.out +++ b/test/golden.out @@ -21,6 +21,9 @@ panic: runtime error: hash of unhashable type []int 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 +=========== ./goprint.go +42 true false true +1.500000e+000 world 0x0 [0/0]0x0 0x0 0x0 255 + =========== ./helloworld.go hello, world diff --git a/test/goprint.go b/test/goprint.go new file mode 100644 index 000000000..c0e34c750 --- /dev/null +++ b/test/goprint.go @@ -0,0 +1,14 @@ +// $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 + +import "time" + +func main() { + go println(42, true, false, true, 1.5, "world", (chan int)(nil), []int(nil), (map[string]int)(nil), (func())(nil), byte(255)) + time.Sleep(1e6) +} diff --git a/test/goto.go b/test/goto.go new file mode 100644 index 000000000..0a50938dc --- /dev/null +++ b/test/goto.go @@ -0,0 +1,535 @@ +// 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. + +// Each test is in a separate function just so that if the +// compiler stops processing after one error, we don't +// lose other ones. + +package main + +var ( + i, n int + x []int + c chan int + m map[int]int + s string +) + +// goto after declaration okay +func _() { + x := 1 + goto L +L: + _ = x +} + +// goto before declaration okay +func _() { + goto L +L: + x := 1 + _ = x +} + +// goto across declaration not okay +func _() { + goto L // ERROR "goto L jumps over declaration of x at LINE+1" + x := 1 + _ = x +L: +} + +// goto across declaration in inner scope okay +func _() { + goto L + { + x := 1 + _ = x + } +L: +} + +// goto across declaration after inner scope not okay +func _() { + goto L // ERROR "goto L jumps over declaration of x at LINE+5" + { + x := 1 + _ = x + } + x := 1 + _ = x +L: +} + +// goto across declaration in reverse okay +func _() { +L: + x := 1 + _ = x + goto L +} + +// error shows first offending variable +func _() { + goto L // ERROR "goto L jumps over declaration of x at LINE+1" + x := 1 + _ = x + y := 1 + _ = y +L: +} + +// goto not okay even if code path is dead +func _() { + goto L // ERROR "goto L jumps over declaration of x at LINE+1" + x := 1 + _ = x + y := 1 + _ = y + return +L: +} + +// goto into outer block okay +func _() { + { + goto L + } +L: +} + +// goto backward into outer block okay +func _() { +L: + { + goto L + } +} + +// goto into inner block not okay +func _() { + goto L // ERROR "goto L jumps into block starting at LINE+1" + { + L: + } +} + +// goto backward into inner block still not okay +func _() { + { + L: + } + goto L // ERROR "goto L jumps into block starting at LINE-3" +} + +// error shows first (outermost) offending block +func _() { + goto L // ERROR "goto L jumps into block starting at LINE+1" + { + { + { + L: + } + } + } +} + +// error prefers block diagnostic over declaration diagnostic +func _() { + goto L // ERROR "goto L jumps into block starting at LINE+3" + x := 1 + _ = x + { + L: + } +} + +// many kinds of blocks, all invalid to jump into or among, +// but valid to jump out of + +// if + +func _() { +L: + if true { + goto L + } +} + +func _() { +L: + if true { + goto L + } else { + } +} + +func _() { +L: + if false { + } else { + goto L + } +} + +func _() { + goto L // ERROR "goto L jumps into block starting at LINE+1" + if true { + L: + } +} + +func _() { + goto L // ERROR "goto L jumps into block starting at LINE+1" + if true { + L: + } else { + } +} + +func _() { + goto L // ERROR "goto L jumps into block starting at LINE+1" + if true { + } else { + L: + } +} + +func _() { + if false { + L: + } else { + goto L // ERROR "goto L jumps into block starting at LINE-3" + } +} + +func _() { + if true { + goto L // ERROR "goto L jumps into block starting at LINE+1" + } else { + L: + } +} + +func _() { + if true { + goto L // ERROR "goto L jumps into block starting at LINE+1" + } else if false { + L: + } +} + +func _() { + if true { + goto L // ERROR "goto L jumps into block starting at LINE+1" + } else if false { + L: + } else { + } +} + +func _() { + // This one is tricky. There is an implicit scope + // starting at the second if statement, and it contains + // the final else, so the outermost offending scope + // really is LINE+1 (like in the previous test), + // even though it looks like it might be LINE+3 instead. + if true { + goto L // ERROR "goto L jumps into block starting at LINE+1" + } else if false { + } else { + L: + } +} + +/* Want to enable these tests but gofmt mangles them. Issue 1972. + +func _() { + // This one is okay, because the else is in the + // implicit whole-if block and has no inner block + // (no { }) around it. + if true { + goto L + } else + L: +} + +func _() { + // Still not okay. + if true { + L: + } else + goto L //// ERROR "goto L jumps into block starting at LINE-3" +} + +*/ + +// for + +func _() { + for { + goto L + } +L: +} + +func _() { + for { + goto L + L: + } +} + +func _() { + for { + L: + } + goto L // ERROR "goto L jumps into block starting at LINE-3" +} + +func _() { + for { + goto L + L1: + } +L: + goto L1 // ERROR "goto L1 jumps into block starting at LINE-5" +} + +func _() { + for i < n { + L: + } + goto L // ERROR "goto L jumps into block starting at LINE-3" +} + +func _() { + for i = 0; i < n; i++ { + L: + } + goto L // ERROR "goto L jumps into block starting at LINE-3" +} + +func _() { + for i = range x { + L: + } + goto L // ERROR "goto L jumps into block starting at LINE-3" +} + +func _() { + for i = range c { + L: + } + goto L // ERROR "goto L jumps into block starting at LINE-3" +} + +func _() { + for i = range m { + L: + } + goto L // ERROR "goto L jumps into block starting at LINE-3" +} + +func _() { + for i = range s { + L: + } + goto L // ERROR "goto L jumps into block starting at LINE-3" +} + +// switch + +func _() { +L: + switch i { + case 0: + goto L + } +} + +func _() { +L: + switch i { + case 0: + + default: + goto L + } +} + +func _() { + switch i { + case 0: + + default: + L: + goto L + } +} + +func _() { + switch i { + case 0: + + default: + goto L + L: + } +} + +func _() { + switch i { + case 0: + goto L + L: + ; + default: + } +} + +func _() { + goto L // ERROR "goto L jumps into block starting at LINE+1" + switch i { + case 0: + L: + } +} + +func _() { + goto L // ERROR "goto L jumps into block starting at LINE+1" + switch i { + case 0: + L: + ; + default: + } +} + +func _() { + goto L // ERROR "goto L jumps into block starting at LINE+1" + switch i { + case 0: + default: + L: + } +} + +func _() { + switch i { + default: + goto L // ERROR "goto L jumps into block starting at LINE+1" + case 0: + L: + } +} + +func _() { + switch i { + case 0: + L: + ; + default: + goto L // ERROR "goto L jumps into block starting at LINE-4" + } +} + +// select +// different from switch. the statement has no implicit block around it. + +func _() { +L: + select { + case <-c: + goto L + } +} + +func _() { +L: + select { + case c <- 1: + + default: + goto L + } +} + +func _() { + select { + case <-c: + + default: + L: + goto L + } +} + +func _() { + select { + case c <- 1: + + default: + goto L + L: + } +} + +func _() { + select { + case <-c: + goto L + L: + ; + default: + } +} + +func _() { + goto L // ERROR "goto L jumps into block starting at LINE+2" + select { + case c <- 1: + L: + } +} + +func _() { + goto L // ERROR "goto L jumps into block starting at LINE+2" + select { + case c <- 1: + L: + ; + default: + } +} + +func _() { + goto L // ERROR "goto L jumps into block starting at LINE+3" + select { + case <-c: + default: + L: + } +} + +func _() { + select { + default: + goto L // ERROR "goto L jumps into block starting at LINE+1" + case <-c: + L: + } +} + +func _() { + select { + case <-c: + L: + ; + default: + goto L // ERROR "goto L jumps into block starting at LINE-4" + } +} @@ -23,11 +23,6 @@ Xarm) exit 1 esac -case X"$GOOS" in -Xnacl) - export E=${GORUN:-$GOROOT/misc/nacl/naclrun} -esac - export G=${A}g export L=${A}l export GOTRACEBACK=0 @@ -112,7 +107,6 @@ done | # clean up some stack noise /^Trace\/BPT trap/d /RUNFILE/ s/line 1: *[0-9]*/line 1: PID/ /^\$RUNFILE: line 1: PID Trace\/breakpoint trap/d - /Fault in NaCl untrusted code/d /Segmentation fault/d /^qemu: uncaught target signal 11 (Segmentation fault) - exiting/d' > run.out diff --git a/test/sizeof.go b/test/sizeof.go new file mode 100644 index 000000000..544e4c52c --- /dev/null +++ b/test/sizeof.go @@ -0,0 +1,23 @@ +// $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 "unsafe" + +type T struct { + X int +} + +var t T + +func isUintptr(uintptr) {} + +func main() { + isUintptr(unsafe.Sizeof(t)) + isUintptr(unsafe.Alignof(t)) + isUintptr(unsafe.Offsetof(t.X)) +} |