add a unittest for an internally messed up subcommand path

This commit is contained in:
Alex Flint 2023-10-08 20:24:18 -04:00
parent 960d38c3ce
commit e7a4f77ed0
1 changed files with 11 additions and 0 deletions

View File

@ -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)
}