]> Cypherpunks repositories - gostls13.git/commitdiff
- added test script
authorRobert Griesemer <gri@golang.org>
Fri, 17 Oct 2008 02:24:33 +0000 (19:24 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 17 Oct 2008 02:24:33 +0000 (19:24 -0700)
- fixed a couple of printing bugs
status: parses, reproduces, and idempotently reproduces all correct .go files

R=r
OCL=17332
CL=17332

usr/gri/pretty/Makefile
usr/gri/pretty/parser.go
usr/gri/pretty/printer.go
usr/gri/pretty/test.sh [new file with mode: 0755]

index fe99249c828e091644444a3d75ca19544c7f56d6..24b00bb2309e0ee5e1db84e8990fef449af9d18b 100644 (file)
@@ -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
index 23dbf55e2985df291c8df6f9235185eaf55322eb..808852da5d5186bb0dc6441db8b1a086b49e89ec 100644 (file)
@@ -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
index 9ec7594fb61ff64aa471bfceab9f68f5aaf0264e..055226313dc9699bd38f0e85a475ae7442097da3 100644 (file)
@@ -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,11 +301,13 @@ 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;
-                       P.Blank();
-                       P.Stat(s.post);
-                       P.semi = false
+                       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);
diff --git a/usr/gri/pretty/test.sh b/usr/gri/pretty/test.sh
new file mode 100755 (executable)
index 0000000..7964fe3
--- /dev/null
@@ -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)"
+