mirror of https://github.com/golang/go.git
all: make safe for new vet analyzer
The unused analyzer handles dot imports now, so a few tests have picked up vet errors. This CL errors like: context/x_test.go:524:47: result of context.WithValue call not used Change-Id: I711a62fd7b50381f8ea45ac526bf0c946a171047 Reviewed-on: https://go-review.googlesource.com/c/go/+/493598 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
4576184b43
commit
91ebed3fd2
|
|
@ -521,26 +521,26 @@ func TestWithCancelSimultaneouslyCanceledParent(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWithValueChecksKey(t *testing.T) {
|
||||
panicVal := recoveredValue(func() { WithValue(Background(), []byte("foo"), "bar") })
|
||||
panicVal := recoveredValue(func() { _ = WithValue(Background(), []byte("foo"), "bar") })
|
||||
if panicVal == nil {
|
||||
t.Error("expected panic")
|
||||
}
|
||||
panicVal = recoveredValue(func() { WithValue(Background(), nil, "bar") })
|
||||
panicVal = recoveredValue(func() { _ = WithValue(Background(), nil, "bar") })
|
||||
if got, want := fmt.Sprint(panicVal), "nil key"; got != want {
|
||||
t.Errorf("panic = %q; want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidDerivedFail(t *testing.T) {
|
||||
panicVal := recoveredValue(func() { WithCancel(nil) })
|
||||
panicVal := recoveredValue(func() { _, _ = WithCancel(nil) })
|
||||
if panicVal == nil {
|
||||
t.Error("expected panic")
|
||||
}
|
||||
panicVal = recoveredValue(func() { WithDeadline(nil, time.Now().Add(shortDuration)) })
|
||||
panicVal = recoveredValue(func() { _, _ = WithDeadline(nil, time.Now().Add(shortDuration)) })
|
||||
if panicVal == nil {
|
||||
t.Error("expected panic")
|
||||
}
|
||||
panicVal = recoveredValue(func() { WithValue(nil, "foo", "bar") })
|
||||
panicVal = recoveredValue(func() { _ = WithValue(nil, "foo", "bar") })
|
||||
if panicVal == nil {
|
||||
t.Error("expected panic")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1238,7 +1238,7 @@ func TestReorder(t *testing.T) {
|
|||
func BenchmarkSprintfPadding(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("%16f", 1.0)
|
||||
_ = Sprintf("%16f", 1.0)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1246,7 +1246,7 @@ func BenchmarkSprintfPadding(b *testing.B) {
|
|||
func BenchmarkSprintfEmpty(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("")
|
||||
_ = Sprintf("")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1254,7 +1254,7 @@ func BenchmarkSprintfEmpty(b *testing.B) {
|
|||
func BenchmarkSprintfString(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("%s", "hello")
|
||||
_ = Sprintf("%s", "hello")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1262,7 +1262,7 @@ func BenchmarkSprintfString(b *testing.B) {
|
|||
func BenchmarkSprintfTruncateString(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("%.3s", "日本語日本語日本語日本語")
|
||||
_ = Sprintf("%.3s", "日本語日本語日本語日本語")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1271,7 +1271,7 @@ func BenchmarkSprintfTruncateBytes(b *testing.B) {
|
|||
var bytes any = []byte("日本語日本語日本語日本語")
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("%.3s", bytes)
|
||||
_ = Sprintf("%.3s", bytes)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1279,7 +1279,7 @@ func BenchmarkSprintfTruncateBytes(b *testing.B) {
|
|||
func BenchmarkSprintfSlowParsingPath(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("%.v", nil)
|
||||
_ = Sprintf("%.v", nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1287,7 +1287,7 @@ func BenchmarkSprintfSlowParsingPath(b *testing.B) {
|
|||
func BenchmarkSprintfQuoteString(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("%q", "日本語日本語日本語")
|
||||
_ = Sprintf("%q", "日本語日本語日本語")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1295,7 +1295,7 @@ func BenchmarkSprintfQuoteString(b *testing.B) {
|
|||
func BenchmarkSprintfInt(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("%d", 5)
|
||||
_ = Sprintf("%d", 5)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1303,7 +1303,7 @@ func BenchmarkSprintfInt(b *testing.B) {
|
|||
func BenchmarkSprintfIntInt(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("%d %d", 5, 6)
|
||||
_ = Sprintf("%d %d", 5, 6)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1311,7 +1311,7 @@ func BenchmarkSprintfIntInt(b *testing.B) {
|
|||
func BenchmarkSprintfPrefixedInt(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("This is some meaningless prefix text that needs to be scanned %d", 6)
|
||||
_ = Sprintf("This is some meaningless prefix text that needs to be scanned %d", 6)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1319,7 +1319,7 @@ func BenchmarkSprintfPrefixedInt(b *testing.B) {
|
|||
func BenchmarkSprintfFloat(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("%g", 5.23184)
|
||||
_ = Sprintf("%g", 5.23184)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1327,7 +1327,7 @@ func BenchmarkSprintfFloat(b *testing.B) {
|
|||
func BenchmarkSprintfComplex(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("%f", 5.23184+5.23184i)
|
||||
_ = Sprintf("%f", 5.23184+5.23184i)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1335,7 +1335,7 @@ func BenchmarkSprintfComplex(b *testing.B) {
|
|||
func BenchmarkSprintfBoolean(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("%t", true)
|
||||
_ = Sprintf("%t", true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1343,7 +1343,7 @@ func BenchmarkSprintfBoolean(b *testing.B) {
|
|||
func BenchmarkSprintfHexString(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("% #x", "0123456789abcdef")
|
||||
_ = Sprintf("% #x", "0123456789abcdef")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1352,7 +1352,7 @@ func BenchmarkSprintfHexBytes(b *testing.B) {
|
|||
data := []byte("0123456789abcdef")
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("% #x", data)
|
||||
_ = Sprintf("% #x", data)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1361,7 +1361,7 @@ func BenchmarkSprintfBytes(b *testing.B) {
|
|||
data := []byte("0123456789abcdef")
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("%v", data)
|
||||
_ = Sprintf("%v", data)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1370,7 +1370,7 @@ func BenchmarkSprintfStringer(b *testing.B) {
|
|||
stringer := I(12345)
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("%v", stringer)
|
||||
_ = Sprintf("%v", stringer)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1379,7 +1379,7 @@ func BenchmarkSprintfStructure(b *testing.B) {
|
|||
s := &[]any{SI{12345}, map[int]string{0: "hello"}}
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
Sprintf("%#v", s)
|
||||
_ = Sprintf("%#v", s)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1428,14 +1428,14 @@ var mallocTest = []struct {
|
|||
desc string
|
||||
fn func()
|
||||
}{
|
||||
{0, `Sprintf("")`, func() { Sprintf("") }},
|
||||
{1, `Sprintf("xxx")`, func() { Sprintf("xxx") }},
|
||||
{0, `Sprintf("%x")`, func() { Sprintf("%x", 7) }},
|
||||
{1, `Sprintf("%x")`, func() { Sprintf("%x", 1<<16) }},
|
||||
{3, `Sprintf("%80000s")`, func() { Sprintf("%80000s", "hello") }}, // large buffer (>64KB)
|
||||
{1, `Sprintf("%s")`, func() { Sprintf("%s", "hello") }},
|
||||
{1, `Sprintf("%x %x")`, func() { Sprintf("%x %x", 7, 112) }},
|
||||
{1, `Sprintf("%g")`, func() { Sprintf("%g", float32(3.14159)) }},
|
||||
{0, `Sprintf("")`, func() { _ = Sprintf("") }},
|
||||
{1, `Sprintf("xxx")`, func() { _ = Sprintf("xxx") }},
|
||||
{0, `Sprintf("%x")`, func() { _ = Sprintf("%x", 7) }},
|
||||
{1, `Sprintf("%x")`, func() { _ = Sprintf("%x", 1<<16) }},
|
||||
{3, `Sprintf("%80000s")`, func() { _ = Sprintf("%80000s", "hello") }}, // large buffer (>64KB)
|
||||
{1, `Sprintf("%s")`, func() { _ = Sprintf("%s", "hello") }},
|
||||
{1, `Sprintf("%x %x")`, func() { _ = Sprintf("%x %x", 7, 112) }},
|
||||
{1, `Sprintf("%g")`, func() { _ = Sprintf("%g", float32(3.14159)) }},
|
||||
{0, `Fprintf(buf, "%s")`, func() { mallocBuf.Reset(); Fprintf(&mallocBuf, "%s", "hello") }},
|
||||
{0, `Fprintf(buf, "%x")`, func() { mallocBuf.Reset(); Fprintf(&mallocBuf, "%x", 7) }},
|
||||
{0, `Fprintf(buf, "%x")`, func() { mallocBuf.Reset(); Fprintf(&mallocBuf, "%x", 1<<16) }},
|
||||
|
|
@ -1773,13 +1773,13 @@ func (r *Recur) String() string {
|
|||
func TestBadVerbRecursion(t *testing.T) {
|
||||
failed := false
|
||||
r := &Recur{3, &failed}
|
||||
Sprintf("recur@%p value: %d\n", &r, r.i)
|
||||
_ = Sprintf("recur@%p value: %d\n", &r, r.i)
|
||||
if failed {
|
||||
t.Error("fail with pointer")
|
||||
}
|
||||
failed = false
|
||||
r = &Recur{4, &failed}
|
||||
Sprintf("recur@%p, value: %d\n", r, r.i)
|
||||
_ = Sprintf("recur@%p, value: %d\n", r, r.i)
|
||||
if failed {
|
||||
t.Error("fail with value")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue