Skip to content

Commit

Permalink
add a unittest for an internally messed up subcommand path
Browse files Browse the repository at this point in the history
  • Loading branch information
alexflint committed Oct 9, 2023
1 parent 960d38c commit e7a4f77
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions subcommand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,14 @@ func TestValForNilStruct(t *testing.T) {
v := p.val(path{fields: []reflect.StructField{subField, subField}})
assert.False(t, v.IsValid())
}

func TestSubcommandInvalidInternal(t *testing.T) {
// this situation should never arise in practice but still good to test for it
var cmd struct{}
p, err := NewParser(Config{}, &cmd)
require.NoError(t, err)

p.subcommand = []string{"should", "never", "happen"}
sub := p.Subcommand()
assert.Nil(t, sub)
}

0 comments on commit e7a4f77

Please sign in to comment.