github.com/mckael/restic@v0.8.3/cmd/restic/flags_test.go (about) 1 package main 2 3 import ( 4 "io/ioutil" 5 "testing" 6 ) 7 8 // TestFlags checks for double defined flags, the commands will panic on 9 // ParseFlags() when a shorthand flag is defined twice. 10 func TestFlags(t *testing.T) { 11 for _, cmd := range cmdRoot.Commands() { 12 t.Run(cmd.Name(), func(t *testing.T) { 13 cmd.Flags().SetOutput(ioutil.Discard) 14 err := cmd.ParseFlags([]string{"--help"}) 15 if err.Error() == "pflag: help requested" { 16 err = nil 17 } 18 19 if err != nil { 20 t.Fatal(err) 21 } 22 }) 23 } 24 }