mirror of
https://github.com/golang/go
synced 2024-11-13 19:00:25 -07:00
- added test script
- fixed a couple of printing bugs status: parses, reproduces, and idempotently reproduces all correct .go files R=r OCL=17332 CL=17332
This commit is contained in:
parent
060f157dc8
commit
c4f9f369a6
@ -9,54 +9,7 @@ pretty: pretty.6
|
||||
$(L) -o pretty pretty.6
|
||||
|
||||
test: pretty
|
||||
pretty -s *.go
|
||||
pretty -s ../gosrc/*.go
|
||||
#pretty -s $(GOROOT)/test/*.go # contains incorrect programs
|
||||
pretty -s $(GOROOT)/test/235.go
|
||||
pretty -s $(GOROOT)/test/args.go
|
||||
pretty -s $(GOROOT)/test/bufiolib.go
|
||||
pretty -s $(GOROOT)/test/char_lit.go
|
||||
pretty -s $(GOROOT)/test/complit.go
|
||||
pretty -s $(GOROOT)/test/const.go
|
||||
pretty -s $(GOROOT)/test/dialgoogle.go
|
||||
pretty -s $(GOROOT)/test/empty.go
|
||||
pretty -s $(GOROOT)/test/env.go
|
||||
pretty -s $(GOROOT)/test/float_lit.go
|
||||
pretty -s $(GOROOT)/test/fmt_test.go
|
||||
pretty -s $(GOROOT)/test/for.go
|
||||
pretty -s $(GOROOT)/test/func.go
|
||||
pretty -s $(GOROOT)/test/func1.go
|
||||
pretty -s $(GOROOT)/test/func2.go
|
||||
pretty -s $(GOROOT)/src/pkg/*.go
|
||||
pretty -s $(GOROOT)/src/lib/*.go
|
||||
pretty -s $(GOROOT)/src/lib/*/*.go
|
||||
pretty -s $(GOROOT)/usr/r/*/*.go
|
||||
echo "DONE"
|
||||
|
||||
testnoisy: pretty
|
||||
pretty *.go
|
||||
pretty ../gosrc/*.go
|
||||
#pretty $(GOROOT)/test/*.go # contains incorrect programs
|
||||
pretty $(GOROOT)/test/235.go
|
||||
pretty $(GOROOT)/test/args.go
|
||||
pretty $(GOROOT)/test/bufiolib.go
|
||||
pretty $(GOROOT)/test/char_lit.go
|
||||
pretty $(GOROOT)/test/complit.go
|
||||
pretty $(GOROOT)/test/const.go
|
||||
pretty $(GOROOT)/test/dialgoogle.go
|
||||
pretty $(GOROOT)/test/empty.go
|
||||
pretty $(GOROOT)/test/env.go
|
||||
pretty $(GOROOT)/test/float_lit.go
|
||||
pretty $(GOROOT)/test/fmt_test.go
|
||||
pretty $(GOROOT)/test/for.go
|
||||
pretty $(GOROOT)/test/func.go
|
||||
pretty $(GOROOT)/test/func1.go
|
||||
pretty $(GOROOT)/test/func2.go
|
||||
pretty $(GOROOT)/src/pkg/*.go
|
||||
pretty $(GOROOT)/src/lib/*.go
|
||||
pretty $(GOROOT)/src/lib/*/*.go
|
||||
pretty $(GOROOT)/usr/r/*/*.go
|
||||
echo "DONE"
|
||||
test.sh
|
||||
|
||||
install: pretty
|
||||
cp pretty $(HOME)/bin/pretty
|
||||
|
@ -1283,29 +1283,35 @@ func (P *Parser) ParseFunctionDecl(exported bool) *Node.Decl {
|
||||
}
|
||||
|
||||
|
||||
func (P *Parser) ParseExportDecl() {
|
||||
func (P *Parser) ParseExportDecl() *Node.Decl {
|
||||
P.Trace("ExportDecl");
|
||||
|
||||
// TODO This is deprecated syntax and should go away eventually.
|
||||
// (Also at the moment the syntax is everything goes...)
|
||||
//P.Expect(Scanner.EXPORT);
|
||||
|
||||
d := Node.NewDecl(P.pos, Scanner.EXPORT, false);
|
||||
|
||||
has_paren := false;
|
||||
if P.tok == Scanner.LPAREN {
|
||||
P.Next();
|
||||
has_paren = true;
|
||||
}
|
||||
d.ident = P.ParseIdentList();
|
||||
/*
|
||||
for P.tok == Scanner.IDENT {
|
||||
P.ParseIdent();
|
||||
if P.tok == Scanner.COMMA {
|
||||
P.Next(); // TODO this seems wrong
|
||||
}
|
||||
}
|
||||
*/
|
||||
if has_paren {
|
||||
P.Expect(Scanner.RPAREN)
|
||||
}
|
||||
|
||||
P.Ecart();
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
@ -1335,10 +1341,10 @@ func (P *Parser) ParseDeclaration() *Node.Decl {
|
||||
P.Error(P.pos, "cannot mark export declaration for export");
|
||||
}
|
||||
P.Next();
|
||||
P.ParseExportDecl();
|
||||
d = P.ParseExportDecl();
|
||||
default:
|
||||
if exported && (P.tok == Scanner.IDENT || P.tok == Scanner.LPAREN) {
|
||||
P.ParseExportDecl();
|
||||
d = P.ParseExportDecl();
|
||||
} else {
|
||||
P.Error(P.pos, "declaration expected");
|
||||
P.Next(); // make progress
|
||||
|
@ -47,7 +47,7 @@ func (P *Printer) Token(pos int, tok int) {
|
||||
|
||||
|
||||
func (P *Printer) OpenScope(paren string) {
|
||||
P.semi, P.newl = false, 0;
|
||||
//P.semi, P.newl = false, 0;
|
||||
P.String(0, paren);
|
||||
P.level++;
|
||||
P.indent++;
|
||||
@ -138,7 +138,7 @@ func (P *Printer) Type(t *Node.Type) {
|
||||
}
|
||||
|
||||
case Scanner.MAP:
|
||||
P.String(t.pos, "[");
|
||||
P.String(t.pos, "map [");
|
||||
P.Type(t.key);
|
||||
P.String(0, "]");
|
||||
P.Type(t.elt);
|
||||
@ -301,13 +301,15 @@ func (P *Printer) ControlClause(s *Node.Stat) {
|
||||
if s.expr != nil {
|
||||
P.Expr(s.expr);
|
||||
}
|
||||
if has_post {
|
||||
if s.tok == Scanner.FOR {
|
||||
P.semi = true;
|
||||
if has_post {
|
||||
P.Blank();
|
||||
P.Stat(s.post);
|
||||
P.semi = false
|
||||
}
|
||||
}
|
||||
}
|
||||
P.Blank();
|
||||
}
|
||||
|
||||
@ -425,7 +427,7 @@ func (P *Printer) Declaration(d *Node.Decl, parenthesized bool) {
|
||||
P.Blank();
|
||||
}
|
||||
|
||||
if d.ident == nil {
|
||||
if d.tok != Scanner.FUNC && d.list != nil {
|
||||
P.OpenScope("(");
|
||||
for i := 0; i < d.list.len(); i++ {
|
||||
P.Declaration(d.list.at(i).(*Node.Decl), true);
|
||||
|
95
usr/gri/pretty/test.sh
Executable file
95
usr/gri/pretty/test.sh
Executable file
@ -0,0 +1,95 @@
|
||||
# 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
|
||||
COUNT=0
|
||||
|
||||
apply1() {
|
||||
#echo $1 $2
|
||||
$1 $2
|
||||
let COUNT=$COUNT+1
|
||||
}
|
||||
|
||||
apply() {
|
||||
for F in \
|
||||
$GOROOT/usr/gri/pretty/*.go \
|
||||
$GOROOT/usr/gri/gosrc/*.go \
|
||||
$GOROOT/test/235.go \
|
||||
$GOROOT/test/args.go \
|
||||
$GOROOT/test/bufiolib.go \
|
||||
$GOROOT/test/char_lit.go \
|
||||
$GOROOT/test/complit.go \
|
||||
$GOROOT/test/const.go \
|
||||
$GOROOT/test/dialgoogle.go \
|
||||
$GOROOT/test/empty.go \
|
||||
$GOROOT/test/env.go \
|
||||
$GOROOT/test/float_lit.go \
|
||||
$GOROOT/test/fmt_test.go \
|
||||
$GOROOT/test/for.go \
|
||||
$GOROOT/test/func.go \
|
||||
$GOROOT/test/func1.go \
|
||||
$GOROOT/test/func2.go \
|
||||
$GOROOT/src/pkg/*.go \
|
||||
$GOROOT/src/lib/*.go \
|
||||
$GOROOT/src/lib/*/*.go \
|
||||
$GOROOT/usr/r/*/*.go
|
||||
do
|
||||
apply1 $1 $F
|
||||
done
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
rm -f $TMP1 $TMP2
|
||||
}
|
||||
|
||||
silent() {
|
||||
cleanup
|
||||
pretty -s $1 > $TMP1
|
||||
if [ $? != 0 ]; then
|
||||
cat $TMP1
|
||||
echo "Error (silent mode test): test.sh $1"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
idempotent() {
|
||||
cleanup
|
||||
pretty $1 > $TMP1
|
||||
pretty $TMP1 > $TMP2
|
||||
cmp -s $TMP1 $TMP2
|
||||
if [ $? != 0 ]; then
|
||||
diff $TMP1 $TMP2
|
||||
echo "Error (idempotency test): test.sh $1"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
runtest() {
|
||||
#echo "Testing silent mode"
|
||||
cleanup
|
||||
$1 silent $2
|
||||
|
||||
#echo "Testing idempotency"
|
||||
cleanup
|
||||
$1 idempotent $2
|
||||
}
|
||||
|
||||
runtests() {
|
||||
if [ $# == 0 ]; then
|
||||
runtest apply
|
||||
else
|
||||
for F in $*; do
|
||||
runtest apply1 $F
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
runtests $*
|
||||
cleanup
|
||||
let COUNT=$COUNT/2 # divide by number of tests in runtest
|
||||
echo "PASSED ($COUNT files)"
|
||||
|
Loading…
Reference in New Issue
Block a user