Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1] do fix CI #1384

Merged
merged 2 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 0 additions & 25 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions go116_test.go
Original file line number Diff line number Diff line change
@@ -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"))
}
33 changes: 33 additions & 0 deletions go117_test.go
Original file line number Diff line number Diff line change
@@ -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)
}