Skip to content

Commit e9142ea

Browse files
FiloSottilemvdan
authored andcommitted
testscript: exit 0 in runCoverSubcommand if -help is used
flag.ExitOnError will exit 0 for -h/-help, while the flag.PanicOnError override in runCoverSubcommand was always exiting 2, making the success/failure of running a command with -hhelp depend on whether coverage is active.
1 parent 3b43157 commit e9142ea

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

testscript/exe.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,14 @@ func runCoverSubcommand(cprof string, mainf func() int) (exitCode int) {
202202
flag.CommandLine.Init(flag.CommandLine.Name(), flag.PanicOnError)
203203
defer func() {
204204
panicErr := recover()
205-
if _, ok := panicErr.(error); ok {
205+
if err, ok := panicErr.(error); ok {
206206
// The flag package will already have printed this error, assuming,
207207
// that is, that the error was created in the flag package.
208208
// TODO check the stack to be sure it was actually raised by the flag package.
209209
exitCode = 2
210+
if err == flag.ErrHelp {
211+
exitCode = 0
212+
}
210213
panicErr = nil
211214
}
212215
// Set os.Args so that flag.Parse will tell testing the correct

0 commit comments

Comments
 (0)