package noliteral import ( "go/ast" "go/parser" "go/token" "path/filepath" "runtime" "testing" "golang.org/x/tools/go/analysis" ) func TestAnalyzer_negative(t *testing.T) { _, filename, _, _ := runtime.Caller(0) dir := filepath.Dir(filename) fset := token.NewFileSet() f, err := parser.ParseFile(fset, filepath.Join(dir, "test-case/src/negative._go"), nil, parser.AllErrors) if err != nil { t.Fatal(err) } Count := 0 pass := &analysis.Pass{ Fset: fset, Files: []*ast.File{f}, Report: func(diag analysis.Diagnostic) { Count++ }, } _, err = run(pass) if Count != 6 { t.Fail() } if err != nil { t.Fatal(err) } } func TestAnalyzer_positive(t *testing.T) { _, filename, _, _ := runtime.Caller(0) dir := filepath.Dir(filename) fset := token.NewFileSet() f, err := parser.ParseFile(fset, filepath.Join(dir, "test-case/src/positive._go"), nil, parser.AllErrors) if err != nil { t.Fatal(err) } flag := false pass := &analysis.Pass{ Fset: fset, Files: []*ast.File{f}, Report: func(diag analysis.Diagnostic) { flag = true }, } _, err = run(pass) if flag { t.Fail() } if err != nil { t.Fatal(err) } }