2009-12-01 20:30:17 -07:00
|
|
|
#!/usr/bin/env bash
|
2009-06-16 13:03:32 -06:00
|
|
|
# Copyright 2009 The Go Authors. All rights reserved.
|
2008-10-16 20:24:33 -06:00
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
2009-11-23 18:32:51 -07:00
|
|
|
. "$GOROOT"/src/Make.$GOARCH
|
2009-06-05 11:59:55 -06:00
|
|
|
if [ -z "$O" ]; then
|
|
|
|
echo 'missing $O - maybe no Make.$GOARCH?' 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2009-06-15 17:23:16 -06:00
|
|
|
CMD="./gofmt"
|
2008-10-16 20:24:33 -06:00
|
|
|
TMP1=test_tmp1.go
|
|
|
|
TMP2=test_tmp2.go
|
2008-12-01 18:20:59 -07:00
|
|
|
TMP3=test_tmp3.go
|
2008-10-16 20:24:33 -06:00
|
|
|
COUNT=0
|
|
|
|
|
2008-10-18 17:42:25 -06:00
|
|
|
count() {
|
2009-01-15 18:16:41 -07:00
|
|
|
#echo $1
|
2008-10-18 17:42:25 -06:00
|
|
|
let COUNT=$COUNT+1
|
|
|
|
let M=$COUNT%10
|
|
|
|
if [ $M == 0 ]; then
|
|
|
|
echo -n "."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-10 20:07:10 -07:00
|
|
|
error() {
|
|
|
|
echo $1
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-20 18:13:02 -06:00
|
|
|
# apply to one file
|
2008-10-16 20:24:33 -06:00
|
|
|
apply1() {
|
2009-11-19 17:42:49 -07:00
|
|
|
# the following files are skipped because they are test cases
|
|
|
|
# for syntax errors and thus won't parse in the first place:
|
2010-02-12 16:28:11 -07:00
|
|
|
case `basename "$F"` in
|
2010-06-09 16:19:22 -06:00
|
|
|
func3.go | const2.go | char_lit1.go | \
|
2009-11-01 16:27:10 -07:00
|
|
|
bug014.go | bug050.go | bug068.go | bug083.go | bug088.go | \
|
|
|
|
bug106.go | bug121.go | bug125.go | bug133.go | bug160.go | \
|
2009-12-10 20:07:10 -07:00
|
|
|
bug163.go | bug166.go | bug169.go | bug217.go | bug222.go | \
|
2010-06-08 18:25:04 -06:00
|
|
|
bug226.go | bug228.go | bug248.go | bug274.go | bug280.go | \
|
2010-07-09 14:03:25 -06:00
|
|
|
bug282.go | bug287.go ) return ;;
|
2008-10-20 18:13:02 -06:00
|
|
|
esac
|
2010-02-12 16:28:11 -07:00
|
|
|
# the following directories are skipped because they contain test
|
|
|
|
# cases for syntax errors and thus won't parse in the first place:
|
|
|
|
case `dirname "$F"` in
|
|
|
|
$GOROOT/test/syntax ) return ;;
|
|
|
|
esac
|
|
|
|
#echo $1 $2
|
|
|
|
"$1" "$2"; count "$F"
|
2008-10-16 20:24:33 -06:00
|
|
|
}
|
|
|
|
|
2008-10-18 17:42:25 -06:00
|
|
|
|
2008-10-20 18:13:02 -06:00
|
|
|
# apply to local files
|
|
|
|
applydot() {
|
2009-11-01 16:27:10 -07:00
|
|
|
for F in `find . -name "*.go" | grep -v "._"`; do
|
2009-11-23 18:32:51 -07:00
|
|
|
apply1 "$1" $F
|
2008-10-20 18:13:02 -06:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-27 16:40:17 -07:00
|
|
|
# apply to all .go files we can find
|
2008-10-16 20:24:33 -06:00
|
|
|
apply() {
|
2009-11-23 18:32:51 -07:00
|
|
|
for F in `find "$GOROOT" -name "*.go" | grep -v "._"`; do
|
|
|
|
apply1 "$1" $F
|
2008-10-16 20:24:33 -06:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2008-10-18 17:42:25 -06:00
|
|
|
|
2008-10-16 20:24:33 -06:00
|
|
|
cleanup() {
|
2008-12-01 18:20:59 -07:00
|
|
|
rm -f $TMP1 $TMP2 $TMP3
|
2008-10-16 20:24:33 -06:00
|
|
|
}
|
|
|
|
|
2008-10-18 17:42:25 -06:00
|
|
|
|
2008-10-16 20:24:33 -06:00
|
|
|
silent() {
|
|
|
|
cleanup
|
2009-11-23 18:32:51 -07:00
|
|
|
$CMD "$1" > /dev/null 2> $TMP1
|
2008-10-16 20:24:33 -06:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
cat $TMP1
|
2009-12-10 20:07:10 -07:00
|
|
|
error "Error (silent mode test): test.sh $1"
|
2008-10-16 20:24:33 -06:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-10-18 17:42:25 -06:00
|
|
|
|
2008-10-16 20:24:33 -06:00
|
|
|
idempotent() {
|
|
|
|
cleanup
|
2009-11-23 18:32:51 -07:00
|
|
|
$CMD "$1" > $TMP1
|
2009-05-06 17:28:18 -06:00
|
|
|
if [ $? != 0 ]; then
|
2009-12-10 20:07:10 -07:00
|
|
|
error "Error (step 1 of idempotency test): test.sh $1"
|
2009-05-06 17:28:18 -06:00
|
|
|
fi
|
2009-06-05 11:59:55 -06:00
|
|
|
|
2009-02-05 12:05:02 -07:00
|
|
|
$CMD $TMP1 > $TMP2
|
2009-05-06 17:28:18 -06:00
|
|
|
if [ $? != 0 ]; then
|
2009-12-10 20:07:10 -07:00
|
|
|
error "Error (step 2 of idempotency test): test.sh $1"
|
2009-05-06 17:28:18 -06:00
|
|
|
fi
|
|
|
|
|
2009-02-05 12:05:02 -07:00
|
|
|
$CMD $TMP2 > $TMP3
|
2009-05-06 17:28:18 -06:00
|
|
|
if [ $? != 0 ]; then
|
2009-12-10 20:07:10 -07:00
|
|
|
error "Error (step 3 of idempotency test): test.sh $1"
|
2009-05-06 17:28:18 -06:00
|
|
|
fi
|
|
|
|
|
2008-12-01 18:20:59 -07:00
|
|
|
cmp -s $TMP2 $TMP3
|
2008-10-16 20:24:33 -06:00
|
|
|
if [ $? != 0 ]; then
|
2008-12-01 18:20:59 -07:00
|
|
|
diff $TMP2 $TMP3
|
2009-12-10 20:07:10 -07:00
|
|
|
error "Error (step 4 of idempotency test): test.sh $1"
|
2008-10-16 20:24:33 -06:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-10-18 17:42:25 -06:00
|
|
|
|
2008-10-20 17:44:03 -06:00
|
|
|
valid() {
|
|
|
|
cleanup
|
2009-11-23 18:32:51 -07:00
|
|
|
$CMD "$1" > $TMP1
|
2009-05-06 17:28:18 -06:00
|
|
|
if [ $? != 0 ]; then
|
2009-12-10 20:07:10 -07:00
|
|
|
error "Error (step 1 of validity test): test.sh $1"
|
2009-05-06 17:28:18 -06:00
|
|
|
fi
|
|
|
|
|
2009-06-05 11:59:55 -06:00
|
|
|
$GC -o /dev/null $TMP1
|
2008-10-20 17:44:03 -06:00
|
|
|
if [ $? != 0 ]; then
|
2009-12-10 20:07:10 -07:00
|
|
|
error "Error (step 2 of validity test): test.sh $1"
|
2008-10-20 17:44:03 -06:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-16 20:24:33 -06:00
|
|
|
runtest() {
|
|
|
|
#echo "Testing silent mode"
|
|
|
|
cleanup
|
2009-11-23 18:32:51 -07:00
|
|
|
"$1" silent "$2"
|
2008-10-16 20:24:33 -06:00
|
|
|
|
|
|
|
#echo "Testing idempotency"
|
|
|
|
cleanup
|
2009-11-23 18:32:51 -07:00
|
|
|
"$1" idempotent "$2"
|
2008-10-16 20:24:33 -06:00
|
|
|
}
|
|
|
|
|
2008-10-18 17:42:25 -06:00
|
|
|
|
2008-10-16 20:24:33 -06:00
|
|
|
runtests() {
|
2010-01-12 10:45:11 -07:00
|
|
|
if [ $# = 0 ]; then
|
2008-10-16 20:24:33 -06:00
|
|
|
runtest apply
|
2009-06-05 11:59:55 -06:00
|
|
|
# verify the pretty-printed files can be compiled with $GC again
|
2008-10-20 18:13:02 -06:00
|
|
|
# do it in local directory only because of the prerequisites required
|
|
|
|
#echo "Testing validity"
|
2009-12-01 14:08:36 -07:00
|
|
|
# Disabled for now due to dependency problems
|
|
|
|
# cleanup
|
|
|
|
# applydot valid
|
2008-10-16 20:24:33 -06:00
|
|
|
else
|
2009-12-01 14:08:36 -07:00
|
|
|
for F in "$@"; do
|
2009-11-23 18:32:51 -07:00
|
|
|
runtest apply1 "$F"
|
2008-10-16 20:24:33 -06:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-10-18 17:42:25 -06:00
|
|
|
|
|
|
|
# run over all .go files
|
2010-01-12 10:45:11 -07:00
|
|
|
runtests "$@"
|
2008-10-16 20:24:33 -06:00
|
|
|
cleanup
|
|
|
|
|
2008-10-18 17:42:25 -06:00
|
|
|
# done
|
|
|
|
echo
|
|
|
|
echo "PASSED ($COUNT tests)"
|