Skip to content

Commit d508d86

Browse files
committed
cmd/go: account for flags when parsing regexps in TestScript
Test script expects the regexp argument for stdout, stderr, and cmp to be the first argument after the command, but that might not be the case if the -q or -count flags are provided. Treat the first argument after a flag as a regexp instead. For #39958 Change-Id: I369926109ec10cca8b2c3baca27e7a3f7baf364b Reviewed-on: https://go-review.googlesource.com/c/go/+/267877 Trust: Michael Matloob <[email protected]> Run-TryBot: Michael Matloob <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 370682a commit d508d86

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/cmd/go/script_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,12 @@ func (ts *testScript) parse(line string) command {
12551255

12561256
if cmd.name != "" {
12571257
cmd.args = append(cmd.args, arg)
1258-
isRegexp = false // Commands take only one regexp argument, so no subsequent args are regexps.
1258+
// Commands take only one regexp argument (after the optional flags),
1259+
// so no subsequent args are regexps. Liberally assume an argument that
1260+
// starts with a '-' is a flag.
1261+
if len(arg) == 0 || arg[0] != '-' {
1262+
isRegexp = false
1263+
}
12591264
return
12601265
}
12611266

0 commit comments

Comments
 (0)