Skip to content

Commit

Permalink
test: use testlib in a few more cases (part 2)
Browse files Browse the repository at this point in the history
        Introduced "runoutput" cmd for running generated program

R=golang-dev, iant, bradfitz, remyoudompheng
CC=golang-dev
https://golang.org/cl/5869049
  • Loading branch information
minux committed Apr 20, 2012
1 parent f8dde60 commit dda6d6a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
4 changes: 1 addition & 3 deletions test/64bit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go &&
// $G tmp.go && $L tmp.$A && ./$A.out || echo BUG: 64bit
// rm -f tmp.go
// runoutput

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
Expand Down
4 changes: 1 addition & 3 deletions test/chan/select5.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go &&
// $G tmp.go && $L tmp.$A && ./$A.out || echo BUG: select5
// rm -f tmp.go
// runoutput

// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
Expand Down
4 changes: 1 addition & 3 deletions test/crlf.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// $G $D/$F.go && $L $F.$A && ./$A.out >tmp.go &&
// $G tmp.go && $L tmp.$A && ./$A.out
// rm -f tmp.go
// runoutput

// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
Expand Down
2 changes: 1 addition & 1 deletion test/run
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ do
echo $i >>pass.out
fi
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 | # clean up some stack noise
egrep -v '^(r[0-9a-z]+|[cfg]s) +0x' |
Expand Down
24 changes: 22 additions & 2 deletions test/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ type test struct {
donec chan bool // closed when done

src string
action string // "compile", "build", "run", "errorcheck", "skip"
action string // "compile", "build", "run", "errorcheck", "skip", "runoutput"

tempDir string
err error
Expand Down Expand Up @@ -251,7 +251,7 @@ func (t *test) run() {
case "cmpout":
action = "run" // the run case already looks for <dir>/<test>.out files
fallthrough
case "compile", "build", "run", "errorcheck":
case "compile", "build", "run", "errorcheck", "runoutput":
t.action = action
case "skip":
t.action = "skip"
Expand Down Expand Up @@ -316,6 +316,26 @@ func (t *test) run() {
if string(out) != t.expectedOutput() {
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)
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/testlib
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ build() {
$G $D/$F.go && $L $F.$A
}

runoutput() {
go run "$D/$F.go" > tmp.go
go run tmp.go
}

run() {
gofiles=""
ingo=true
Expand Down

0 comments on commit dda6d6a

Please sign in to comment.