2009-06-16 13:03:32 -06:00
|
|
|
#!/bin/bash
|
|
|
|
# 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-06-05 11:59:55 -06:00
|
|
|
. $GOROOT/src/Make.$GOARCH
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-07-28 17:38:59 -06:00
|
|
|
# the following have semantic errors:
|
|
|
|
# bug039.go | bug040.go
|
|
|
|
# the following are not idempotent at the moment because of comment formatting:
|
2009-09-10 18:27:06 -06:00
|
|
|
# TODO: restructure script so these files are only excluded from idempotency testing
|
2009-10-05 20:32:10 -06:00
|
|
|
comment.go | net.go | powser1.go | powser2.go | bug052.go | simpbool.go | shift.go | range.go | \
|
2009-09-10 18:27:06 -06:00
|
|
|
goyacc.go | godoc.go | rpc.go | struct.go | log.go | decimal.go | tabwriter.go | encoder.go | debug.go | \
|
2009-10-05 20:32:10 -06:00
|
|
|
elf.go | meteor-contest.go | elffmt.go | xml.go | read.go | \
|
2009-07-28 17:38:59 -06:00
|
|
|
\
|
2009-03-13 17:59:51 -06:00
|
|
|
test_errors.go | calc.go | method1.go | selftest1.go | func3.go | const2.go | \
|
2009-01-23 10:44:01 -07:00
|
|
|
bug014.go | bug025.go | bug029.go | bug032.go | bug039.go | bug040.go | bug050.go | bug068.go | \
|
2009-07-02 16:38:36 -06:00
|
|
|
bug088.go | bug083.go | bug106.go | bug121.go | bug125.go | bug126.go | bug132.go | bug133.go | \
|
2009-07-28 17:38:59 -06:00
|
|
|
bug134.go | bug160.go | bug163.go | bug166.go | bug169.go ) ;;
|
2009-01-15 18:16:41 -07:00
|
|
|
* ) $1 $2; count $F;;
|
2008-10-20 18:13:02 -06:00
|
|
|
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() {
|
2009-05-15 19:52:59 -06:00
|
|
|
for F in `find . -name "*.go" | grep -v "OLD" | grep -v "._"`; do
|
2008-10-20 18:13:02 -06:00
|
|
|
apply1 $1 $F
|
|
|
|
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-05-15 19:52:59 -06:00
|
|
|
for F in `find $GOROOT -name "*.go" | grep -v "OLD" | grep -v "._"`; 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
|
2009-02-05 12:05:02 -07:00
|
|
|
$CMD -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
|
2009-02-05 12:05:02 -07:00
|
|
|
$CMD $1 > $TMP1
|
2009-05-06 17:28:18 -06:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "Error (step 1 of idempotency test): test.sh $1"
|
|
|
|
exit 1
|
|
|
|
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
|
|
|
|
echo "Error (step 2 of idempotency test): test.sh $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2009-02-05 12:05:02 -07:00
|
|
|
$CMD $TMP2 > $TMP3
|
2009-05-06 17:28:18 -06:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "Error (step 3 of idempotency test): test.sh $1"
|
|
|
|
exit 1
|
|
|
|
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-05-06 17:28:18 -06:00
|
|
|
echo "Error (step 4 of idempotency test): test.sh $1"
|
2008-10-16 20:24:33 -06:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-10-18 17:42:25 -06:00
|
|
|
|
2008-10-20 17:44:03 -06:00
|
|
|
valid() {
|
|
|
|
cleanup
|
2009-02-05 12:05:02 -07:00
|
|
|
$CMD $1 > $TMP1
|
2009-05-06 17:28:18 -06:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "Error (step 1 of validity test): test.sh $1"
|
|
|
|
exit 1
|
|
|
|
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-05-06 17:28:18 -06:00
|
|
|
echo "Error (step 2 of validity test): test.sh $1"
|
2008-10-20 17:44:03 -06:00
|
|
|
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
|
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"
|
|
|
|
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
|
|
|
|
|
|
|
# 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)"
|