summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2014-08-25 11:07:08 -0700
committerRob Pike <r@golang.org>2014-08-25 11:07:08 -0700
commit5f8ad5f6c1d4bd6537ab86a90d7ccc96259a36be (patch)
tree3d950335dcaf6900877cdfdd0681d54a6657c832
parenteb4f947aaa3037a1401a1c553c060b90ff0d23e2 (diff)
downloadgo-5f8ad5f6c1d4bd6537ab86a90d7ccc96259a36be.tar.gz
cmd/go: add simple test for generate's line parser
LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/128710043
-rw-r--r--src/cmd/go/generate_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/cmd/go/generate_test.go b/src/cmd/go/generate_test.go
new file mode 100644
index 000000000..6be815763
--- /dev/null
+++ b/src/cmd/go/generate_test.go
@@ -0,0 +1,46 @@
+// Copyright 2011 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.
+
+package main
+
+import (
+ "reflect"
+ "runtime"
+ "testing"
+)
+
+type splitTest struct {
+ in string
+ out []string
+}
+
+var splitTests = []splitTest{
+ {"", nil},
+ {"x", []string{"x"}},
+ {" a b\tc ", []string{"a", "b", "c"}},
+ {` " a " `, []string{" a "}},
+ {"$GOFILE", []string{"proc.go"}},
+ {"a $XXNOTDEFINEDXX b", []string{"a", "", "b"}},
+ {"/$XXNOTDEFINED/", []string{"//"}},
+ {"$GOARCH", []string{runtime.GOARCH}},
+ {"yacc -o $GOARCH/yacc_$GOFILE", []string{"go", "tool", "yacc", "-o", runtime.GOARCH + "/yacc_proc.go"}},
+}
+
+func TestGenerateCommandParse(t *testing.T) {
+ g := &Generator{
+ r: nil, // Unused here.
+ path: "/usr/ken/sys/proc.go",
+ dir: "/usr/ken/sys",
+ file: "proc.go",
+ pkg: "sys",
+ commands: make(map[string][]string),
+ }
+ g.setShorthand([]string{"-command", "yacc", "go", "tool", "yacc"})
+ for _, test := range splitTests {
+ got := g.split("//go:generate " + test.in)
+ if !reflect.DeepEqual(got, test.out) {
+ t.Errorf("split(%q): got %q expected %q", test.in, got, test.out)
+ }
+ }
+}