Skip to content

Commit f20d068

Browse files
committed
Update spec with example faulty duplication files, better tests
1 parent fabd839 commit f20d068

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

spec/cc/engine/analyzers/go/main_spec.rb

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module CC::Engine::Analyzers
3636
"path" => "foo.go",
3737
"lines" => { "begin" => 6, "end" => 6 },
3838
})
39-
expect(json["remediation_points"]).to eq(500_000)
39+
expect(json["remediation_points"]).to eq(540_000)
4040
expect(json["other_locations"]).to eq([
4141
{"path" => "foo.go", "lines" => { "begin" => 7, "end" => 7} },
4242
])
@@ -82,7 +82,7 @@ module CC::Engine::Analyzers
8282
"path" => "foo.go",
8383
"lines" => { "begin" => 5, "end" => 7 },
8484
})
85-
expect(json["remediation_points"]).to eq(1_220_000)
85+
expect(json["remediation_points"]).to eq(1_260_000)
8686
expect(json["other_locations"]).to eq([
8787
{"path" => "foo.go", "lines" => { "begin" => 9, "end" => 11} },
8888
{"path" => "foo.go", "lines" => { "begin" => 13, "end" => 15} },
@@ -127,6 +127,15 @@ module CC::Engine::Analyzers
127127
expect(issues).to be_empty
128128
end
129129

130+
it "does not flag entire file as issue" do
131+
create_source_file("foo.go", File.read(fixture_path("issue_6609_1.go")))
132+
create_source_file("bar.go", File.read(fixture_path("issue_6609_2.go")))
133+
issues = run_engine(engine_conf).strip.split("\0")
134+
issues.map! {|issue| JSON.parse issue}
135+
invalid_issues = issues.find_all{|issue| issue["location"]["lines"]["begin"] == 1}
136+
expect(invalid_issues).to be_empty, invalid_issues.map {|issue| issue["location"]}.join("\n")
137+
end
138+
130139
it "does not flag duplicate comments" do
131140
create_source_file("foo.go", <<-EOGO)
132141
// This is a comment.
@@ -137,7 +146,10 @@ module CC::Engine::Analyzers
137146
138147
package main
139148
149+
// import "fmt"
150+
140151
func main() {
152+
fmt.Println("This is a duplicate!")
141153
}
142154
143155
/* This is a multiline comment */
@@ -171,7 +183,14 @@ module CC::Engine::Analyzers
171183
172184
package main
173185
186+
// import "fmt"
187+
174188
func main() {
189+
// This is a comment.
190+
// This is a comment.
191+
// This is a comment.
192+
// This is also a comment.
193+
// This is also a comment.
175194
}
176195
177196
/* This is a multiline comment */
@@ -212,7 +231,7 @@ def engine_conf
212231
},
213232
'languages' => {
214233
'go' => {
215-
'mass_threshold' => 11,
234+
'mass_threshold' => 10,
216235
},
217236
},
218237
},

0 commit comments

Comments
 (0)