1
0
mirror of https://github.com/golang/go synced 2024-11-25 06:07:58 -07:00

pkg: remove .String() from some print arguments

I found these by adding a check to govet, but the check
produces far too many false positives to be useful.
Even so, these few seem worth cleaning up.

R=golang-dev, bradfitz, iant
CC=golang-dev
https://golang.org/cl/5311067
This commit is contained in:
Russ Cox 2011-10-27 18:03:52 -07:00
parent 053549ca1b
commit 32f3770ec5
10 changed files with 28 additions and 28 deletions

View File

@ -86,7 +86,7 @@ func TestInvalidHashErrors(t *testing.T) {
t.Errorf("%s: Should have returned an error", name)
}
if err != nil && err != expected {
t.Errorf("%s gave err %v but should have given %v", name, err.String(), expected.String())
t.Errorf("%s gave err %v but should have given %v", name, err, expected)
}
}
for _, iht := range invalidTests {

View File

@ -87,7 +87,7 @@ func (c *conn) writeSocket() {
setU32LE(c.flushBuf0[16:20], uint32(y<<16))
if _, err := c.w.Write(c.flushBuf0[:24]); err != nil {
if err != os.EOF {
log.Println("x11:", err.String())
log.Println("x11:", err)
}
return
}
@ -106,7 +106,7 @@ func (c *conn) writeSocket() {
x += nx
if _, err := c.w.Write(c.flushBuf1[:nx]); err != nil {
if err != os.EOF {
log.Println("x11:", err.String())
log.Println("x11:", err)
}
return
}
@ -114,7 +114,7 @@ func (c *conn) writeSocket() {
}
if err := c.w.Flush(); err != nil {
if err != os.EOF {
log.Println("x11:", err.String())
log.Println("x11:", err)
}
return
}

View File

@ -102,7 +102,7 @@ func (v *Map) String() string {
if !first {
fmt.Fprintf(b, ", ")
}
fmt.Fprintf(b, "\"%s\": %v", key, val.String())
fmt.Fprintf(b, "\"%s\": %v", key, val)
first = false
}
fmt.Fprintf(b, "}")

View File

@ -149,7 +149,7 @@ func (p *printer) print(x reflect.Value) {
p.print(x.Elem())
case reflect.Map:
p.printf("%s (len = %d) {\n", x.Type().String(), x.Len())
p.printf("%s (len = %d) {\n", x.Type(), x.Len())
p.indent++
for _, key := range x.MapKeys() {
p.print(key)
@ -178,7 +178,7 @@ func (p *printer) print(x reflect.Value) {
p.printf("%#q", s)
return
}
p.printf("%s (len = %d) {\n", x.Type().String(), x.Len())
p.printf("%s (len = %d) {\n", x.Type(), x.Len())
p.indent++
for i, n := 0, x.Len(); i < n; i++ {
p.printf("%d: ", i)
@ -189,7 +189,7 @@ func (p *printer) print(x reflect.Value) {
p.printf("}")
case reflect.Struct:
p.printf("%s {\n", x.Type().String())
p.printf("%s {\n", x.Type())
p.indent++
t := x.Type()
for i, n := 0, t.NumField(); i < n; i++ {

View File

@ -92,7 +92,7 @@ func (p ErrorList) String() string {
case 1:
return p[0].String()
}
return fmt.Sprintf("%s (and %d more errors)", p[0].String(), len(p)-1)
return fmt.Sprintf("%s (and %d more errors)", p[0], len(p)-1)
}
// These constants control the construction of the ErrorList

View File

@ -237,7 +237,7 @@ func TestScan(t *testing.T) {
}
checkPos(t, lit, pos, epos)
if tok != e.tok {
t.Errorf("bad token for %q: got %s, expected %s", lit, tok.String(), e.tok.String())
t.Errorf("bad token for %q: got %s, expected %s", lit, tok, e.tok)
}
if e.tok.IsLiteral() && lit != e.lit {
t.Errorf("bad literal for %q: got %q, expected %q", lit, lit, e.lit)
@ -286,7 +286,7 @@ func checkSemi(t *testing.T, line string, mode uint) {
}
checkPos(t, line, pos, semiPos)
} else {
t.Errorf("bad token for %q: got %s, expected ;", line, tok.String())
t.Errorf("bad token for %q: got %s, expected ;", line, tok)
}
} else if tok == token.SEMICOLON {
t.Errorf("bad token for %q: got ;, expected no ;", line)
@ -509,7 +509,7 @@ func TestInit(t *testing.T) {
s.Scan() // true
_, tok, _ := s.Scan() // {
if tok != token.LBRACE {
t.Errorf("bad token: got %s, expected %s", tok.String(), token.LBRACE)
t.Errorf("bad token: got %s, expected %s", tok, token.LBRACE)
}
// 2nd init
@ -521,7 +521,7 @@ func TestInit(t *testing.T) {
}
_, tok, _ = s.Scan() // go
if tok != token.GO {
t.Errorf("bad token: got %s, expected %s", tok.String(), token.GO)
t.Errorf("bad token: got %s, expected %s", tok, token.GO)
}
if s.ErrorCount != 0 {

View File

@ -881,7 +881,7 @@ func (dec *Decoder) decOpFor(wireId typeId, rt reflect.Type, name string, inProg
}
}
if op == nil {
errorf("decode can't handle type %s", rt.String())
errorf("decode can't handle type %s", rt)
}
return &op, indir
}
@ -1110,7 +1110,7 @@ func (dec *Decoder) compileDec(remoteId typeId, ut *userTypeInfo) (engine *decEn
wireStruct = wire.StructT
}
if wireStruct == nil {
errorf("type mismatch in decoder: want struct type %s; got non-struct", rt.String())
errorf("type mismatch in decoder: want struct type %s; got non-struct", rt)
}
engine = new(decEngine)
engine.instr = make([]decInstr, len(wireStruct.Field))

View File

@ -610,7 +610,7 @@ func (enc *Encoder) encOpFor(rt reflect.Type, inProgress map[reflect.Type]*encOp
}
}
if op == nil {
errorf("can't happen: encode type %s", rt.String())
errorf("can't happen: encode type %s", rt)
}
return &op, indir
}

View File

@ -37,14 +37,14 @@ testLoop:
t.Errorf("#%d got response %s, expected %s", i, resp, test.responses[0])
}
if err != nil {
t.Errorf("#%d error: %s", i, err.String())
t.Errorf("#%d error: %s", i, err)
}
for j := range test.challenges {
challenge := []byte(test.challenges[j])
expected := []byte(test.responses[j+1])
resp, err := test.auth.Next(challenge, true)
if err != nil {
t.Errorf("#%d error: %s", i, err.String())
t.Errorf("#%d error: %s", i, err)
continue testLoop
}
if !bytes.Equal(resp, expected) {
@ -74,13 +74,13 @@ func TestBasic(t *testing.T) {
c := &Client{Text: textproto.NewConn(fake)}
if err := c.helo(); err != nil {
t.Fatalf("HELO failed: %s", err.String())
t.Fatalf("HELO failed: %s", err)
}
if err := c.ehlo(); err == nil {
t.Fatalf("Expected first EHLO to fail")
}
if err := c.ehlo(); err != nil {
t.Fatalf("Second EHLO failed: %s", err.String())
t.Fatalf("Second EHLO failed: %s", err)
}
if ok, args := c.Extension("aUtH"); !ok || args != "LOGIN PLAIN" {
@ -105,14 +105,14 @@ func TestBasic(t *testing.T) {
c.tls = true
c.serverName = "smtp.google.com"
if err := c.Auth(PlainAuth("", "user", "pass", "smtp.google.com")); err != nil {
t.Fatalf("AUTH failed: %s", err.String())
t.Fatalf("AUTH failed: %s", err)
}
if err := c.Mail("user@gmail.com"); err != nil {
t.Fatalf("MAIL failed: %s", err.String())
t.Fatalf("MAIL failed: %s", err)
}
if err := c.Rcpt("golang-nuts@googlegroups.com"); err != nil {
t.Fatalf("RCPT failed: %s", err.String())
t.Fatalf("RCPT failed: %s", err)
}
msg := `From: user@gmail.com
To: golang-nuts@googlegroups.com
@ -123,17 +123,17 @@ Line 1
Goodbye.`
w, err := c.Data()
if err != nil {
t.Fatalf("DATA failed: %s", err.String())
t.Fatalf("DATA failed: %s", err)
}
if _, err := w.Write([]byte(msg)); err != nil {
t.Fatalf("Data write failed: %s", err.String())
t.Fatalf("Data write failed: %s", err)
}
if err := w.Close(); err != nil {
t.Fatalf("Bad data response: %s", err.String())
t.Fatalf("Bad data response: %s", err)
}
if err := c.Quit(); err != nil {
t.Fatalf("QUIT failed: %s", err.String())
t.Fatalf("QUIT failed: %s", err)
}
bcmdbuf.Flush()

View File

@ -96,7 +96,7 @@ func myatof32(s string) (f float32, ok bool) {
func TestFp(t *testing.T) {
f, err := os.Open("testfp.txt")
if err != nil {
t.Fatal("testfp: open testfp.txt:", err.String())
t.Fatal("testfp: open testfp.txt:", err)
}
defer f.Close()