2 # Copyright 2009 The Go Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style
4 # license that can be found in the LICENSE file.
6 # Using all the *_test.go files in the current directory, write out a file
7 # _testmain.go that runs all its tests. Compile everything and run the
9 # If files are named on the command line, use them instead of *_test.go.
11 # Makes egrep,grep work better in general if we put them
12 # in ordinary C mode instead of what the current language is.
22 # srcdir is where the source files are found. basedir is where the
23 # source file paths are relative to.
24 # gofiles are the test files. pkgfiles are the source files.
41 srcdir
=`echo $1 | sed -e 's/^--srcdir=//'`
50 basedir
=`echo $1 | sed -e 's/^--basedir=//'`
59 prefix
=`echo $1 | sed -e 's/^--prefix=//'`
72 pkgfiles
=`echo $1 | sed -e 's/^--pkgfiles=//'`
81 dejagnu
=`echo $1 | sed -e 's/^--dejagnu=//'`
103 if test $keep = false
; then
104 trap "cd ..; rm -rf $DIR" 0 1 2 3 14 15
106 trap "cd ..; echo Keeping $DIR" 0 1 2 3 14 15
124 basedir
="../$basedir"
128 # Link all the files/directories in srcdir into our working directory,
129 # so that the tests do not have to refer to srcdir to find test data.
132 # Copy the .go files because io/utils_test.go expects a regular file.
137 for f
in `cd $srcdir; ls *.go`; do
143 for f
in $pkgfiles; do
144 if test -f $basedir/$f; then
148 elif test -f ..
/$f; then
153 echo "file $f not found" 1>&2
157 for f
in `cd $srcdir; ls *_test.go`; do
165 for f
in $gofiles; do
172 for f
in `cd $srcdir; ls *.go | grep -v *_test.go`; do
178 for f
in $pkgfiles; do
179 if test -f $basedir/$f; then
183 elif test -f ..
/$f; then
188 echo "file $f not found" 1>&2
197 # Some tests expect the _obj directory created by the gc Makefiles.
200 # Some tests expect the _test directory created by the gc Makefiles.
205 gofiles
=$
(echo -n $
(ls *_test.go
2>/dev
/null
))
210 echo 'no test files found' 1>&2
214 # Run any commands given in sources, like
215 # // gotest: $GC foo.go
216 # to build any test-only dependencies.
219 sed -n 's/^\/\/ gotest: //p' $gofiles | sh
224 pkgbasefiles
=$
(echo -n $
(ls *.go |
grep -v _test.go
2>/dev
/null
))
227 for f
in $pkgfiles; do
228 pkgbasefiles
="$pkgbasefiles `basename $f`"
235 echo 'no source files found' 1>&2
240 # Split $gofiles into external gofiles (those in *_test packages)
241 # and internal ones (those in the main package).
242 xgofiles
=$
(echo $
(grep '^package[ ]' $gofiles /dev
/null |
grep ':.*_test' |
sed 's/:.*//'))
243 gofiles
=$
(echo $
(grep '^package[ ]' $gofiles /dev
/null |
grep -v ':.*_test' |
sed 's/:.*//'))
248 if [ "x$xgofiles" != "x" ]; then
255 package
=`echo ${srcdir} | sed -e 's|^.*libgo/go/||'`
258 if test -n "$prefix"; then
259 prefixarg
="-fgo-prefix=$prefix"
262 $GC -g $prefixarg -c -I .
-o _gotest_.o
$gofiles $pkgbasefiles
264 mkdir
-p `dirname $package`
265 cp _gotest_.o
`dirname $package`/lib
`basename $package`.a
266 $GC -g -c -I .
-o $xofile $xgofiles
269 # They all compile; now generate the code to call them.
271 # test functions are named TestFoo
272 # the grep -v eliminates methods and other special names
273 # that have multiple dots.
274 pattern
='Test([^a-z].*)?'
275 tests
=$
(nm
-s _gotest_.o
$xofile |
egrep ' T .*\.'$pattern'$' |
grep -v '\..*\..*\.' |
sed 's/.* //' |
sed 's/.*\.\(.*\.\)/\1/')
276 if [ "x$tests" = x
]; then
277 echo 'gotest: warning: no tests matching '$pattern in _gotest_.o
$xofile 1>&2
285 if echo "$tests" |
egrep -v '_test\.' >/dev
/null
; then
286 echo 'import "./_gotest_"'
289 echo 'import "./_xtest_"'
291 if [ $package != "testing" ]; then
292 echo 'import "testing"'
293 echo 'import __regexp__ "regexp"' # rename in case tested package is called regexp
297 echo 'var tests = []testing.InternalTest {'
300 echo ' { "'$i'", '$i' },'
306 echo ' testing.Main(__regexp__.MatchString, tests)'
312 ${GC} -g -c _testmain.go
317 # This is the only file which is optionally made.
318 # All others are overwritten on copying/building,
319 # but this may remain and cause conflicts if not
321 rm -rf ..
/testsuite
/_xtest_.o
322 cp *.o _testmain.go ..
/testsuite
324 $MAKE check RUNTESTFLAGS
="$RUNTESTFLAGS GOTEST_TMPDIR=$DIR"
325 # Useful when using make check-target-libgo
326 cat libgo.log
>> libgo-all.log
327 cat libgo.
sum >> libgo-all.
sum