github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/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 54 timeout=" 55 timeout1 56 timeout2 57 " 58 59 gobs=" 60 gobs1 61 gobs2 62 " 63 64 json=" 65 json1 66 json2 67 json3 68 json4 69 json5 70 " 71 72 image_package=" 73 image_package1 74 image_package2 75 image_package3 76 image_package4 77 image_package5 78 image_package6 79 " 80 81 all=$(echo $defer_panic_recover $effective_go $error_handling $law_of_reflection $c_go_cgo $timeout $gobs $json $image_package slices go1) 82 83 for i in $all; do 84 go build $i.go 85 done 86 87 # Write to temporary file to avoid mingw bash bug. 88 TMPFILE="${TMPDIR:-/tmp}/gotest3.$USER" 89 90 function testit { 91 ./$1 >"$TMPFILE" 2>&1 || true 92 x=$(echo $(cat "$TMPFILE")) # extra echo canonicalizes 93 if ! echo "$x" | grep "$2" > /dev/null 94 then 95 echo $1 failed: '"'$x'"' is not '"'$2'"' 96 fi 97 } 98 99 100 testit defer '^0 3210 2$' 101 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.$' 102 103 testit eff_bytesize '^1.00YB 9.09TB$' 104 testit eff_sequence '^\[-1 2 6 16 44\]$' 105 106 testit go1 '^Christmas is a holiday: true Sleeping for 0.123s.*go1.go already exists$' 107 108 testit interface2 "^type: float64$" 109 110 testit json1 "^$" 111 testit json2 "the reciprocal of i is" 112 testit json3 "Age is int 6" 113 testit json4 "^$" 114 115 testit image_package1 "^X is 2 Y is 1$" 116 testit image_package2 "^3 4 false$" 117 testit image_package3 "^3 4 true$" 118 testit image_package4 "^image.Point{X:2, Y:1}$" 119 testit image_package5 "^{255 0 0 255}$" 120 testit image_package6 "^8 4 true$" 121 122 rm -f $all "$TMPFILE"