]> Cypherpunks repositories - gostls13.git/commitdiff
exp/template: silence test noise (but add a flag to put it back)
authorRob Pike <r@golang.org>
Wed, 6 Jul 2011 07:46:36 +0000 (17:46 +1000)
committerRob Pike <r@golang.org>
Wed, 6 Jul 2011 07:46:36 +0000 (17:46 +1000)
Also delete a TODO and clean up a little evaluation code.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4643071

src/pkg/exp/template/exec.go
src/pkg/exp/template/parse_test.go
src/pkg/exp/template/set_test.go

index b8cfb5480677bd4f94e21d5fe45fcc4a87e00754..6f171da3847c652ad6f801cbb511823223dd3774 100644 (file)
@@ -200,8 +200,7 @@ func (s *state) evalCommand(data reflect.Value, cmd *commandNode, final reflect.
                return s.evalFieldOrCall(data, n.ident, cmd.args, final)
        }
        if len(cmd.args) > 1 || final.IsValid() {
-               // TODO: functions
-               s.errorf("can't give argument to non-method %s", cmd.args[0])
+               s.errorf("can't give argument to non-function %s", cmd.args[0])
        }
        switch word := cmd.args[0].(type) {
        case *dotNode:
@@ -224,9 +223,8 @@ func (s *state) evalCommand(data reflect.Value, cmd *commandNode, final reflect.
                }
        case *stringNode:
                return reflect.ValueOf(word.text)
-       default:
-               s.errorf("can't handle command %q", firstWord)
        }
+       s.errorf("can't handle command %q", firstWord)
        panic("not reached")
 }
 
index 70c9f5a64ce6de67b36a037b5fd1eef9be48e604..34b0da6ebf97b27cce9c2d0a1e74d05f2b0416b9 100644 (file)
@@ -5,11 +5,12 @@
 package template
 
 import (
+       "flag"
        "fmt"
        "testing"
 )
 
-const dumpErrors = true
+var debug = flag.Bool("debug", false, "show the errors produced by the tests")
 
 type numberTest struct {
        text      string
@@ -193,7 +194,7 @@ func TestParse(t *testing.T) {
                        continue
                case err != nil && !test.ok:
                        // expected error, got one
-                       if dumpErrors {
+                       if *debug {
                                fmt.Printf("%s: %s\n\t%s\n", test.name, test.input, err)
                        }
                        continue
index 873d261b3d4682f3759eb92c0fc4488340e9d0a2..c0115ec0ade14a23f64ac72f1cf94717a5979f19 100644 (file)
@@ -49,7 +49,7 @@ func TestSetParse(t *testing.T) {
                        continue
                case err != nil && !test.ok:
                        // expected error, got one
-                       if dumpErrors {
+                       if *debug {
                                fmt.Printf("%s: %s\n\t%s\n", test.name, test.input, err)
                        }
                        continue