summaryrefslogtreecommitdiff
path: root/test/ken
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2012-01-18 14:31:31 -0800
committerIan Lance Taylor <iant@golang.org>2012-01-18 14:31:31 -0800
commit46690a30548a029c3ced15c58088685898d52f6f (patch)
treef6e33856c806d3b0fc8b6ac55d74d26541db145c /test/ken
parent43a23b4d1dd11c9fe4b58923c589ae30648ca59e (diff)
downloadgo-46690a30548a029c3ced15c58088685898d52f6f.tar.gz
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 http://codereview.appspot.com/5536058
Diffstat (limited to 'test/ken')
-rw-r--r--test/ken/cplx4.go28
-rw-r--r--test/ken/label.go2
-rw-r--r--test/ken/rob1.go18
-rw-r--r--test/ken/rob2.go32
-rw-r--r--test/ken/simpprint.go13
-rw-r--r--test/ken/simpswitch.go13
6 files changed, 59 insertions, 47 deletions
diff --git a/test/ken/cplx4.go b/test/ken/cplx4.go
index 8524e47ae..738afcd2c 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 fa5dc0621..7a509f048 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 8f1da4b7c..a5854b93e 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 76a471cfb..d13e2441d 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 6077f7eb0..000000000
--- 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 4db98b1c0..710af2e08 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")
}