github.com/gwaycc/gometalinter@v3.0.0+incompatible/regressiontests/gocyclo_test.go (about) 1 package regressiontests 2 3 import "testing" 4 5 func TestGocyclo(t *testing.T) { 6 t.Parallel() 7 source := `package test 8 9 func processOutput(state *linterState, out []byte) { 10 re := state.Match() 11 all := re.FindAllSubmatchIndex(out, -1) 12 debug("%s hits %d: %s", state.name, len(all), state.pattern) 13 for _, indices := range all { 14 group := [][]byte{} 15 for i := 0; i < len(indices); i += 2 { 16 fragment := out[indices[i]:indices[i+1]] 17 group = append(group, fragment) 18 } 19 20 issue := &Issue{} 21 issue.Linter = Linter(state.name) 22 for i, name := range re.SubexpNames() { 23 part := string(group[i]) 24 if name != "" { 25 state.vars[name] = part 26 } 27 switch name { 28 case "path": 29 issue.Path = part 30 31 case "line": 32 n, err := strconv.ParseInt(part, 10, 32) 33 kingpin.FatalIfError(err, "line matched invalid integer") 34 issue.Line = int(n) 35 36 case "col": 37 n, err := strconv.ParseInt(part, 10, 32) 38 kingpin.FatalIfError(err, "col matched invalid integer") 39 issue.Col = int(n) 40 41 case "message": 42 issue.Message = part 43 44 case "": 45 } 46 } 47 if m, ok := linterMessageOverrideFlag[state.name]; ok { 48 issue.Message = state.vars.Replace(m) 49 } 50 if sev, ok := linterSeverityFlag[state.name]; ok { 51 issue.Severity = Severity(sev) 52 } else { 53 issue.Severity = "error" 54 } 55 if state.filter != nil && state.filter.MatchString(issue.String()) { 56 continue 57 } 58 state.issues <- issue 59 } 60 return 61 } 62 ` 63 expected := Issues{ 64 {Linter: "gocyclo", Severity: "warning", Path: "test.go", Line: 3, Col: 0, Message: "cyclomatic complexity 14 of function processOutput() is high (> 10)"}, 65 } 66 ExpectIssues(t, "gocyclo", source, expected) 67 }