(t *testing.T)
| 630 | func (e *myErrType2) Error() string { return e.msg } |
| 631 | |
| 632 | func 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, ` |
| 647 | woo |
| 648 | (1) forced error mark |
| 649 | | "foo" |
| 650 | | errors/*errors.errorString:: |
| 651 | Wraps: (2) woo |
| 652 | Error types: (1) *markers.withMark (2) *errors.errorString`}, |
| 653 | |
| 654 | {"marked + wrapper", |
| 655 | markers.Mark(&werrFmt{errors.New("woo"), "waa"}, refErr), |
| 656 | waawoo, ` |
| 657 | waa: woo |
| 658 | (1) forced error mark |
| 659 | | "foo" |
| 660 | | errors/*errors.errorString:: |
| 661 | Wraps: (2) waa |
| 662 | | -- this is waa's |
| 663 | | multi-line payload |
| 664 | Wraps: (3) woo |
| 665 | Error 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, ` |
| 670 | waa: woo |
| 671 | (1) waa |
| 672 | | -- this is waa's |
| 673 | | multi-line payload |
| 674 | Wraps: (2) forced error mark |
| 675 | | "foo" |
| 676 | | errors/*errors.errorString:: |
| 677 | Wraps: (3) woo |
| 678 | Error 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…