Debian Codegraph @

ci_test.go

raw
1 package dns
2
3 import (
4 "fmt"
5 "go/ast"
6 "go/parser"
7 "go/token"
8 "os"
9 "path/filepath"
10 "strings"
11 "testing"
12 )
13
14 func init() {
15 os.Remove("cmd/reflect/reflect")
16 os.Remove("cmd/atomdns/atomdns")
17 }
18
19 func TestPrint(t *testing.T) {
20 files, _ := filepath.Glob("*.go")
21 subdirFiles, _ := filepath.Glob("*/*.go")
22 files = append(files, subdirFiles...)
23
24 for _, file := range files {
25 if strings.HasSuffix(file, "_test.go") {
26 continue
27 }
28
29 fset := token.NewFileSet()
30 node, err := parser.ParseFile(fset, file, nil, parser.ParseComments)
31 if err != nil {
32 t.Errorf("failed to parse file %s: %v", file, err)
33 continue
34 }
35
36 ast.Inspect(node, func(n ast.Node) bool {
37 sel, ok := n.(*ast.SelectorExpr)
38 if ok {
39 if sel.Sel.Name == "Printf" {
40 pkg := fmt.Sprintf("%s", sel.X)
41 if pkg == "fmt" {
42 pos := fset.Position(sel.Pos())
43 t.Errorf("%s:%d:%d: use of %s()", file, pos.Line, pos.Column, "fmt.Printf")
44 }
45 }
46 }
47
48 call, ok := n.(*ast.CallExpr)
49 if !ok {
50 return true
51 }
52
53 // Check if it's an identifier (function call)
54 if ident, ok := call.Fun.(*ast.Ident); ok {
55 switch ident.Name {
56 case "println":
57 fallthrough
58 case "print":
59 pos := fset.Position(ident.Pos())
60 t.Errorf("%s:%d:%d: use of %s()", file, pos.Line, pos.Column, ident.Name)
61
62 default:
63 }
64 }
65 return true
66 })
67 }
68 }