diff options
Diffstat (limited to 'test')
29 files changed, 467 insertions, 132 deletions
diff --git a/test/bench/garbage/Makefile b/test/bench/garbage/Makefile index 8002a2017..98838453a 100644 --- a/test/bench/garbage/Makefile +++ b/test/bench/garbage/Makefile @@ -2,27 +2,22 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. -include ../../../src/Make.inc - ALL=\ parser\ peano\ tree\ tree2\ -all: $(addsuffix .out, $(ALL)) - -%.$O: %.go stats.go - $(GC) $(GCFLAGS) $(GCIMPORTS) $*.go stats.go +all: $(ALL) -%.out: %.$O - $(LD) -o $@ $*.$O +%: %.go + go build $*.go stats.go -%.bench: %.out - time ./$*.out +%.bench: % + time ./$* bench: $(addsuffix .bench, $(ALL)) clean: - rm -f *.[$(OS)] $(addsuffix .out, $(ALL)) + rm -f $(ALL) diff --git a/test/bench/go1/Makefile b/test/bench/go1/Makefile deleted file mode 100644 index aa5585335..000000000 --- a/test/bench/go1/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -include $(GOROOT)/src/Make.inc - -TARG=go1 -GOFILES=\ - dummy.go\ - -include $(GOROOT)/src/Make.pkg - -test: - echo go1: tests disabled for now TODO diff --git a/test/bench/go1/dummy.go b/test/bench/go1/dummy.go deleted file mode 100644 index 4956bc7b7..000000000 --- a/test/bench/go1/dummy.go +++ /dev/null @@ -1,3 +0,0 @@ -package go1 - -// Nothing to see here: everything is in the _test files. diff --git a/test/bench/go1/gzip_test.go b/test/bench/go1/gzip_test.go index c9eeb175f..fe4c480eb 100644 --- a/test/bench/go1/gzip_test.go +++ b/test/bench/go1/gzip_test.go @@ -21,20 +21,14 @@ var ( func init() { var buf bytes.Buffer - c, err := gz.NewWriter(&buf) - if err != nil { - panic(err) - } + c := gz.NewWriter(&buf) c.Write(jsongunz) c.Close() jsongz = buf.Bytes() } func gzip() { - c, err := gz.NewWriter(ioutil.Discard) - if err != nil { - panic(err) - } + c := gz.NewWriter(ioutil.Discard) if _, err := c.Write(jsongunz); err != nil { panic(err) } diff --git a/test/bugs/424.go b/test/bugs/424.go deleted file mode 100644 index b22776086..000000000 --- a/test/bugs/424.go +++ /dev/null @@ -1,9 +0,0 @@ -// $G $D/$F.dir/lib.go && $G $D/$F.dir/main.go && $L main.$A && $A.out - -// Copyright 2012 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. - -// Test case for embedded method invocation. - -ignored diff --git a/test/cmplxdivide.c b/test/cmplxdivide.c index b340f04d8..12dc4f1c0 100644 --- a/test/cmplxdivide.c +++ b/test/cmplxdivide.c @@ -51,6 +51,7 @@ main(void) int i, j, k, l; double complex n, d, q; + printf("// skip\n"); printf("// # generated by cmplxdivide.c\n"); printf("\n"); printf("package main\n"); diff --git a/test/cmplxdivide.go b/test/cmplxdivide.go index 461ee9796..92a98356d 100644 --- a/test/cmplxdivide.go +++ b/test/cmplxdivide.go @@ -1,4 +1,4 @@ -// $G $D/$F.go $D/cmplxdivide1.go && $L $D/$F.$A && ./$A.out +// run cmplxdivide1.go // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/cmplxdivide1.go b/test/cmplxdivide1.go index 6a1dee9fe..e9031dd15 100644 --- a/test/cmplxdivide1.go +++ b/test/cmplxdivide1.go @@ -1,3 +1,4 @@ +// skip // # generated by cmplxdivide.c package main diff --git a/test/const4.go b/test/const4.go new file mode 100644 index 000000000..677fcefa7 --- /dev/null +++ b/test/const4.go @@ -0,0 +1,77 @@ +// run + +// Copyright 2011 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. + +// Test len constants and non-constants, http://golang.org/issue/3244. + +package main + +var b struct { + a[10]int +} + +var m map[string][20]int + +var s [][30]int + +const ( + n1 = len(b.a) + n2 = len(m[""]) + n3 = len(s[10]) +) + +// Non-constants (see also const5.go). +var ( + n4 = len(f()) + n5 = len(<-c) + n6 = cap(g()) + n7 = cap(<-c1) +) + +var calledF = false + +func f() *[40]int { + calledF = true + return nil +} + +var c = func() chan *[50]int { + c := make(chan *[50]int, 2) + c <- nil + c <- new([50]int) + return c +}() + +var calledG = false + +func g() *[60]int { + calledG = true + return nil +} + +var c1 = func() chan *[70]int { + c := make(chan *[70]int, 2) + c <- nil + c <- new([70]int) + return c +}() + +func main() { + if n1 != 10 || n2 != 20 || n3 != 30 || n4 != 40 || n5 != 50 || n6 != 60 || n7 != 70 { + println("BUG:", n1, n2, n3, n4, n5, n6, n7) + } + if !calledF { + println("BUG: did not call f") + } + if <-c == nil { + println("BUG: did not receive from c") + } + if !calledG { + println("BUG: did not call g") + } + if <-c1 == nil { + println("BUG: did not receive from c1") + } +} diff --git a/test/const5.go b/test/const5.go new file mode 100644 index 000000000..8e0385e9a --- /dev/null +++ b/test/const5.go @@ -0,0 +1,33 @@ +// errorcheck + +// Copyright 2011 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. + +// Test that len non-constants are not constants, http://golang.org/issue/3244. + +package p + +var b struct { + a[10]int +} + +var m map[string][20]int + +var s [][30]int + +func f() *[40]int +var c chan *[50]int + +const ( + n1 = len(b.a) + n2 = len(m[""]) + n3 = len(s[10]) + + n4 = len(f()) // ERROR "must be constant" + n5 = len(<-c) // ERROR "must be constant" + + n6 = cap(f()) // ERROR "must be constant" + n7 = cap(<-c) // ERROR "must be constant" +) + diff --git a/test/ddd.go b/test/ddd.go index f35836331..01768b89f 100644 --- a/test/ddd.go +++ b/test/ddd.go @@ -60,6 +60,10 @@ type U struct { *T } +type I interface { + Sum(...int) int +} + func main() { if x := sum(1, 2, 3); x != 6 { println("sum 6", x) @@ -207,7 +211,14 @@ func main() { println("i(=u).Sum", x) panic("fail") } - /* TODO(rsc): Enable once nested method expressions work. + var s struct { + I + } + s.I = &u + if x := s.Sum(2, 3, 5, 8); x != 18 { + println("s{&u}.Sum", x) + panic("fail") + } if x := (*U).Sum(&U{}, 1, 3, 5, 2); x != 11 { println("(*U).Sum", x) panic("fail") @@ -216,5 +227,4 @@ func main() { println("U.Sum", x) panic("fail") } - */ } diff --git a/test/ddd2.go b/test/ddd2.go index 2edae36b1..a141a39c7 100644 --- a/test/ddd2.go +++ b/test/ddd2.go @@ -1,4 +1,4 @@ -// true +// skip // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/escape4.go b/test/escape4.go index ab3aee224..887570896 100644 --- a/test/escape4.go +++ b/test/escape4.go @@ -11,8 +11,8 @@ package foo var p *int -func alloc(x int) *int { // ERROR "can inline alloc" "moved to heap: x" - return &x // ERROR "&x escapes to heap" +func alloc(x int) *int { // ERROR "can inline alloc" "moved to heap: x" + return &x // ERROR "&x escapes to heap" } var f func() @@ -22,12 +22,18 @@ func f1() { // Escape analysis used to miss inlined code in closures. - func() { // ERROR "func literal does not escape" - p = alloc(3) // ERROR "inlining call to alloc" "&x escapes to heap" "moved to heap: x" + func() { // ERROR "func literal does not escape" + p = alloc(3) // ERROR "inlining call to alloc" "&x escapes to heap" "moved to heap: x" }() - - f = func() { // ERROR "func literal escapes to heap" - p = alloc(3) // ERROR "inlining call to alloc" "&x escapes to heap" "moved to heap: x" + + f = func() { // ERROR "func literal escapes to heap" + p = alloc(3) // ERROR "inlining call to alloc" "&x escapes to heap" "moved to heap: x" } f() } + +func f2() {} // ERROR "can inline f2" + +// No inline for panic, recover. +func f3() { panic(1) } +func f4() { recover() } diff --git a/test/fixedbugs/bug223.go b/test/fixedbugs/bug223.go index 80f9cae81..eccf574a1 100644 --- a/test/fixedbugs/bug223.go +++ b/test/fixedbugs/bug223.go @@ -1,4 +1,4 @@ -// (! $G $D/$F.go) | grep 'initialization loop' >/dev/null || echo BUG: bug223 +// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -18,4 +18,4 @@ func f() { } } -var m = map[string]F{"f": f} +var m = map[string]F{"f": f} // ERROR "initialization loop" diff --git a/test/fixedbugs/bug388.go b/test/fixedbugs/bug388.go index aa4cc5a97..d41f9ea54 100644 --- a/test/fixedbugs/bug388.go +++ b/test/fixedbugs/bug388.go @@ -9,13 +9,13 @@ package main import "runtime" -func foo(runtime.UintType, i int) { // ERROR "cannot declare name runtime.UintType|named/anonymous mix" - println(i, runtime.UintType) +func foo(runtime.UintType, i int) { // ERROR "cannot declare name runtime.UintType|named/anonymous mix|undefined identifier" + println(i, runtime.UintType) // GCCGO_ERROR "undefined identifier" } func bar(i int) { - runtime.UintType := i // ERROR "cannot declare name runtime.UintType|non-name on left side" - println(runtime.UintType) // GCCGO_ERROR "invalid use of type" + runtime.UintType := i // ERROR "cannot declare name runtime.UintType|non-name on left side|undefined identifier" + println(runtime.UintType) // GCCGO_ERROR "invalid use of type|undefined identifier" } func baz() { diff --git a/test/bugs/424.dir/lib.go b/test/fixedbugs/bug424.dir/lib.go index 97054da3a..97054da3a 100644 --- a/test/bugs/424.dir/lib.go +++ b/test/fixedbugs/bug424.dir/lib.go diff --git a/test/bugs/424.dir/main.go b/test/fixedbugs/bug424.go index 64a600b55..42cff54d4 100644 --- a/test/bugs/424.dir/main.go +++ b/test/fixedbugs/bug424.go @@ -1,15 +1,19 @@ +// $G $D/$F.dir/lib.go && $G $D/$F.go && $L $F.$A && ./$A.out + // Copyright 2012 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. // Tests that method calls through an interface always -// call the the locally defined method localT.m independent +// call the locally defined method localT.m independent // at which embedding level it is and in which order // embedding is done. package main import "./lib" +import "reflect" +import "fmt" type localI interface { m() string @@ -53,9 +57,43 @@ func main() { println("BUG: myT2:", i.m(), "called") } + t3 := new(myT3) + if t3.m() != "main.localT.m" { + println("BUG: t3:", t3.m(), "called") + } + i = new(myT3) if i.m() != "main.localT.m" { + t := reflect.TypeOf(i) + n := t.NumMethod() + for j := 0; j < n; j++ { + m := t.Method(j) + fmt.Printf("#%d: %s.%s %s\n", j, m.PkgPath, m.Name, m.Type) + } println("BUG: myT3:", i.m(), "called") } - + + var t4 struct { + localT + lib.T + } + if t4.m() != "main.localT.m" { + println("BUG: t4:", t4.m(), "called") + } + i = &t4 + if i.m() != "main.localT.m" { + println("BUG: myT4:", i.m(), "called") + } + + var t5 struct { + lib.T + localT + } + if t5.m() != "main.localT.m" { + println("BUG: t5:", t5.m(), "called") + } + i = &t5 + if i.m() != "main.localT.m" { + println("BUG: myT5:", i.m(), "called") + } } diff --git a/test/fixedbugs/bug427.go b/test/fixedbugs/bug427.go new file mode 100644 index 000000000..1239e7a33 --- /dev/null +++ b/test/fixedbugs/bug427.go @@ -0,0 +1,39 @@ +// compile + +// Copyright 2012 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. + +// http://code.google.com/p/go/issues/detail?id=3351 + +package main + +// struct with four fields of basic type +type S struct {a, b, c, d int} + +// struct with five fields of basic type +type T struct {a, b, c, d, e int} + +// array with four elements +type A [4]int + +// array with five elements +type B [5]int + +func main() { + var i interface{} + + var s1, s2 S + i = s1 == s2 + + var t1, t2 T + i = t1 == t2 + + var a1, a2 A + i = a1 == a2 + + var b1, b2 B + i = b1 == b2 + + _ = i +} diff --git a/test/fixedbugs/bug428.go b/test/fixedbugs/bug428.go new file mode 100644 index 000000000..298c45518 --- /dev/null +++ b/test/fixedbugs/bug428.go @@ -0,0 +1,19 @@ +// run + +// Copyright 2012 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. + +// Test that when the compiler expands append inline it does not +// overwrite a value before it needs it (issue 3369). + +package main + +func main() { + s := make([]byte, 5, 6) + copy(s, "12346") + s = append(s[:len(s)-1], '5', s[len(s)-1]) + if string(s) != "123456" { + panic(s) + } +} diff --git a/test/golden.out b/test/golden.out index b7d759450..764f56196 100644 --- a/test/golden.out +++ b/test/golden.out @@ -17,8 +17,5 @@ == bugs/ -=========== bugs/424.go -BUG: myT3: lib.T.m called - =========== bugs/bug395.go bug395 is broken diff --git a/test/import2.go b/test/import2.go index 0acfabcc1..5c275f34b 100644 --- a/test/import2.go +++ b/test/import2.go @@ -1,4 +1,4 @@ -// true # used by import3 +// skip # used by import3 // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/interface/embed0.go b/test/interface/embed0.go index dee8319e4..e2ee20ade 100644 --- a/test/interface/embed0.go +++ b/test/interface/embed0.go @@ -1,4 +1,4 @@ -// true # used by embed1.go +// skip # used by embed1.go // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/interface/private1.go b/test/interface/private1.go index 9c831a2f4..3281c38be 100644 --- a/test/interface/private1.go +++ b/test/interface/private1.go @@ -1,4 +1,4 @@ -// true # used by private.go +// skip # used by private.go // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/interface/recursive1.go b/test/interface/recursive1.go index 524dda82c..cc3cdc37f 100644 --- a/test/interface/recursive1.go +++ b/test/interface/recursive1.go @@ -1,4 +1,4 @@ -// true # used by recursive2 +// skip # used by recursive2 // Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/method.go b/test/method.go index 6080ce5a7..0c239afbd 100644 --- a/test/method.go +++ b/test/method.go @@ -94,27 +94,27 @@ func main() { } if val(s) != 1 { - println("s.val:", val(s)) + println("val(s):", val(s)) panic("fail") } if val(ps) != 2 { - println("ps.val:", val(ps)) + println("val(ps):", val(ps)) panic("fail") } if val(i) != 3 { - println("i.val:", val(i)) + println("val(i):", val(i)) panic("fail") } if val(pi) != 4 { - println("pi.val:", val(pi)) + println("val(pi):", val(pi)) panic("fail") } if val(t) != 7 { - println("t.val:", val(t)) + println("val(t):", val(t)) panic("fail") } if val(pt) != 8 { - println("pt.val:", val(pt)) + println("val(pt):", val(pt)) panic("fail") } @@ -127,4 +127,124 @@ func main() { println("Val.val(v):", Val.val(v)) panic("fail") } + + var zs struct { S } + var zps struct { *S1 } + var zi struct { I } + var zpi struct { *I1 } + var zpt struct { *T1 } + var zt struct { T } + var zv struct { Val } + + if zs.val() != 1 { + println("zs.val:", zs.val()) + panic("fail") + } + if zps.val() != 2 { + println("zps.val:", zps.val()) + panic("fail") + } + if zi.val() != 3 { + println("zi.val:", zi.val()) + panic("fail") + } + if zpi.val() != 4 { + println("zpi.val:", zpi.val()) + panic("fail") + } + if zt.val() != 7 { + println("zt.val:", zt.val()) + panic("fail") + } + if zpt.val() != 8 { + println("zpt.val:", zpt.val()) + panic("fail") + } + + if val(zs) != 1 { + println("val(zs):", val(zs)) + panic("fail") + } + if val(zps) != 2 { + println("val(zps):", val(zps)) + panic("fail") + } + if val(zi) != 3 { + println("val(zi):", val(zi)) + panic("fail") + } + if val(zpi) != 4 { + println("val(zpi):", val(zpi)) + panic("fail") + } + if val(zt) != 7 { + println("val(zt):", val(zt)) + panic("fail") + } + if val(zpt) != 8 { + println("val(zpt):", val(zpt)) + panic("fail") + } + + zv.Val = zi + if zv.val() != 3 { + println("zv.val():", zv.val()) + panic("fail") + } + + if (&zs).val() != 1 { + println("(&zs).val:", (&zs).val()) + panic("fail") + } + if (&zps).val() != 2 { + println("(&zps).val:", (&zps).val()) + panic("fail") + } + if (&zi).val() != 3 { + println("(&zi).val:", (&zi).val()) + panic("fail") + } + if (&zpi).val() != 4 { + println("(&zpi).val:", (&zpi).val()) + panic("fail") + } + if (&zt).val() != 7 { + println("(&zt).val:", (&zt).val()) + panic("fail") + } + if (&zpt).val() != 8 { + println("(&zpt).val:", (&zpt).val()) + panic("fail") + } + + if val(&zs) != 1 { + println("val(&zs):", val(&zs)) + panic("fail") + } + if val(&zps) != 2 { + println("val(&zps):", val(&zps)) + panic("fail") + } + if val(&zi) != 3 { + println("val(&zi):", val(&zi)) + panic("fail") + } + if val(&zpi) != 4 { + println("val(&zpi):", val(&zpi)) + panic("fail") + } + if val(&zt) != 7 { + println("val(&zt):", val(&zt)) + panic("fail") + } + if val(&zpt) != 8 { + println("val(&zpt):", val(&zpt)) + panic("fail") + } + + zv.Val = &zi + if zv.val() != 3 { + println("zv.val():", zv.val()) + panic("fail") + } } diff --git a/test/method4a.go b/test/method4a.go index 11fa218f3..d23039bfa 100644 --- a/test/method4a.go +++ b/test/method4a.go @@ -1,4 +1,4 @@ -// true +// skip // Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -29,6 +29,8 @@ export GOTRACEBACK=0 export LANG=C unset GREP_OPTIONS # in case user has a non-standard set +unset GOROOT_FINAL # breaks ./ imports + failed=0 PATH=${GOBIN:-$GOROOT/bin}:`pwd`:/bin:/usr/bin:/usr/local/bin diff --git a/test/run.go b/test/run.go index 3ba35f9d4..ac6e3c0e2 100644 --- a/test/run.go +++ b/test/run.go @@ -1,4 +1,4 @@ -// #ignore +// skip // Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -30,7 +30,7 @@ import ( var ( verbose = flag.Bool("v", false, "verbose. if set, parallelism is set to 1.") - numParallel = flag.Int("n", 8, "number of parallel tests to run") + numParallel = flag.Int("n", runtime.NumCPU(), "number of parallel tests to run") summary = flag.Bool("summary", false, "show summary of results") showSkips = flag.Bool("show_skips", false, "show skipped tests") ) @@ -60,13 +60,15 @@ const maxTests = 5000 func main() { flag.Parse() + + // Disable parallelism if printing if *verbose { *numParallel = 1 } ratec = make(chan bool, *numParallel) var err error - letter, err = build.ArchChar(build.DefaultContext.GOARCH) + letter, err = build.ArchChar(build.Default.GOARCH) check(err) gc = letter + "g" ld = letter + "l" @@ -145,7 +147,7 @@ func goFiles(dir string) []string { check(err) names := []string{} for _, name := range dirnames { - if strings.HasSuffix(name, ".go") { + if !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go") { names = append(names, name) } } @@ -170,7 +172,7 @@ type test struct { donec chan bool // closed when done src string - action string // "compile", "build", "run", "errorcheck" + action string // "compile", "build", "run", "errorcheck", "skip" tempDir string err error @@ -208,6 +210,8 @@ func runTests() { } } +var cwd, _ = os.Getwd() + func (t *test) goFileName() string { return filepath.Join(t.dir, t.gofile) } @@ -235,7 +239,13 @@ func (t *test) run() { if strings.HasPrefix(action, "//") { action = action[2:] } - action = strings.TrimSpace(action) + + var args []string + f := strings.Fields(action) + if len(f) > 0 { + action = f[0] + args = f[1:] + } switch action { case "cmpout": @@ -243,6 +253,9 @@ func (t *test) run() { fallthrough case "compile", "build", "run", "errorcheck": t.action = action + case "skip": + t.action = "skip" + return default: t.err = skipError("skipped; unknown pattern: " + action) t.action = "??" @@ -255,66 +268,55 @@ func (t *test) run() { err = ioutil.WriteFile(filepath.Join(t.tempDir, t.gofile), srcBytes, 0644) check(err) - cmd := exec.Command("go", "tool", gc, "-e", "-o", "a."+letter, t.gofile) - var buf bytes.Buffer - cmd.Stdout = &buf - cmd.Stderr = &buf - cmd.Dir = t.tempDir - err = cmd.Run() - out := buf.String() - - if action == "errorcheck" { - t.err = t.errorCheck(out) - return - } + // A few tests (of things like the environment) require these to be set. + os.Setenv("GOOS", runtime.GOOS) + os.Setenv("GOARCH", runtime.GOARCH) - if err != nil { - t.err = fmt.Errorf("build = %v (%q)", err, out) - return + useTmp := true + runcmd := func(args ...string) ([]byte, error) { + cmd := exec.Command(args[0], args[1:]...) + var buf bytes.Buffer + cmd.Stdout = &buf + cmd.Stderr = &buf + if useTmp { + cmd.Dir = t.tempDir + } + err := cmd.Run() + return buf.Bytes(), err } - if action == "compile" { + long := filepath.Join(cwd, t.goFileName()) + switch action { + default: + t.err = fmt.Errorf("unimplemented action %q", action) + + case "errorcheck": + out, _ := runcmd("go", "tool", gc, "-e", "-o", "a."+letter, long) + t.err = t.errorCheck(string(out), long, t.gofile) return - } - if action == "build" || action == "run" { - buf.Reset() - cmd = exec.Command("go", "tool", ld, "-o", "a.out", "a."+letter) - cmd.Stdout = &buf - cmd.Stderr = &buf - cmd.Dir = t.tempDir - err = cmd.Run() - out = buf.String() + case "compile": + out, err := runcmd("go", "tool", gc, "-e", "-o", "a."+letter, long) if err != nil { - t.err = fmt.Errorf("link = %v (%q)", err, out) - return + t.err = fmt.Errorf("%s\n%s", err, out) } - if action == "build" { - return - } - } - if action == "run" { - buf.Reset() - cmd = exec.Command(filepath.Join(t.tempDir, "a.out")) - cmd.Stdout = &buf - cmd.Stderr = &buf - cmd.Dir = t.tempDir - cmd.Env = append(cmd.Env, "GOARCH="+runtime.GOARCH) - err = cmd.Run() - out = buf.String() + case "build": + out, err := runcmd("go", "build", "-o", "a.exe", long) if err != nil { - t.err = fmt.Errorf("run = %v (%q)", err, out) - return + t.err = fmt.Errorf("%s\n%s", err, out) } - if out != t.expectedOutput() { - t.err = fmt.Errorf("output differs; got:\n%s", out) + case "run": + useTmp = false + out, err := runcmd(append([]string{"go", "run", t.goFileName()}, args...)...) + 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) } - return } - - t.err = fmt.Errorf("unimplemented action %q", action) } func (t *test) String() string { @@ -335,7 +337,7 @@ func (t *test) expectedOutput() string { return string(b) } -func (t *test) errorCheck(outStr string) (err error) { +func (t *test) errorCheck(outStr string, full, short string) (err error) { defer func() { if *verbose && err != nil { log.Printf("%s gc output:\n%s", t, outStr) @@ -354,11 +356,16 @@ func (t *test) errorCheck(outStr string) (err error) { } } + // Cut directory name. + for i := range out { + out[i] = strings.Replace(out[i], full, short, -1) + } + for _, we := range t.wantedErrors() { var errmsgs []string errmsgs, out = partitionStrings(we.filterRe, out) if len(errmsgs) == 0 { - errs = append(errs, fmt.Errorf("errchk: %s:%d: missing expected error: %s", we.file, we.lineNum, we.reStr)) + errs = append(errs, fmt.Errorf("%s:%d: missing error %q", we.file, we.lineNum, we.reStr)) continue } matched := false @@ -370,7 +377,7 @@ func (t *test) errorCheck(outStr string) (err error) { } } if !matched { - errs = append(errs, fmt.Errorf("errchk: %s:%d: error(s) on line didn't match pattern: %s", we.file, we.lineNum, we.reStr)) + errs = append(errs, fmt.Errorf("%s:%d: no match for %q in%s", we.file, we.lineNum, we.reStr, strings.Join(out, "\n"))) continue } } @@ -382,7 +389,7 @@ func (t *test) errorCheck(outStr string) (err error) { return errs[0] } var buf bytes.Buffer - buf.WriteString("Multiple errors:\n") + fmt.Fprintf(&buf, "\n") for _, err := range errs { fmt.Fprintf(&buf, "%s\n", err.Error()) } diff --git a/test/testlib b/test/testlib index 2e4fefc8c..3858431a7 100644 --- a/test/testlib +++ b/test/testlib @@ -14,7 +14,21 @@ build() { } run() { - $G $D/$F.go && $L $F.$A && ./$A.out "$@" + gofiles="" + ingo=true + while $ingo; do + case "$1" in + *.go) + gofiles="$gofiles $1" + shift + ;; + *) + ingo=false + ;; + esac + done + + $G $D/$F.go $gofiles && $L $F.$A && ./$A.out "$@" } cmpout() { @@ -24,3 +38,7 @@ cmpout() { errorcheck() { errchk $G -e $D/$F.go } + +skip() { + true +} |