Skip to content

Commit

Permalink
testscript: fix RequireExplicitExec error messages
Browse files Browse the repository at this point in the history
They used args[0], which is the first argument to the command,
rather than the command name itself:

	> gofumpt foo.go
	FAIL: [...] use 'exec foo.go' rather than 'foo.go' (because RequireExplicitExec is enabled)

I believe I introduced this regression when refactoring the pull request
due to Roger's review, as I moved the code out of TestMain, where
args[0] was still the name of the command to be run.

Note that I can't easily add a regression test here, because the
testscript command being used in the tests is not a top-level command
run as a separate process, so it does not produce stdout nor stderr.
The change seems easy enough to review manually,
and our tests don't strictly check all error messages anyway.

While here, remove the unnecessary use of -verbose.
  • Loading branch information
mvdan committed Aug 3, 2022
1 parent 2431384 commit bb36173
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion testscript/exe.go
Expand Up @@ -122,7 +122,7 @@ func RunMain(m TestingM, commands map[string]func() int) (exitCode int) {
}
scriptCmds[name] = func(ts *TestScript, neg bool, args []string) {
if ts.params.RequireExplicitExec {
ts.Fatalf("use 'exec %s' rather than '%s' (because RequireExplicitExec is enabled)", args[0], args[0])
ts.Fatalf("use 'exec %s' rather than '%s' (because RequireExplicitExec is enabled)", name, name)
}
ts.cmdExec(neg, append([]string{name}, args...))
}
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/testscript_explicit_exec.txt
Expand Up @@ -9,8 +9,8 @@ unquote scripts-explicit/testscript.txt
testscript scripts-implicit
testscript scripts-explicit

! testscript -verbose -explicit-exec scripts-implicit
testscript -verbose -explicit-exec scripts-explicit
! testscript -explicit-exec scripts-implicit
testscript -explicit-exec scripts-explicit

-- scripts-implicit/testscript.txt --
>fprintargs stdout right
Expand Down

0 comments on commit bb36173

Please sign in to comment.