blob: 6e680b83bfd30880589177cb571ef4d3af77cff8 [file] [log] [blame]
Russ Cox43bcf472009-11-18 09:11:17 -08001#!/usr/bin/env bash
Rob Pikef7a506b2008-09-17 12:14:52 -07002# 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
Russ Cox00f9f0c2010-03-30 10:34:57 -07006set -e
7
Andrew Gerrandd2d7de92012-03-13 11:55:16 +11008goos=$(go env GOOS)
9
Andrew Gerrand49d82b42011-12-12 13:15:29 +110010defer_panic_recover="
Rob Pikef5a1dd82012-03-05 12:49:31 +110011 defer
12 defer2
Andrew Gerrand49d82b42011-12-12 13:15:29 +110013"
14
15effective_go="
Rob Pikef5a1dd82012-03-05 12:49:31 +110016 eff_bytesize
17 eff_qr
18 eff_sequence
Rob Pike9e329a02013-03-08 10:41:20 -080019 eff_unused2
Andrew Gerrand49d82b42011-12-12 13:15:29 +110020"
21
Andrew Gerrandc400a0b2011-12-13 09:44:06 +110022error_handling="
Rob Pikef5a1dd82012-03-05 12:49:31 +110023 error
24 error2
25 error3
26 error4
Andrew Gerrandc400a0b2011-12-13 09:44:06 +110027"
28
Shenghou Maefbd79c2012-03-07 08:05:10 +110029law_of_reflection="
30 interface
31 interface2
32"
33
Francisco Souza60b98d62012-03-13 09:07:37 +110034c_go_cgo="
Andrew Gerrandd2d7de92012-03-13 11:55:16 +110035 cgo1
36 cgo2
37 cgo3
38 cgo4
Francisco Souza60b98d62012-03-13 09:07:37 +110039"
Andrew Gerrandd2d7de92012-03-13 11:55:16 +110040# cgo1 and cgo2 don't run on freebsd, srandom has a different signature
41if [ "$goos" == "freebsd" ]; then
42 c_go_cgo="cgo3 cgo4"
43fi
Joel Sing5131dee2012-06-05 01:43:04 +100044# 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
46if [ "$goos" == "netbsd" ]; then
47 c_go_cgo=""
48fi
Joel Sing708db792012-12-21 01:43:19 +110049# cgo3 and cgo4 don't run on openbsd, since cgo cannot handle stdout correctly
50if [ "$goos" == "openbsd" ]; then
51 c_go_cgo="cgo1 cgo2"
52fi
Ian Lance Taylordb3374e2013-10-11 08:55:13 -070053if [ "$CGO_ENABLED" != 1 ]; then
54 c_go_cgo=""
55fi
Francisco Souza60b98d62012-03-13 09:07:37 +110056
Francisco Souza56598262012-03-14 13:03:11 +110057timeout="
58 timeout1
59 timeout2
60"
61
Francisco Souza9e03dcb2012-03-16 08:21:13 +110062gobs="
63 gobs1
64 gobs2
65"
66
Francisco Souza289a3572012-03-22 18:25:40 +110067json="
68 json1
69 json2
70 json3
71 json4
72 json5
73"
74
Francisco Souza18f1a712012-03-28 14:20:51 +110075image_package="
76 image_package1
77 image_package2
78 image_package3
79 image_package4
80 image_package5
81 image_package6
82"
83
84all=$(echo $defer_panic_recover $effective_go $error_handling $law_of_reflection $c_go_cgo $timeout $gobs $json $image_package slices go1)
Rob Pikef5a1dd82012-03-05 12:49:31 +110085
86for i in $all; do
87 go build $i.go
Rob Pikef7a506b2008-09-17 12:14:52 -070088done
89
Jaroslavas Počepkoff866c42011-10-14 20:37:07 +010090# Write to temporary file to avoid mingw bash bug.
Shenghou Maefbd79c2012-03-07 08:05:10 +110091TMPFILE="${TMPDIR:-/tmp}/gotest3.$USER"
Jaroslavas Počepkoff866c42011-10-14 20:37:07 +010092
Rob Pikef7a506b2008-09-17 12:14:52 -070093function testit {
Rob Pikef5a1dd82012-03-05 12:49:31 +110094 ./$1 >"$TMPFILE" 2>&1 || true
Jaroslavas Počepkoff866c42011-10-14 20:37:07 +010095 x=$(echo $(cat "$TMPFILE")) # extra echo canonicalizes
Rob Pikef5a1dd82012-03-05 12:49:31 +110096 if ! echo "$x" | grep "$2" > /dev/null
Rob Pikef7a506b2008-09-17 12:14:52 -070097 then
Rob Pikef5a1dd82012-03-05 12:49:31 +110098 echo $1 failed: '"'$x'"' is not '"'$2'"'
Rob Pikef7a506b2008-09-17 12:14:52 -070099 fi
100}
101
Rob Pikef7a506b2008-09-17 12:14:52 -0700102
Rob Pikef5a1dd82012-03-05 12:49:31 +1100103testit defer '^0 3210 2$'
104testit 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.$'
Rob Pikef7a506b2008-09-17 12:14:52 -0700105
Rob Pikef5a1dd82012-03-05 12:49:31 +1100106testit eff_bytesize '^1.00YB 9.09TB$'
107testit eff_sequence '^\[-1 2 6 16 44\]$'
Rob Pike18b21c72011-08-22 22:46:59 +1000108
Rob Pikef5a1dd82012-03-05 12:49:31 +1100109testit go1 '^Christmas is a holiday: true Sleeping for 0.123s.*go1.go already exists$'
Rob Pike2fa987b2011-12-07 16:11:17 -0800110
Shenghou Maefbd79c2012-03-07 08:05:10 +1100111testit interface2 "^type: float64$"
Francisco Souza18f1a712012-03-28 14:20:51 +1100112
Francisco Souza289a3572012-03-22 18:25:40 +1100113testit json1 "^$"
114testit json2 "the reciprocal of i is"
115testit json3 "Age is int 6"
116testit json4 "^$"
Shenghou Maefbd79c2012-03-07 08:05:10 +1100117
Francisco Souza18f1a712012-03-28 14:20:51 +1100118testit image_package1 "^X is 2 Y is 1$"
119testit image_package2 "^3 4 false$"
120testit image_package3 "^3 4 true$"
121testit image_package4 "^image.Point{X:2, Y:1}$"
122testit image_package5 "^{255 0 0 255}$"
123testit image_package6 "^8 4 true$"
124
Rob Pikef5a1dd82012-03-05 12:49:31 +1100125rm -f $all "$TMPFILE"