Commit 052c942e authored by Alan Donovan's avatar Alan Donovan

test: ensure all failing tests exit nonzero.

Previously merely printing an error would cause the golden
file comparison (in 'bash run') to fail, but that is no longer
the case with the new run.go driver.

R=iant
CC=golang-dev
https://golang.org/cl/7310087
parent 2fdd60b9
...@@ -17,7 +17,7 @@ func main() { ...@@ -17,7 +17,7 @@ func main() {
case uint8: case uint8:
// ok // ok
default: default:
println("byte != uint8") panic("byte != uint8")
} }
x = uint8(2) x = uint8(2)
...@@ -25,7 +25,7 @@ func main() { ...@@ -25,7 +25,7 @@ func main() {
case byte: case byte:
// ok // ok
default: default:
println("uint8 != byte") panic("uint8 != byte")
} }
rune32 := false rune32 := false
...@@ -37,7 +37,7 @@ func main() { ...@@ -37,7 +37,7 @@ func main() {
// must be new code // must be new code
rune32 = true rune32 = true
default: default:
println("rune != int and rune != int32") panic("rune != int and rune != int32")
} }
if rune32 { if rune32 {
...@@ -49,6 +49,6 @@ func main() { ...@@ -49,6 +49,6 @@ func main() {
case rune: case rune:
// ok // ok
default: default:
println("int (or int32) != rune") panic("int (or int32) != rune")
} }
} }
...@@ -15,18 +15,21 @@ type T struct { ...@@ -15,18 +15,21 @@ type T struct {
d byte d byte
} }
var a = []int{ 1, 2, 3 } var a = []int{1, 2, 3}
var NIL []int var NIL []int
func arraycmptest() { func arraycmptest() {
if NIL != nil { if NIL != nil {
println("fail1:", NIL, "!= nil") println("fail1:", NIL, "!= nil")
panic("bigalg")
} }
if nil != NIL { if nil != NIL {
println("fail2: nil !=", NIL) println("fail2: nil !=", NIL)
panic("bigalg")
} }
if a == nil || nil == a { if a == nil || nil == a {
println("fail3:", a, "== nil") println("fail3:", a, "== nil")
panic("bigalg")
} }
} }
...@@ -49,12 +52,14 @@ func maptest() { ...@@ -49,12 +52,14 @@ func maptest() {
t1 := mt[0] t1 := mt[0]
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d { if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
println("fail: map val struct", t1.a, t1.b, t1.c, t1.d) println("fail: map val struct", t1.a, t1.b, t1.c, t1.d)
panic("bigalg")
} }
ma[1] = a ma[1] = a
a1 := ma[1] a1 := ma[1]
if !SameArray(a, a1) { if !SameArray(a, a1) {
println("fail: map val array", a, a1) println("fail: map val array", a, a1)
panic("bigalg")
} }
} }
...@@ -72,15 +77,18 @@ func chantest() { ...@@ -72,15 +77,18 @@ func chantest() {
t1 := <-ct t1 := <-ct
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d { if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
println("fail: map val struct", t1.a, t1.b, t1.c, t1.d) println("fail: map val struct", t1.a, t1.b, t1.c, t1.d)
panic("bigalg")
} }
a1 := <-ca a1 := <-ca
if !SameArray(a, a1) { if !SameArray(a, a1) {
println("fail: map val array", a, a1) println("fail: map val array", a, a1)
panic("bigalg")
} }
} }
type E struct { } type E struct{}
var e E var e E
func interfacetest() { func interfacetest() {
...@@ -90,6 +98,7 @@ func interfacetest() { ...@@ -90,6 +98,7 @@ func interfacetest() {
a1 := i.([]int) a1 := i.([]int)
if !SameArray(a, a1) { if !SameArray(a, a1) {
println("interface <-> []int", a, a1) println("interface <-> []int", a, a1)
panic("bigalg")
} }
pa := new([]int) pa := new([]int)
*pa = a *pa = a
...@@ -97,12 +106,14 @@ func interfacetest() { ...@@ -97,12 +106,14 @@ func interfacetest() {
a1 = *i.(*[]int) a1 = *i.(*[]int)
if !SameArray(a, a1) { if !SameArray(a, a1) {
println("interface <-> *[]int", a, a1) println("interface <-> *[]int", a, a1)
panic("bigalg")
} }
i = t i = t
t1 := i.(T) t1 := i.(T)
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d { if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
println("interface <-> struct", t1.a, t1.b, t1.c, t1.d) println("interface <-> struct", t1.a, t1.b, t1.c, t1.d)
panic("bigalg")
} }
i = e i = e
......
...@@ -45,4 +45,7 @@ func main() { ...@@ -45,4 +45,7 @@ func main() {
fmt.Printf("%v/%v: expected %v error; got %v\n", t.f, t.g, t.out, x) fmt.Printf("%v/%v: expected %v error; got %v\n", t.f, t.g, t.out, x)
} }
} }
if bad {
panic("cmplxdivide failed.")
}
} }
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
package main package main
var b struct { var b struct {
a[10]int a [10]int
} }
var m map[string][20]int var m map[string][20]int
...@@ -61,17 +61,22 @@ var c1 = func() chan *[70]int { ...@@ -61,17 +61,22 @@ var c1 = func() chan *[70]int {
func main() { func main() {
if n1 != 10 || n2 != 20 || n3 != 30 || n4 != 40 || n5 != 50 || n6 != 60 || n7 != 70 { if n1 != 10 || n2 != 20 || n3 != 30 || n4 != 40 || n5 != 50 || n6 != 60 || n7 != 70 {
println("BUG:", n1, n2, n3, n4, n5, n6, n7) println("BUG:", n1, n2, n3, n4, n5, n6, n7)
panic("fail")
} }
if !calledF { if !calledF {
println("BUG: did not call f") println("BUG: did not call f")
panic("fail")
} }
if <-c == nil { if <-c == nil {
println("BUG: did not receive from c") println("BUG: did not receive from c")
panic("fail")
} }
if !calledG { if !calledG {
println("BUG: did not call g") println("BUG: did not call g")
panic("fail")
} }
if <-c1 == nil { if <-c1 == nil {
println("BUG: did not receive from c1") println("BUG: did not receive from c1")
panic("fail")
} }
} }
...@@ -132,6 +132,7 @@ func verify8(length, in, out, m int) { ...@@ -132,6 +132,7 @@ func verify8(length, in, out, m int) {
n := ncopied(length, in, out) n := ncopied(length, in, out)
if m != n { if m != n {
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
os.Exit(1)
return return
} }
// before // before
...@@ -172,6 +173,7 @@ func verifyS(length, in, out, m int) { ...@@ -172,6 +173,7 @@ func verifyS(length, in, out, m int) {
n := ncopied(length, in, out) n := ncopied(length, in, out)
if m != n { if m != n {
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
os.Exit(1)
return return
} }
// before // before
...@@ -212,6 +214,7 @@ func verify16(length, in, out, m int) { ...@@ -212,6 +214,7 @@ func verify16(length, in, out, m int) {
n := ncopied(length, in, out) n := ncopied(length, in, out)
if m != n { if m != n {
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
os.Exit(1)
return return
} }
// before // before
...@@ -252,6 +255,7 @@ func verify32(length, in, out, m int) { ...@@ -252,6 +255,7 @@ func verify32(length, in, out, m int) {
n := ncopied(length, in, out) n := ncopied(length, in, out)
if m != n { if m != n {
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
os.Exit(1)
return return
} }
// before // before
...@@ -292,6 +296,7 @@ func verify64(length, in, out, m int) { ...@@ -292,6 +296,7 @@ func verify64(length, in, out, m int) {
n := ncopied(length, in, out) n := ncopied(length, in, out)
if m != n { if m != n {
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n) fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
os.Exit(1)
return return
} }
// before // before
......
...@@ -33,8 +33,9 @@ func main() { ...@@ -33,8 +33,9 @@ func main() {
m, h, s := f3() m, h, s := f3()
_, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h _, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h
} }
if x() != "3" { if y := x(); y != "3" {
println("x() failed") println("x() failed", y)
panic("fail")
} }
_, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h _, _, _, _, _, _, _, _, _ = i, f, s, j, k, m, g, s, h
} }
...@@ -25,6 +25,7 @@ func test1() { ...@@ -25,6 +25,7 @@ func test1() {
test1helper() test1helper()
if result != "9876543210" { if result != "9876543210" {
fmt.Printf("test1: bad defer result (should be 9876543210): %q\n", result) fmt.Printf("test1: bad defer result (should be 9876543210): %q\n", result)
panic("defer")
} }
} }
...@@ -41,6 +42,7 @@ func test2() { ...@@ -41,6 +42,7 @@ func test2() {
test2helper() test2helper()
if result != "9876543210" { if result != "9876543210" {
fmt.Printf("test2: bad defer result (should be 9876543210): %q\n", result) fmt.Printf("test2: bad defer result (should be 9876543210): %q\n", result)
panic("defer")
} }
} }
......
...@@ -13,36 +13,44 @@ import "fmt" ...@@ -13,36 +13,44 @@ import "fmt"
func f8(x, y, q, r int8) { func f8(x, y, q, r int8) {
if t := x / y; t != q { if t := x / y; t != q {
fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q) fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
panic("divide")
} }
if t := x % y; t != r { if t := x % y; t != r {
fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r) fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
panic("divide")
} }
} }
func f16(x, y, q, r int16) { func f16(x, y, q, r int16) {
if t := x / y; t != q { if t := x / y; t != q {
fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q) fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
panic("divide")
} }
if t := x % y; t != r { if t := x % y; t != r {
fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r) fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
panic("divide")
} }
} }
func f32(x, y, q, r int32) { func f32(x, y, q, r int32) {
if t := x / y; t != q { if t := x / y; t != q {
fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q) fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
panic("divide")
} }
if t := x % y; t != r { if t := x % y; t != r {
fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r) fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
panic("divide")
} }
} }
func f64(x, y, q, r int64) { func f64(x, y, q, r int64) {
if t := x / y; t != q { if t := x / y; t != q {
fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q) fmt.Printf("%d/%d = %d, want %d\n", x, y, t, q)
panic("divide")
} }
if t := x % y; t != r { if t := x % y; t != r {
fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r) fmt.Printf("%d%%%d = %d, want %d\n", x, y, t, r)
panic("divide")
} }
} }
......
...@@ -52,9 +52,11 @@ func chk(p, q *int, v int, s string) { ...@@ -52,9 +52,11 @@ func chk(p, q *int, v int, s string) {
func chkalias(p, q *int, v int, s string) { func chkalias(p, q *int, v int, s string) {
if p != q { if p != q {
println("want aliased pointers but got different after", s) println("want aliased pointers but got different after", s)
bad = true
} }
if *q != v+1 { if *q != v+1 {
println("wrong value want", v+1, "got", *q, "after", s) println("wrong value want", v+1, "got", *q, "after", s)
bad = true
} }
} }
......
...@@ -196,4 +196,8 @@ func main() { ...@@ -196,4 +196,8 @@ func main() {
if !close(-210.012e19, -210012, 1000, 19) { if !close(-210.012e19, -210012, 1000, 19) {
print("-210.012e19 is ", -210.012e19, "\n") print("-210.012e19 is ", -210.012e19, "\n")
} }
if bad {
panic("float_lit")
}
} }
...@@ -87,4 +87,7 @@ func main() { ...@@ -87,4 +87,7 @@ func main() {
println(t.name, "=", t.expr, "want", t.want) println(t.name, "=", t.expr, "want", t.want)
} }
} }
if bad {
panic("floatcmp failed")
}
} }
...@@ -17,7 +17,7 @@ func f() int { ...@@ -17,7 +17,7 @@ func f() int {
func g() int { func g() int {
if !calledf { if !calledf {
println("BUG: func7 - called g before f") panic("BUG: func7 - called g before f")
} }
return 0 return 0
} }
...@@ -28,4 +28,3 @@ func main() { ...@@ -28,4 +28,3 @@ func main() {
panic("wrong answer") panic("wrong answer")
} }
} }
...@@ -37,13 +37,13 @@ func y() string { ...@@ -37,13 +37,13 @@ func y() string {
func main() { func main() {
if f() == g() { if f() == g() {
println("wrong f,g order") panic("wrong f,g order")
} }
if x() == (y() == "abc") { if x() == (y() == "abc") {
panic("wrong compare") panic("wrong compare")
} }
if xy != "xy" { if xy != "xy" {
println("wrong x,y order") panic("wrong x,y order")
} }
} }
...@@ -33,6 +33,7 @@ func init() { ...@@ -33,6 +33,7 @@ func init() {
sys1 := memstats.Sys sys1 := memstats.Sys
if sys1-sys > chunk*50 { if sys1-sys > chunk*50 {
println("allocated 1000 chunks of", chunk, "and used ", sys1-sys, "memory") println("allocated 1000 chunks of", chunk, "and used ", sys1-sys, "memory")
panic("init1")
} }
} }
......
...@@ -24,7 +24,6 @@ func equal(a, b float32) bool { ...@@ -24,7 +24,6 @@ func equal(a, b float32) bool {
return a == b return a == b
} }
func main() { func main() {
// bool // bool
var t bool = true var t bool = true
...@@ -225,6 +224,6 @@ func main() { ...@@ -225,6 +224,6 @@ func main() {
assert(sj0 == sj3, "sj3") assert(sj0 == sj3, "sj3")
if nbad > 0 { if nbad > 0 {
println() panic("literal failed")
} }
} }
This diff is collapsed.
...@@ -115,7 +115,7 @@ func chantest() { ...@@ -115,7 +115,7 @@ func chantest() {
}) })
shouldBlock(func() { shouldBlock(func() {
x, ok := <-ch x, ok := <-ch
println(x, ok) println(x, ok) // unreachable
}) })
if len(ch) != 0 { if len(ch) != 0 {
......
...@@ -71,6 +71,10 @@ func main() { ...@@ -71,6 +71,10 @@ func main() {
inter = 1 inter = 1
check("type-concrete", func() { println(inter.(string)) }, "int, not string") check("type-concrete", func() { println(inter.(string)) }, "int, not string")
check("type-interface", func() { println(inter.(m)) }, "missing method m") check("type-interface", func() { println(inter.(m)) }, "missing method m")
if didbug {
panic("recover3")
}
} }
type m interface { type m interface {
......
...@@ -8,7 +8,10 @@ ...@@ -8,7 +8,10 @@
package main package main
import "fmt" import (
"fmt"
"runtime"
)
func main() { func main() {
n := n :=
...@@ -52,6 +55,7 @@ func main() { ...@@ -52,6 +55,7 @@ func main() {
iota iota
if n != NUM*(NUM-1)/2 { if n != NUM*(NUM-1)/2 {
fmt.Println("BUG: wrong n", n, NUM*(NUM-1)/2) fmt.Println("BUG: wrong n", n, NUM*(NUM-1)/2)
runtime.Breakpoint() // panic is inaccessible
} }
} }
......
...@@ -33,6 +33,7 @@ func assert(a, b, c string) { ...@@ -33,6 +33,7 @@ func assert(a, b, c string) {
print("\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n") print("\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n")
} }
} }
panic("string_lit")
} }
} }
......
...@@ -237,4 +237,7 @@ func main() { ...@@ -237,4 +237,7 @@ func main() {
fmt.Printf("%v/%v: expected %g error; got %g\n", t.f, t.g, t.out, x) fmt.Printf("%v/%v: expected %g error; got %g\n", t.f, t.g, t.out, x)
} }
} }
if bad {
panic("zerodivide")
}
} }
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