@@ -17,8 +17,9 @@ import (
17
17
var _ = Describe ("Analyzer" , func () {
18
18
19
19
var (
20
- analyzer * gas.Analyzer
21
- logger * log.Logger
20
+ analyzer * gas.Analyzer
21
+ logger * log.Logger
22
+ buildTags []string
22
23
)
23
24
BeforeEach (func () {
24
25
logger , _ = testutils .NewLogger ()
@@ -32,7 +33,7 @@ var _ = Describe("Analyzer", func() {
32
33
dir , err := ioutil .TempDir ("" , "empty" )
33
34
defer os .RemoveAll (dir )
34
35
Expect (err ).ShouldNot (HaveOccurred ())
35
- err = analyzer .Process (dir )
36
+ err = analyzer .Process (buildTags , dir )
36
37
Expect (err ).Should (HaveOccurred ())
37
38
Expect (err .Error ()).Should (MatchRegexp ("no buildable Go source files" ))
38
39
})
@@ -44,7 +45,7 @@ var _ = Describe("Analyzer", func() {
44
45
pkg .AddFile ("wonky.go" , `func main(){ println("forgot the package")}` )
45
46
pkg .Build ()
46
47
47
- err := analyzer .Process (pkg .Path )
48
+ err := analyzer .Process (buildTags , pkg .Path )
48
49
Expect (err ).Should (HaveOccurred ())
49
50
Expect (err .Error ()).Should (MatchRegexp (`expected 'package'` ))
50
51
@@ -65,7 +66,7 @@ var _ = Describe("Analyzer", func() {
65
66
println("package has two files!")
66
67
}` )
67
68
pkg .Build ()
68
- err := analyzer .Process (pkg .Path )
69
+ err := analyzer .Process (buildTags , pkg .Path )
69
70
Expect (err ).ShouldNot (HaveOccurred ())
70
71
_ , metrics := analyzer .Report ()
71
72
Expect (metrics .NumFiles ).To (Equal (2 ))
@@ -87,7 +88,7 @@ var _ = Describe("Analyzer", func() {
87
88
}` )
88
89
pkg1 .Build ()
89
90
pkg2 .Build ()
90
- err := analyzer .Process (pkg1 .Path , pkg2 .Path )
91
+ err := analyzer .Process (buildTags , pkg1 .Path , pkg2 .Path )
91
92
Expect (err ).ShouldNot (HaveOccurred ())
92
93
_ , metrics := analyzer .Report ()
93
94
Expect (metrics .NumFiles ).To (Equal (2 ))
@@ -104,7 +105,7 @@ var _ = Describe("Analyzer", func() {
104
105
defer controlPackage .Close ()
105
106
controlPackage .AddFile ("md5.go" , source )
106
107
controlPackage .Build ()
107
- analyzer .Process (controlPackage .Path )
108
+ analyzer .Process (buildTags , controlPackage .Path )
108
109
controlIssues , _ := analyzer .Report ()
109
110
Expect (controlIssues ).Should (HaveLen (sample .Errors ))
110
111
@@ -122,7 +123,7 @@ var _ = Describe("Analyzer", func() {
122
123
nosecPackage .AddFile ("md5.go" , nosecSource )
123
124
nosecPackage .Build ()
124
125
125
- analyzer .Process (nosecPackage .Path )
126
+ analyzer .Process (buildTags , nosecPackage .Path )
126
127
nosecIssues , _ := analyzer .Report ()
127
128
Expect (nosecIssues ).Should (BeEmpty ())
128
129
})
@@ -139,7 +140,7 @@ var _ = Describe("Analyzer", func() {
139
140
nosecPackage .AddFile ("md5.go" , nosecSource )
140
141
nosecPackage .Build ()
141
142
142
- analyzer .Process (nosecPackage .Path )
143
+ analyzer .Process (buildTags , nosecPackage .Path )
143
144
nosecIssues , _ := analyzer .Report ()
144
145
Expect (nosecIssues ).Should (BeEmpty ())
145
146
})
@@ -156,7 +157,7 @@ var _ = Describe("Analyzer", func() {
156
157
nosecPackage .AddFile ("md5.go" , nosecSource )
157
158
nosecPackage .Build ()
158
159
159
- analyzer .Process (nosecPackage .Path )
160
+ analyzer .Process (buildTags , nosecPackage .Path )
160
161
nosecIssues , _ := analyzer .Report ()
161
162
Expect (nosecIssues ).Should (HaveLen (sample .Errors ))
162
163
})
@@ -173,10 +174,23 @@ var _ = Describe("Analyzer", func() {
173
174
nosecPackage .AddFile ("md5.go" , nosecSource )
174
175
nosecPackage .Build ()
175
176
176
- analyzer .Process (nosecPackage .Path )
177
+ analyzer .Process (buildTags , nosecPackage .Path )
177
178
nosecIssues , _ := analyzer .Report ()
178
179
Expect (nosecIssues ).Should (BeEmpty ())
179
180
})
181
+
182
+ It ("should pass the build tags" , func () {
183
+ sample := testutils .SampleCode601 [0 ]
184
+ source := sample .Code
185
+ analyzer .LoadRules (rules .Generate ().Builders ())
186
+ pkg := testutils .NewTestPackage ()
187
+ defer pkg .Close ()
188
+ pkg .AddFile ("tags.go" , source )
189
+
190
+ buildTags = append (buildTags , "test" )
191
+ err := analyzer .Process (buildTags , pkg .Path )
192
+ Expect (err ).Should (HaveOccurred ())
193
+ })
180
194
})
181
195
182
196
It ("should be possible to overwrite nosec comments, and report issues" , func () {
@@ -197,7 +211,7 @@ var _ = Describe("Analyzer", func() {
197
211
nosecPackage .AddFile ("md5.go" , nosecSource )
198
212
nosecPackage .Build ()
199
213
200
- customAnalyzer .Process (nosecPackage .Path )
214
+ customAnalyzer .Process (buildTags , nosecPackage .Path )
201
215
nosecIssues , _ := customAnalyzer .Report ()
202
216
Expect (nosecIssues ).Should (HaveLen (sample .Errors ))
203
217
0 commit comments