MCPcopy Index your code
hub / github.com/cockroachdb/errors / TestFormat

Function TestFormat

markers/markers_test.go:632–701  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

630func (e *myErrType2) Error() string { return e.msg }
631
632func TestFormat(t *testing.T) {
633 tt := testutils.T{t}
634
635 refErr := errors.New("foo")
636 const woo = `woo`
637 const waawoo = `waa: woo`
638 testCases := []struct {
639 name string
640 err error
641 expFmtSimple string
642 expFmtVerbose string
643 }{
644 {"marked",
645 markers.Mark(errors.New("woo"), refErr),
646 woo, `
647woo
648(1) forced error mark
649 | "foo"
650 | errors/*errors.errorString::
651Wraps: (2) woo
652Error types: (1) *markers.withMark (2) *errors.errorString`},
653
654 {"marked + wrapper",
655 markers.Mark(&werrFmt{errors.New("woo"), "waa"}, refErr),
656 waawoo, `
657waa: woo
658(1) forced error mark
659 | "foo"
660 | errors/*errors.errorString::
661Wraps: (2) waa
662 | -- this is waa's
663 | multi-line payload
664Wraps: (3) woo
665Error types: (1) *markers.withMark (2) *markers_test.werrFmt (3) *errors.errorString`},
666
667 {"wrapper + marked",
668 &werrFmt{markers.Mark(errors.New("woo"), refErr), "waa"},
669 waawoo, `
670waa: woo
671(1) waa
672 | -- this is waa's
673 | multi-line payload
674Wraps: (2) forced error mark
675 | "foo"
676 | errors/*errors.errorString::
677Wraps: (3) woo
678Error types: (1) *markers_test.werrFmt (2) *markers.withMark (3) *errors.errorString`},
679 }
680
681 for _, test := range testCases {
682 tt.Run(test.name, func(tt testutils.T) {
683 err := test.err
684
685 // %s is simple formatting
686 tt.CheckStringEqual(fmt.Sprintf("%s", err), test.expFmtSimple)
687
688 // %v is simple formatting too, for compatibility with the past.
689 tt.CheckStringEqual(fmt.Sprintf("%v", err), test.expFmtSimple)

Callers

nothing calls this directly

Calls 3

RunMethod · 0.95
CheckStringEqualMethod · 0.95
MarkFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…