From f2030938522fae7c6b65569a20a7b9ed1431b8f8 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 18 Jan 2012 14:31:31 -0800 Subject: [PATCH] test: change several tests to not print This will make these tests more meaningful for gccgo, which runs tests in parallel and has no equivalent to golden.out. Remove ken/simpprint.go since it duplicates helloworld.go. R=golang-dev, r CC=golang-dev https://golang.org/cl/5536058 --- test/fixedbugs/bug027.go | 23 +++++++++++++--- test/fixedbugs/bug070.go | 19 +++++++++++--- test/golden.out | 57 ---------------------------------------- test/ken/cplx4.go | 28 +++++++++++++++----- test/ken/label.go | 2 -- test/ken/rob1.go | 18 ++++++++----- test/ken/rob2.go | 32 +++++++++++++--------- test/ken/simpprint.go | 13 --------- test/ken/simpswitch.go | 13 +++++---- test/peano.go | 10 ++++++- test/turing.go | 6 ++++- 11 files changed, 108 insertions(+), 113 deletions(-) delete mode 100644 test/ken/simpprint.go diff --git a/test/fixedbugs/bug027.go b/test/fixedbugs/bug027.go index a7b639474e..cf2daaecf0 100644 --- a/test/fixedbugs/bug027.go +++ b/test/fixedbugs/bug027.go @@ -6,6 +6,8 @@ package main +import "fmt" + type Element interface { } @@ -43,7 +45,7 @@ func main() { i4 := new(I) i4.val = 44444 v := New() - print("hi\n") + r := "hi\n" v.Insert(i4) v.Insert(i3) v.Insert(i2) @@ -52,10 +54,25 @@ func main() { for i := 0; i < v.nelem; i++ { var x *I x = v.At(i).(*I) - print(i, " ", x.val, "\n") // prints correct list + r += fmt.Sprintln(i, x.val) // prints correct list } for i := 0; i < v.nelem; i++ { - print(i, " ", v.At(i).(*I).val, "\n") + r += fmt.Sprintln(i, v.At(i).(*I).val) + } + expect := `hi +0 44444 +1 3333 +2 222 +3 11 +4 0 +0 44444 +1 3333 +2 222 +3 11 +4 0 +` + if r != expect { + panic(r) } } diff --git a/test/fixedbugs/bug070.go b/test/fixedbugs/bug070.go index f63caa9655..24ac779888 100644 --- a/test/fixedbugs/bug070.go +++ b/test/fixedbugs/bug070.go @@ -6,11 +6,14 @@ package main +import "fmt" + func main() { var i, k int + var r string outer: for k = 0; k < 2; k++ { - print("outer loop top k ", k, "\n") + r += fmt.Sprintln("outer loop top k", k) if k != 0 { panic("k not zero") } // inner loop breaks this one every time @@ -18,12 +21,20 @@ outer: if i != 0 { panic("i not zero") } // loop breaks every time - print("inner loop top i ", i, "\n") + r += fmt.Sprintln("inner loop top i", i) if true { - print("do break\n") + r += "do break\n" break outer } } } - print("broke\n") + r += "broke\n" + expect := `outer loop top k 0 +inner loop top i 0 +do break +broke +` + if r != expect { + panic(r) + } } diff --git a/test/golden.out b/test/golden.out index 6dccb6ec01..58a0df2854 100644 --- a/test/golden.out +++ b/test/golden.out @@ -11,18 +11,6 @@ printing: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 =========== ./helloworld.go hello, world -=========== ./peano.go -0! = 1 -1! = 1 -2! = 2 -3! = 6 -4! = 24 -5! = 120 -6! = 720 -7! = 5040 -8! = 40320 -9! = 362880 - =========== ./printbig.go -9223372036854775808 9223372036854775807 @@ -30,9 +18,6 @@ hello, world =========== ./sigchld.go survived SIGCHLD -=========== ./turing.go -Hello World! - == ken/ =========== ken/cplx0.go @@ -45,14 +30,6 @@ Hello World! (+1.292308e+000-1.384615e-001i) (+1.292308e+000-1.384615e-001i) -=========== ken/cplx4.go -c = (-5.000000-6.000000i) -c = (5.000000+6.000000i) -c = (5.000000+6.000000i) -c = (5.000000+6.000000i) -c = (5+6i) -c = (13+7i) - =========== ken/cplx5.go (+5.000000e+000-5.000000e+000i) (+5.000000e+000-5.000000e+000i) @@ -65,21 +42,6 @@ c = (13+7i) =========== ken/intervar.go print 1 bio 2 file 3 -- abc -=========== ken/label.go -100 - -=========== ken/rob1.go -9876543210 - -=========== ken/rob2.go -(defn foo (add 12 34)) - -=========== ken/simpprint.go -hello world - -=========== ken/simpswitch.go -0out01out12out2aout34out4fiveout56out6aout78out89out9 - =========== ken/string.go abcxyz-abcxyz-abcxyz-abcxyz-abcxyz-abcxyz-abcxyz @@ -93,28 +55,9 @@ abcxyz-abcxyz-abcxyz-abcxyz-abcxyz-abcxyz-abcxyz == fixedbugs/ -=========== fixedbugs/bug027.go -hi -0 44444 -1 3333 -2 222 -3 11 -4 0 -0 44444 -1 3333 -2 222 -3 11 -4 0 - =========== fixedbugs/bug067.go ok -=========== fixedbugs/bug070.go -outer loop top k 0 -inner loop top i 0 -do break -broke - =========== fixedbugs/bug328.go 0x0 diff --git a/test/ken/cplx4.go b/test/ken/cplx4.go index 8524e47aec..738afcd2ca 100644 --- a/test/ken/cplx4.go +++ b/test/ken/cplx4.go @@ -15,30 +15,44 @@ const ( C1 = R + I // ADD(5,6) ) -func doprint(c complex128) { fmt.Printf("c = %f\n", c) } +func want(s, w string) { + if s != w { + panic(s + " != " + w) + } +} + +func doprint(c complex128, w string) { + s := fmt.Sprintf("%f", c) + want(s, w) +} func main() { // constants - fmt.Printf("c = %f\n", -C1) - doprint(C1) + s := fmt.Sprintf("%f", -C1) + want(s, "(-5.000000-6.000000i)") + doprint(C1, "(5.000000+6.000000i)") // variables c1 := C1 - fmt.Printf("c = %f\n", c1) - doprint(c1) + s = fmt.Sprintf("%f", c1) + want(s, "(5.000000+6.000000i)") + doprint(c1, "(5.000000+6.000000i)") // 128 c2 := complex128(C1) - fmt.Printf("c = %G\n", c2) + s = fmt.Sprintf("%G", c2) + want(s, "(5+6i)") // real, imag, complex c3 := complex(real(c2)+3, imag(c2)-5) + c2 - fmt.Printf("c = %G\n", c3) + s = fmt.Sprintf("%G", c3) + want(s, "(13+7i)") // compiler used to crash on nested divide c4 := complex(real(c3/2), imag(c3/2)) if c4 != c3/2 { fmt.Printf("BUG: c3 = %G != c4 = %G\n", c3, c4) + panic(0) } } diff --git a/test/ken/label.go b/test/ken/label.go index fa5dc0621f..7a509f0484 100644 --- a/test/ken/label.go +++ b/test/ken/label.go @@ -25,8 +25,6 @@ loop: if i < 100 { goto loop } - print(i) - print("\n") return gogoloop: diff --git a/test/ken/rob1.go b/test/ken/rob1.go index 8f1da4b7c6..a5854b93e2 100644 --- a/test/ken/rob1.go +++ b/test/ken/rob1.go @@ -7,7 +7,7 @@ package main type Item interface { - Print() + Print() string } type ListItem struct { @@ -30,12 +30,14 @@ func (list *List) Insert(i Item) { list.head = item } -func (list *List) Print() { +func (list *List) Print() string { + r := "" i := list.head for i != nil { - i.item.Print() + r += i.item.Print() i = i.next } + return r } // Something to put in a list @@ -48,8 +50,8 @@ func (this *Integer) Init(i int) *Integer { return this } -func (this *Integer) Print() { - print(this.val) +func (this *Integer) Print() string { + return string(this.val + '0') } func main() { @@ -61,6 +63,8 @@ func main() { list.Insert(integer) } - list.Print() - print("\n") + r := list.Print() + if r != "9876543210" { + panic(r) + } } diff --git a/test/ken/rob2.go b/test/ken/rob2.go index 76a471cfb3..d13e2441d4 100644 --- a/test/ken/rob2.go +++ b/test/ken/rob2.go @@ -6,6 +6,8 @@ package main +import "fmt" + const nilchar = 0 type Atom struct { @@ -80,40 +82,44 @@ func main() { if list == nil { break } - list.Print() + r := list.Print() list.Free() + if r != "(defn foo (add 12 34))" { + panic(r) + } break } } -func (slist *Slist) PrintOne(doparen bool) { +func (slist *Slist) PrintOne(doparen bool) string { if slist == nil { - return + return "" } + var r string if slist.isatom { if slist.isstring { - print(slist.String()) + r = slist.String() } else { - print(slist.Integer()) + r = fmt.Sprintf("%v", slist.Integer()) } } else { if doparen { - print("(") + r += "(" } - slist.Car().PrintOne(true) + r += slist.Car().PrintOne(true) if slist.Cdr() != nil { - print(" ") - slist.Cdr().PrintOne(false) + r += " " + r += slist.Cdr().PrintOne(false) } if doparen { - print(")") + r += ")" } } + return r } -func (slist *Slist) Print() { - slist.PrintOne(true) - print("\n") +func (slist *Slist) Print() string { + return slist.PrintOne(true) } func Get() int { diff --git a/test/ken/simpprint.go b/test/ken/simpprint.go deleted file mode 100644 index 6077f7eb02..0000000000 --- a/test/ken/simpprint.go +++ /dev/null @@ -1,13 +0,0 @@ -// $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() { - print("hello world\n"); -} diff --git a/test/ken/simpswitch.go b/test/ken/simpswitch.go index 4db98b1c09..710af2e08c 100644 --- a/test/ken/simpswitch.go +++ b/test/ken/simpswitch.go @@ -7,17 +7,20 @@ package main func main() { + r := "" a := 3 for i := 0; i < 10; i = i + 1 { switch i { case 5: - print("five") + r += "five" case a, 7: - print("a") + r += "a" default: - print(i) + r += string(i + '0') } - print("out", i) + r += "out" + string(i+'0') + } + if r != "0out01out12out2aout34out4fiveout56out6aout78out89out9" { + panic(r) } - print("\n") } diff --git a/test/peano.go b/test/peano.go index fb74e6533c..dd4c36e0b4 100644 --- a/test/peano.go +++ b/test/peano.go @@ -107,8 +107,16 @@ func init() { // ------------------------------------- // Factorial +var results = [...]int{ + 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, + 39916800, 479001600, +} + func main() { for i := 0; i <= 9; i++ { - print(i, "! = ", count(fact(gen(i))), "\n") + if f := count(fact(gen(i))); f != results[i] { + println("FAIL:", i, "!:", f, "!=", results[i]) + panic(0) + } } } diff --git a/test/turing.go b/test/turing.go index 9d3f3a669d..366982e67f 100644 --- a/test/turing.go +++ b/test/turing.go @@ -25,6 +25,7 @@ func scan(dir int) { } func main() { + r := "" for { switch prog[pc] { case '>': @@ -36,7 +37,7 @@ func main() { case '-': a[p]-- case '.': - print(string(a[p])) + r += string(a[p]) case '[': if a[p] == 0 { scan(1) @@ -46,6 +47,9 @@ func main() { scan(-1) } default: + if r != "Hello World!\n" { + panic(r) + } return } pc++ -- 2.48.1