diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index 91c8aa533e..93aca5781b 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -31,7 +31,7 @@ jobs: run: npm install markdown-toc - name: Run Tests - run: + run: | go run build.go vet go run build.go test go run build.go toc docs/v1/manual.md diff --git a/app_test.go b/app_test.go index 9aac30cb83..4dc43ba623 100644 --- a/app_test.go +++ b/app_test.go @@ -507,31 +507,6 @@ func TestApp_RunAsSubcommandParseFlags(t *testing.T) { expect(t, context.String("lang"), "spanish") } -func TestApp_RunAsSubCommandIncorrectUsage(t *testing.T) { - // Go 1.17+ panics when invalid flag is given. - // Catch it here and consider the test passed. - defer func() { - if err := recover(); err == nil { - t.Fatal("expected error, got nothing") - } - }() - - a := App{ - Flags: []Flag{ - StringFlag{Name: "--foo"}, - }, - Writer: bytes.NewBufferString(""), - } - - set := flag.NewFlagSet("", flag.ContinueOnError) - _ = set.Parse([]string{"", "---foo"}) - c := &Context{flagSet: set} - - err := a.RunAsSubcommand(c) - - expect(t, err, errors.New("bad flag syntax: ---foo")) -} - func TestApp_CommandWithFlagBeforeTerminator(t *testing.T) { var parsedOption string var args []string diff --git a/go116_test.go b/go116_test.go new file mode 100644 index 0000000000..f6b5524015 --- /dev/null +++ b/go116_test.go @@ -0,0 +1,28 @@ +//go:build !go1.17 +// +build !go1.17 + +package cli + +import ( + "bytes" + "errors" + "flag" + "testing" +) + +func TestApp_RunAsSubCommandIncorrectUsage(t *testing.T) { + a := App{ + Flags: []Flag{ + StringFlag{Name: "--foo"}, + }, + Writer: bytes.NewBufferString(""), + } + + set := flag.NewFlagSet("", flag.ContinueOnError) + _ = set.Parse([]string{"", "---foo"}) + c := &Context{flagSet: set} + + err := a.RunAsSubcommand(c) + + expect(t, err, errors.New("bad flag syntax: ---foo")) +} diff --git a/go117_test.go b/go117_test.go new file mode 100644 index 0000000000..f40ec4ea82 --- /dev/null +++ b/go117_test.go @@ -0,0 +1,33 @@ +//go:build go1.17 +// +build go1.17 + +package cli + +import ( + "bytes" + "flag" + "testing" +) + +func TestApp_RunAsSubCommandIncorrectUsage(t *testing.T) { + a := App{ + Flags: []Flag{ + StringFlag{Name: "--foo"}, + }, + Writer: bytes.NewBufferString(""), + } + + set := flag.NewFlagSet("", flag.ContinueOnError) + _ = set.Parse([]string{"", "---foo"}) + c := &Context{flagSet: set} + + // Go 1.17+ panics when invalid flag is given. + // Catch it here and consider the test passed. + defer func() { + if err := recover(); err == nil { + t.Fatal("expected error, got nothing") + } + }() + + _ = a.RunAsSubcommand(c) +}