Skip to content

Commit c788ab2

Browse files
committed
Merge pull request #119 from adangel:update-manual-integration-test
Update manual integration test for PMD 7 #119
2 parents 56d03ab + 9eab21d commit c788ab2

14 files changed

+180
-132
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
## Enhancements
66
* [#118](https://github.com/pmd/pmd-regression-tester/pull/118): Update js libraries
7+
* [#119](https://github.com/pmd/pmd-regression-tester/pull/119): Update manual integration test for PMD 7
78
* [#120](https://github.com/pmd/pmd-regression-tester/pull/120): Support new PMD 7 binary dist filename
89

910
## Fixed Issues

README.rdoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ The tool creates the following folders:
136136
bundle exec pmdtester ... # run this to directly execute pmdtester from source
137137

138138
Run a single test class, e.g.:
139-
bundle exec ruby -I test test/test_diff_report_builder.rb
139+
bundle exec ruby -I test test/test_project_diff_report.rb
140140

141141
Run a single test, e.g.:
142-
bundle exec ruby -I test test/test_diff_report_builder.rb -n test_diff_report_builder
142+
bundle exec ruby -I test test/test_project_diff_report.rb -n test_diff_report_builder
143143

144144
=== Releasing
145145

lib/pmdtester/builders/pmd_report_builder.rb

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,12 @@ def build_pmd(into_dir:)
6060
# In CI, that's not a problem, because the workspace is always fresh.
6161
logger.warn "#{@pmd_branch_name}: Reusing already existing #{pmd_dist_target}"
6262
else
63-
logger.info "#{@pmd_branch_name}: Building PMD #{@pmd_version}..."
64-
package_cmd = './mvnw clean package' \
65-
' -Dmaven.test.skip=true' \
66-
' -Dmaven.javadoc.skip=true' \
67-
' -Dmaven.source.skip=true' \
68-
' -Dcheckstyle.skip=true' \
69-
' -Dpmd.skip=true' \
70-
' -T1C -B'
71-
Cmd.execute_successfully(package_cmd)
72-
63+
build_pmd_with_maven
7364
pmd_dist_target, binary_exists = find_pmd_dist_target
7465
unless binary_exists
7566
logger.error "#{@pmd_branch_name}: Dist zip not found at #{pmd_dist_target}!"
7667
raise "No Dist zip found at #{pmd_dist_target}"
7768
end
78-
7969
end
8070

8171
logger.info "#{@pmd_branch_name}: Extracting the zip"
@@ -101,7 +91,7 @@ def get_last_commit_message
10191

10292
def generate_pmd_report(project)
10393
error_recovery_options = @error_recovery ? 'PMD_JAVA_OPTS="-Dpmd.error_recovery -ea" ' : ''
104-
fail_on_violation = should_use_long_cli_options? ? '--fail-on-violation false' : '-failOnViolation false'
94+
fail_on_violation = create_failonviolation_option
10595
auxclasspath_option = create_auxclasspath_option(project)
10696
pmd_cmd = "#{error_recovery_options}" \
10797
"#{determine_run_path} -d #{project.local_source_path} -f xml " \
@@ -218,6 +208,16 @@ def create_auxclasspath_option(project)
218208
auxclasspath_option
219209
end
220210

211+
def create_failonviolation_option
212+
if pmd7?
213+
'--no-fail-on-violation'
214+
elsif should_use_long_cli_options?
215+
'--fail-on-violation false'
216+
else
217+
'-failOnViolation false'
218+
end
219+
end
220+
221221
def pmd7?
222222
Semver.compare(@pmd_version, '7.0.0-SNAPSHOT') >= 0
223223
end
@@ -244,5 +244,18 @@ def find_pmd_dist_target
244244
end
245245
[pmd_dist_target, binary_exists]
246246
end
247+
248+
def build_pmd_with_maven
249+
logger.info "#{@pmd_branch_name}: Building PMD #{@pmd_version}..."
250+
package_cmd = './mvnw clean package' \
251+
' -Dmaven.test.skip=true' \
252+
' -Dmaven.javadoc.skip=true' \
253+
' -Dmaven.source.skip=true' \
254+
' -Dcheckstyle.skip=true' \
255+
' -Dpmd.skip=true' \
256+
' -T1C -B'
257+
logger.debug "#{@pmd_branch_name}: maven command: #{package_cmd}"
258+
Cmd.execute_successfully(package_cmd)
259+
end
247260
end
248261
end

lib/pmdtester/cmd.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def self.execute_successfully(cmd)
3030
stdout, stderr, status = internal_execute(cmd)
3131

3232
unless status.success?
33+
logger.error "Command failed: #{cmd}"
3334
logger.error stdout
3435
logger.error stderr
3536
raise CmdException.new(cmd, stdout, stderr, status)

pmdtester.gemspec

Lines changed: 1 addition & 1 deletion
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, "Cl\u00E9ment Fournier".freeze]
14-
s.date = "2023-05-26"
14+
s.date = "2023-05-27"
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, "[email protected]".freeze]
1717
s.executables = ["pmdtester".freeze]

test/integration_test_pmd_report_builder.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,21 @@ def setup
1010
`rake clean`
1111
end
1212

13-
def test_build
13+
# Tests whether we can build successfully PMD from the sources of the master branch.
14+
# The master branch should always be buildable by the regression tester. For older
15+
# versions, we can rely on baselines.
16+
#
17+
# Note 1: Although a base branch is configured here, this is not used. Only the patch
18+
# branch is built.
19+
# Note 2: We use a limited set of projects and rules, to make the test faster.
20+
def test_build_master_branch
1421
argv = ['-r', 'target/repositories/pmd',
15-
'-b', 'master',
16-
'-p', 'origin/pmd/7.0.x',
22+
'-b', 'pmd_releases/6.55.0',
23+
'-p', 'master',
1724
'-c', 'test/resources/integration_test_pmd_report_builder/pmd7-config.xml',
1825
'-l', 'test/resources/integration_test_pmd_report_builder/project-test.xml',
1926
'--error-recovery',
20-
'--debug',
27+
# '--debug',
2128
'--threads', Etc.nprocessors.to_s]
2229

2330
options = PmdTester::Options.new(argv)
@@ -27,6 +34,6 @@ def test_build
2734
builder.build
2835

2936
assert_equal(0, $CHILD_STATUS.exitstatus)
30-
assert_path_exist('target/reports/origin_pmd_7.0.x/checkstyle/pmd_report.xml')
37+
assert_path_exist('target/reports/master/checkstyle/pmd_report.xml')
3138
end
3239
end

test/integration_test_runner.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,23 @@ def test_single_mode_with_html_flag_option
6969
end
7070

7171
def test_online_mode
72-
# This test depends on the file test_branch_2-baseline.zip being available at:
73-
# https://pmd-code.org/pmd-regression-tester/test_branch_2-baseline.zip
74-
base_branch = 'test_branch_2'
75-
argv = "-r target/repositories/pmd -m online -b #{base_branch} -p pmd_releases/6.41.0 " \
72+
# This test depends on the file pmd_releases_7.0.0-rc1-baseline.zip being available at:
73+
# https://pmd-code.org/pmd-regression-tester/pmd_releases_7.0.0-rc1-baseline.zip
74+
base_branch = 'pmd_releases/7.0.0-rc1'
75+
patch_branch = 'pmd_releases/7.0.0-rc2'
76+
argv = "-r target/repositories/pmd -m online -b #{base_branch} -p #{patch_branch} " \
7677
'--baseline-download-url https://pmd-code.org/pmd-regression-tester/' \
7778
' --threads ' + Etc.nprocessors.to_s
7879

7980
system("bundle exec bin/pmdtester #{argv}")
8081

81-
assert_path_exist("target/reports/#{base_branch}-baseline.zip")
82-
assert_path_exist("target/reports/#{base_branch}/checkstyle/pmd_report.xml")
83-
assert_path_exist("target/reports/#{base_branch}/spring-framework/pmd_report.xml")
84-
assert_path_exist('target/reports/pmd_releases_6.41.0/checkstyle/pmd_report.xml')
85-
assert_path_exist('target/reports/pmd_releases_6.41.0/checkstyle/config.xml')
86-
assert_path_exist('target/reports/pmd_releases_6.41.0/spring-framework/pmd_report.xml')
87-
assert_path_exist('target/reports/pmd_releases_6.41.0/spring-framework/config.xml')
82+
assert_path_exist("target/reports/#{base_branch.tr('/', '_')}-baseline.zip")
83+
assert_path_exist("target/reports/#{base_branch.tr('/', '_')}/checkstyle/pmd_report.xml")
84+
assert_path_exist("target/reports/#{base_branch.tr('/', '_')}/spring-framework/pmd_report.xml")
85+
assert_path_exist("target/reports/#{patch_branch.tr('/', '_')}/checkstyle/pmd_report.xml")
86+
assert_path_exist("target/reports/#{patch_branch.tr('/', '_')}/checkstyle/config.xml")
87+
assert_path_exist("target/reports/#{patch_branch.tr('/', '_')}/spring-framework/pmd_report.xml")
88+
assert_path_exist("target/reports/#{patch_branch.tr('/', '_')}/spring-framework/config.xml")
8889
assert_path_exist('target/reports/diff/checkstyle/index.html')
8990
assert_path_exist('target/reports/diff/spring-framework/index.html')
9091
assert_path_exist('target/reports/diff/index.html')

test/manual_integration_tests.rb

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,34 @@ def test_case_1_single_java_rule_changed
4646
assert_equal(0, @summary[:violations][:changed], 'found changed violations')
4747
assert_equal(0, @summary[:violations][:new], 'found new violations')
4848
# These are the artificially created false-negatives for AbstractClassWithoutAbstractMethod rule
49-
# checkstyle: 204 violations
49+
# checkstyle: 195 violations
5050
# spring-framework: 280 violations
5151
# openjdk11: 29 violations
52-
# -> total = 513
53-
assert_equal(204 + 280 + 29, @summary[:violations][:removed], 'found removed violations')
52+
# -> total = 504
53+
assert_equal(195 + 280 + 29, @summary[:violations][:removed], 'found removed violations')
5454

5555
# errors might have been caused in the baseline for other rules (only visible in the stacktrace)
5656
# hence they might appear as removed
5757

58-
# project "apex-link" has 2 errors, since we only executed java rules, 2 errors are removed
59-
assert_equal(2, @summary[:errors][:removed], 'found removed errors')
60-
assert_equal(0, @summary[:errors][:changed], 'found changed errors')
58+
# project "apex-link" has 2 errors removed, since we only executed java rules
59+
# project "checkstyle" has 10 errors removed and 1 changed
60+
# project "openjdk-11" has 0 error removed or changed
61+
# project "spring-framework" has 1 error removed
62+
# each project has 1 config error removed (LoosePackageCoupling dysfunctional): in total 7 config errors removed
63+
assert_equal(13, @summary[:errors][:removed], 'found removed errors')
64+
# The stack overflow exception might vary in the beginning/end of the stack frames shown
65+
# This stack overflow error is from checkstyle's InputIndentationLongConcatenatedString.java
66+
# instead of assert_equal(0, @summary[:errors][:changed], 'found changed errors')
67+
# allow 0 or 1 changed errors
68+
assert @summary[:errors][:changed] <= 1
6169
assert_equal(0, @summary[:errors][:new], 'found new errors')
6270
assert_equal(0, @summary[:configerrors][:changed], 'found changed configerrors')
6371
assert_equal(0, @summary[:configerrors][:new], 'found new configerrors')
64-
# Only the rule AbstractClassWithoutAbtractMethod has been executed, so the
65-
# configerrors about LoosePackageCoupling are gone, one for each project
66-
# we now have 7 projects in total (4 java, 3 apex)
6772
assert_equal(7, @summary[:configerrors][:removed], 'found removed configerrors')
6873

6974
assert_equal("This changeset changes 0 violations,\n" \
7075
"introduces 0 new violations, 0 new errors and 0 new configuration errors,\n" \
71-
'removes 513 violations, 2 errors and 7 configuration errors.',
76+
'removes 504 violations, 13 errors and 7 configuration errors.',
7277
create_summary_message)
7378

7479
assert_file_equals("#{PATCHES_PATH}/expected_patch_config_1.xml", 'target/reports/diff/patch_config.xml')
@@ -93,20 +98,25 @@ def test_case_2_single_xpath_rule_changed
9398
# errors might have been caused in the baseline for other rules (only visible in the stacktrace)
9499
# hence they might appear as removed
95100

96-
# project "apex-link" has 2 errors, since we only executed java rules, 2 errors are removed
97-
assert_equal(2, @summary[:errors][:removed], 'found removed errors')
98-
assert_equal(0, @summary[:errors][:changed], 'found changed errors')
101+
# project "apex-link" has 2 errors removed, since we only executed java rules
102+
# project "checkstyle" has 5 errors removed and 1 errors changed
103+
# project "openjdk-11" has 0 error removed or changed
104+
# project "spring-framework" has 1 error removed
105+
# each project has 1 config error removed (LoosePackageCoupling dysfunctional): in total 7 config errors removed
106+
assert_equal(8, @summary[:errors][:removed], 'found removed errors')
107+
# The stack overflow exception might vary in the beginning/end of the stack frames shown
108+
# This stack overflow error is from checkstyle's InputIndentationLongConcatenatedString.java
109+
# instead of assert_equal(0, @summary[:errors][:changed], 'found changed errors')
110+
# allow 0 or 1 changed errors
111+
assert @summary[:errors][:changed] <= 1
99112
assert_equal(0, @summary[:errors][:new], 'found new errors')
100113
assert_equal(0, @summary[:configerrors][:changed], 'found changed configerrors')
101114
assert_equal(0, @summary[:configerrors][:new], 'found new configerrors')
102-
# Only the rule AvoidMessageDigestField and all other rules from bestpractices have been executed, so the
103-
# configerrors about LoosePackageCoupling are gone, one for each project
104-
# we now have 7 projects in total (4 java, 3 apex)
105115
assert_equal(7, @summary[:configerrors][:removed], 'found removed configerrors')
106116

107117
assert_equal("This changeset changes 0 violations,\n" \
108118
"introduces 0 new violations, 0 new errors and 0 new configuration errors,\n" \
109-
'removes 22 violations, 2 errors and 7 configuration errors.',
119+
'removes 22 violations, 8 errors and 7 configuration errors.',
110120
create_summary_message)
111121

112122
assert_file_equals("#{PATCHES_PATH}/expected_patch_config_2.xml", 'target/reports/diff/patch_config.xml')
@@ -115,7 +125,7 @@ def test_case_2_single_xpath_rule_changed
115125

116126
def test_case_3_change_in_core
117127
checkout_pmd_branch
118-
prepare_patch_branch('patch_test_case_3_modify_PMD.patch', 'test-case-3')
128+
prepare_patch_branch('patch_test_case_3_modify_pmd-core.patch', 'test-case-3')
119129

120130
run_pmd_tester
121131

@@ -125,7 +135,11 @@ def test_case_3_change_in_core
125135
assert_equal(0, @summary[:violations][:new], 'found new violations')
126136
assert_equal(0, @summary[:violations][:removed], 'found removed violations')
127137
assert_equal(0, @summary[:errors][:removed], 'found removed errors')
128-
assert_equal(0, @summary[:errors][:changed], 'found changed errors')
138+
# The stack overflow exception might vary in the beginning/end of the stack frames shown
139+
# This stack overflow error is from checkstyle's InputIndentationLongConcatenatedString.java
140+
# instead of assert_equal(0, @summary[:errors][:changed], 'found changed errors')
141+
# allow 0 or 1 changed errors
142+
assert @summary[:errors][:changed] <= 1
129143
assert_equal(0, @summary[:errors][:new], 'found new errors')
130144
assert_equal(0, @summary[:configerrors][:changed], 'found changed configerrors')
131145
assert_equal(0, @summary[:configerrors][:new], 'found new configerrors')
@@ -231,7 +245,7 @@ def checkout_pmd_branch(branch = 'master')
231245
system('git config user.email "[email protected]"')
232246
system('git config user.name "PMD CI (pmd-bot)"')
233247
# remove any already existing binary to force a rebuild
234-
FileUtils.rm Dir.glob('pmd-dist/target/pmd-bin-*.zip')
248+
FileUtils.rm Dir.glob('pmd-dist/target/pmd-*.zip')
235249
end
236250
end
237251

@@ -248,19 +262,19 @@ def prepare_patch_branch(patch_file, local_branch, base_branch = 'master')
248262
end
249263

250264
def assert_master_baseline
251-
assert_path_exist('target/reports/master/checkstyle/config.xml')
252-
assert_path_exist('target/reports/master/checkstyle/report_info.json')
253-
assert_path_exist('target/reports/master/checkstyle/pmd_report.xml')
254-
assert(File.size('target/reports/master/checkstyle/pmd_report.xml') > 50 * 1024 * 1024)
255-
256-
assert_path_exist('target/reports/master/openjdk-11/config.xml')
257-
assert_path_exist('target/reports/master/openjdk-11/report_info.json')
258-
assert_path_exist('target/reports/master/openjdk-11/pmd_report.xml')
259-
assert(File.size('target/reports/master/openjdk-11/pmd_report.xml') > 100 * 1024 * 1024)
260-
261-
assert_path_exist('target/reports/master/spring-framework/config.xml')
262-
assert_path_exist('target/reports/master/spring-framework/report_info.json')
263-
assert_path_exist('target/reports/master/spring-framework/pmd_report.xml')
264-
assert(File.size('target/reports/master/spring-framework/pmd_report.xml') > 150 * 1024 * 1024)
265+
assert_master_baseline_project('checkstyle', 40 * 1024 * 1024)
266+
assert_master_baseline_project('openjdk-11', 80 * 1024 * 1024)
267+
assert_master_baseline_project('spring-framework', 100 * 1024 * 1024)
268+
assert_master_baseline_project('java-regression-tests', 100 * 1024)
269+
assert_master_baseline_project('apex-link', 10 * 1024)
270+
assert_master_baseline_project('fflib-apex-common', 400 * 1024)
271+
assert_master_baseline_project('Schedul-o-matic-9000', 20 * 1024)
272+
end
273+
274+
def assert_master_baseline_project(project_name, report_size_in_bytes)
275+
assert_path_exist("target/reports/master/#{project_name}/config.xml")
276+
assert_path_exist("target/reports/master/#{project_name}/report_info.json")
277+
assert_path_exist("target/reports/master/#{project_name}/pmd_report.xml")
278+
assert(File.size("target/reports/master/#{project_name}/pmd_report.xml") > report_size_in_bytes)
265279
end
266280
end
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From df7e43732794442b7c787493a2189b0c4a0e3f85 Mon Sep 17 00:00:00 2001
1+
From ab94c0fed1813eb5e8376be51a7c93164652e26b Mon Sep 17 00:00:00 2001
22
From: Andreas Dangel <[email protected]>
3-
Date: Thu, 14 Jan 2021 11:25:58 +0100
4-
Subject: [PATCH] pmd-regression-test: test case 1 - single java rule changed
3+
Date: Thu, 4 May 2023 19:44:31 +0200
4+
Subject: [PATCH] test case 1 - single java rule changed
55

66
A single rule (java class) is changed. Only this rule should be executed
77
and only this rule should be compared (ruleset is filtered).
@@ -15,34 +15,33 @@ exactly this rule.
1515
2 files changed, 4 insertions(+), 1 deletion(-)
1616

1717
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractClassWithoutAbstractMethodRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractClassWithoutAbstractMethodRule.java
18-
index 3f20b559d5..4ef489c23b 100644
18+
index 0d0d8c33e4..972e1bd62a 100644
1919
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractClassWithoutAbstractMethodRule.java
2020
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractClassWithoutAbstractMethodRule.java
21-
@@ -35,7 +35,7 @@ public class AbstractClassWithoutAbstractMethodRule extends AbstractJavaRule {
22-
}
21+
@@ -22,7 +22,7 @@ public class AbstractClassWithoutAbstractMethodRule extends AbstractJavaRulechai
2322
}
24-
if (countOfAbstractMethods == 0) {
23+
24+
if (node.getDeclarations(ASTMethodDeclaration.class).none(ASTMethodDeclaration::isAbstract)) {
2525
- addViolation(data, node);
2626
+ //addViolation(data, node);
2727
}
2828
return data;
2929
}
3030
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractClassWithoutAbstractMethodTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractClassWithoutAbstractMethodTest.java
31-
index a7ff179f29..ac4d852e26 100644
31+
index b319c5e9f1..77698edb60 100644
3232
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractClassWithoutAbstractMethodTest.java
3333
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractClassWithoutAbstractMethodTest.java
3434
@@ -4,8 +4,11 @@
3535

3636
package net.sourceforge.pmd.lang.java.rule.bestpractices;
3737

38-
+import org.junit.Ignore;
38+
+import org.junit.jupiter.api.Disabled;
3939
+
4040
import net.sourceforge.pmd.testframework.PmdRuleTst;
4141

42-
+@Ignore
43-
public class AbstractClassWithoutAbstractMethodTest extends PmdRuleTst {
42+
+@Disabled
43+
class AbstractClassWithoutAbstractMethodTest extends PmdRuleTst {
4444
// no additional unit tests
4545
}
4646
--
47-
2.29.2
48-
47+
2.39.2

0 commit comments

Comments
 (0)