Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Side by Side Diff: src/cmd/govet/govet.go

Issue 4629084: code review 4629084: govet: automate test (Closed)
Patch Set: diff -r 8d3830d81510 https://go.googlecode.com/hg/ Created 13 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/cmd/govet/Makefile ('k') | src/pkg/Makefile » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Govet is a simple checker for static errors in Go source code. 5 // Govet is a simple checker for static errors in Go source code.
6 // See doc.go for more information. 6 // See doc.go for more information.
7 package main 7 package main
8 8
9 import ( 9 import (
10 "flag" 10 "flag"
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 arg = args[len(call.Args)-1] 372 arg = args[len(call.Args)-1]
373 if lit, ok := arg.(*ast.BasicLit); ok && lit.Kind == token.STRIN G { 373 if lit, ok := arg.(*ast.BasicLit); ok && lit.Kind == token.STRIN G {
374 if strings.HasSuffix(lit.Value, `\n"`) { 374 if strings.HasSuffix(lit.Value, `\n"`) {
375 f.Badf(call.Pos(), "%s call ends with newline", name) 375 f.Badf(call.Pos(), "%s call ends with newline", name)
376 } 376 }
377 } 377 }
378 } 378 }
379 } 379 }
380 380
381 // This function never executes, but it serves as a simple test for the program. 381 // This function never executes, but it serves as a simple test for the program.
382 // Test with govet -printfuncs="Bad:1,Badf:1,Warn:1,Warnf:1" govet.go 382 // Test with make test.
383 func BadFunctionUsedInTests() { 383 func BadFunctionUsedInTests() {
384 » fmt.Println() // niladic call 384 » fmt.Println() // not an error
385 » fmt.Println("%s", "hi") // % in call to Println 385 » fmt.Println("%s", "hi") // ERROR "possible formatting directi ve in Println call"
386 » fmt.Printf("%s", "hi", 3) // wrong # percents 386 » fmt.Printf("%s", "hi", 3) // ERROR "wrong number of args in Pri ntf call"
387 » fmt.Printf("%s%%%d", "hi", 3) // right # percents 387 » fmt.Printf("%s%%%d", "hi", 3) // correct
388 » fmt.Printf("%.*d", 3, 3) // right # percents, with a * 388 » fmt.Printf("%.*d", 3, 3) // correct
389 » fmt.Printf("%.*d", 3, 3, 3) // wrong # percents, with a * 389 » fmt.Printf("%.*d", 3, 3, 3) // ERROR "wrong number of args in Pri ntf call"
390 » printf("now is the time", "buddy") // no %s 390 » printf("now is the time", "buddy") // ERROR "no formatting directive"
391 » Printf("now is the time", "buddy") // no %s 391 » Printf("now is the time", "buddy") // ERROR "no formatting directive"
392 » Printf("hi") // ok
392 f := new(File) 393 f := new(File)
393 » f.Warn(0, "%s", "hello", 3) // % in call to added function 394 » f.Warn(0, "%s", "hello", 3) // ERROR "possible formatting directive in Warn call"
394 » f.Warnf(0, "%s", "hello", 3) // wrong # %s in call to added function 395 » f.Warnf(0, "%s", "hello", 3) // ERROR "wrong number of args in Warnf cal l"
395 } 396 }
396 397
397 type BadTypeUsedInTests struct { 398 type BadTypeUsedInTests struct {
398 » X int "hello" // struct field not well-formed 399 » X int "hello" // ERROR "struct field tag"
399 } 400 }
400 401
401 // printf is used by the test. 402 // printf is used by the test.
402 func printf(format string, args ...interface{}) { 403 func printf(format string, args ...interface{}) {
403 panic("don't call - testing only") 404 panic("don't call - testing only")
404 } 405 }
OLDNEW
« no previous file with comments | « src/cmd/govet/Makefile ('k') | src/pkg/Makefile » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b