From 8f4f1f63e9d5d171a669d0a9c4594bbaaf9ea6f7 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 30 Oct 2017 23:14:21 -0400 Subject: [PATCH] fmt: hide bad format in test from vet Hide in the source code instead of in the separate whitelist. Removes the only printf false positive in the standard library. Change-Id: I99285e67588c7c93bd56d59ee768a03be7c301e7 Reviewed-on: https://go-review.googlesource.com/74590 Run-TryBot: Russ Cox TryBot-Result: Gobot Gobot Reviewed-by: Rob Pike --- src/cmd/vet/all/whitelist/all.txt | 3 --- src/fmt/fmt_test.go | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cmd/vet/all/whitelist/all.txt b/src/cmd/vet/all/whitelist/all.txt index 5467db9880..98415ef056 100644 --- a/src/cmd/vet/all/whitelist/all.txt +++ b/src/cmd/vet/all/whitelist/all.txt @@ -13,9 +13,6 @@ go/types/scope.go: method WriteTo(w io.Writer, n int, recurse bool) should have // False positives. -// Test of how fmt handles nil. -fmt/fmt_test.go: arg nil for printf verb %s of wrong type: untyped nil - // Nothing much to do about cross-package assembly. Unfortunate. runtime/asm_ARCHSUFF.s: [GOARCH] cannot check cross-package assembly function: call is in package reflect runtime/asm_ARCHSUFF.s: [GOARCH] cannot check cross-package assembly function: Equal is in package bytes diff --git a/src/fmt/fmt_test.go b/src/fmt/fmt_test.go index 0e09f16dbf..08e46b4e93 100644 --- a/src/fmt/fmt_test.go +++ b/src/fmt/fmt_test.go @@ -1733,12 +1733,14 @@ func TestIsSpace(t *testing.T) { } } +func hideFromVet(s string) string { return s } + func TestNilDoesNotBecomeTyped(t *testing.T) { type A struct{} type B struct{} var a *A = nil var b B = B{} - got := Sprintf("%s %s %s %s %s", nil, a, nil, b, nil) // go vet should complain about this line. + got := Sprintf(hideFromVet("%s %s %s %s %s"), nil, a, nil, b, nil) const expect = "%!s() %!s(*fmt_test.A=) %!s() {} %!s()" if got != expect { t.Errorf("expected:\n\t%q\ngot:\n\t%q", expect, got) -- 2.48.1