From d508d86cf12a3c4ee139d31f5f5c9e5e53566ecc Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Tue, 3 Nov 2020 13:12:19 -0500 Subject: [PATCH] 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 Run-TryBot: Michael Matloob TryBot-Result: Go Bot Reviewed-by: Bryan C. Mills --- src/cmd/go/script_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/script_test.go b/src/cmd/go/script_test.go index d81f299c3c..e301f2fb06 100644 --- a/src/cmd/go/script_test.go +++ b/src/cmd/go/script_test.go @@ -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 } -- 2.50.0