From e7a4f77ed026b53d5c2c1e1fea3001f8d7700cf7 Mon Sep 17 00:00:00 2001 From: Alex Flint Date: Sun, 8 Oct 2023 20:24:18 -0400 Subject: [PATCH] add a unittest for an internally messed up subcommand path --- subcommand_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/subcommand_test.go b/subcommand_test.go index b215d3d..00efae0 100644 --- a/subcommand_test.go +++ b/subcommand_test.go @@ -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) +}