@@ -68,7 +68,7 @@ var _ = Describe("Analyzer", func() {
6868 pkg .Build ()
6969 err := analyzer .Process (buildTags , pkg .Path )
7070 Expect (err ).ShouldNot (HaveOccurred ())
71- _ , metrics := analyzer .Report ()
71+ _ , metrics , _ := analyzer .Report ()
7272 Expect (metrics .NumFiles ).To (Equal (2 ))
7373 })
7474
@@ -90,7 +90,7 @@ var _ = Describe("Analyzer", func() {
9090 pkg2 .Build ()
9191 err := analyzer .Process (buildTags , pkg1 .Path , pkg2 .Path )
9292 Expect (err ).ShouldNot (HaveOccurred ())
93- _ , metrics := analyzer .Report ()
93+ _ , metrics , _ := analyzer .Report ()
9494 Expect (metrics .NumFiles ).To (Equal (2 ))
9595 })
9696
@@ -106,11 +106,36 @@ var _ = Describe("Analyzer", func() {
106106 controlPackage .AddFile ("md5.go" , source )
107107 controlPackage .Build ()
108108 analyzer .Process (buildTags , controlPackage .Path )
109- controlIssues , _ := analyzer .Report ()
109+ controlIssues , _ , _ := analyzer .Report ()
110110 Expect (controlIssues ).Should (HaveLen (sample .Errors ))
111111
112112 })
113113
114+ It ("should report for Golang errors and invalid files" , func () {
115+ analyzer .LoadRules (rules .Generate ().Builders ())
116+ pkg := testutils .NewTestPackage ()
117+ defer pkg .Close ()
118+ pkg .AddFile ("foo.go" , `
119+ package main
120+ func main()
121+ }` )
122+ pkg .Build ()
123+ err := analyzer .Process (buildTags , pkg .Path )
124+ Expect (err ).ShouldNot (HaveOccurred ())
125+ _ , _ , golangErrors := analyzer .Report ()
126+ keys := make ([]string , len (golangErrors ))
127+ i := 0
128+ for key := range golangErrors {
129+ keys [i ] = key
130+ i ++
131+ }
132+ fileErr := golangErrors [keys [0 ]]
133+ Expect (len (fileErr )).To (Equal (1 ))
134+ Expect (fileErr [0 ].Line ).To (Equal (4 ))
135+ Expect (fileErr [0 ].Column ).To (Equal (5 ))
136+ Expect (fileErr [0 ].Err ).Should (MatchRegexp (`expected declaration, found '}'` ))
137+ })
138+
114139 It ("should not report errors when a nosec comment is present" , func () {
115140 // Rule for MD5 weak crypto usage
116141 sample := testutils .SampleCodeG401 [0 ]
@@ -124,7 +149,7 @@ var _ = Describe("Analyzer", func() {
124149 nosecPackage .Build ()
125150
126151 analyzer .Process (buildTags , nosecPackage .Path )
127- nosecIssues , _ := analyzer .Report ()
152+ nosecIssues , _ , _ := analyzer .Report ()
128153 Expect (nosecIssues ).Should (BeEmpty ())
129154 })
130155
@@ -141,7 +166,7 @@ var _ = Describe("Analyzer", func() {
141166 nosecPackage .Build ()
142167
143168 analyzer .Process (buildTags , nosecPackage .Path )
144- nosecIssues , _ := analyzer .Report ()
169+ nosecIssues , _ , _ := analyzer .Report ()
145170 Expect (nosecIssues ).Should (BeEmpty ())
146171 })
147172
@@ -158,7 +183,7 @@ var _ = Describe("Analyzer", func() {
158183 nosecPackage .Build ()
159184
160185 analyzer .Process (buildTags , nosecPackage .Path )
161- nosecIssues , _ := analyzer .Report ()
186+ nosecIssues , _ , _ := analyzer .Report ()
162187 Expect (nosecIssues ).Should (HaveLen (sample .Errors ))
163188 })
164189
@@ -175,7 +200,7 @@ var _ = Describe("Analyzer", func() {
175200 nosecPackage .Build ()
176201
177202 analyzer .Process (buildTags , nosecPackage .Path )
178- nosecIssues , _ := analyzer .Report ()
203+ nosecIssues , _ , _ := analyzer .Report ()
179204 Expect (nosecIssues ).Should (BeEmpty ())
180205 })
181206
@@ -212,7 +237,7 @@ var _ = Describe("Analyzer", func() {
212237 nosecPackage .Build ()
213238
214239 customAnalyzer .Process (buildTags , nosecPackage .Path )
215- nosecIssues , _ := customAnalyzer .Report ()
240+ nosecIssues , _ , _ := customAnalyzer .Report ()
216241 Expect (nosecIssues ).Should (HaveLen (sample .Errors ))
217242
218243 })
0 commit comments