github.com/guyezi/gofrontend@v0.0.0-20200228202240-7a62a49e62c0/libgo/testsuite/gotest (about)

     1  #!/bin/sh
     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.
     5  
     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
     8  # tests.
     9  # If files are named on the command line, use them instead of *_test.go.
    10  
    11  # Makes egrep,grep work better in general if we put them
    12  # in ordinary C mode instead of what the current language is.
    13  LANG=C
    14  LC_ALL=C
    15  LC_CTYPE=C
    16  export LANG LC_ALL LC_CTYPE
    17  
    18  GC=${GC:-gccgo}
    19  GL=${GL:-${GC-gccgo}}
    20  GOLIBS=${GOLIBS:-}
    21  export GC GL GOLIBS
    22  
    23  NM=${NM:-nm}
    24  
    25  # srcdir is where the source files are found.  basedir is where the
    26  # source file paths are relative to.
    27  # gofiles are the test files.  pkgfiles are the source files.
    28  srcdir=.
    29  basedir=.
    30  goarch=""
    31  gofiles=""
    32  goos=""
    33  pkgfiles=""
    34  loop=true
    35  keep=false
    36  pkgpath=
    37  prefix=
    38  dejagnu=no
    39  timeout=240
    40  testname=""
    41  bench=""
    42  trace=false
    43  while $loop; do
    44  	case "x$1" in
    45          x--srcdir)
    46  		srcdir=$2
    47  		shift
    48  		shift
    49  		;;
    50  	x--srcdir=*)
    51  		srcdir=`echo $1 | sed -e 's/^--srcdir=//'`
    52  		shift
    53  		;;
    54          x--basedir)
    55  		basedir=$2
    56  		shift
    57  		shift
    58  		;;
    59  	x--basedir=*)
    60  		basedir=`echo $1 | sed -e 's/^--basedir=//'`
    61  		shift
    62  		;;
    63  	x--goarch)
    64  		goarch=$2
    65  		shift
    66  		shift
    67  		;;
    68  	x--goarch=*)
    69  		goarch=`echo $1 | sed -e 's/^--goarch=//'`
    70  		shift
    71  		;;
    72  	x--goos)
    73  		goos=$2
    74  		shift
    75  		shift
    76  		;;
    77  	x--goos=*)
    78  		goos=`echo $1 | sed -e 's/^--goos=//'`
    79  		shift
    80  		;;
    81  	x--pkgpath)
    82  		pkgpath=$2
    83  		shift
    84  		shift
    85  		;;
    86  	x--pkgpath=*)
    87  		pkgpath=`echo $1 | sed -e 's/^--pkgpath=//'`
    88  		shift
    89  		;;
    90  	x--prefix)
    91  		prefix=$2
    92  		shift
    93  		shift
    94  		;;
    95  	x--prefix=*)
    96  		prefix=`echo $1 | sed -e 's/^--prefix=//'`
    97  		shift
    98  		;;
    99  	x--keep)
   100  		keep=true
   101                  shift
   102  		;;
   103  	x--pkgfiles)
   104  		pkgfiles=$2
   105  		shift
   106  		shift
   107  		;;
   108  	x--pkgfiles=*)
   109  		pkgfiles=`echo $1 | sed -e 's/^--pkgfiles=//'`
   110  		shift
   111  		;;
   112  	x--dejagnu)
   113  		dejagnu=$2
   114  		shift
   115  		shift
   116  		;;
   117  	x--dejagnu=*)
   118  		dejagnu=`echo $1 | sed -e 's/^--dejagnu=//'`
   119  		shift
   120  		;;
   121  	x--timeout)
   122  		timeout=$2
   123  		shift
   124  		shift
   125  		;;
   126  	x--timeout=*)
   127  		timeout=`echo $1 | sed -e 's/^--timeout=//'`
   128  		shift
   129  		;;
   130  	x--testname)
   131  		testname=$2
   132  		shift
   133  		shift
   134  		;;
   135  	x--testname=*)
   136  		testname=`echo $1 | sed -e 's/^--testname=//'`
   137  		shift
   138  		;;
   139  	x--bench)
   140  		bench=$2
   141  		shift
   142  		shift
   143  		;;
   144  	x--bench=*)
   145  		bench=`echo $1 | sed -e 's/^--bench=//'`
   146  		shift
   147  		;;
   148  	x--trace)
   149  		trace=true
   150  		shift
   151  		;;
   152  	x-*)
   153  		loop=false
   154  		;;
   155  	x)
   156  		loop=false
   157  		;;
   158  	*)
   159  		gofiles="$gofiles $1"
   160  		shift
   161  		;;
   162  	esac
   163  done
   164  
   165  DIR=gotest$$
   166  rm -rf $DIR
   167  mkdir $DIR
   168  
   169  cd $DIR
   170  mkdir test
   171  cd test
   172  
   173  if test $keep = false; then
   174    trap "cd ../..; rm -rf $DIR" 0 1 2 3 14 15
   175  else
   176    trap "cd ../..; echo Keeping $DIR" 0 1 2 3 14 15
   177  fi
   178  
   179  case "$srcdir" in
   180  	/*)
   181  		;;
   182  	*)
   183  		srcdir="../../$srcdir"
   184                  ;;
   185  esac
   186  
   187  SRCDIR=$srcdir
   188  export SRCDIR
   189  
   190  case "$basedir" in
   191  	/*)
   192  		;;
   193  	*)
   194  		basedir="../../$basedir"
   195                  ;;
   196  esac
   197  
   198  # Link all the files/directories in srcdir into our working directory,
   199  # so that the tests do not have to refer to srcdir to find test data.
   200  ln -s $srcdir/* .
   201  
   202  # Some tests refer to a ../testdata directory.
   203  if test -e $srcdir/../testdata; then
   204    rm -f ../testdata
   205    abssrcdir=`cd $srcdir && pwd`
   206    ln -s $abssrcdir/../testdata ../testdata
   207  fi
   208  
   209  # Copy the .go files because io/utils_test.go expects a regular file.
   210  case "x$gofiles" in
   211  x)
   212  	case "x$pkgfiles" in
   213  	x)
   214  		for f in `cd $srcdir; ls *.go`; do
   215  		    rm -f $f;
   216  		    cp $srcdir/$f .
   217  		done
   218  		;;
   219  	*)
   220  		for f in $pkgfiles; do
   221                      case $f in
   222                      /*)
   223                          b=`basename $f`
   224                          rm -f $b
   225                          cp $f $b
   226                          ;;
   227                      *)
   228  		        if test -f $basedir/$f; then
   229  			  b=`basename $f`
   230  			  rm -f $b
   231  			  cp $basedir/$f $b
   232  		        elif test -f ../../$f; then
   233  			  b=`basename $f`
   234  			  rm -f $b
   235  			  cp ../../$f $b
   236  		        else
   237  			  echo "file $f not found" 1>&2
   238  			  exit 1
   239  		        fi
   240                          ;;
   241                      esac
   242  		done
   243  		for f in `cd $srcdir; ls *_test.go`; do
   244  		    rm -f $f
   245  		    cp $srcdir/$f .
   246  		done
   247  		;;
   248  	esac
   249  	;;
   250  *)
   251  	for f in $gofiles; do
   252  	    b=`basename $f`
   253  	    rm -f $b
   254  	    cp $basedir/$f $b
   255  	done
   256  	case "x$pkgfiles" in
   257  	x)
   258  		for f in `cd $srcdir; ls *.go | grep -v *_test.go`; do
   259  		    rm -f $f
   260  		    cp $srcdir/$f .
   261  		done
   262  		;;
   263  	*)
   264  		for f in $pkgfiles; do
   265                      case $f in
   266                      /*)
   267                          b=`basename $f`
   268                          rm -f $b
   269                          cp $f $b
   270                          ;;
   271                      *)
   272  		        if test -f $basedir/$f; then
   273  			  b=`basename $f`
   274  			  rm -f $b
   275  			  cp $basedir/$f $b
   276  		        elif test -f ../../$f; then
   277  			  b=`basename $f`
   278  			  rm -f $b
   279  			  cp ../../$f $b
   280  		        else
   281  			  echo "file $f not found" 1>&2
   282  			  exit 1
   283  		        fi
   284                          ;;
   285                      esac
   286  		done
   287  		;;
   288  	esac
   289  	;;
   290  esac
   291  
   292  case "x$gofiles" in
   293  x)
   294  	for f in `ls *_test.go`; do
   295  	    tag1=`echo $f | sed -e 's/^.*_\([^_]*\)_test.go$/\1/'`
   296  	    tag2=`echo $f | sed -e 's/^.*_\([^_]*\)_[^_]*_test.go$/\1/'`
   297  	    if test x$tag1 = x$f; then
   298  		tag1=
   299  	    fi
   300  	    if test x$tag2 = x$f; then
   301  		tag2=
   302  	    fi
   303  
   304  	    case "$tag1" in
   305  	    "") ;;
   306  	    $goarch) ;;
   307  	    $goos) ;;
   308  	    aix | android | darwin | dragonfly | freebsd | hurd | illumos | js | linux | nacl | netbsd | openbsd | plan9 | solaris | windows)
   309  		tag1=nonmatchingtag
   310  		;;
   311  	    386 | amd64 | amd64p32 | arm | armbe | arm64 | arm64be | alpha | ia64 | m68k | mips | mipsle | mips64 | mips64le | mips64p32 | mips64p32le·| nios2 | ppc | ppc64 | ppc64le | riscv64 | s390 | s390x | sh | shbe | sparc | sparc64 | wasm)
   312  		tag1=nonmatchingtag
   313  		;;
   314  	    esac
   315  
   316  	    case "$tag2" in
   317  	    "") ;;
   318  	    $goarch) ;;
   319  	    $goos) ;;
   320  	    aix | android | darwin | dragonfly | freebsd | hurd | illumos | js | linux | nacl | netbsd | openbsd | plan9 | solaris | windows)
   321  		tag2=nonmatchingtag
   322  		;;
   323  	    386 | amd64 | amd64p32 | arm | armbe | arm64 | arm64be | alpha | ia64 | m68k | mips | mipsle | mips64 | mips64le | mips64p32 | mips64p32le·| nios2 | ppc | ppc64 | ppc64le | riscv64 | s390 | s390x | sh | shbe | sparc | sparc64 | wasm)
   324  		tag2=nonmatchingtag
   325  		;;
   326  	    esac
   327  
   328  	    if test x$tag1 != xnonmatchingtag -a x$tag2 != xnonmatchingtag; then
   329  		tags=`sed '/^package /q' < $f | grep '^// *+build '`
   330  		omatch=true
   331  		first=true
   332  		match=false
   333  		for tag in $tags; do
   334  		    case $tag in
   335  		    "//")
   336  			;;
   337  		    "+build" | "//+build")
   338  			if test "$first" = "true"; then
   339  			    first=false
   340  			elif test "$match" = "false"; then
   341  			    omatch=false
   342  			fi
   343  			match=false
   344  			;;
   345  		    $goos | $goarch | cgo | gccgo | go1.[0-9])
   346  			match=true
   347  			;;
   348  		    "!"$goos | "!"$goarch | "!cgo" | "!gccgo" | "!"go1.[0-9])
   349  			;;
   350  		    *,*)
   351  			cmatch=true
   352  			for ctag in `echo $tag | sed -e 's/,/ /g'`; do
   353  			    case $ctag in
   354  			    $goos | $goarch | cgo | gccgo | go1.[0-9])
   355  				;;
   356  			    "!"$goos | "!"$goarch | "!cgo" | "!gccgo" | "!"go1.[0-9])
   357  				cmatch=false
   358  				;;
   359  			    "!"*)
   360  			        ;;
   361  			    *)
   362  				cmatch=false
   363  				;;
   364  			    esac
   365  			done
   366  			if test "$cmatch" = "true"; then
   367  			    match=true
   368  			fi
   369  			;;
   370  		    "!"*)
   371  			match=true
   372  			;;
   373  		    esac
   374  		done
   375  
   376  		if test "$match" = "false" -a "$first" = "false"; then
   377  		    omatch=false
   378  		fi
   379  
   380  		if test "$omatch" = "true"; then
   381  		    gofiles="$gofiles $f"
   382  		fi
   383  	    fi
   384  	done
   385  	;;
   386  *)
   387  	xgofiles=$gofiles
   388  	gofiles=
   389  	for f in $xgofiles; do
   390  	    gofiles="$gofiles `basename $f`"
   391  	done
   392  esac
   393  
   394  case "x$gofiles" in
   395  x)
   396  	echo 'no test files found' 1>&2
   397  	exit 1
   398  	;;
   399  esac
   400  
   401  case "x$pkgfiles" in
   402  x)
   403  	pkgbasefiles=`ls *.go | grep -v _test.go 2>/dev/null`
   404  	;;
   405  *)
   406  	for f in $pkgfiles; do
   407  	    pkgbasefiles="$pkgbasefiles `basename $f`"
   408  	done
   409  	;;
   410  esac
   411  
   412  case "x$pkgfiles" in
   413  x)
   414  	echo 'no source files found' 1>&2
   415  	exit 1
   416  	;;
   417  esac
   418  
   419  # Split $gofiles into external gofiles (those in *_test packages)
   420  # and internal ones (those in the main package).
   421  xgofiles=
   422  xpackage=
   423  for f in $gofiles; do
   424      package=`grep '^package[ 	]' $f | sed 1q`
   425      case "$package" in
   426      *_test)
   427  	xpackage=`echo $package | sed -e 's/package[ 	]//' -e 's/[ 	]*$//'`
   428  	xgofiles="$xgofiles $f"
   429  	;;
   430      *)
   431  	ngofiles="$ngofiles $f"
   432  	;;
   433      esac
   434  done
   435  gofiles=$ngofiles
   436  
   437  # External $O file
   438  xofile=""
   439  havex=false
   440  if [ "x$xgofiles" != "x" ]; then
   441  	xofile="_xtest_.o"
   442  	havex=true
   443  fi
   444  
   445  testmain=
   446  if $havex && fgrep 'func TestMain(' $xgofiles >/dev/null 2>&1; then
   447    package=`grep '^package[ 	]' $xgofiles | sed 1q | sed -e 's/.* //'`
   448    testmain="${package}.TestMain"
   449  elif test -n "$gofiles" && fgrep 'func TestMain(' $gofiles >/dev/null 2>&1; then
   450    package=`grep '^package[ 	]' $gofiles | sed 1q | sed -e 's/.* //'`
   451    testmain="${package}.TestMain"
   452  fi
   453  
   454  set -e
   455  
   456  package=`echo ${srcdir} | sed -e 's|^.*libgo/go/||'`
   457  
   458  pkgpatharg=
   459  xpkgpatharg=
   460  prefixarg=
   461  if test -n "$pkgpath"; then
   462  	pkgpatharg="-fgo-pkgpath=$pkgpath"
   463  	xpkgpatharg="-fgo-pkgpath=${pkgpath}_test"
   464  elif test -n "$prefix"; then
   465  	prefixarg="-fgo-prefix=$prefix"
   466  fi
   467  
   468  if test "$trace" = "true"; then
   469    echo $GC -g $pkgpatharg $prefixarg -c -I . -fno-toplevel-reorder -o _gotest_.o $gofiles $pkgbasefiles
   470  fi
   471  $GC -g $pkgpatharg $prefixarg -c -I . -fno-toplevel-reorder -o _gotest_.o $gofiles $pkgbasefiles
   472  
   473  if $havex; then
   474  	mkdir -p `dirname $package`
   475  	cp _gotest_.o `dirname $package`/lib`basename $package`.a
   476  
   477  	# Force the test version of the package to be imported first,
   478  	# so that its type definitions will be used, in case any new
   479  	# methods appear in export_test.go files.
   480  	echo "package $xpackage" > _first_test.go
   481  	echo 'import _ "'$package'"' >> _first_test.go
   482  
   483  	if test "$trace" = "true"; then
   484  	    echo $GC -g $xpkgpatharg -c -I . -fno-toplevel-reorder -o $xofile _first_test.go $xgofiles
   485  	fi
   486  	$GC -g $xpkgpatharg -c -I . -fno-toplevel-reorder -o $xofile _first_test.go $xgofiles
   487  fi
   488  
   489  # They all compile; now generate the code to call them.
   490  
   491  testname() {
   492  	# Remove the package from the name used with the -test option.
   493  	echo $1 | sed 's/^.*\.//'
   494  }
   495  
   496  localname() {
   497  	# The package main has been renamed to __main__ when imported.
   498  	# Adjust its uses.
   499  	echo $1 | sed 's/^main\./__main__./'
   500  }
   501  
   502  # Takes a list of tests derived from 'nm' output (whose symbols are mangled)
   503  # and emits a demangled list of tests, using only the terminal package.
   504  # Example:
   505  #
   506  #    Original symbol:   foo/bar/leaf.Mumble
   507  #    Mangled symbol:    foo..z2fbar..z2fleaf.Mumble
   508  #    Returned:          leaf.Mumble
   509  #
   510  symtogo() {
   511    result=""
   512    for tp in $*; do
   513      # Discard symbols with a leading dot.
   514      # On AIX, this will remove function text symbols (with a leading dot).
   515      # Therefore, only function descriptor symbols (without this leading dot)
   516      # will be used to retrieve the go symbols, avoiding duplication.
   517      if expr "$tp" : '^\.' >/dev/null 2>&1; then
   518        continue
   519      fi
   520      # Skip type descriptors.  These are normally skipped because they
   521      # are weak symbols, but if not using GNU nm we may see them here.
   522      if expr "$tp" : '^type\.\.' >/dev/null 2>&1; then
   523        continue
   524      fi
   525      s=$(echo "$tp" | sed -e 's/\.\.z2f/%/g' | sed -e 's/.*%//')
   526      # Screen out methods (X.Y.Z).
   527      if ! expr "$s" : '^[^.]*\.[^.]*$' >/dev/null 2>&1; then
   528        continue
   529      fi
   530      tname=$(testname $s)
   531      # Skip TestMain.
   532      if test x$tname = xTestMain; then
   533        continue
   534      fi
   535      # Check that the function is defined in a test file,
   536      # not an ordinary non-test file.
   537      if grep "^func $tname(" $gofiles $xgofiles >/dev/null 2>&1; then
   538        echo "$s"
   539      fi
   540    done
   541  }
   542  
   543  # Takes an example name and puts any output into the file example.txt.
   544  # It strips comment markers but does not otherwise change the output.
   545  exampleoutput() {
   546      n=$(testname $1)
   547      for f in $gofiles $xgofiles; do
   548  	if ! grep "^func $n(" $f >/dev/null 2>&1; then
   549  	    continue
   550  	fi
   551  	# Copy the output comment, if any, into example.txt.
   552  	# Remove the comment markers.
   553  	sed -n "/^func $n(/,/^}$/ p" $f |
   554  	    sed -n '\|// \([Uu]nordered \)\?[Oo]utput:|,$ p' |
   555  	    sed -n '\|//| s|[ 	]*// \?||p' > example.txt
   556  	# Check whether we found an output comment.
   557  	if ! sed -n '1p' < example.txt | grep '[Oo]utput:' >/dev/null 2>&1; then
   558  	    rm -f example.txt
   559  	fi
   560  	return
   561      done
   562  }
   563  
   564  {
   565  	# On systems using PPC64 ELF ABI v1 function symbols show up
   566  	# as descriptors in the data section.
   567  	text="[TD]"
   568  
   569  	# test functions are named TestFoo
   570  	# the grep -v eliminates methods and other special names
   571  	# that have multiple dots.
   572  	pattern='Test([^a-z].*)?'
   573  	# The -p option tells GNU nm not to sort.
   574  	# The -v option tells Solaris nm to sort by value.
   575          testsyms=$($NM -p -v _gotest_.o | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
   576  	testxsyms=
   577  	if $havex; then
   578  	    testxsyms=$($NM -p -v $xofile | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
   579  	    testsyms="$testsyms $testxsyms"
   580  	fi
   581          tests=$(symtogo "$testsyms")
   582  	if [ "x$tests" = x ]; then
   583  		echo 'gotest: warning: no tests matching '$pattern in _gotest_.o $xofile 1>&2
   584  		exit 2
   585  	fi
   586  	# benchmarks are named BenchmarkFoo.
   587  	pattern='Benchmark([^a-z].*)?'
   588  	benchmarksyms=$($NM -p -v _gotest_.o | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
   589  	if $havex; then
   590  	    benchmarkxsyms=$($NM -p -v $xofile | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
   591  	    benchmarksyms="$benchmarksyms $benchmarkxsyms"
   592  	fi
   593          benchmarks=$(symtogo "$benchmarksyms")
   594  
   595  	# examples are named ExampleFoo
   596  	pattern='Example([^a-z].*)?'
   597  	examplesyms=$($NM -p -v _gotest_.o | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
   598  	if $havex; then
   599  	    examplexsyms=$($NM -p -v $xofile | egrep " $text .*\."$pattern'$' | fgrep -v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
   600  	    examplesyms="$examplesyms $examplexsyms"
   601  	fi
   602  	examples=$(symtogo "$examplesyms")
   603  
   604  	# package spec
   605  	echo 'package main'
   606  	echo
   607  	# imports
   608  	if echo "$tests" | egrep -v '_test\.' >/dev/null; then
   609  		echo 'import "./_gotest_"'
   610  	fi
   611  	if $havex; then
   612  	    needxtest=false
   613  	    if test -n "$testxsyms" -o -n "$benchmarkxsyms"; then
   614  		needxtest=true
   615  	    else
   616  		# Check whether any example has output.
   617  		for i in $(symtogo "$examplexsyms"); do
   618  		    exampleoutput $i
   619  		    if test -f example.txt; then
   620  			rm -f example.txt
   621  			needxtest=true
   622  			break
   623  		    fi
   624  		done
   625  	    fi
   626  	    if test x$needxtest = xtrue; then
   627  		echo 'import "./_xtest_"'
   628  	    else
   629  		echo 'import _ "./_xtest_"'
   630  	    fi
   631  	fi
   632  	if test "$package" != "testing"; then
   633  		echo 'import "testing"'
   634  	fi
   635  	echo 'import "testing/internal/testdeps"'
   636  	if ! test -n "$testmain"; then
   637  		echo 'import __os__ "os"'
   638  	fi
   639  	# test array
   640  	echo
   641  	echo 'var tests = []testing.InternalTest {'
   642  	for i in $tests; do
   643  		n=$(testname $i)
   644  		j=$(localname $i)
   645  		echo '	{"'$n'", '$j'},'
   646  	done
   647  	echo '}'
   648  
   649  	# benchmark array
   650  	# The comment makes the multiline declaration
   651  	# gofmt-safe even when there are no benchmarks.
   652  	echo 'var benchmarks = []testing.InternalBenchmark{'
   653  	for i in $benchmarks; do
   654  		n=$(testname $i)
   655  		j=$(localname $i)
   656  		echo '	{"'$n'", '$j'},'
   657  	done
   658  	echo '}'
   659  
   660  	# examples array
   661  	echo 'var examples = []testing.InternalExample{'
   662  	for i in $examples; do
   663  		n=$(testname $i)
   664  		j=$(localname $i)
   665  		# Look for a //output comment.
   666  		hasoutput=false
   667  		unordered=false
   668  		output=
   669  		exampleoutput $i
   670  		if ! test -f example.txt; then
   671  		    continue
   672  		fi
   673  		# Check whether the output can be unordered.
   674  		unordered=false
   675  		if sed -n '1p' < example.txt | grep -i unordered >/dev/null 2>&1; then
   676  		    unordered=true
   677  		fi
   678  		# Remove the output header.
   679  		# Quote backslashes.
   680  		# Quote quotation characters.
   681  		# Turn tab into \t.
   682  		# Turn pairs of spaces into " \x20", because $() will
   683  		# drop duplicate spaces.
   684  		# Drop trailing spaces, and turn newlines into \n.
   685  		# Remove leading and trailing \n.
   686  		sed '1 s/\([Uu]nordered \)\?[Oo]utput:[ 	]*//' < example.txt |
   687  			     sed -e 's/\\/\\\\/g' \
   688  				 -e 's/"/\\"/g' \
   689  				 -e 's/	/\\t/g' \
   690  				 -e 's/  / \\x20/g' \
   691  				 -e 's/[ 	]*$/\\n/g' |
   692  			     tr -d '\n' |
   693  			     sed -e 's/^\(\\n\)*//' \
   694  				 -e 's/\(\\n\)*$//' > example2.txt
   695  		hasoutput=true
   696  		echo '	{"'$n'", '$j','
   697  		sed -e 's/^/		"/' -e 's/$/", /' < example2.txt
   698  		echo $unordered'},'
   699  		rm -f example.txt example2.txt
   700  	done
   701  	echo '}'
   702  
   703  	# body
   704  	echo \
   705  '
   706  func main() {
   707  	m := testing.MainStart(testdeps.TestDeps{}, tests, benchmarks, examples)
   708  '
   709  	if test -n "$testmain"; then
   710  		echo "	${testmain}(m)"
   711  	else
   712  		echo '	__os__.Exit(m.Run())'
   713  	fi
   714  
   715  	echo '}'
   716  }>_testmain.go
   717  
   718  case "x$dejagnu" in
   719  xno)
   720  	if test "$trace" = "true"; then
   721  	    echo ${GC} -g -c _testmain.go
   722  	fi
   723  	${GC} -g -c _testmain.go
   724  
   725  	if test "$trace" = "true"; then
   726  	    echo ${GL} *.o ${GOLIBS}
   727  	fi
   728  	${GL} *.o ${GOLIBS}
   729  
   730  	set +e
   731  	if test "$bench" = ""; then
   732  		if test "$trace" = "true"; then
   733  		    echo ./a.out -test.short -test.timeout=${timeout}s "$@"
   734  		fi
   735  		./a.out -test.short -test.timeout=${timeout}s "$@" &
   736  		pid=$!
   737  		(sleep `expr $timeout + 10`
   738  		    echo > gotest-timeout
   739  		    echo "timed out in gotest" 1>&2
   740  		    kill -9 $pid) &
   741  		alarmpid=$!
   742  		wait $pid
   743  		status=$?
   744  		if ! test -f gotest-timeout; then
   745  		    sleeppid=`ps -o pid,ppid,comm | grep " $alarmpid " | grep sleep | sed -e 's/ *\([0-9]*\) .*$/\1/'`
   746  		    kill $alarmpid
   747  		    wait $alarmpid
   748  		    if test "$sleeppid" != ""; then
   749  			kill $sleeppid
   750  		    fi
   751  		fi
   752  	else
   753  		if test "$trace" = "true"; then
   754  		    echo ./a.out -test.run=^\$ -test.bench="${bench}" "$@"
   755  		fi
   756  		./a.out -test.run=^\$ -test.bench="${bench}" "$@"
   757  		status=$?
   758  	fi
   759  	exit $status
   760  	;;
   761  xyes)
   762  	rm -rf ../../testsuite/*.o
   763  	files=`echo *`
   764  	for f in $files; do
   765  		if test "$f" = "_obj" || test "$f" = "_test"; then
   766  			continue
   767  		fi
   768  		rm -rf ../../testsuite/$f
   769  		if test -f $f; then
   770  			cp $f ../../testsuite/
   771  		else
   772  			ln -s ../$DIR/test/$f ../../testsuite/
   773  		fi
   774  	done
   775  	cd ../../testsuite
   776  	rm -rf _obj _test
   777  	mkdir _obj _test
   778  	if test "$testname" != ""; then
   779  	    GOTESTNAME="$testname"
   780  	    export GOTESTNAME
   781  	fi
   782  	$MAKE check RUNTESTFLAGS="$RUNTESTFLAGS GOTEST_TMPDIR=$DIR/test"
   783  	# Useful when using make check-target-libgo
   784  	cat libgo.log >> libgo-all.log
   785  	cat libgo.sum >> libgo-all.sum
   786  	rm -rf $files
   787  	;;
   788  esac