Present help failures through the common diagnostic path
This commit is contained in:
@@ -413,3 +413,27 @@ func (shortWriter) Write(data []byte) (int, error) {
|
||||
}
|
||||
return len(data) - 1, nil
|
||||
}
|
||||
|
||||
func TestHelpEntryFormsPresentReportAndDiagnosticFailures(t *testing.T) {
|
||||
group, err := commandkit.Group("notes", "Notes metadata.")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
app, err := commandkit.New(commandkit.Identity{Name: "example"}, group)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reportErr := errors.New("report failed")
|
||||
diagnosticErr := errors.New("diagnostic failed")
|
||||
for _, args := range [][]string{nil, {"notes"}, {"--help"}, {"-h"}, {"notes", "--help"}, {"help"}, {"help", "notes"}} {
|
||||
var diagnostics bytes.Buffer
|
||||
result := app.Execute(context.Background(), args, commandkit.Streams{Out: failingWriter{reportErr}, Err: &diagnostics})
|
||||
if result.Kind != commandkit.OutcomeOperational || !result.ReportIncomplete || !errors.Is(result.Cause, reportErr) || !errors.Is(result.DeliveryError, reportErr) || result.DiagnosticDelivery != commandkit.DeliveryComplete || strings.Count(diagnostics.String(), reportErr.Error()) != 1 {
|
||||
t.Fatalf("%v: result=%#v diagnostics=%q", args, result, diagnostics.String())
|
||||
}
|
||||
result = app.Execute(context.Background(), args, commandkit.Streams{Out: failingWriter{reportErr}, Err: failingWriter{diagnosticErr}})
|
||||
if result.DiagnosticDelivery != commandkit.DeliveryIncomplete || !errors.Is(result.Cause, reportErr) || !errors.Is(result.DeliveryError, reportErr) || !errors.Is(result.DeliveryError, diagnosticErr) {
|
||||
t.Fatalf("%v: result=%#v", args, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user