From 3fecd3722faf3239e50c40fb0eff7affab8105c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 24 Jul 2022 13:30:43 +0200 Subject: [PATCH] testscript: fix RequireExplicitExec error messages 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. --- testscript/exe.go | 2 +- testscript/testdata/testscript_explicit_exec.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/testscript/exe.go b/testscript/exe.go index 3c3579e7..e163a769 100644 --- a/testscript/exe.go +++ b/testscript/exe.go @@ -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...)) } diff --git a/testscript/testdata/testscript_explicit_exec.txt b/testscript/testdata/testscript_explicit_exec.txt index c2fc0a6a..cc818696 100644 --- a/testscript/testdata/testscript_explicit_exec.txt +++ b/testscript/testdata/testscript_explicit_exec.txt @@ -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