Skip to content

Commit

Permalink
test: update and fix unit test error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Aug 13, 2022
1 parent 80e07fd commit 2664e20
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions gcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func (g *GOptions) SetDisable() {
func (g *GOptions) bindingFlags(fs *Flags) {
fs.BoolOpt(&g.showHelp, "help", "h", false, "Display the help information")

// disabled
if g.Disable {
return
}
Expand Down
26 changes: 21 additions & 5 deletions gcli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,24 @@ func TestVerbose(t *testing.T) {
gcli.SetQuietMode()
is.Eq(gcli.VerbQuiet, gcli.Verbose())

gcli.SetVerbose(gcli.VerbInfo)
is.Eq(gcli.VerbInfo, gcli.Verbose())
is.Eq("info", gcli.Verbose().Name())
is.Eq("INFO", gcli.Verbose().Upper())
info := gcli.VerbInfo
gcli.SetVerbose(info)
is.Eq(info, gcli.Verbose())
is.Eq(3, info.Int())
is.Eq("info", info.Name())
is.Eq("INFO", info.Upper())

gcli.SetVerbose(old)
is.Eq(gcli.VerbError, gcli.Verbose())
}

func TestVerbLevel(t *testing.T) {
is := assert.New(t)

verb := gcli.VerbLevel(23)
is.Eq("unknown", verb.Name())
is.Eq(23, verb.Int())

err := verb.Set("2")
is.NoErr(err)
is.Eq(gcli.VerbWarn, verb)
Expand All @@ -56,7 +64,10 @@ func TestVerbose(t *testing.T) {
func TestStrictMode(t *testing.T) {
is := assert.New(t)

is.True(gcli.StrictMode())
old := gcli.StrictMode()
defer func() {
gcli.SetStrictMode(old)
}()

gcli.SetStrictMode(false)
is.False(gcli.StrictMode())
Expand Down Expand Up @@ -121,5 +132,10 @@ func TestSetStrictMode(t *testing.T) {
app.Run([]string{"test", "-ob"})
assert.True(t, opts.ok)
assert.True(t, opts.bl)
}

func TestString(t *testing.T) {
s := gcli.String("ab,cd")
assert.Eq(t, "ab,cd", s.String())
assert.Eq(t, []string{"ab", "cd"}, s.Split(","))
}

0 comments on commit 2664e20

Please sign in to comment.