1
0
mirror of https://github.com/golang/go synced 2024-11-26 04:47:57 -07:00
go/test/testlib
Daniel Morsing ebb0e5db75 test: Add rundir, rundircmpout and errorcheckdir commands to testlib and run.go
rundir will compile each file in the directory in lexicographic order, link the last file as the main package and run the resulting program. rundircmpout is an related command, that will compare the output of the program to an corresponding .out file

errorcheckdir will compile each file in a directory in lexicographic order, running errorcheck on each file as it compiles. All compilations are assumed to be successful except for the last file. However, If a -0 flag is present on the command, the last compilation will also be assumed successful

This CL also includes a small refactoring of run.go. It was getting unwieldy and the meaning of the run commands was hidden behind argument line formatting.

Fixes #4058.

R=rsc, minux.ma, remyoudompheng, iant
CC=golang-dev
https://golang.org/cl/6554071
2012-10-06 09:23:31 +02:00

102 lines
1.5 KiB
Plaintext

# 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.
# These function names are also known to
# (and are the plan for transitioning to) run.go.
compile() {
$G $D/$F.go
}
compiledir() {
for gofile in $D/$F.dir/*.go
do
$G -I. "$gofile" || return 1
done
}
errorcheckdir() {
lastzero=""
if [ "$1" = "-0" ]; then
lastzero="-0"
fi
files=($D/$F.dir/*.go)
for gofile in ${files[@]}
do
zero="-0"
if [ ${files[${#files[@]}-1]} = $gofile ]; then
zero=$lastzero
fi
errchk $zero $G -D. -I. -e $gofile
done
}
rundir() {
lastfile=""
for gofile in $D/$F.dir/*.go
do
name=$(basename ${gofile/\.go/} )
$G -D. -I. -e "$gofile" || return 1
lastfile=$name
done
$L -o $A.out -L. $lastfile.$A
./$A.out
}
rundircmpout() {
lastfile=""
for gofile in $D/$F.dir/*.go
do
name=$(basename ${gofile/\.go/} )
$G -D. -I. -e "$gofile" || return 1
lastfile=$name
done
$L -o $A.out -L. $lastfile.$A
./$A.out | cmp - $D/$F.out
}
build() {
$G $D/$F.go && $L $F.$A
}
runoutput() {
go run "$D/$F.go" > tmp.go
go run tmp.go
}
run() {
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() {
$G $D/$F.go && $L $F.$A && ./$A.out 2>&1 | cmp - $D/$F.out
}
errorcheck() {
zero=""
if [ "$1" = "-0" ]; then
zero="-0"
shift
fi
errchk $zero $G -e $* $D/$F.go
}
skip() {
true
}