@@ -309,18 +309,21 @@ func TestParsing(t *testing.T) {
309309 },
310310 },
311311 },
312- }, {
312+ }, func () * testCase {
313313 // subcommands (with missing or unknown error checks)
314- name : "subcommands" ,
315- cmd : NewCmd ("cmd" ).
316- Opt (NewBoolOpt ("aa" )).
317- Subcmd (NewCmd ("one" ).
318- Opt (NewOpt ("bb" )).
319- Opt (NewOpt ("cc" ))).
320- Subcmd (NewCmd ("two" ).
321- Opt (NewOpt ("dd" )).
322- Opt (NewOpt ("ee" ))),
323- variations : []testInputOutput {
314+ tc := testCase {
315+ name : "subcommands" ,
316+ cmd : NewCmd ("cmd" ).
317+ Opt (NewBoolOpt ("aa" )).
318+ Subcmd (NewCmd ("one" ).
319+ Opt (NewOpt ("bb" )).
320+ Opt (NewOpt ("cc" ))).
321+ Subcmd (NewCmd ("two" ).
322+ Opt (NewOpt ("dd" )).
323+ Opt (NewOpt ("ee" ))).
324+ Subcmd (NewCmd ("four" ).Subcmd (NewCmd ("five" ))),
325+ }
326+ tc .variations = []testInputOutput {
324327 {
325328 Case : ttCase (),
326329 args : []string {"one" , "--bb" , "B" },
@@ -346,14 +349,19 @@ func TestParsing(t *testing.T) {
346349 }, {
347350 Case : ttCase (),
348351 args : []string {"three" , "--dd" , "D" },
349- expErr : UnknownSubcmdError {Name : "three" },
352+ expErr : UnknownSubcmdError {Cmd : & tc .cmd , Name : "three" },
353+ }, {
354+ Case : ttCase (),
355+ args : []string {"four" , "six" },
356+ expErr : UnknownSubcmdError {Cmd : & tc .cmd .Subcmds [2 ], Name : "six" },
350357 }, {
351358 Case : ttCase (),
352359 args : []string {"--aa" },
353360 expErr : ErrNoSubcmd ,
354361 },
355- },
356- }, {
362+ }
363+ return & tc
364+ }(), {
357365 // subcommand help won't require required values
358366 name : "subcommands" ,
359367 cmd : NewCmd ("cmd" ).
@@ -587,7 +595,7 @@ func TestParsing(t *testing.T) {
587595 }
588596 if gotErr != nil {
589597 if tio .expErr == nil {
590- t .Fatalf ("expected no error, got %[1]T: %[1]v" , gotErr )
598+ t .Fatalf ("%s: expected no error, got %[1]T: %[1]v" , tio . Case , gotErr )
591599 }
592600 if ! errors .Is (gotErr , tio .expErr ) {
593601 t .Fatalf ("%s: errors don't match:\n expected: (%[2]T) %+#[2]v\n got: (%[3]T) %+#[3]v" ,
0 commit comments