run 2.4 KB
Newer Older
Russ Cox's avatar
Russ Cox committed
1
#!/usr/bin/env bash
Rob Pike's avatar
Rob Pike committed
2 3 4 5
# Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

Russ Cox's avatar
Russ Cox committed
6 7
set -e

8
eval $(gomake --no-print-directory -f ../../src/Make.inc go-env)
9 10 11 12 13 14 15

if [ -z "$O" ]; then
	echo 'missing $O - maybe no Make.$GOARCH?' 1>&2
	exit 1
fi

rm -f *.$O
Rob Pike's avatar
Rob Pike committed
16

17
if [ "$GOOS" = "windows" ];then
18
	$GC -o file.$O file_windows.go
19 20 21 22
else
	$GC file.go
fi

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
defer_panic_recover="
	defer.go 
	defer2.go 
"

effective_go="
	eff_bytesize.go
	eff_qr.go 
	eff_sequence.go
"

go_tutorial="
	cat.go 
	cat_rot13.go 
	echo.go 
	file.go
	helloworld.go 
	helloworld3.go 
	print.go 
	print_string.go 
	server.go 
	server1.go 
	sieve.go 
	sieve1.go 
	sort.go 
	sortmain.go 
	strings.go 
	sum.go 
"

Rob Pike's avatar
Rob Pike committed
53
for i in \
54 55 56 57
	$defer_panic_recover \
	$effective_go \
	$go_tutorial \
	go1.go \
Rob Pike's avatar
Rob Pike committed
58
; do
59
	$GC $i
Rob Pike's avatar
Rob Pike committed
60 61
done

62 63 64
# Write to temporary file to avoid mingw bash bug.
TMPFILE="/tmp/gotest3"

Rob Pike's avatar
Rob Pike committed
65
function testit {
66
	$LD $1.$O
67 68
	./$O.out $2 2>&1 >"$TMPFILE" || true
	x=$(echo $(cat "$TMPFILE")) # extra echo canonicalizes
Rob Pike's avatar
Rob Pike committed
69 70 71 72 73 74 75
	if [ "$x" != "$3" ]
	then
		echo $1 failed: '"'$x'"' is not '"'$3'"'
	fi
}

function testitpipe {
76
	$LD $1.$O
77 78
	./$O.out | $2 2>&1 >"$TMPFILE" || true
	x=$(echo $(cat "$TMPFILE")) # extra echo canonicalizes
Rob Pike's avatar
Rob Pike committed
79 80 81 82 83 84 85 86
	if [ "$x" != "$3" ]
	then
		echo $1 failed: '"'$x'"' is not '"'$3'"'
	fi
}


testit helloworld "" "Hello, world; or Καλημέρα κόσμε; or こんにちは 世界"
87
testit helloworld3 "" "hello, world can't open file; err=no such file or directory"
Rob Pike's avatar
Rob Pike committed
88 89
testit echo "hello, world" "hello, world"
testit sum "" "6"
90
testit strings "" ""
Rob Pike's avatar
Rob Pike committed
91 92 93 94 95 96 97

alphabet=abcdefghijklmnopqrstuvwxyz
rot13=nopqrstuvwxyzabcdefghijklm
echo $alphabet | testit cat "" $alphabet
echo $alphabet | testit cat_rot13 "--rot13" $rot13
echo $rot13 | testit cat_rot13 "--rot13" $alphabet

98
testit sortmain "" "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
Rob Pike's avatar
Rob Pike committed
99

Rob Pike's avatar
Rob Pike committed
100 101 102
testit print "" "18446744073709551615 -1 18446744073709551615 {77 Sunset Strip} [1 2 3 4] 18446744073709551615 {77 Sunset Strip} [1 2 3 4] 18446744073709551615 {77 Sunset Strip} [1 2 3 4]"
testit print_string "" "77 Sunset Strip"

Rob Pike's avatar
Rob Pike committed
103 104 105
testitpipe sieve "sed 10q" "2 3 5 7 11 13 17 19 23 29"
testitpipe sieve "sed 10q" "2 3 5 7 11 13 17 19 23 29"

Rob Pike's avatar
Rob Pike committed
106
# server hangs; don't run it, just compile it
107
$GC server.go
Rob Pike's avatar
Rob Pike committed
108
testit server1 "" ""
109

110 111 112
testit eff_bytesize "" "1.00YB 9.09TB"
testit eff_sequence "" "[-1 2 6 16 44]"

Rob Pike's avatar
Rob Pike committed
113 114
testit go1 "" ""

115
rm -f $O.out $O.out.exe *.$O "$TMPFILE"