-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add end2end testing for checkers #8
Comments
The proposed test format is this (tests for //>Loud:0 consider `in' name instead of `IN'
//>Loud:1 consider `out' name instead of `OUT'
func f1(IN int) (OUT int) { //<Loud:0,Loud:1
return 0
}
//>Loud:2 consider `in' name instead of `IN'
//>Capitalized:0 `X' should not be capitalized
//>Capitalized:1 `Y' should not be capitalized
//>Capitalized:2 `Z' should not be capitalized
func f2(IN, X int) (Y, Z int) { //<Loud:2,Capitalized:0,Capitalized:1,Capitalized:2
return 0, 0
} For that file,
It checks that:
The benefits of this format:
For every warning we want to match, there must be two comment directives inside test file:
Anchor is required to bind expected warning line, Anchors and matchers connected with keys that consist of Matcher looks like this:
Anchor for the matcher above:
Because one line can trigger multiple warnings, it's possible to specify more than one anchor (they may have different kinds):
|
Now I think that requiring explicit ID's is dumb. func f5(x, y, z interface{}) int {
//>:8 case 0 can benefit from type switch with assignment
switch x.(type) { //<:8
case int:
//>:9 case 0 can benefit from type switch with assignment
switch y.(type) { //<:9
case int:
//>:10 case 0 can benefit from type switch with assignment
switch z.(type) { //<:10
case int:
return x.(int) + y.(int) + z.(int)
}
}
}
return 0
} When there are many warnings, it gets harder to assign proper ID. Maybe something like this is more bearable: func f5(x, y, z interface{}) int {
//>> case 0 can benefit from type switch with assignment
switch x.(type) { //<<
case int:
//>> case 0 can benefit from type switch with assignment
switch y.(type) { //<<
case int:
//>> case 0 can benefit from type switch with assignment
switch z.(type) { //<<
case int:
return x.(int) + y.(int) + z.(int)
}
}
}
return 0
} |
Now I'm wondering if explicit |
Anyway, we can improve functionality later. We need to test this first. I, actually, can not say a word without trying it myself. |
@fexolm, OK. I'm going to remove "anchors" completely. |
Almost there...
|
Ported all existing testdata files to new format. The format is simple: Use "///: blah-blah" or "///kind: blah-blah" comments to mark line that comes after a sequence of "///" comments as warning triggering line. Warning triggering line is expected to make linter emit every message enumerated among these directives. See changed test files for examples. Updates #8
Ported all existing testdata files to new format. The format is simple: Use "///: blah-blah" or "///kind: blah-blah" comments to mark line that comes after a sequence of "///" comments as warning triggering line. Warning triggering line is expected to make linter emit every message enumerated among these directives. See changed test files for examples. Updates #8
We need to test that checkers output does match expectations.
I like how end2end testing is done in Go, see go vet tests for example.
It's possible to grab "errcheck" functionality used there for our purposes,
or we can adapt something else (or roll our own).
The text was updated successfully, but these errors were encountered: