Commit dda6d6aa authored by Shenghou Ma's avatar Shenghou Ma

test: use testlib in a few more cases (part 2)

        Introduced "runoutput" cmd for running generated program

R=golang-dev, iant, bradfitz, remyoudompheng
CC=golang-dev
https://golang.org/cl/5869049
parent f8dde60e
// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go && // runoutput
// $G tmp.go && $L tmp.$A && ./$A.out || echo BUG: 64bit
// rm -f tmp.go
// Copyright 2009 The Go Authors. All rights reserved. // Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
......
// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go && // runoutput
// $G tmp.go && $L tmp.$A && ./$A.out || echo BUG: select5
// rm -f tmp.go
// Copyright 2011 The Go Authors. All rights reserved. // Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
......
// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go && // runoutput
// $G tmp.go && $L tmp.$A && ./$A.out
// rm -f tmp.go
// Copyright 2011 The Go Authors. All rights reserved. // Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
......
...@@ -100,7 +100,7 @@ do ...@@ -100,7 +100,7 @@ do
echo $i >>pass.out echo $i >>pass.out
fi fi
echo $(awk 'NR==1{print $2}' "$TMP2FILE") $D/$F >>times.out echo $(awk 'NR==1{print $2}' "$TMP2FILE") $D/$F >>times.out
rm -f $F.$A $A.out rm -f $F.$A $A.out tmp.go
) done ) done
done | # clean up some stack noise done | # clean up some stack noise
egrep -v '^(r[0-9a-z]+|[cfg]s) +0x' | egrep -v '^(r[0-9a-z]+|[cfg]s) +0x' |
......
...@@ -172,7 +172,7 @@ type test struct { ...@@ -172,7 +172,7 @@ type test struct {
donec chan bool // closed when done donec chan bool // closed when done
src string src string
action string // "compile", "build", "run", "errorcheck", "skip" action string // "compile", "build", "run", "errorcheck", "skip", "runoutput"
tempDir string tempDir string
err error err error
...@@ -251,7 +251,7 @@ func (t *test) run() { ...@@ -251,7 +251,7 @@ func (t *test) run() {
case "cmpout": case "cmpout":
action = "run" // the run case already looks for <dir>/<test>.out files action = "run" // the run case already looks for <dir>/<test>.out files
fallthrough fallthrough
case "compile", "build", "run", "errorcheck": case "compile", "build", "run", "errorcheck", "runoutput":
t.action = action t.action = action
case "skip": case "skip":
t.action = "skip" t.action = "skip"
...@@ -316,6 +316,26 @@ func (t *test) run() { ...@@ -316,6 +316,26 @@ func (t *test) run() {
if string(out) != t.expectedOutput() { if string(out) != t.expectedOutput() {
t.err = fmt.Errorf("incorrect output\n%s", out) t.err = fmt.Errorf("incorrect output\n%s", out)
} }
case "runoutput":
useTmp = false
out, err := runcmd("go", "run", t.goFileName())
if err != nil {
t.err = fmt.Errorf("%s\n%s", err, out)
}
tfile := filepath.Join(t.tempDir, "tmp__.go")
err = ioutil.WriteFile(tfile, out, 0666)
if err != nil {
t.err = fmt.Errorf("write tempfile:%s", err)
return
}
out, err = runcmd("go", "run", tfile)
if err != nil {
t.err = fmt.Errorf("%s\n%s", err, out)
}
if string(out) != t.expectedOutput() {
t.err = fmt.Errorf("incorrect output\n%s", out)
}
} }
} }
......
...@@ -13,6 +13,11 @@ build() { ...@@ -13,6 +13,11 @@ build() {
$G $D/$F.go && $L $F.$A $G $D/$F.go && $L $F.$A
} }
runoutput() {
go run "$D/$F.go" > tmp.go
go run tmp.go
}
run() { run() {
gofiles="" gofiles=""
ingo=true ingo=true
......
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