Skip to content

Commit

Permalink
Merge pull request #1384 from kolyshkin/v1-do-fix-ci
Browse files Browse the repository at this point in the history
[v1] do fix CI
  • Loading branch information
meatballhat authored May 4, 2022
2 parents 936bd2e + 22281d3 commit 9810d12
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 26 deletions.
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)
}

0 comments on commit 9810d12

Please sign in to comment.