merge in test file
This commit is contained in:
parent
fa8187f2ce
commit
e6842c0b75
57
flag_test.go
57
flag_test.go
@ -1,6 +1,7 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -1052,7 +1053,7 @@ func TestParseBoolShortOptionHandle(t *testing.T) {
|
||||
a := App{
|
||||
Commands: []Command{
|
||||
{
|
||||
Name: "foobar",
|
||||
Name: "foobar",
|
||||
UseShortOptionHandling: true,
|
||||
Action: func(ctx *Context) error {
|
||||
if ctx.Bool("serve") != true {
|
||||
@ -1352,3 +1353,57 @@ func TestFlagFromFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext_CheckRequiredFlagsSuccess(t *testing.T) {
|
||||
flags := []Flag{
|
||||
StringFlag{
|
||||
Name: "required",
|
||||
Required: true,
|
||||
},
|
||||
StringFlag{
|
||||
Name: "optional",
|
||||
},
|
||||
}
|
||||
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
for _, f := range flags {
|
||||
f.Apply(set)
|
||||
}
|
||||
|
||||
e := set.Parse([]string{"--required", "foo"})
|
||||
if e != nil {
|
||||
t.Errorf("Expected no error parsing but there was one: %s", e)
|
||||
}
|
||||
|
||||
err := checkRequiredFlags(flags, set)
|
||||
if err != nil {
|
||||
t.Error("Expected flag parsing to be successful")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext_CheckRequiredFlagsFailure(t *testing.T) {
|
||||
flags := []Flag{
|
||||
StringFlag{
|
||||
Name: "required",
|
||||
Required: true,
|
||||
},
|
||||
StringFlag{
|
||||
Name: "optional",
|
||||
},
|
||||
}
|
||||
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
for _, f := range flags {
|
||||
f.Apply(set)
|
||||
}
|
||||
|
||||
e := set.Parse([]string{"--optional", "foo"})
|
||||
if e != nil {
|
||||
t.Errorf("Expected no error parsing but there was one: %s", e)
|
||||
}
|
||||
|
||||
err := checkRequiredFlags(flags, set)
|
||||
if err == nil {
|
||||
t.Error("Expected flag parsing to be unsuccessful")
|
||||
}
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestContext_CheckRequiredFlagsSuccess(t *testing.T) {
|
||||
flags := []Flag{
|
||||
StringFlag{
|
||||
Name: "required",
|
||||
Required: true,
|
||||
},
|
||||
StringFlag{
|
||||
Name: "optional",
|
||||
},
|
||||
}
|
||||
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
for _, f := range flags {
|
||||
f.Apply(set)
|
||||
}
|
||||
|
||||
e := set.Parse([]string{"--required", "foo"})
|
||||
if e != nil {
|
||||
t.Errorf("Expected no error parsing but there was one: %s", e)
|
||||
}
|
||||
|
||||
err := checkRequiredFlags(flags, set)
|
||||
if err != nil {
|
||||
t.Error("Expected flag parsing to be successful")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext_CheckRequiredFlagsFailure(t *testing.T) {
|
||||
flags := []Flag{
|
||||
StringFlag{
|
||||
Name: "required",
|
||||
Required: true,
|
||||
},
|
||||
StringFlag{
|
||||
Name: "optional",
|
||||
},
|
||||
}
|
||||
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
for _, f := range flags {
|
||||
f.Apply(set)
|
||||
}
|
||||
|
||||
e := set.Parse([]string{"--optional", "foo"})
|
||||
if e != nil {
|
||||
t.Errorf("Expected no error parsing but there was one: %s", e)
|
||||
}
|
||||
|
||||
err := checkRequiredFlags(flags, set)
|
||||
if err == nil {
|
||||
t.Error("Expected flag parsing to be unsuccessful")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user