Skip to content

Commit c97ab9f

Browse files
committed
Fix missing violations in diff report (#134)
Merge pull request #134 from adangel:fix-missing-violations
2 parents 1b20b79 + 59d737d commit c97ab9f

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ With this version, Ruby 3.3 or higher is required.
2828
* [#131](https://github.com/pmd/pmd-regression-tester/pull/131): Refactor GitHub Actions Workflows
2929
* [#132](https://github.com/pmd/pmd-regression-tester/pull/132): Fix manual integration test - Update expected_patch_config_3.xml: no more plsql exclusion
3030
* [#133](https://github.com/pmd/pmd-regression-tester/pull/133): \[ci] Make build a reuseable workflow
31+
* [#134](https://github.com/pmd/pmd-regression-tester/pull/134): Fix missing violations in diff report
3132
* [#136](https://github.com/pmd/pmd-regression-tester/pull/136): Fix integration tests - missing pmd-core:jar:tests
3233

3334
## Dependency Updates

lib/pmdtester/report_diff.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def build_diffs(counters, &getter)
211211
# Values are lists of violations/errors
212212
diffs = base_hash.to_h.merge(patch_hash.to_h) do |_key, base_value, patch_value|
213213
# make the difference of values
214-
(base_value | patch_value) - (base_value & patch_value)
214+
(base_value + patch_value) - (base_value & patch_value)
215215
end
216216

217217
diffs.delete_if do |_key, value|
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<pmd xmlns="http://pmd.sourceforge.net/report/2.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://pmd.sourceforge.net/report/2.0.0 https://pmd.github.io/schema/report_2_0_0.xsd"
5+
version="6.3.0-SNAPSHOT" timestamp="2018-04-16T22:41:45.065">
6+
<file name="File1.java">
7+
<violation beginline="7" endline="8" begincolumn="1" endcolumn="2" rule="GenericNaming" ruleset="Codestyle" class="Null" method="Null" externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd_rules_java_codestyle.html#genericnaming" priority="3">
8+
Same message for the two violations on the same line.
9+
</violation>
10+
<violation beginline="7" endline="8" begincolumn="1" endcolumn="2" rule="GenericNaming" ruleset="Codestyle" class="Null" method="Null" externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd_rules_java_codestyle.html#genericnaming" priority="3">
11+
Same message for the two violations on the same line.
12+
</violation>
13+
</file>
14+
</pmd>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<pmd xmlns="http://pmd.sourceforge.net/report/2.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://pmd.sourceforge.net/report/2.0.0 https://pmd.github.io/schema/report_2_0_0.xsd"
5+
version="6.3.0-SNAPSHOT" timestamp="2018-04-16T22:41:45.065">
6+
<file name="File1.java">
7+
<violation beginline="7" endline="8" begincolumn="1" endcolumn="2" rule="TypeParameterNamingConvention" ruleset="Codestyle" class="Null" method="Null" externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd_rules_java_codestyle.html#typeparameternamingconvention" priority="3">
8+
Message for first type name.
9+
</violation>
10+
<violation beginline="7" endline="8" begincolumn="1" endcolumn="2" rule="TypeParameterNamingConvention" ruleset="Codestyle" class="Null" method="Null" externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd_rules_java_codestyle.html#typeparameternamingconvention" priority="3">
11+
Message for second type name.
12+
</violation>
13+
</file>
14+
</pmd>

test/test_diff_builder.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ def test_violation_diffs
3838
# assert_equal('00:00:56', diffs_report.diff_execution_time)
3939
end
4040

41+
def test_violation_diffs_rule_message_change
42+
base_report_path = 'test/resources/diff_builder/test_violation_diffs_rule_message_change_base.xml'
43+
patch_report_path = 'test/resources/diff_builder/test_violation_diffs_rule_message_change_patch.xml'
44+
diffs_report = build_report_diff(base_report_path, patch_report_path,
45+
BASE_REPORT_INFO_PATH, PATCH_REPORT_INFO_PATH)
46+
violation_diffs = diffs_report.violation_diffs_by_file
47+
keys = violation_diffs.keys
48+
49+
assert_counters_empty(diffs_report.error_counts)
50+
assert_counters_eq(diffs_report.violation_counts,
51+
base_total: 2, patch_total: 2, changed_total: 4)
52+
assert_changes_eq(diffs_report.violation_counts,
53+
removed: 2, added: 2, changed: 0)
54+
55+
assert_equal('File1.java', keys[0])
56+
assert_equal(4, violation_diffs[keys[0]].size)
57+
end
58+
4159
def test_violation_diffs_with_filter
4260
base_report_path = 'test/resources/diff_builder/test_violation_diffs_base.xml'
4361
patch_report_path = 'test/resources/diff_builder/test_violation_diffs_patch.xml'

0 commit comments

Comments
 (0)