mirror of
https://github.com/mgechev/revive.git
synced 2025-03-17 20:57:58 +02:00
Improve tests
This commit is contained in:
parent
e2e5db7203
commit
6b50d1f05c
23
fixtures/cyclomatic-2.go
Normal file
23
fixtures/cyclomatic-2.go
Normal file
@ -0,0 +1,23 @@
|
||||
// Test of return+else warning.
|
||||
|
||||
// Package pkg ...
|
||||
package pkg
|
||||
|
||||
import "log"
|
||||
|
||||
func f(x int) bool { // MATCH /function f has cyclomatic complexity 4/
|
||||
if x > 0 && true || false {
|
||||
return true
|
||||
} else {
|
||||
log.Printf("non-positive x: %d", x)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func g(f func() bool) string {
|
||||
if ok := f(); ok {
|
||||
return "it's okay"
|
||||
} else {
|
||||
return "it's NOT okay!"
|
||||
}
|
||||
}
|
@ -60,6 +60,9 @@ func TestVarDeclaration(t *testing.T) {
|
||||
testRule(t, "cyclomatic", &rule.CyclomaticRule{}, &lint.RuleConfig{
|
||||
Arguments: []string{"1"},
|
||||
})
|
||||
testRule(t, "cyclomatic-2", &rule.CyclomaticRule{}, &lint.RuleConfig{
|
||||
Arguments: []string{"3"},
|
||||
})
|
||||
}
|
||||
|
||||
func testRule(t *testing.T, filename string, rule lint.Rule, config ...*lint.RuleConfig) {
|
||||
@ -91,7 +94,8 @@ func TestAll(t *testing.T) {
|
||||
baseDir := "../fixtures/"
|
||||
|
||||
ignoreFiles := map[string]bool{
|
||||
"cyclomatic.go": true,
|
||||
"cyclomatic.go": true,
|
||||
"cyclomatic-2.go": true,
|
||||
}
|
||||
|
||||
rx, err := regexp.Compile(*lintMatch)
|
||||
|
Loading…
x
Reference in New Issue
Block a user