|
|
@@ -439,3 +439,21 @@ func TestParameterMistakesAreParamErrors(t *testing.T) {
|
|
|
require.EqualError(t, err, "ran and failed")
|
|
|
assert.NotErrorAs(t, err, &pe, "a Run error is the command's, not the caller's")
|
|
|
}
|
|
|
+
|
|
|
+// TestRunErrorIsShown: an error Run returns reaches the person at the prompt on the
|
|
|
+// error stream, as well as the surface that logs it.
|
|
|
+func TestRunErrorIsShown(t *testing.T) {
|
|
|
+ r := New()
|
|
|
+ r.Register(&Command{
|
|
|
+ Name: "broken",
|
|
|
+ ShortDescription: "cannot do what it is asked",
|
|
|
+ Run: func(fs any, a []string) (Result, error) {
|
|
|
+ return Result{}, errors.New("no certificate is loaded")
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ out, errOut := &bytes.Buffer{}, &bytes.Buffer{}
|
|
|
+ require.EqualError(t, r.DispatchArgs([]string{"broken"}, Output{Out: out, Err: errOut}), "no certificate is loaded")
|
|
|
+ assert.Empty(t, out.String())
|
|
|
+ assert.Equal(t, "no certificate is loaded\n", errOut.String())
|
|
|
+}
|