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