]> Cypherpunks.ru repositories - gostls13.git/commitdiff
log/slog: use the general regex expression of datetime in TestPanics
authorAndy Pan <panjf2000@gmail.com>
Tue, 5 Sep 2023 11:32:49 +0000 (19:32 +0800)
committerJonathan Amsterdam <jba@google.com>
Thu, 7 Sep 2023 17:11:06 +0000 (17:11 +0000)
When I added this test in CL 514135, I missed the timeRE,
we should use it to make this test more precise.

Change-Id: I486f8e8bbbc3a17166107ef361d242ddf4ea2928
Reviewed-on: https://go-review.googlesource.com/c/go/+/525556
Run-TryBot: Andy Pan <panjf2000@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/log/slog/logger_test.go

index 7d0243e415df6081fc57bceac6e4ec770d22dd7a..17bdff2ba5d15bfc6cc03decfce252dd083ad1bc 100644 (file)
@@ -22,7 +22,7 @@ import (
        "time"
 )
 
-const timeRE = `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}(Z|[+-]\d{2}:\d{2})`
+const timeRE = `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}(Z|[+-]\d{2}:\d{2})`
 
 func TestLogTextHandler(t *testing.T) {
        ctx := context.Background()
@@ -633,10 +633,10 @@ func TestPanics(t *testing.T) {
                in  any
                out string
        }{
-               {(*panicTextAndJsonMarshaler)(nil), `{"time":".*?","level":"INFO","msg":"msg","p":null}`},
-               {panicTextAndJsonMarshaler{io.ErrUnexpectedEOF}, `{"time":".*?","level":"INFO","msg":"msg","p":"!PANIC: unexpected EOF"}`},
-               {panicTextAndJsonMarshaler{"panicking"}, `{"time":".*?","level":"INFO","msg":"msg","p":"!PANIC: panicking"}`},
-               {panicTextAndJsonMarshaler{42}, `{"time":".*?","level":"INFO","msg":"msg","p":"!PANIC: 42"}`},
+               {(*panicTextAndJsonMarshaler)(nil), `{"time":"` + timeRE + `","level":"INFO","msg":"msg","p":null}`},
+               {panicTextAndJsonMarshaler{io.ErrUnexpectedEOF}, `{"time":"` + timeRE + `","level":"INFO","msg":"msg","p":"!PANIC: unexpected EOF"}`},
+               {panicTextAndJsonMarshaler{"panicking"}, `{"time":"` + timeRE + `","level":"INFO","msg":"msg","p":"!PANIC: panicking"}`},
+               {panicTextAndJsonMarshaler{42}, `{"time":"` + timeRE + `","level":"INFO","msg":"msg","p":"!PANIC: 42"}`},
        } {
                Info("msg", "p", pt.in)
                checkLogOutput(t, logBuf.String(), pt.out)