github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/src/cmd/go/test.bash (about)

     1  #!/bin/bash
     2  # Copyright 2012 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  set -e
     7  go build -o testgo
     8  go() {
     9  	echo TEST ERROR: ran go, not testgo: go "$@" >&2
    10  	exit 2
    11  }
    12  
    13  started=false
    14  TEST() {
    15  	if $started; then
    16  		stop
    17  	fi
    18  	echo TEST: "$@"
    19  	started=true
    20  	ok=true
    21  }
    22  stop() {
    23  	if ! $started; then
    24  		echo TEST ERROR: stop missing start >&2
    25  		exit 2
    26  	fi
    27  	started=false
    28  	if $ok; then
    29  		echo PASS
    30  	else
    31  		echo FAIL
    32  		allok=false
    33  	fi
    34  }
    35  
    36  ok=true
    37  allok=true
    38  
    39  unset GOPATH
    40  unset GOBIN
    41  
    42  TEST 'file:line in error messages'
    43  # Test that error messages have file:line information at beginning of
    44  # the line. Also test issue 4917: that the error is on stderr.
    45  d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
    46  fn=$d/err.go
    47  echo "package main" > $fn
    48  echo 'import "bar"' >> $fn
    49  ./testgo run $fn 2>$d/err.out || true
    50  if ! grep -q "^$fn:" $d/err.out; then
    51  	echo "missing file:line in error message"
    52  	cat $d/err.out
    53  	ok=false
    54  fi
    55  rm -r $d
    56  
    57  # Test local (./) imports.
    58  testlocal() {
    59  	local="$1"
    60  	TEST local imports $2 '(easy)'
    61  	./testgo build -o hello "testdata/$local/easy.go"
    62  	./hello >hello.out
    63  	if ! grep -q '^easysub\.Hello' hello.out; then
    64  		echo "testdata/$local/easy.go did not generate expected output"
    65  		cat hello.out
    66  		ok=false
    67  	fi
    68  	
    69  	TEST local imports $2 '(easysub)'
    70  	./testgo build -o hello "testdata/$local/easysub/main.go"
    71  	./hello >hello.out
    72  	if ! grep -q '^easysub\.Hello' hello.out; then
    73  		echo "testdata/$local/easysub/main.go did not generate expected output"
    74  		cat hello.out
    75  		ok=false
    76  	fi
    77  	
    78  	TEST local imports $2 '(hard)'
    79  	./testgo build -o hello "testdata/$local/hard.go"
    80  	./hello >hello.out
    81  	if ! grep -q '^sub\.Hello' hello.out || ! grep -q '^subsub\.Hello' hello.out ; then
    82  		echo "testdata/$local/hard.go did not generate expected output"
    83  		cat hello.out
    84  		ok=false
    85  	fi
    86  	
    87  	rm -f hello.out hello
    88  	
    89  	# Test that go install x.go fails.
    90  	TEST local imports $2 '(go install should fail)'
    91  	if ./testgo install "testdata/$local/easy.go" >/dev/null 2>&1; then
    92  		echo "go install testdata/$local/easy.go succeeded"
    93  		ok=false
    94  	fi
    95  }
    96  
    97  # Test local imports
    98  testlocal local ''
    99  
   100  # Test local imports again, with bad characters in the directory name.
   101  bad='#$%:, &()*;<=>?\^{}'
   102  rm -rf "testdata/$bad"
   103  cp -R testdata/local "testdata/$bad"
   104  testlocal "$bad" 'with bad characters in path'
   105  rm -rf "testdata/$bad"
   106  
   107  TEST error message for syntax error in test go file says FAIL
   108  export GOPATH=$(pwd)/testdata
   109  if ./testgo test syntaxerror 2>testdata/err; then
   110  	echo 'go test syntaxerror succeeded'
   111  	ok=false
   112  elif ! grep FAIL testdata/err >/dev/null; then
   113  	echo 'go test did not say FAIL:'
   114  	cat testdata/err
   115  	ok=false
   116  fi
   117  rm -f ./testdata/err
   118  unset GOPATH
   119  
   120  TEST wildcards do not look in useless directories
   121  export GOPATH=$(pwd)/testdata
   122  if ./testgo list ... >testdata/err 2>&1; then
   123  	echo "go list ... succeeded"
   124  	ok=false
   125  elif ! grep badpkg testdata/err >/dev/null; then
   126  	echo "go list ... failure does not mention badpkg"
   127  	cat testdata/err
   128  	ok=false
   129  elif ! ./testgo list m... >testdata/err 2>&1; then
   130  	echo "go list m... failed"
   131  	ok=false
   132  fi
   133  rm -rf ./testdata/err
   134  unset GOPATH
   135  
   136  # Test tests with relative imports.
   137  TEST relative imports '(go test)'
   138  if ! ./testgo test ./testdata/testimport; then
   139  	echo "go test ./testdata/testimport failed"
   140  	ok=false
   141  fi
   142  
   143  # Test installation with relative imports.
   144  TEST relative imports '(go test -i)'
   145  if ! ./testgo test -i ./testdata/testimport; then
   146      echo "go test -i ./testdata/testimport failed"
   147      ok=false
   148  fi
   149  
   150  # Test tests with relative imports in packages synthesized
   151  # from Go files named on the command line.
   152  TEST relative imports in command-line package
   153  if ! ./testgo test ./testdata/testimport/*.go; then
   154  	echo "go test ./testdata/testimport/*.go failed"
   155  	ok=false
   156  fi
   157  
   158  TEST version control error message includes correct directory
   159  export GOPATH=$(pwd)/testdata/shadow/root1
   160  if ./testgo get -u foo 2>testdata/err; then
   161  	echo "go get -u foo succeeded unexpectedly"
   162  	ok=false
   163  elif ! grep testdata/shadow/root1/src/foo testdata/err >/dev/null; then
   164  	echo "go get -u error does not mention shadow/root1/src/foo:"
   165  	cat testdata/err
   166  	ok=false
   167  fi
   168  unset GOPATH
   169  
   170  TEST go install fails with no buildable files
   171  export GOPATH=$(pwd)/testdata
   172  export CGO_ENABLED=0
   173  if ./testgo install cgotest 2>testdata/err; then
   174  	echo "go install cgotest succeeded unexpectedly"
   175  elif ! grep 'no buildable Go source files' testdata/err >/dev/null; then
   176  	echo "go install cgotest did not report 'no buildable Go source files'"
   177  	cat testdata/err
   178  	ok=false
   179  fi
   180  unset CGO_ENABLED
   181  unset GOPATH
   182  
   183  # Test that without $GOBIN set, binaries get installed
   184  # into the GOPATH bin directory.
   185  TEST install into GOPATH
   186  rm -rf testdata/bin
   187  if ! GOPATH=$(pwd)/testdata ./testgo install go-cmd-test; then
   188  	echo "go install go-cmd-test failed"
   189  	ok=false
   190  elif ! test -x testdata/bin/go-cmd-test; then
   191  	echo "go install go-cmd-test did not write to testdata/bin/go-cmd-test"
   192  	ok=false
   193  fi
   194  
   195  TEST package main_test imports archive not binary
   196  export GOBIN=$(pwd)/testdata/bin
   197  mkdir -p $GOBIN
   198  export GOPATH=$(pwd)/testdata
   199  touch ./testdata/src/main_test/m.go
   200  if ! ./testgo test main_test; then
   201  	echo "go test main_test failed without install"
   202  	ok=false
   203  elif ! ./testgo install main_test; then
   204  	echo "go test main_test failed"
   205  	ok=false
   206  elif [ "$(./testgo list -f '{{.Stale}}' main_test)" != false ]; then
   207  	echo "after go install, main listed as stale"
   208  	ok=false
   209  elif ! ./testgo test main_test; then
   210  	echo "go test main_test failed after install"
   211  	ok=false
   212  fi
   213  rm -rf $GOBIN
   214  unset GOBIN
   215  
   216  # And with $GOBIN set, binaries get installed to $GOBIN.
   217  TEST install into GOBIN
   218  if ! GOBIN=$(pwd)/testdata/bin1 GOPATH=$(pwd)/testdata ./testgo install go-cmd-test; then
   219  	echo "go install go-cmd-test failed"
   220  	ok=false
   221  elif ! test -x testdata/bin1/go-cmd-test; then
   222  	echo "go install go-cmd-test did not write to testdata/bin1/go-cmd-test"
   223  	ok=false
   224  fi
   225  
   226  # Without $GOBIN set, installing a program outside $GOPATH should fail
   227  # (there is nowhere to install it).
   228  TEST install without destination fails
   229  if ./testgo install testdata/src/go-cmd-test/helloworld.go 2>testdata/err; then
   230  	echo "go install testdata/src/go-cmd-test/helloworld.go should have failed, did not"
   231  	ok=false
   232  elif ! grep 'no install location for .go files listed on command line' testdata/err; then
   233  	echo "wrong error:"
   234  	cat testdata/err
   235  	ok=false
   236  fi
   237  rm -f testdata/err
   238  
   239  # With $GOBIN set, should install there.
   240  TEST install to GOBIN '(command-line package)'
   241  if ! GOBIN=$(pwd)/testdata/bin1 ./testgo install testdata/src/go-cmd-test/helloworld.go; then
   242  	echo "go install testdata/src/go-cmd-test/helloworld.go failed"
   243  	ok=false
   244  elif ! test -x testdata/bin1/helloworld; then
   245  	echo "go install testdata/src/go-cmd-test/helloworld.go did not write testdata/bin1/helloworld"
   246  	ok=false
   247  fi
   248  
   249  TEST godoc installs into GOBIN
   250  d=$(mktemp -d -t testgoXXX)
   251  export GOPATH=$d
   252  mkdir $d/gobin
   253  GOBIN=$d/gobin ./testgo get code.google.com/p/go.tools/cmd/godoc
   254  if [ ! -x $d/gobin/godoc ]; then
   255  	echo did not install godoc to '$GOBIN'
   256  	GOBIN=$d/gobin ./testgo list -f 'Target: {{.Target}}' code.google.com/p/go.tools/cmd/godoc
   257  	ok=false
   258  fi
   259  
   260  TEST godoc installs into GOROOT
   261  rm -f $GOROOT/bin/godoc
   262  ./testgo install code.google.com/p/go.tools/cmd/godoc
   263  if [ ! -x $GOROOT/bin/godoc ]; then
   264  	echo did not install godoc to '$GOROOT/bin'
   265  	./testgo list -f 'Target: {{.Target}}' code.google.com/p/go.tools/cmd/godoc
   266  	ok=false
   267  fi
   268  
   269  TEST cmd/fix installs into tool
   270  GOOS=$(./testgo env GOOS)
   271  GOARCH=$(./testgo env GOARCH)
   272  rm -f $GOROOT/pkg/tool/${GOOS}_${GOARCH}/fix
   273  ./testgo install cmd/fix
   274  if [ ! -x $GOROOT/pkg/tool/${GOOS}_${GOARCH}/fix ]; then
   275  	echo 'did not install cmd/fix to $GOROOT/pkg/tool'
   276  	GOBIN=$d/gobin ./testgo list -f 'Target: {{.Target}}' cmd/fix
   277  	ok=false
   278  fi
   279  rm -f $GOROOT/pkg/tool/${GOOS}_${GOARCH}/fix
   280  GOBIN=$d/gobin ./testgo install cmd/fix
   281  if [ ! -x $GOROOT/pkg/tool/${GOOS}_${GOARCH}/fix ]; then
   282  	echo 'did not install cmd/fix to $GOROOT/pkg/tool with $GOBIN set'
   283  	GOBIN=$d/gobin ./testgo list -f 'Target: {{.Target}}' cmd/fix
   284  	ok=false
   285  fi
   286  
   287  TEST gopath program installs into GOBIN
   288  mkdir $d/src/progname
   289  echo 'package main; func main() {}' >$d/src/progname/p.go
   290  GOBIN=$d/gobin ./testgo install progname
   291  if [ ! -x $d/gobin/progname ]; then
   292  	echo 'did not install progname to $GOBIN/progname'
   293  	./testgo list -f 'Target: {{.Target}}' cmd/api
   294  	ok=false
   295  fi
   296  rm -f $d/gobin/progname $d/bin/progname
   297  
   298  TEST gopath program installs into GOPATH/bin
   299  ./testgo install progname
   300  if [ ! -x $d/bin/progname ]; then
   301  	echo 'did not install progname to $GOPATH/bin/progname'
   302  	./testgo list -f 'Target: {{.Target}}' progname
   303  	ok=false
   304  fi
   305  
   306  unset GOPATH
   307  rm -rf $d
   308  
   309  # Reject relative paths in GOPATH.
   310  TEST reject relative paths in GOPATH '(command-line package)'
   311  if GOPATH=. ./testgo build testdata/src/go-cmd-test/helloworld.go; then
   312      echo 'GOPATH="." go build should have failed, did not'
   313      ok=false
   314  fi
   315  
   316  TEST reject relative paths in GOPATH 
   317  if GOPATH=:$(pwd)/testdata:. ./testgo build go-cmd-test; then
   318      echo 'GOPATH=":$(pwd)/testdata:." go build should have failed, did not'
   319      ok=false
   320  fi
   321  
   322  # issue 4104
   323  TEST go test with package listed multiple times
   324  if [ $(./testgo test fmt fmt fmt fmt fmt | wc -l) -ne 1 ] ; then
   325      echo 'go test fmt fmt fmt fmt fmt tested the same package multiple times'
   326      ok=false
   327  fi
   328  
   329  # ensure that output of 'go list' is consistent between runs
   330  TEST go list is consistent
   331  ./testgo list std > test_std.list
   332  if ! ./testgo list std | cmp -s test_std.list - ; then
   333  	echo "go list std ordering is inconsistent"
   334  	ok=false
   335  fi
   336  rm -f test_std.list
   337  
   338  # issue 4096. Validate the output of unsuccessful go install foo/quxx 
   339  TEST unsuccessful go install should mention missing package
   340  if [ $(./testgo install 'foo/quxx' 2>&1 | grep -c 'cannot find package "foo/quxx" in any of') -ne 1 ] ; then
   341  	echo 'go install foo/quxx expected error: .*cannot find package "foo/quxx" in any of'
   342  	ok=false
   343  fi 
   344  # test GOROOT search failure is reported
   345  TEST GOROOT search failure reporting
   346  if [ $(./testgo install 'foo/quxx' 2>&1 | egrep -c 'foo/quxx \(from \$GOROOT\)$') -ne 1 ] ; then
   347          echo 'go install foo/quxx expected error: .*foo/quxx (from $GOROOT)'
   348          ok=false
   349  fi
   350  # test multiple GOPATH entries are reported separately
   351  TEST multiple GOPATH entries reported separately
   352  if [ $(GOPATH=$(pwd)/testdata/a:$(pwd)/testdata/b ./testgo install 'foo/quxx' 2>&1 | egrep -c 'testdata/./src/foo/quxx') -ne 2 ] ; then
   353          echo 'go install foo/quxx expected error: .*testdata/a/src/foo/quxx (from $GOPATH)\n.*testdata/b/src/foo/quxx'
   354          ok=false
   355  fi
   356  # test (from $GOPATH) annotation is reported for the first GOPATH entry
   357  TEST mention GOPATH in first GOPATH entry
   358  if [ $(GOPATH=$(pwd)/testdata/a:$(pwd)/testdata/b ./testgo install 'foo/quxx' 2>&1 | egrep -c 'testdata/a/src/foo/quxx \(from \$GOPATH\)$') -ne 1 ] ; then
   359          echo 'go install foo/quxx expected error: .*testdata/a/src/foo/quxx (from $GOPATH)'
   360          ok=false
   361  fi
   362  # but not on the second
   363  TEST but not the second entry
   364  if [ $(GOPATH=$(pwd)/testdata/a:$(pwd)/testdata/b ./testgo install 'foo/quxx' 2>&1 | egrep -c 'testdata/b/src/foo/quxx$') -ne 1 ] ; then
   365          echo 'go install foo/quxx expected error: .*testdata/b/src/foo/quxx'
   366          ok=false
   367  fi
   368  # test missing GOPATH is reported
   369  TEST missing GOPATH is reported
   370  if [ $(GOPATH= ./testgo install 'foo/quxx' 2>&1 | egrep -c '\(\$GOPATH not set\)$') -ne 1 ] ; then
   371          echo 'go install foo/quxx expected error: ($GOPATH not set)'
   372          ok=false
   373  fi
   374  
   375  # issue 4186. go get cannot be used to download packages to $GOROOT
   376  # Test that without GOPATH set, go get should fail
   377  TEST without GOPATH, go get fails
   378  d=$(mktemp -d -t testgoXXX)
   379  mkdir -p $d/src/pkg
   380  if GOPATH= GOROOT=$d ./testgo get -d code.google.com/p/go.codereview/cmd/hgpatch ; then 
   381  	echo 'go get code.google.com/p/go.codereview/cmd/hgpatch should not succeed with $GOPATH unset'
   382  	ok=false
   383  fi	
   384  rm -rf $d
   385  
   386  # Test that with GOPATH=$GOROOT, go get should fail
   387  TEST with GOPATH=GOROOT, go get fails
   388  d=$(mktemp -d -t testgoXXX)
   389  mkdir -p $d/src/pkg
   390  if GOPATH=$d GOROOT=$d ./testgo get -d code.google.com/p/go.codereview/cmd/hgpatch ; then
   391          echo 'go get code.google.com/p/go.codereview/cmd/hgpatch should not succeed with GOPATH=$GOROOT'
   392          ok=false
   393  fi
   394  rm -rf $d
   395  
   396  TEST ldflags arguments with spaces '(issue 3941)'
   397  d=$(mktemp -d -t testgoXXX)
   398  cat >$d/main.go<<EOF
   399  package main
   400  var extern string
   401  func main() {
   402  	println(extern)
   403  }
   404  EOF
   405  ./testgo run -ldflags '-X main.extern "hello world"' $d/main.go 2>hello.out
   406  if ! grep -q '^hello world' hello.out; then
   407  	echo "ldflags -X main.extern 'hello world' failed. Output:"
   408  	cat hello.out
   409  	ok=false
   410  fi
   411  rm -rf $d hello.out
   412  
   413  TEST go test -cpuprofile leaves binary behind
   414  ./testgo test -cpuprofile strings.prof strings || ok=false
   415  if [ ! -x strings.test ]; then
   416  	echo "go test -cpuprofile did not create strings.test"
   417  	ok=false
   418  fi
   419  rm -f strings.prof strings.test
   420  
   421  TEST symlinks do not confuse go list '(issue 4568)'
   422  old=$(pwd)
   423  tmp=$(cd /tmp && pwd -P)
   424  d=$(TMPDIR=$tmp mktemp -d -t testgoXXX)
   425  mkdir -p $d/src
   426  (
   427  	ln -s $d $d/src/dir1
   428  	cd $d/src/dir1
   429  	echo package p >p.go
   430  	export GOPATH=$d
   431  	if [ "$($old/testgo list -f '{{.Root}}' .)" != "$d" ]; then
   432  		echo Confused by symlinks.
   433  		echo "Package in current directory $(pwd) should have Root $d"
   434  		env|grep WD
   435  		$old/testgo list -json . dir1
   436  		touch $d/failed
   437  	fi		
   438  )
   439  if [ -f $d/failed ]; then
   440  	ok=false
   441  fi
   442  rm -rf $d
   443  
   444  TEST 'install with tags (issue 4515)'
   445  d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
   446  mkdir -p $d/src/example/a $d/src/example/b $d/bin
   447  cat >$d/src/example/a/main.go <<EOF
   448  package main
   449  func main() {}
   450  EOF
   451  cat >$d/src/example/b/main.go <<EOF
   452  // +build mytag
   453  
   454  package main
   455  func main() {}
   456  EOF
   457  GOPATH=$d ./testgo install -tags mytag example/a example/b || ok=false
   458  if [ ! -x $d/bin/a -o ! -x $d/bin/b ]; then
   459  	echo go install example/a example/b did not install binaries
   460  	ok=false
   461  fi
   462  rm -f $d/bin/*
   463  GOPATH=$d ./testgo install -tags mytag example/... || ok=false
   464  if [ ! -x $d/bin/a -o ! -x $d/bin/b ]; then
   465  	echo go install example/... did not install binaries
   466  	ok=false
   467  fi
   468  rm -f $d/bin/*go
   469  export GOPATH=$d
   470  if [ "$(./testgo list -tags mytag example/b...)" != "example/b" ]; then
   471  	echo go list example/b did not find example/b
   472  	ok=false
   473  fi
   474  unset GOPATH
   475  rm -rf $d
   476  
   477  TEST case collisions '(issue 4773)'
   478  d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
   479  export GOPATH=$d
   480  mkdir -p $d/src/example/a $d/src/example/b
   481  cat >$d/src/example/a/a.go <<EOF
   482  package p
   483  import (
   484  	_ "math/rand"
   485  	_ "math/Rand"
   486  )
   487  EOF
   488  if ./testgo list example/a 2>$d/out; then
   489  	echo go list example/a should have failed, did not.
   490  	ok=false
   491  elif ! grep "case-insensitive import collision" $d/out >/dev/null; then
   492  	echo go list example/a did not report import collision.
   493  	ok=false
   494  fi
   495  cat >$d/src/example/b/file.go <<EOF
   496  package b
   497  EOF
   498  cat >$d/src/example/b/FILE.go <<EOF
   499  package b
   500  EOF
   501  if [ $(ls $d/src/example/b | wc -l) = 2 ]; then
   502  	# case-sensitive file system, let directory read find both files
   503  	args="example/b"
   504  else
   505  	# case-insensitive file system, list files explicitly on command line.
   506  	args="$d/src/example/b/file.go $d/src/example/b/FILE.go"
   507  fi
   508  if ./testgo list $args 2>$d/out; then
   509  	echo go list example/b should have failed, did not.
   510  	ok=false
   511  elif ! grep "case-insensitive file name collision" $d/out >/dev/null; then
   512  	echo go list example/b did not report file name collision.
   513  	ok=false
   514  fi
   515  
   516  TEST go get cover
   517  ./testgo get code.google.com/p/go.tools/cmd/cover || ok=false
   518  
   519  unset GOPATH
   520  rm -rf $d
   521  
   522  TEST shadowing logic
   523  export GOPATH=$(pwd)/testdata/shadow/root1:$(pwd)/testdata/shadow/root2
   524  
   525  # The math in root1 is not "math" because the standard math is.
   526  cdir=$(./testgo list -f '({{.ImportPath}}) ({{.ConflictDir}})' ./testdata/shadow/root1/src/math)
   527  if [ "$cdir" != "(_$(pwd)/testdata/shadow/root1/src/math) ($GOROOT/src/pkg/math)" ]; then
   528  	echo shadowed math is not shadowed: "$cdir"
   529  	ok=false
   530  fi
   531  
   532  # The foo in root1 is "foo".
   533  cdir=$(./testgo list -f '({{.ImportPath}}) ({{.ConflictDir}})' ./testdata/shadow/root1/src/foo)
   534  if [ "$cdir" != "(foo) ()" ]; then
   535  	echo unshadowed foo is shadowed: "$cdir"
   536  	ok=false
   537  fi
   538  
   539  # The foo in root2 is not "foo" because the foo in root1 got there first.
   540  cdir=$(./testgo list -f '({{.ImportPath}}) ({{.ConflictDir}})' ./testdata/shadow/root2/src/foo)
   541  if [ "$cdir" != "(_$(pwd)/testdata/shadow/root2/src/foo) ($(pwd)/testdata/shadow/root1/src/foo)" ]; then
   542  	echo shadowed foo is not shadowed: "$cdir"
   543  	ok=false
   544  fi
   545  
   546  # The error for go install should mention the conflicting directory.
   547  err=$(! ./testgo install ./testdata/shadow/root2/src/foo 2>&1)
   548  if [ "$err" != "go install: no install location for directory $(pwd)/testdata/shadow/root2/src/foo hidden by $(pwd)/testdata/shadow/root1/src/foo" ]; then
   549  	echo wrong shadowed install error: "$err"
   550  	ok=false
   551  fi
   552  
   553  # Only succeeds if source order is preserved.
   554  TEST source file name order preserved
   555  ./testgo test testdata/example[12]_test.go || ok=false
   556  
   557  # Check that coverage analysis works at all.
   558  # Don't worry about the exact numbers
   559  TEST coverage runs
   560  ./testgo test -short -coverpkg=strings strings regexp || ok=false
   561  ./testgo test -short -cover strings math regexp || ok=false
   562  
   563  TEST cgo depends on syscall
   564  rm -rf $GOROOT/pkg/*_race
   565  d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
   566  export GOPATH=$d
   567  mkdir -p $d/src/foo
   568  echo '
   569  package foo
   570  //#include <stdio.h>
   571  import "C"
   572  ' >$d/src/foo/foo.go
   573  ./testgo build -race foo || ok=false
   574  rm -rf $d
   575  unset GOPATH
   576  
   577  TEST cgo shows full path names
   578  d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
   579  export GOPATH=$d
   580  mkdir -p $d/src/x/y/dirname
   581  echo '
   582  package foo
   583  import "C"
   584  func f() {
   585  ' >$d/src/x/y/dirname/foo.go
   586  if ./testgo build x/y/dirname >$d/err 2>&1; then
   587  	echo build succeeded unexpectedly.
   588  	ok=false
   589  elif ! grep x/y/dirname $d/err >/dev/null; then
   590  	echo error did not use full path.
   591  	cat $d/err
   592  	ok=false
   593  fi
   594  rm -rf $d
   595  unset GOPATH
   596  
   597  TEST 'cgo handles -Wl,$ORIGIN'
   598  d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
   599  export GOPATH=$d
   600  mkdir -p $d/src/origin
   601  echo '
   602  package origin
   603  // #cgo LDFLAGS: -Wl,-rpath -Wl,$ORIGIN
   604  // void f(void) {}
   605  import "C"
   606  
   607  func f() { C.f() }
   608  ' >$d/src/origin/origin.go
   609  if ! ./testgo build origin; then
   610  	echo build failed
   611  	ok=false
   612  fi
   613  rm -rf $d
   614  unset GOPATH
   615  
   616  TEST 'Issue 6480: "go test -c -test.bench=XXX fmt" should not hang'
   617  if ! ./testgo test -c -test.bench=XXX fmt; then
   618  	echo build test failed
   619  	ok=false
   620  fi
   621  rm -f fmt.test
   622  
   623  # clean up
   624  if $started; then stop; fi
   625  rm -rf testdata/bin testdata/bin1
   626  rm -f testgo
   627  
   628  if $allok; then
   629  	echo PASS
   630  else
   631  	echo FAIL
   632  	exit 1
   633  fi