Skip to content

Commit aed6930

Browse files
author
Andrew LeFevre
committed
combine log messages, use t.Error instead of t.Fatal when appropriate
2 parents c096ac2 + a4c9d7d commit aed6930

File tree

1 file changed

+17
-30
lines changed

1 file changed

+17
-30
lines changed

src/net/netip/fuzz_test.go

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ func FuzzParse(f *testing.F) {
138138
if !strings.Contains(s, "%") {
139139
stdip := net.ParseIP(s)
140140
if !ip.IsValid() != (stdip == nil) {
141-
t.Logf("ip=%q stdip=%q", ip, stdip)
142-
t.Fatal("ParseAddr zero != net.ParseIP nil")
141+
t.Errorf("ParseAddr zero != net.ParseIP nil: ip=%q stdip=%q", ip, stdip)
143142
}
144143

145144
if ip.IsValid() && !ip.Is4In6() {
@@ -152,56 +151,46 @@ func FuzzParse(f *testing.F) {
152151
t.Fatal(err)
153152
}
154153
if !bytes.Equal(buf, buf2) {
155-
t.Logf("ip=%q stdip=%q", ip, stdip)
156-
t.Fatal("Addr.MarshalText() != net.IP.MarshalText()")
154+
t.Errorf("Addr.MarshalText() != net.IP.MarshalText(): ip=%q stdip=%q", ip, stdip)
157155
}
158156
if ip.String() != stdip.String() {
159-
t.Logf("ip=%q stdip=%q", ip, stdip)
160-
t.Fatal("Addr.String() != net.IP.String()")
157+
t.Errorf("Addr.String() != net.IP.String(): ip=%q stdip=%q", ip, stdip)
161158
}
162159
if ip.IsGlobalUnicast() != stdip.IsGlobalUnicast() {
163-
t.Logf("ip=%q stdip=%q", ip, stdip)
164-
t.Fatal("Addr.IsGlobalUnicast() != net.IP.IsGlobalUnicast()")
160+
t.Errorf("Addr.IsGlobalUnicast() != net.IP.IsGlobalUnicast(): ip=%q stdip=%q", ip, stdip)
165161
}
166162
if ip.IsInterfaceLocalMulticast() != stdip.IsInterfaceLocalMulticast() {
167-
t.Logf("ip=%q stdip=%q", ip, stdip)
168-
t.Fatal("Addr.IsInterfaceLocalMulticast() != net.IP.IsInterfaceLocalMulticast()")
163+
t.Errorf("Addr.IsInterfaceLocalMulticast() != net.IP.IsInterfaceLocalMulticast(): ip=%q stdip=%q", ip, stdip)
169164
}
170165
if ip.IsLinkLocalMulticast() != stdip.IsLinkLocalMulticast() {
171-
t.Logf("ip=%q stdip=%q", ip, stdip)
172-
t.Fatal("Addr.IsLinkLocalMulticast() != net.IP.IsLinkLocalMulticast()")
166+
t.Errorf("Addr.IsLinkLocalMulticast() != net.IP.IsLinkLocalMulticast(): ip=%q stdip=%q", ip, stdip)
173167
}
174168
if ip.IsLinkLocalUnicast() != stdip.IsLinkLocalUnicast() {
175-
t.Logf("ip=%q stdip=%q", ip, stdip)
176-
t.Fatal("Addr.IsLinkLocalUnicast() != net.IP.IsLinkLocalUnicast()")
169+
t.Errorf("Addr.IsLinkLocalUnicast() != net.IP.IsLinkLocalUnicast(): ip=%q stdip=%q", ip, stdip)
177170
}
178171
if ip.IsLoopback() != stdip.IsLoopback() {
179-
t.Logf("ip=%q stdip=%q", ip, stdip)
180-
t.Fatal("Addr.IsLoopback() != net.IP.IsLoopback()")
172+
t.Errorf("Addr.IsLoopback() != net.IP.IsLoopback(): ip=%q stdip=%q", ip, stdip)
181173
}
182174
if ip.IsMulticast() != stdip.IsMulticast() {
183-
t.Logf("ip=%q stdip=%q", ip, stdip)
184-
t.Fatal("Addr.IsMulticast() != net.IP.IsMulticast()")
175+
t.Errorf("Addr.IsMulticast() != net.IP.IsMulticast(): ip=%q stdip=%q", ip, stdip)
185176
}
186177
if ip.IsPrivate() != stdip.IsPrivate() {
187-
t.Logf("ip=%q stdip=%q", ip, stdip)
188-
t.Fatal("Addr.IsPrivate() != net.IP.IsPrivate()")
178+
t.Errorf("Addr.IsPrivate() != net.IP.IsPrivate(): ip=%q stdip=%q", ip, stdip)
189179
}
190180
if ip.IsUnspecified() != stdip.IsUnspecified() {
191-
t.Logf("ip=%q stdip=%q", ip, stdip)
192-
t.Fatal("Addr.IsUnspecified() != net.IP.IsUnspecified()")
181+
t.Errorf("Addr.IsUnspecified() != net.IP.IsUnspecified(): ip=%q stdip=%q", ip, stdip)
193182
}
194183
}
195184
}
196185

197186
// Check that .Next().Prev() and .Prev().Next() preserve the IP.
198187
if ip.IsValid() && ip.Next().IsValid() && ip.Next().Prev() != ip {
199-
t.Log("ip=", ip, ".next=", ip.Next(), ".next.prev=", ip.Next().Prev())
200-
t.Fatal(".Next.Prev did not round trip")
188+
t.Logf("ip=%q .next=%q .next.prev=%q", ip, ip.Next(), ip.Next().Prev())
189+
t.Error(".Next.Prev did not round trip")
201190
}
202191
if ip.IsValid() && ip.Prev().IsValid() && ip.Prev().Next() != ip {
203-
t.Log("ip=", ip, ".prev=", ip.Prev(), ".prev.next=", ip.Prev().Next())
204-
t.Fatal(".Prev.Next did not round trip")
192+
t.Logf("ip=%q .prev=%q .prev.next=%q", ip, ip.Prev(), ip.Prev().Next())
193+
t.Error(".Prev.Next did not round trip")
205194
}
206195

207196
port, err := ParseAddrPort(s)
@@ -347,13 +336,11 @@ func checkStringParseRoundTrip[P netipTypeCmp](t *testing.T, x P, parse func(str
347336
t.Fatalf("s=%q err=%v", s, err)
348337
}
349338
if x != y {
350-
t.Logf("s=%q x=%#v y=%#v", s, x, y)
351-
t.Fatalf("%T round trip identity failure", x)
339+
t.Fatalf("%T round trip identity failure: s=%q x=%#v y=%#v", x, s, x, y)
352340
}
353341
s2 := y.String()
354342
if s != s2 {
355-
t.Logf("s=%#v s2=%#v", s, s2)
356-
t.Fatalf("%T String round trip identity failure", x)
343+
t.Fatalf("%T String round trip identity failure: s=%#v s2=%#v", x, s, s2)
357344
}
358345
}
359346

0 commit comments

Comments
 (0)