aboutsummaryrefslogtreecommitdiff
path: root/src/log/slog/value_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/log/slog/value_test.go')
-rw-r--r--src/log/slog/value_test.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/log/slog/value_test.go b/src/log/slog/value_test.go
index d2c427b96e..e0c60c3652 100644
--- a/src/log/slog/value_test.go
+++ b/src/log/slog/value_test.go
@@ -7,6 +7,7 @@ package slog
import (
"fmt"
"reflect"
+ "strings"
"testing"
"time"
"unsafe"
@@ -185,6 +186,20 @@ func TestLogValue(t *testing.T) {
if !attrsEqual(got2, want2) {
t.Errorf("got %v, want %v", got2, want2)
}
+
+ // Verify that panics in Resolve are caught and turn into errors.
+ v = AnyValue(panickingLogValue{})
+ got = v.Resolve().Any()
+ gotErr, ok := got.(error)
+ if !ok {
+ t.Errorf("expected error, got %T", got)
+ }
+ // The error should provide some context information.
+ // We'll just check that this function name appears in it.
+ fmt.Println(got)
+ if got, want := gotErr.Error(), "TestLogValue"; !strings.Contains(got, want) {
+ t.Errorf("got %q, want substring %q", got, want)
+ }
}
func TestZeroTime(t *testing.T) {
@@ -201,6 +216,10 @@ type replace struct {
func (r *replace) LogValue() Value { return r.v }
+type panickingLogValue struct{}
+
+func (panickingLogValue) LogValue() Value { panic("bad") }
+
// A Value with "unsafe" strings is significantly faster:
// safe: 1785 ns/op, 0 allocs
// unsafe: 690 ns/op, 0 allocs