]> Cypherpunks repositories - gostls13.git/commitdiff
test: change several tests to not print
authorIan Lance Taylor <iant@golang.org>
Wed, 18 Jan 2012 22:31:31 +0000 (14:31 -0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 18 Jan 2012 22:31:31 +0000 (14:31 -0800)
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
test/fixedbugs/bug070.go
test/golden.out
test/ken/cplx4.go
test/ken/label.go
test/ken/rob1.go
test/ken/rob2.go
test/ken/simpprint.go [deleted file]
test/ken/simpswitch.go
test/peano.go
test/turing.go

index a7b639474ef925f73a63b8275d11853aa1147b88..cf2daaecf06b42b9a8e058171f9098113640ffa8 100644 (file)
@@ -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)
        }
 }
 
index f63caa9655ed6af7e4c625783180f5cca7d0f76e..24ac7798889ad9d4af3fb3f17a2e7c4dc7af5fdd 100644 (file)
@@ -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)
+       }
 }
index 6dccb6ec01d7e6e89c0b6f0fb687de5b8f33c044..58a0df2854c80072c40dae13197f3338d25b3424 100644 (file)
@@ -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
 
index 8524e47aec3b303a95b5e0fae2b3e9b32c1ac8df..738afcd2cad3df54fca8f4391fbc5b6551f5c02e 100644 (file)
@@ -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)
        }
 }
index fa5dc0621f214436d5761c2ba5c191d0637ca285..7a509f0484a92630c47dc174dda79f0a121be0b7 100644 (file)
@@ -25,8 +25,6 @@ loop:
        if i < 100 {
                goto loop
        }
-       print(i)
-       print("\n")
        return
 
 gogoloop:
index 8f1da4b7c630920a555a349cf4cfff689c989c1e..a5854b93e2f3627e2f22c62f8fb80268671a5e0a 100644 (file)
@@ -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)
+       }
 }
index 76a471cfb39521fcb92f596ba77b4f66443198fd..d13e2441d401488add0f6aad2775a7cb8ca9c981 100644 (file)
@@ -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 (file)
index 6077f7e..0000000
+++ /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");
-}
index 4db98b1c09e2d1e460a1fcee3f6e943c657f3795..710af2e08c69b277e2f264f0829abe79075fa380 100644 (file)
@@ -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")
 }
index fb74e6533cf78e1aca1e403407ea713b2e7006f3..dd4c36e0b434f02ea0715daca3c491026b716d30 100644 (file)
@@ -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)
+               }
        }
 }
index 9d3f3a669d1fb9938819a13562e1e9060581064b..366982e67f12e8ecb4d381f022342a7fb4bffce7 100644 (file)
@@ -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++