mirror of
https://github.com/golang/go
synced 2024-11-19 12:04:43 -07:00
c400a0b7db
Originally published on The Go Programming Language Blog, July 12, 2011. http://blog.golang.org/2011/07/error-handling-and-go.html Update #2547 R=golang-dev, r CC=golang-dev https://golang.org/cl/5475060
123 lines
2.5 KiB
Bash
Executable File
123 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# 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.
|
|
|
|
set -e
|
|
|
|
eval $(gomake --no-print-directory -f ../../src/Make.inc go-env)
|
|
|
|
if [ -z "$O" ]; then
|
|
echo 'missing $O - maybe no Make.$GOARCH?' 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
rm -f *.$O
|
|
|
|
if [ "$GOOS" = "windows" ];then
|
|
$GC -o file.$O file_windows.go
|
|
else
|
|
$GC file.go
|
|
fi
|
|
|
|
defer_panic_recover="
|
|
defer.go
|
|
defer2.go
|
|
"
|
|
|
|
effective_go="
|
|
eff_bytesize.go
|
|
eff_qr.go
|
|
eff_sequence.go
|
|
"
|
|
|
|
error_handling="
|
|
error.go
|
|
error2.go
|
|
error3.go
|
|
error4.go
|
|
"
|
|
|
|
go_tutorial="
|
|
cat.go
|
|
cat_rot13.go
|
|
echo.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
|
|
"
|
|
|
|
for i in \
|
|
$defer_panic_recover \
|
|
$effective_go \
|
|
$error_handling \
|
|
$go_tutorial \
|
|
go1.go \
|
|
; do
|
|
$GC $i
|
|
done
|
|
|
|
# Write to temporary file to avoid mingw bash bug.
|
|
TMPFILE="/tmp/gotest3"
|
|
|
|
function testit {
|
|
$LD $1.$O
|
|
./$O.out $2 2>&1 >"$TMPFILE" || true
|
|
x=$(echo $(cat "$TMPFILE")) # extra echo canonicalizes
|
|
if [ "$x" != "$3" ]
|
|
then
|
|
echo $1 failed: '"'$x'"' is not '"'$3'"'
|
|
fi
|
|
}
|
|
|
|
function testitpipe {
|
|
$LD $1.$O
|
|
./$O.out | $2 2>&1 >"$TMPFILE" || true
|
|
x=$(echo $(cat "$TMPFILE")) # extra echo canonicalizes
|
|
if [ "$x" != "$3" ]
|
|
then
|
|
echo $1 failed: '"'$x'"' is not '"'$3'"'
|
|
fi
|
|
}
|
|
|
|
|
|
testit helloworld "" "Hello, world; or Καλημέρα κόσμε; or こんにちは 世界"
|
|
testit helloworld3 "" "hello, world can't open file; err=no such file or directory"
|
|
testit echo "hello, world" "hello, world"
|
|
testit sum "" "6"
|
|
testit strings "" ""
|
|
|
|
alphabet=abcdefghijklmnopqrstuvwxyz
|
|
rot13=nopqrstuvwxyzabcdefghijklm
|
|
echo $alphabet | testit cat "" $alphabet
|
|
echo $alphabet | testit cat_rot13 "--rot13" $rot13
|
|
echo $rot13 | testit cat_rot13 "--rot13" $alphabet
|
|
|
|
testit sortmain "" "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
|
|
|
|
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"
|
|
|
|
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"
|
|
|
|
# server hangs; don't run it, just compile it
|
|
$GC server.go
|
|
testit server1 "" ""
|
|
|
|
testit eff_bytesize "" "1.00YB 9.09TB"
|
|
testit eff_sequence "" "[-1 2 6 16 44]"
|
|
|
|
testit go1 "" ""
|
|
|
|
rm -f $O.out $O.out.exe *.$O "$TMPFILE"
|