github.com/yanyiwu/go@v0.0.0-20150106053140-03d6637dbb7f/doc/progs/run (about)

     1  #!/usr/bin/env bash
     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  set -e
     7  
     8  goos=$(go env GOOS)
     9  
    10  defer_panic_recover="
    11  	defer
    12  	defer2
    13  "
    14  
    15  effective_go="
    16  	eff_bytesize
    17  	eff_qr
    18  	eff_sequence
    19  	eff_unused2
    20  "
    21  
    22  error_handling="
    23  	error
    24  	error2
    25  	error3
    26  	error4
    27  "
    28  
    29  law_of_reflection="
    30  	interface
    31  	interface2
    32  "
    33  
    34  c_go_cgo="
    35  	cgo1
    36  	cgo2
    37  	cgo3
    38  	cgo4
    39  "
    40  # cgo1 and cgo2 don't run on freebsd, srandom has a different signature
    41  if [ "$goos" == "freebsd" ]; then
    42  	c_go_cgo="cgo3 cgo4"
    43  fi
    44  # cgo1 and cgo2 don't run on netbsd, srandom has a different signature
    45  # cgo3 and cgo4 don't run on netbsd, since cgo cannot handle stdout correctly
    46  if [ "$goos" == "netbsd" ]; then
    47  	c_go_cgo=""
    48  fi
    49  # cgo3 and cgo4 don't run on openbsd, since cgo cannot handle stdout correctly
    50  if [ "$goos" == "openbsd" ]; then
    51  	c_go_cgo="cgo1 cgo2"
    52  fi
    53  if [ "$CGO_ENABLED" != 1 ]; then
    54  	c_go_cgo=""
    55  fi
    56  
    57  timeout="
    58  	timeout1
    59  	timeout2
    60  "
    61  
    62  gobs="
    63  	gobs1
    64  	gobs2
    65  "
    66  
    67  json="
    68  	json1
    69  	json2
    70  	json3
    71  	json4
    72  	json5
    73  "
    74  
    75  image_package="
    76  	image_package1
    77  	image_package2
    78  	image_package3
    79  	image_package4
    80  	image_package5
    81  	image_package6
    82  "
    83  
    84  all=$(echo $defer_panic_recover $effective_go $error_handling $law_of_reflection $c_go_cgo $timeout $gobs $json $image_package slices go1)
    85  
    86  for i in $all; do
    87  	go build $i.go
    88  done
    89  
    90  # Write to temporary file to avoid mingw bash bug.
    91  TMPFILE="${TMPDIR:-/tmp}/gotest3.$USER"
    92  
    93  function testit {
    94  	./$1 >"$TMPFILE" 2>&1 || true
    95  	x=$(echo $(cat "$TMPFILE")) # extra echo canonicalizes
    96  	if ! echo "$x" | grep "$2" > /dev/null
    97  	then
    98  		echo $1 failed: '"'$x'"' is not '"'$2'"'
    99  	fi
   100  }
   101  
   102  
   103  testit defer '^0 3210 2$'
   104  testit defer2 '^Calling g. Printing in g 0 Printing in g 1 Printing in g 2 Printing in g 3 Panicking! Defer in g 3 Defer in g 2 Defer in g 1 Defer in g 0 Recovered in f 4 Returned normally from f.$'
   105  
   106  testit eff_bytesize '^1.00YB 9.09TB$'
   107  testit eff_sequence '^\[-1 2 6 16 44\]$'
   108  
   109  testit go1 '^Christmas is a holiday: true Sleeping for 0.123s.*go1.go already exists$'
   110  
   111  testit interface2 "^type: float64$"
   112  
   113  testit json1 "^$"
   114  testit json2 "the reciprocal of i is"
   115  testit json3 "Age is int 6"
   116  testit json4 "^$"
   117  
   118  testit image_package1 "^X is 2 Y is 1$"
   119  testit image_package2 "^3 4 false$"
   120  testit image_package3 "^3 4 true$"
   121  testit image_package4 "^image.Point{X:2, Y:1}$"
   122  testit image_package5 "^{255 0 0 255}$"
   123  testit image_package6 "^8 4 true$"
   124  
   125  rm -f $all "$TMPFILE"