Skip to content

Commit 60342ba

Browse files
committed
Also consider line moves
1 parent 4dbcc87 commit 60342ba

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

lib/pmdtester/parsers/pmd_report_document.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def start_element(name, attrs = [])
3131
when 'file'
3232
remove_work_dir!(attrs['name'])
3333
@current_violations = []
34-
@current_filename = attrs['name']
34+
@current_filename = attrs['name'].freeze
3535
when 'violation'
36-
@current_violation = PmdViolation.new(attrs, @branch_name)
36+
@current_violation = PmdViolation.new(attrs, @branch_name, @current_filename)
3737
when 'error'
3838
remove_work_dir!(attrs['filename'])
3939
remove_work_dir!(attrs['msg'])

lib/pmdtester/pmd_violation.rb

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,40 +47,58 @@ class PmdViolation
4747
# </xs:complexType>
4848

4949
attr_reader :attrs
50+
attr_reader :fname
5051
attr_accessor :text
5152

5253
# means it was in both branches but changed messages
5354
attr_accessor :changed
5455

55-
def initialize(attrs, branch)
56+
def initialize(attrs, branch, fname)
5657
@attrs = attrs
5758
@branch = branch
5859
@changed = false
60+
@fname = fname
5961
@text = ''
6062
end
6163

62-
def same_modulo_message?(other)
63-
@attrs['beginline'].eql?(other.attrs['beginline']) &&
64-
@attrs['rule'].eql?(other.attrs['rule'])
64+
def line_move?(other)
65+
message.eql?(other.message) && (line - other.line).abs == 1
6566
end
6667

6768
def try_merge?(other)
68-
if branch != BASE && @branch != other.branch && same_modulo_message?(other)
69+
if branch != BASE && branch != other.branch && rule_name == other.rule_name &&
70+
(line == other.line || line_move?(other))
6971
@changed = true
7072
@attrs['oldMessage'] = other.text
73+
@attrs['oldLine'] = other.line
74+
puts "Merged #{self} into #{other}"
7175
true
7276
else
7377
false
7478
end
7579
end
7680

81+
def line
82+
@attrs['beginline']
83+
end
84+
85+
def rule_name
86+
@attrs['rule']
87+
end
88+
89+
def message
90+
@text
91+
end
92+
7793
def eql?(other)
78-
same_modulo_message?(other) &&
79-
@text.eql?(other.text)
94+
rule_name.eql?(other.rule_name) &&
95+
line.eql?(other.line) &&
96+
fname.eql?(other.fname) &&
97+
message.eql?(other.message)
8098
end
8199

82100
def hash
83-
[@attrs['beginline'], @attrs['rule'], @text].hash
101+
[line, rule_name, message].hash
84102
end
85103
end
86104
end

lib/pmdtester/report_diff.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def build_diffs(base_hash, patch_hash)
151151
# @param diff_violations a hash { filename => list[violation]}, containing those that changed
152152
def merge_changed_violations(diff_violations)
153153
diff_violations.each do |fname, different|
154+
different.sort_by!(&:line)
154155
diff_violations[fname] = different.dup.delete_if do |v|
155156
v.branch == BASE &&
156157
# try_merge will set v2.changed = true if it succeeds

pmdtester.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
1111
s.metadata = { "bug_tracker_uri" => "https://github.com/pmd/pmd-regression-tester/issues", "homepage_uri" => "https://pmd.github.io", "source_code_uri" => "https://github.com/pmd/pmd-regression-tester" } if s.respond_to? :metadata=
1212
s.require_paths = ["lib".freeze]
1313
s.authors = ["Andreas Dangel".freeze, "Binguo Bao".freeze]
14-
s.date = "2020-10-28"
14+
s.date = "2020-11-04"
1515
s.description = "A regression testing tool ensure that new problems and unexpected behaviors will not be introduced to PMD project after fixing an issue , and new rules can work as expected.".freeze
1616
s.email = ["[email protected]".freeze, "[email protected]".freeze]
1717
s.executables = ["pmdtester".freeze]
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
2121
s.licenses = ["BSD-2-Clause".freeze]
2222
s.rdoc_options = ["--main".freeze, "README.rdoc".freeze]
2323
s.required_ruby_version = Gem::Requirement.new(">= 2.7".freeze)
24-
s.rubygems_version = "3.1.4".freeze
24+
s.rubygems_version = "3.1.2".freeze
2525
s.summary = "A regression testing tool ensure that new problems and unexpected behaviors will not be introduced to PMD project after fixing an issue , and new rules can work as expected.".freeze
2626

2727
if s.respond_to? :specification_version then

0 commit comments

Comments
 (0)