requireFileValidationError asserts err is a typed *errs.ValidationError with the expected subtype, exit code 2 (legacy ErrValidation parity), and a param diagnostic referencing --file (either Param or one of Params).
(t *testing.T, err error, wantSubtype errs.Subtype)
| 25 | // the expected subtype, exit code 2 (legacy ErrValidation parity), and a |
| 26 | // param diagnostic referencing --file (either Param or one of Params). |
| 27 | func requireFileValidationError(t *testing.T, err error, wantSubtype errs.Subtype) *errs.ValidationError { |
| 28 | t.Helper() |
| 29 | var valErr *errs.ValidationError |
| 30 | if !errors.As(err, &valErr) { |
| 31 | t.Fatalf("expected *errs.ValidationError, got %T: %v", err, err) |
| 32 | } |
| 33 | if valErr.Subtype != wantSubtype { |
| 34 | t.Errorf("subtype = %q, want %q", valErr.Subtype, wantSubtype) |
| 35 | } |
| 36 | if got := output.ExitCodeOf(err); got != output.ExitValidation { |
| 37 | t.Errorf("exit code = %d, want %d (ExitValidation, legacy parity)", got, output.ExitValidation) |
| 38 | } |
| 39 | mentionsFile := valErr.Param == "--file" |
| 40 | for _, p := range valErr.Params { |
| 41 | if p.Name == "--file" { |
| 42 | mentionsFile = true |
| 43 | } |
| 44 | } |
| 45 | if !mentionsFile { |
| 46 | t.Errorf("expected --file in Param/Params, got Param=%q Params=%v", valErr.Param, valErr.Params) |
| 47 | } |
| 48 | return valErr |
| 49 | } |
| 50 | |
| 51 | func TestParseFileFlag(t *testing.T) { |
| 52 | tests := []struct { |
no test coverage detected