]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: account for flags when parsing regexps in TestScript
authorMichael Matloob <matloob@golang.org>
Tue, 3 Nov 2020 18:12:19 +0000 (13:12 -0500)
committerMichael Matloob <matloob@golang.org>
Thu, 5 Nov 2020 19:33:55 +0000 (19:33 +0000)
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 <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/script_test.go

index d81f299c3ccfc22243100134e5c35fd9360687ba..e301f2fb069454ac9717c72b4e2e5de97d2a0226 100644 (file)
@@ -1255,7 +1255,12 @@ func (ts *testScript) parse(line string) command {
 
                if cmd.name != "" {
                        cmd.args = append(cmd.args, arg)
-                       isRegexp = false // Commands take only one regexp argument, so no subsequent args are regexps.
+                       // Commands take only one regexp argument (after the optional flags),
+                       // so no subsequent args are regexps. Liberally assume an argument that
+                       // starts with a '-' is a flag.
+                       if len(arg) == 0 || arg[0] != '-' {
+                               isRegexp = false
+                       }
                        return
                }