Skip to content

Commit

Permalink
Fix manual integration tests (#127)
Browse files Browse the repository at this point in the history
The patches needed to be adapted to the final PMD 7 changes.
  • Loading branch information
adangel authored Sep 6, 2024
1 parent 9a6c4ae commit bb59c62
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 47 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

## Fixed Issues
* [#126](https://github.com/pmd/pmd-regression-tester/pull/126): Fix integration tests
* [#127](https://github.com/pmd/pmd-regression-tester/pull/127): Fix manual integration tests

## External Contributions

Expand Down
2 changes: 1 addition & 1 deletion lib/pmdtester/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def download_baseline(url_prefix, branch_name)

url = get_baseline_url(url_prefix, zip_filename)
logger.info "Downloading baseline for branch #{branch_name} from #{url}"
wget_cmd = "wget --timestamping #{url}"
wget_cmd = "wget --no-verbose --timestamping #{url}"
unzip_cmd = "unzip -qo #{zip_filename}"

Dir.chdir(target_path) do
Expand Down
26 changes: 14 additions & 12 deletions test/manual_integration_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ def test_case_1_single_java_rule_changed
# checkstyle: 195 violations
# spring-framework: 280 violations
# openjdk11: 29 violations
# -> total = 504
assert_equal(195 + 280 + 29, @summary[:violations][:removed], 'found removed violations')
# java-regression-tests: 1 violation
# -> total = 505
assert_equal(195 + 280 + 29 + 1, @summary[:violations][:removed], 'found removed violations')

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

# project "apex-link" has 2 errors removed, since we only executed java rules
# project "checkstyle" has 10 errors removed and 1 changed
# project "openjdk-11" has 0 error removed or changed
# project "spring-framework" has 1 error removed
# project "checkstyle" has 0 errors removed and 1 changed
# project "openjdk-11" has 0 errors removed or changed
# project "spring-framework" has 0 errors removed or changed
# project "java-regression-tests" has 0 errors removed or changed
# each project has 1 config error removed (LoosePackageCoupling dysfunctional): in total 7 config errors removed
assert_equal(13, @summary[:errors][:removed], 'found removed errors')
assert_equal(2, @summary[:errors][:removed], 'found removed errors')
# The stack overflow exception might vary in the beginning/end of the stack frames shown
# This stack overflow error is from checkstyle's InputIndentationLongConcatenatedString.java
# instead of assert_equal(0, @summary[:errors][:changed], 'found changed errors')
Expand All @@ -73,7 +75,7 @@ def test_case_1_single_java_rule_changed

assert_equal("This changeset changes 0 violations,\n" \
"introduces 0 new violations, 0 new errors and 0 new configuration errors,\n" \
'removes 504 violations, 13 errors and 7 configuration errors.',
'removes 505 violations, 2 errors and 7 configuration errors.',
create_summary_message)

assert_file_equals("#{PATCHES_PATH}/expected_patch_config_1.xml", 'target/reports/diff/patch_config.xml')
Expand All @@ -99,11 +101,11 @@ def test_case_2_single_xpath_rule_changed
# hence they might appear as removed

# project "apex-link" has 2 errors removed, since we only executed java rules
# project "checkstyle" has 5 errors removed and 1 errors changed
# project "openjdk-11" has 0 error removed or changed
# project "spring-framework" has 1 error removed
# project "checkstyle" has 0 errors removed and 1 errors changed
# project "openjdk-11" has 0 errors removed or changed
# project "spring-framework" has 0 errors removed or changed
# each project has 1 config error removed (LoosePackageCoupling dysfunctional): in total 7 config errors removed
assert_equal(8, @summary[:errors][:removed], 'found removed errors')
assert_equal(2, @summary[:errors][:removed], 'found removed errors')
# The stack overflow exception might vary in the beginning/end of the stack frames shown
# This stack overflow error is from checkstyle's InputIndentationLongConcatenatedString.java
# instead of assert_equal(0, @summary[:errors][:changed], 'found changed errors')
Expand All @@ -116,7 +118,7 @@ def test_case_2_single_xpath_rule_changed

assert_equal("This changeset changes 0 violations,\n" \
"introduces 0 new violations, 0 new errors and 0 new configuration errors,\n" \
'removes 22 violations, 8 errors and 7 configuration errors.',
'removes 22 violations, 2 errors and 7 configuration errors.',
create_summary_message)

assert_file_equals("#{PATCHES_PATH}/expected_patch_config_2.xml", 'target/reports/diff/patch_config.xml')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>

<ruleset name="All Regression Rules"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
From ab94c0fed1813eb5e8376be51a7c93164652e26b Mon Sep 17 00:00:00 2001
From c4b5364d69ea11a139a4fe9bb11f49124afb22af Mon Sep 17 00:00:00 2001
From: Andreas Dangel <andreas.dangel@pmd-code.org>
Date: Thu, 4 May 2023 19:44:31 +0200
Date: Thu, 5 Sep 2024 14:50:24 +0200
Subject: [PATCH] test case 1 - single java rule changed

A single rule (java class) is changed. Only this rule should be executed
and only this rule should be compared (ruleset is filtered).
A single rule (java class) is changed. Only this rule should be
executed and only this rule should be compared (ruleset is
filtered).

The rule "AbstractClassWithoutAbstractMethod" doesn't report
any violations anymore, so false-negatives should appear for
exactly this rule.
---
.../bestpractices/AbstractClassWithoutAbstractMethodRule.java | 2 +-
.../bestpractices/AbstractClassWithoutAbstractMethodTest.java | 3 +++
.../java/rule/design/AbstractClassWithoutAnyMethodTest.java | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)

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
index 0d0d8c33e4..972e1bd62a 100644
index 835acebd14..5129fa0f15 100644
--- 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
@@ -22,7 +22,7 @@ public class AbstractClassWithoutAbstractMethodRule extends AbstractJavaRulechai
}

if (node.getDeclarations(ASTMethodDeclaration.class).none(ASTMethodDeclaration::isAbstract)) {
- addViolation(data, node);
+ //addViolation(data, node);
- asCtx(data).addViolation(node);
+ //asCtx(data).addViolation(node);
}
return data;
}
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
index b319c5e9f1..77698edb60 100644
--- 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
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/design/AbstractClassWithoutAnyMethodTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/design/AbstractClassWithoutAnyMethodTest.java
index a5d9253ee2..2df451e9b8 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/design/AbstractClassWithoutAnyMethodTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/design/AbstractClassWithoutAnyMethodTest.java
@@ -4,8 +4,11 @@

package net.sourceforge.pmd.lang.java.rule.bestpractices;
package net.sourceforge.pmd.lang.java.rule.design;

+import org.junit.jupiter.api.Disabled;
+
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;

+@Disabled
class AbstractClassWithoutAbstractMethodTest extends PmdRuleTst {
class AbstractClassWithoutAnyMethodTest extends PmdRuleTst {
// no additional unit tests
}
--
2.39.2
2.45.2

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
From 1614ba4af8a0869f7bbc7b8dca60f1d7802218cc Mon Sep 17 00:00:00 2001
From e0b3402ef126c6ea412a5e01f271b50e389c4c35 Mon Sep 17 00:00:00 2001
From: Andreas Dangel <andreas.dangel@pmd-code.org>
Date: Thu, 4 May 2023 19:54:59 +0200
Date: Thu, 5 Sep 2024 14:54:26 +0200
Subject: [PATCH] test case 2 - single xpath rule changed

The rule AvoidMessageDigestField is disabled
Expand All @@ -15,20 +15,20 @@ the baseline.
2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/pmd-java/src/main/resources/category/java/bestpractices.xml b/pmd-java/src/main/resources/category/java/bestpractices.xml
index 728ab98c9b..836428d33e 100644
index 4bf4a370bf..41ce59b33a 100644
--- a/pmd-java/src/main/resources/category/java/bestpractices.xml
+++ b/pmd-java/src/main/resources/category/java/bestpractices.xml
@@ -147,7 +147,7 @@ public class Foo {
<property name="xpath">
<value>
<![CDATA[
-//FieldDeclaration/ClassOrInterfaceType[pmd-java:typeIs('java.security.MessageDigest')]
+//FieldDeclaration/ClassOrInterfaceType[pmd-java:typeIs('java.security.MessageDigestFoo')]
-//FieldDeclaration/ClassType[pmd-java:typeIs('java.security.MessageDigest')]
+//FieldDeclaration/ClassType[pmd-java:typeIs('java.security.MessageDigestFoo')]
]]>
</value>
</property>
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidMessageDigestFieldTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidMessageDigestFieldTest.java
index df4543674d..f5c87e6705 100644
index 1403fe41f3..7f4e0947ea 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidMessageDigestFieldTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidMessageDigestFieldTest.java
@@ -4,8 +4,11 @@
Expand All @@ -37,11 +37,12 @@ index df4543674d..f5c87e6705 100644

+import org.junit.jupiter.api.Disabled;
+
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;

+@Disabled
class AvoidMessageDigestFieldTest extends PmdRuleTst {
// no additional unit tests
}
--
2.39.2
2.45.2

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
From 478d9f3767a449aefa8fb211e4e11debd9d7a6b6 Mon Sep 17 00:00:00 2001
From 311f91741d0b1f8e58561e61035e8e432074403c Mon Sep 17 00:00:00 2001
From: Andreas Dangel <andreas.dangel@pmd-code.org>
Date: Thu, 4 May 2023 19:58:47 +0200
Date: Thu, 5 Sep 2024 14:56:46 +0200
Subject: [PATCH] test case 3 - change in pmd-core

This changes the class PMDVersion which will trigger a
Expand All @@ -10,7 +10,7 @@ complete reevaluation of all rules by the regression tester.
1 file changed, 1 insertion(+)

diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMDVersion.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMDVersion.java
index 96565eca93..a9b134b4ff 100644
index 19532bd99e..78f61a81cf 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/PMDVersion.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMDVersion.java
@@ -2,6 +2,7 @@
Expand All @@ -22,4 +22,5 @@ index 96565eca93..a9b134b4ff 100644

import java.io.IOException;
--
2.39.2
2.45.2

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
From e1138cff3fff770e1b74688882e5bf09269b3a06 Mon Sep 17 00:00:00 2001
From 454a8e2bda07ecceaa2b0114d5fd01b16028fcc0 Mon Sep 17 00:00:00 2001
From: Andreas Dangel <andreas.dangel@pmd-code.org>
Date: Thu, 4 May 2023 20:00:52 +0200
Date: Thu, 5 Sep 2024 14:57:32 +0200
Subject: [PATCH] test case 4 - unrelated change

This commit changes a file in /docs. This definitely doesn't
Expand All @@ -11,7 +11,7 @@ execution.
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/index.md b/docs/index.md
index be951ab7f8..eb030aa757 100644
index 3bafc43f4d..ac7b593dfd 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -17,7 +17,7 @@ additional_js:
Expand All @@ -24,4 +24,5 @@ index be951ab7f8..eb030aa757 100644
## 💡 Overview

--
2.39.2
2.45.2

2 changes: 1 addition & 1 deletion test/test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_online_mode
File.stubs(:new).with('target/reports/diff/index.html', anything).returns.once

Dir.stubs(:chdir).with('target/reports').yields.once
Cmd.stubs(:execute_successfully).with('wget --timestamping https://sourceforge.net/projects/pmd/files/pmd-regression-tester/master-baseline.zip').once
Cmd.stubs(:execute_successfully).with('wget --no-verbose --timestamping https://sourceforge.net/projects/pmd/files/pmd-regression-tester/master-baseline.zip').once
Cmd.stubs(:execute_successfully).with('unzip -qo master-baseline.zip').once
ProjectsParser.any_instance.stubs(:parse)
.with('target/reports/master/project-list.xml')
Expand Down

0 comments on commit bb59c62

Please sign in to comment.