mirror of https://github.com/golang/go.git
test/run: handle compiledir and errorcheckdir with multi-file packages
Multiple files with the same package all get compiled together. R=golang-dev, iant, dave CC=golang-dev https://golang.org/cl/7005053
This commit is contained in:
parent
7ced3f12bc
commit
8850d14fe9
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package z
|
||||||
|
|
||||||
import "./p2"
|
import "./p2"
|
||||||
|
|
||||||
|
|
|
||||||
74
test/run.go
74
test/run.go
|
|
@ -171,8 +171,12 @@ func compileFile(runcmd runCmd, longname string) (out []byte, err error) {
|
||||||
return runcmd("go", "tool", gc, "-e", longname)
|
return runcmd("go", "tool", gc, "-e", longname)
|
||||||
}
|
}
|
||||||
|
|
||||||
func compileInDir(runcmd runCmd, dir, name string) (out []byte, err error) {
|
func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err error) {
|
||||||
return runcmd("go", "tool", gc, "-e", "-D.", "-I.", filepath.Join(dir, name))
|
cmd := []string{"go", "tool", gc, "-e", "-D", ".", "-I", "."}
|
||||||
|
for _, name := range names {
|
||||||
|
cmd = append(cmd, filepath.Join(dir, name))
|
||||||
|
}
|
||||||
|
return runcmd(cmd...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func linkFile(runcmd runCmd, goname string) (err error) {
|
func linkFile(runcmd runCmd, goname string) (err error) {
|
||||||
|
|
@ -259,6 +263,36 @@ func goDirFiles(longdir string) (filter []os.FileInfo, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var packageRE = regexp.MustCompile(`(?m)^package (\w+)`)
|
||||||
|
|
||||||
|
func goDirPackages(longdir string) ([][]string, error) {
|
||||||
|
files, err := goDirFiles(longdir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var pkgs [][]string
|
||||||
|
m := make(map[string]int)
|
||||||
|
for _, file := range files {
|
||||||
|
name := file.Name()
|
||||||
|
data, err := ioutil.ReadFile(filepath.Join(longdir, name))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
pkgname := packageRE.FindStringSubmatch(string(data))
|
||||||
|
if pkgname == nil {
|
||||||
|
return nil, fmt.Errorf("cannot find package name in %s", name)
|
||||||
|
}
|
||||||
|
i, ok := m[pkgname[1]]
|
||||||
|
if !ok {
|
||||||
|
i = len(pkgs)
|
||||||
|
pkgs = append(pkgs, nil)
|
||||||
|
m[pkgname[1]] = i
|
||||||
|
}
|
||||||
|
pkgs[i] = append(pkgs[i], name)
|
||||||
|
}
|
||||||
|
return pkgs, nil
|
||||||
|
}
|
||||||
|
|
||||||
// run runs a test.
|
// run runs a test.
|
||||||
func (t *test) run() {
|
func (t *test) run() {
|
||||||
defer close(t.donec)
|
defer close(t.donec)
|
||||||
|
|
@ -376,13 +410,13 @@ func (t *test) run() {
|
||||||
case "compiledir":
|
case "compiledir":
|
||||||
// Compile all files in the directory in lexicographic order.
|
// Compile all files in the directory in lexicographic order.
|
||||||
longdir := filepath.Join(cwd, t.goDirName())
|
longdir := filepath.Join(cwd, t.goDirName())
|
||||||
files, err := goDirFiles(longdir)
|
pkgs, err := goDirPackages(longdir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.err = err
|
t.err = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, gofile := range files {
|
for _, gofiles := range pkgs {
|
||||||
_, t.err = compileInDir(runcmd, longdir, gofile.Name())
|
_, t.err = compileInDir(runcmd, longdir, gofiles...)
|
||||||
if t.err != nil {
|
if t.err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -392,14 +426,14 @@ func (t *test) run() {
|
||||||
// errorcheck all files in lexicographic order
|
// errorcheck all files in lexicographic order
|
||||||
// useful for finding importing errors
|
// useful for finding importing errors
|
||||||
longdir := filepath.Join(cwd, t.goDirName())
|
longdir := filepath.Join(cwd, t.goDirName())
|
||||||
files, err := goDirFiles(longdir)
|
pkgs, err := goDirPackages(longdir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.err = err
|
t.err = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for i, gofile := range files {
|
for i, gofiles := range pkgs {
|
||||||
out, err := compileInDir(runcmd, longdir, gofile.Name())
|
out, err := compileInDir(runcmd, longdir, gofiles...)
|
||||||
if i == len(files)-1 {
|
if i == len(pkgs)-1 {
|
||||||
if wantError && err == nil {
|
if wantError && err == nil {
|
||||||
t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
|
t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
|
||||||
return
|
return
|
||||||
|
|
@ -411,8 +445,11 @@ func (t *test) run() {
|
||||||
t.err = err
|
t.err = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
longname := filepath.Join(longdir, gofile.Name())
|
var fullshort []string
|
||||||
t.err = t.errorCheck(string(out), longname, gofile.Name())
|
for _, name := range gofiles {
|
||||||
|
fullshort = append(fullshort, filepath.Join(longdir, name), name)
|
||||||
|
}
|
||||||
|
t.err = t.errorCheck(string(out), fullshort...)
|
||||||
if t.err != nil {
|
if t.err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -535,7 +572,7 @@ func (t *test) expectedOutput() string {
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *test) errorCheck(outStr string, full, short string) (err error) {
|
func (t *test) errorCheck(outStr string, fullshort ...string) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if *verbose && err != nil {
|
if *verbose && err != nil {
|
||||||
log.Printf("%s gc output:\n%s", t, outStr)
|
log.Printf("%s gc output:\n%s", t, outStr)
|
||||||
|
|
@ -561,10 +598,19 @@ func (t *test) errorCheck(outStr string, full, short string) (err error) {
|
||||||
|
|
||||||
// Cut directory name.
|
// Cut directory name.
|
||||||
for i := range out {
|
for i := range out {
|
||||||
out[i] = strings.Replace(out[i], full, short, -1)
|
for j := 0; j < len(fullshort); j += 2 {
|
||||||
|
full, short := fullshort[j], fullshort[j+1]
|
||||||
|
out[i] = strings.Replace(out[i], full, short, -1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var want []wantedError
|
||||||
|
for j := 0; j < len(fullshort); j += 2 {
|
||||||
|
full, short := fullshort[j], fullshort[j+1]
|
||||||
|
want = append(want, t.wantedErrors(full, short)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, we := range t.wantedErrors(full, short) {
|
for _, we := range want {
|
||||||
var errmsgs []string
|
var errmsgs []string
|
||||||
errmsgs, out = partitionStrings(we.filterRe, out)
|
errmsgs, out = partitionStrings(we.filterRe, out)
|
||||||
if len(errmsgs) == 0 {
|
if len(errmsgs) == 0 {
|
||||||
|
|
|
||||||
43
test/testlib
43
test/testlib
|
|
@ -5,14 +5,25 @@
|
||||||
# These function names are also known to
|
# These function names are also known to
|
||||||
# (and are the plan for transitioning to) run.go.
|
# (and are the plan for transitioning to) run.go.
|
||||||
|
|
||||||
|
# helper (not known to run.go)
|
||||||
|
# group file list by packages and return list of packages
|
||||||
|
# each package is a comma-separated list of go files.
|
||||||
|
pkgs() {
|
||||||
|
pkglist=$(grep -h '^package ' $* | awk '{print $2}' | sort -u)
|
||||||
|
for p in $pkglist
|
||||||
|
do
|
||||||
|
echo $(grep -l "^package $p\$" $*) | tr ' ' ,
|
||||||
|
done | sort
|
||||||
|
}
|
||||||
|
|
||||||
compile() {
|
compile() {
|
||||||
$G $D/$F.go
|
$G $D/$F.go
|
||||||
}
|
}
|
||||||
|
|
||||||
compiledir() {
|
compiledir() {
|
||||||
for gofile in $D/$F.dir/*.go
|
for pkg in $(pkgs $D/$F.dir/*.go)
|
||||||
do
|
do
|
||||||
$G -I. "$gofile" || return 1
|
$G -I . $(echo $pkg | tr , ' ') || return 1
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,38 +32,40 @@ errorcheckdir() {
|
||||||
if [ "$1" = "-0" ]; then
|
if [ "$1" = "-0" ]; then
|
||||||
lastzero="-0"
|
lastzero="-0"
|
||||||
fi
|
fi
|
||||||
files=($D/$F.dir/*.go)
|
pkgs=$(pkgs $D/$F.dir/*.go)
|
||||||
for gofile in ${files[@]}
|
for pkg in $pkgs.last
|
||||||
do
|
do
|
||||||
zero="-0"
|
zero="-0"
|
||||||
if [ ${files[${#files[@]}-1]} = $gofile ]; then
|
case $pkg in
|
||||||
|
*.last)
|
||||||
|
pkg=$(echo $pkg |sed 's/\.last$//')
|
||||||
zero=$lastzero
|
zero=$lastzero
|
||||||
fi
|
esac
|
||||||
errchk $zero $G -D. -I. -e $gofile
|
errchk $zero $G -D . -I . -e $(echo $pkg | tr , ' ')
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
rundir() {
|
rundir() {
|
||||||
lastfile=""
|
lastfile=""
|
||||||
for gofile in $D/$F.dir/*.go
|
for pkg in $(pkgs $D/$F.dir/*.go)
|
||||||
do
|
do
|
||||||
name=$(basename ${gofile/\.go/} )
|
name=$(echo $pkg | sed 's/\.go.*//; s/.*\///')
|
||||||
$G -D. -I. -e "$gofile" || return 1
|
$G -D . -I . -e $(echo $pkg | tr , ' ') || return 1
|
||||||
lastfile=$name
|
lastfile=$name
|
||||||
done
|
done
|
||||||
$L -o $A.out -L. $lastfile.$A
|
$L -o $A.out -L . $lastfile.$A
|
||||||
./$A.out
|
./$A.out
|
||||||
}
|
}
|
||||||
|
|
||||||
rundircmpout() {
|
rundircmpout() {
|
||||||
lastfile=""
|
lastfile=""
|
||||||
for gofile in $D/$F.dir/*.go
|
for pkg in $(pkgs $D/$F.dir/*.go)
|
||||||
do
|
do
|
||||||
name=$(basename ${gofile/\.go/} )
|
name=$(echo $pkg | sed 's/\.go.*//; s/.*\///')
|
||||||
$G -D. -I. -e "$gofile" || return 1
|
$G -D . -I . -e $(echo $pkg | tr , ' ') || return 1
|
||||||
lastfile=$name
|
lastfile=$name
|
||||||
done
|
done
|
||||||
$L -o $A.out -L. $lastfile.$A
|
$L -o $A.out -L . $lastfile.$A
|
||||||
./$A.out 2>&1 | cmp - $D/$F.out
|
./$A.out 2>&1 | cmp - $D/$F.out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue