diff options
author | Marcel van Lohuizen <mpvl@golang.org> | 2019-03-01 09:31:30 -0400 |
---|---|---|
committer | Marcel van Lohuizen <mpvl@golang.org> | 2019-03-14 09:30:54 +0000 |
commit | b6fb6673bc1d132025b75fb6d3928775d959a8e3 (patch) | |
tree | c750b579d06f9a4301ba978998e3fe5aa8550b29 /src/fmt | |
parent | f6695a15e15713cdac16978837d8b01ef4999279 (diff) | |
download | go-b6fb6673bc1d132025b75fb6d3928775d959a8e3.tar.gz go-b6fb6673bc1d132025b75fb6d3928775d959a8e3.zip |
fmt: refined tests for non-string error verbs
This is a refinement of CL 164557.
Make it explicit in tests that using a non-string verb with
fmtError does not result in falling back to using fmt.Formatter.
Change-Id: I6d090f31818eb7cc7668d7565b1449c91cd03a23
Reviewed-on: https://go-review.googlesource.com/c/go/+/164701
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/fmt')
-rw-r--r-- | src/fmt/errors_test.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/fmt/errors_test.go b/src/fmt/errors_test.go index d2957e675b..a3cd26ef3e 100644 --- a/src/fmt/errors_test.go +++ b/src/fmt/errors_test.go @@ -353,6 +353,10 @@ func TestErrorFormatter(t *testing.T) { err: intError(4), fmt: "%d", want: "4", + }, { + err: intError(4), + fmt: "%🤪", + want: "%!🤪(fmt_test.intError=4)", }} for i, tc := range testCases { t.Run(fmt.Sprintf("%d/%s", i, tc.fmt), func(t *testing.T) { @@ -446,6 +450,12 @@ type intError int func (e intError) Error() string { return fmt.Sprint(e) } +func (e wrapped) Format(w fmt.State, r rune) { + // Test that the normal fallback handling after handleMethod for + // non-string verbs is used. This path should not be reached. + fmt.Fprintf(w, "Unreachable: %d", e) +} + func (e intError) FormatError(p errors.Printer) (next error) { p.Printf("error %d", e) return nil |