github.com/hlts2/go@v0.0.0-20170904000733-812b34efaed8/misc/cgo/errors/test.bash (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright 2013 The Go Authors. All rights reserved.
     4  # Use of this source code is governed by a BSD-style
     5  # license that can be found in the LICENSE file.
     6  
     7  check() {
     8  	file=$1
     9  	line=$(grep -n 'ERROR HERE' $file | sed 's/:.*//')
    10  	if [ "$line" = "" ]; then
    11  		echo 1>&2 misc/cgo/errors/test.bash: BUG: cannot find ERROR HERE in $file
    12  		exit 1
    13  	fi
    14  	expect $file $file:$line:
    15  }
    16  
    17  expect() {
    18  	file=$1
    19  	shift
    20  	if go build -gcflags=-C $file >errs 2>&1; then
    21  		echo 1>&2 misc/cgo/errors/test.bash: BUG: expected cgo to fail on $file but it succeeded
    22  		exit 1
    23  	fi
    24  	if ! test -s errs; then
    25  		echo 1>&2 misc/cgo/errors/test.bash: BUG: expected error output for $file but saw none
    26  		exit 1
    27  	fi
    28  	for error; do
    29  		if ! fgrep $error errs >/dev/null 2>&1; then
    30  			echo 1>&2 misc/cgo/errors/test.bash: BUG: expected error output for $file to contain \"$error\" but saw:
    31  			cat 1>&2 errs
    32  			exit 1
    33  		fi
    34  	done
    35  }
    36  
    37  check err1.go
    38  check err2.go
    39  check err3.go
    40  if [ $(go env GOARCH) == "amd64" ]; then # If we find a portable test case, we can remove this.
    41  	check err4.go
    42  fi
    43  check issue7757.go
    44  check issue8442.go
    45  check issue11097a.go
    46  check issue11097b.go
    47  expect issue13129.go C.ushort
    48  check issue13423.go
    49  expect issue13635.go C.uchar C.schar C.ushort C.uint C.ulong C.longlong C.ulonglong C.complexfloat C.complexdouble
    50  check issue13830.go
    51  check issue16116.go
    52  check issue16591.go
    53  check issue18889.go
    54  expect issue18452.go issue18452.go:16 issue18452.go:17
    55  
    56  if ! go build issue14669.go; then
    57  	exit 1
    58  fi
    59  if ! CGO_CFLAGS="-O" go build issue14669.go; then
    60  	exit 1
    61  fi
    62  
    63  if ! go run ptr.go; then
    64  	exit 1
    65  fi
    66  
    67  # The malloc.go test should crash.
    68  rm -f malloc.out
    69  if go run malloc.go >malloc.out 2>&1; then
    70  	echo '`go run malloc.go` succeeded unexpectedly'
    71  	cat malloc.out
    72  	rm -f malloc.out
    73  	exit 1
    74  fi
    75  rm -f malloc.out
    76  
    77  rm -rf errs _obj
    78  exit 0