@@ -78,6 +78,46 @@ func TestCheckerRegexp(t *testing.T) {
78
78
}
79
79
}
80
80
81
+ // TestWholeFile tests Checker.WholeFiles will report any issues in files that have changes, even if
82
+ // they are outside the diff.
83
+ func TestWholeFiles (t * testing.T ) {
84
+ tests := []struct {
85
+ name string
86
+ line string
87
+ matches bool
88
+ }{
89
+ {"inside diff" , "file.go:1:issue" , true },
90
+ {"outside diff" , "file.go:10:5:issue" , true },
91
+ {"different file" , "file2.go:1:issue" , false },
92
+ }
93
+
94
+ diff := []byte (`--- a/file.go
95
+ +++ b/file.go
96
+ @@ -1,1 +1,1 @@
97
+ -func Line() {}
98
+ +func NewLine() {}` )
99
+
100
+ for _ , test := range tests {
101
+ t .Run (test .name , func (t * testing.T ) {
102
+ checker := Checker {
103
+ Patch : bytes .NewReader (diff ),
104
+ WholeFiles : true ,
105
+ }
106
+
107
+ issues , err := checker .Check (bytes .NewReader ([]byte (test .line )), ioutil .Discard )
108
+ if err != nil {
109
+ t .Fatalf ("unexpected error: %v" , err )
110
+ }
111
+ if test .matches && len (issues ) != 1 {
112
+ t .Fatalf ("expected one issue to be returned, but got %#v" , issues )
113
+ }
114
+ if ! test .matches && len (issues ) != 0 {
115
+ t .Fatalf ("expected no issues to be returned, but got %#v" , issues )
116
+ }
117
+ })
118
+ }
119
+ }
120
+
81
121
// TestChangesReturn tests the writer in the argument to the Changes function
82
122
// and generally tests the entire programs functionality.
83
123
func TestChangesWriter (t * testing.T ) {
0 commit comments