2008-10-16 20:24:33 -06:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
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() {
|
|
|
|
let COUNT=$COUNT+1
|
|
|
|
let M=$COUNT%10
|
|
|
|
if [ $M == 0 ]; then
|
|
|
|
echo -n "."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-20 18:13:02 -06:00
|
|
|
# apply to one file
|
2008-10-16 20:24:33 -06:00
|
|
|
apply1() {
|
|
|
|
#echo $1 $2
|
2008-10-20 18:13:02 -06:00
|
|
|
case `basename $F` in
|
2009-01-09 17:28:09 -07:00
|
|
|
# files with errors (skip them)
|
2009-01-07 14:58:56 -07:00
|
|
|
method1.go | selftest1.go | func3.go | bug014.go | bug029.go | bug032.go | bug050.go | \
|
2009-01-09 17:28:09 -07:00
|
|
|
bug068.go | bug088.go | bug083.go | bug106.go | bug125.go | bug126.go ) ;;
|
2008-10-20 18:13:02 -06:00
|
|
|
* ) $1 $2; count ;;
|
|
|
|
esac
|
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() {
|
|
|
|
for F in *.go
|
|
|
|
do
|
|
|
|
apply1 $1 $F
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# apply to all files in the list
|
2008-10-16 20:24:33 -06:00
|
|
|
apply() {
|
|
|
|
for F in \
|
|
|
|
$GOROOT/usr/gri/pretty/*.go \
|
2008-10-18 17:42:25 -06:00
|
|
|
$GOROOT/test/*.go \
|
2008-10-23 18:56:54 -06:00
|
|
|
$GOROOT/test/bugs/*.go \
|
|
|
|
$GOROOT/test/fixedbugs/*.go \
|
2008-10-16 20:24:33 -06:00
|
|
|
$GOROOT/src/lib/*.go \
|
|
|
|
$GOROOT/src/lib/*/*.go \
|
|
|
|
$GOROOT/usr/r/*/*.go
|
|
|
|
do
|
2008-10-20 18:13:02 -06:00
|
|
|
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
|
2008-10-24 21:14:28 -06:00
|
|
|
./pretty -s $1 > $TMP1
|
2008-10-16 20:24:33 -06:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
cat $TMP1
|
|
|
|
echo "Error (silent mode test): test.sh $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-10-18 17:42:25 -06:00
|
|
|
|
2008-10-16 20:24:33 -06:00
|
|
|
idempotent() {
|
|
|
|
cleanup
|
2008-10-24 21:14:28 -06:00
|
|
|
./pretty $1 > $TMP1
|
|
|
|
./pretty $TMP1 > $TMP2
|
2008-12-01 18:20:59 -07:00
|
|
|
./pretty $TMP2 > $TMP3
|
|
|
|
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
|
2008-10-16 20:24:33 -06:00
|
|
|
echo "Error (idempotency test): test.sh $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-10-18 17:42:25 -06:00
|
|
|
|
2008-10-20 17:44:03 -06:00
|
|
|
valid() {
|
|
|
|
cleanup
|
2008-10-24 21:14:28 -06:00
|
|
|
./pretty $1 > $TMP1
|
2008-10-20 17:44:03 -06:00
|
|
|
6g -o /dev/null $TMP1
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "Error (validity test): test.sh $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-16 20:24:33 -06:00
|
|
|
runtest() {
|
|
|
|
#echo "Testing silent mode"
|
|
|
|
cleanup
|
2008-11-13 18:50:46 -07:00
|
|
|
$1 silent $2
|
2008-10-16 20:24:33 -06:00
|
|
|
|
|
|
|
#echo "Testing idempotency"
|
|
|
|
cleanup
|
2008-11-13 18:50:46 -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() {
|
|
|
|
if [ $# == 0 ]; then
|
|
|
|
runtest apply
|
2008-10-20 18:13:02 -06:00
|
|
|
# verify the pretty-printed files can be compiled with 6g again
|
|
|
|
# do it in local directory only because of the prerequisites required
|
|
|
|
#echo "Testing validity"
|
|
|
|
cleanup
|
|
|
|
applydot valid
|
2008-10-16 20:24:33 -06:00
|
|
|
else
|
|
|
|
for F in $*; do
|
|
|
|
runtest apply1 $F
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-10-18 17:42:25 -06:00
|
|
|
|
2008-10-31 15:27:34 -06:00
|
|
|
# run selftest1 always
|
|
|
|
./pretty -t selftest1.go > $TMP1
|
2008-10-18 17:42:25 -06:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
cat $TMP1
|
2008-10-31 15:27:34 -06:00
|
|
|
echo "Error (selftest1): pretty -t selftest1.go"
|
2008-10-18 17:42:25 -06:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
count
|
|
|
|
|
|
|
|
|
|
|
|
# run over all .go files
|
2008-10-16 20:24:33 -06:00
|
|
|
runtests $*
|
|
|
|
cleanup
|
|
|
|
|
2008-10-18 17:42:25 -06:00
|
|
|
# done
|
|
|
|
echo
|
|
|
|
echo "PASSED ($COUNT tests)"
|