diff options
Diffstat (limited to 'src/cmd/go')
-rw-r--r-- | src/cmd/go/doc.go | 1 | ||||
-rw-r--r-- | src/cmd/go/generate.go | 5 | ||||
-rw-r--r-- | src/cmd/go/generate_test.go | 6 |
3 files changed, 12 insertions, 0 deletions
diff --git a/src/cmd/go/doc.go b/src/cmd/go/doc.go index d0d8a8a5b..7191ee0f3 100644 --- a/src/cmd/go/doc.go +++ b/src/cmd/go/doc.go @@ -308,6 +308,7 @@ The generator is run in the package's source directory. Go generate accepts one specific flag: -run="" + TODO: This flag is unimplemented. if non-empty, specifies a regular expression to select directives whose command matches the expression. diff --git a/src/cmd/go/generate.go b/src/cmd/go/generate.go index baf4d2b55..3c0af8760 100644 --- a/src/cmd/go/generate.go +++ b/src/cmd/go/generate.go @@ -106,6 +106,7 @@ The generator is run in the package's source directory. Go generate accepts one specific flag: -run="" + TODO: This flag is unimplemented. if non-empty, specifies a regular expression to select directives whose command matches the expression. @@ -255,6 +256,10 @@ func (g *Generator) split(line string) []string { // Parse line, obeying quoted strings. var words []string line = line[len("//go:generate ") : len(line)-1] // Drop preamble and final newline. + // There may still be a carriage return. + if len(line) > 0 && line[len(line)-1] == '\r' { + line = line[:len(line)-1] + } // One (possibly quoted) word per iteration. Words: for { diff --git a/src/cmd/go/generate_test.go b/src/cmd/go/generate_test.go index 660ebabbe..2ec548630 100644 --- a/src/cmd/go/generate_test.go +++ b/src/cmd/go/generate_test.go @@ -40,9 +40,15 @@ func TestGenerateCommandParse(t *testing.T) { } g.setShorthand([]string{"-command", "yacc", "go", "tool", "yacc"}) for _, test := range splitTests { + // First with newlines. got := g.split("//go:generate " + test.in + "\n") if !reflect.DeepEqual(got, test.out) { t.Errorf("split(%q): got %q expected %q", test.in, got, test.out) } + // Then with CRLFs, thank you Windows. + got = g.split("//go:generate " + test.in + "\r\n") + if !reflect.DeepEqual(got, test.out) { + t.Errorf("split(%q): got %q expected %q", test.in, got, test.out) + } } } |